github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/snatrules/requests.go (about) 1 package snatrules 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 ) 6 7 // CreateOptsBuilder is an interface must satisfy to be used as Create 8 // options. 9 type CreateOptsBuilder interface { 10 ToSnatRuleCreateMap() (map[string]interface{}, error) 11 } 12 13 // CreateOpts contains all the values needed to create a new snat rule 14 // resource. 15 type CreateOpts struct { 16 NatGatewayID string `json:"nat_gateway_id" required:"true"` 17 NetworkID string `json:"network_id,omitempty"` 18 FloatingIPID string `json:"floating_ip_id" required:"true"` 19 Cidr string `json:"cidr,omitempty"` 20 SourceType int `json:"source_type,omitempty"` 21 } 22 23 // ToSnatRuleCreateMap allows CreateOpts to satisfy the CreateOptsBuilder 24 // interface 25 func (opts CreateOpts) ToSnatRuleCreateMap() (map[string]interface{}, error) { 26 return golangsdk.BuildRequestBody(opts, "snat_rule") 27 } 28 29 // Create is a method by which can create a new snat rule 30 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 31 b, err := opts.ToSnatRuleCreateMap() 32 if err != nil { 33 r.Err = err 34 return 35 } 36 _, r.Err = c.Post(rootURL(c), b, &r.Body, &golangsdk.RequestOpts{ 37 OkCodes: []int{201}, 38 }) 39 return 40 } 41 42 // Get is a method by which can get the detailed information of the specified 43 // snat rule. 44 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 45 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 46 return 47 } 48 49 // Delete is a method by which can be able to delete a snat rule 50 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 51 _, r.Err = c.Delete(resourceURL(c, id), nil) 52 return 53 }