github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v2/extensions/natgateways/requests.go (about) 1 package natgateways 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 6 ) 7 8 // CreateOptsBuilder is an interface must satisfy to be used as Create 9 // options. 10 type CreateOptsBuilder interface { 11 ToNatGatewayCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOpts contains all the values needed to create a new nat gateway 15 // resource. 16 type CreateOpts struct { 17 Name string `json:"name" required:"true"` 18 Description string `json:"description,omitempty"` 19 Spec string `json:"spec" required:"true"` 20 RouterID string `json:"router_id" required:"true"` 21 InternalNetworkID string `json:"internal_network_id" required:"true"` 22 TenantID string `json:"tenant_id,omitempty"` 23 } 24 25 type ListOpts struct { 26 Limit int `q:"limit"` 27 ID string `q:"id"` 28 Name string `q:"name"` 29 TenantId string `q:"tenant_id"` 30 Description string `q:"description"` 31 Spec string `q:"spec"` 32 RouterID string `q:"router_id"` 33 InternalNetworkID string `q:"internal_network_id"` 34 Status string `q:"status"` 35 AdminStateUp *bool `q:"admin_state_up"` 36 CreatedAt string `q:"created_at"` 37 } 38 39 // ToNatGatewayCreateMap allows CreateOpts to satisfy the CreateOptsBuilder 40 // interface 41 func (opts CreateOpts) ToNatGatewayCreateMap() (map[string]interface{}, error) { 42 return golangsdk.BuildRequestBody(opts, "nat_gateway") 43 } 44 45 // Create is a method by which can create a new nat gateway 46 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 47 b, err := opts.ToNatGatewayCreateMap() 48 if err != nil { 49 r.Err = err 50 return 51 } 52 _, r.Err = c.Post(rootURL(c), b, &r.Body, &golangsdk.RequestOpts{ 53 OkCodes: []int{201}, 54 }) 55 return 56 } 57 58 // Get is a method by which can get the detailed information of the specified 59 // nat gateway. 60 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 61 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 62 return 63 } 64 65 // Delete is a method by which can be able to delete a nat gateway 66 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 67 _, r.Err = c.Delete(resourceURL(c, id), nil) 68 return 69 } 70 71 // UpdateOptsBuilder is the interface type must satisfy to be used as Update 72 // options. 73 type UpdateOptsBuilder interface { 74 ToNatGatewayUpdateMap() (map[string]interface{}, error) 75 } 76 77 // UpdateOpts is a struct which represents the request body of update method 78 type UpdateOpts struct { 79 Name string `json:"name,omitempty"` 80 Description string `json:"description,omitempty"` 81 Spec string `json:"spec,omitempty"` 82 } 83 84 func (opts UpdateOpts) ToNatGatewayUpdateMap() (map[string]interface{}, error) { 85 return golangsdk.BuildRequestBody(opts, "nat_gateway") 86 } 87 88 func (opts ListOpts) ToNatGatewayListQuery() (string, error) { 89 q, err := golangsdk.BuildQueryString(opts) 90 if err != nil { 91 return "", err 92 } 93 return q.String(), err 94 } 95 96 type ListOptsBuilder interface { 97 ToNatGatewayListQuery() (string, error) 98 } 99 100 // Update allows nat gateway resources to be updated. 101 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 102 b, err := opts.ToNatGatewayUpdateMap() 103 if err != nil { 104 r.Err = err 105 return 106 } 107 _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ 108 OkCodes: []int{200}, 109 }) 110 return 111 } 112 113 func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 114 url := rootURL(c) 115 if opts != nil { 116 query, err := opts.ToNatGatewayListQuery() 117 if err != nil { 118 return pagination.Pager{Err: err} 119 } 120 url += query 121 } 122 123 return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { 124 return NatGatewayPage{pagination.LinkedPageBase{PageResult: r}} 125 }) 126 }