github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/nat/v3/transitips/requests.go (about) 1 package transitips 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/openstack/common/tags" 6 ) 7 8 // CreateOpts is the structure used to create a new transit IP. 9 type CreateOpts struct { 10 // The ID of the subnet to which the transit IP belongs. 11 SubnetId string `json:"virsubnet_id" required:"true"` 12 // The IP address 13 IpAddress string `json:"ip_address,omitempty"` 14 // The ID of the enterprise project to which the transit IP belongs. 15 EnterpriseProjectId string `json:"enterprise_project_id,omitempty"` 16 // The key/value pairs to associate with the transit IP. 17 Tags []tags.ResourceTag `json:"tags,omitempty"` 18 } 19 20 var requestOpts = golangsdk.RequestOpts{ 21 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 22 } 23 24 // Create is a method used to create a new transit IP using given parameters. 25 func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*TransitIp, error) { 26 b, err := golangsdk.BuildRequestBody(opts, "transit_ip") 27 if err != nil { 28 return nil, err 29 } 30 31 var r createResp 32 _, err = c.Post(rootURL(c), b, &r, &golangsdk.RequestOpts{ 33 MoreHeaders: requestOpts.MoreHeaders, 34 }) 35 return &r.TransitIp, err 36 } 37 38 // Get is a method used to obtain the transit IP detail by its ID. 39 func Get(c *golangsdk.ServiceClient, transitIpId string) (*TransitIp, error) { 40 var r queryResp 41 _, err := c.Get(resourceURL(c, transitIpId), &r, &golangsdk.RequestOpts{ 42 MoreHeaders: requestOpts.MoreHeaders, 43 }) 44 return &r.TransitIp, err 45 } 46 47 // Delete is a method to remove the specified transit IP using its ID. 48 func Delete(c *golangsdk.ServiceClient, transitIpId string) error { 49 _, err := c.Delete(resourceURL(c, transitIpId), &golangsdk.RequestOpts{ 50 MoreHeaders: requestOpts.MoreHeaders, 51 }) 52 return err 53 }