github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v2/bandwidths/requests.go (about) 1 package bandwidths 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 6 ) 7 8 type CreateOptsBuilder interface { 9 ToBandwidthCreateMap() (map[string]interface{}, error) 10 } 11 12 type CreateOpts struct { 13 Name string `json:"name" required:"true"` 14 Size int `json:"size" required:"true"` 15 } 16 17 func (opts CreateOpts) ToBandwidthCreateMap() (map[string]interface{}, error) { 18 return golangsdk.BuildRequestBody(opts, "bandwidth") 19 } 20 21 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 22 b, err := opts.ToBandwidthCreateMap() 23 if err != nil { 24 r.Err = err 25 return 26 } 27 28 _, r.Err = client.Post(rootURL(client), b, &r.Body, &golangsdk.RequestOpts{ 29 OkCodes: []int{200, 201}, 30 }) 31 return 32 } 33 34 type UpdateOptsBuilder interface { 35 ToBandwidthUpdateMap() (map[string]interface{}, error) 36 } 37 38 type UpdateOpts struct { 39 Name string `json:"name,omitempty"` 40 Size int `json:"size,omitempty"` 41 } 42 43 func (opts UpdateOpts) ToBandwidthUpdateMap() (map[string]interface{}, error) { 44 return golangsdk.BuildRequestBody(opts, "bandwidth") 45 } 46 47 func Update(client *golangsdk.ServiceClient, bandwidthID string, opts UpdateOptsBuilder) (r CreateResult) { 48 b, err := opts.ToBandwidthUpdateMap() 49 if err != nil { 50 r.Err = err 51 return 52 } 53 54 _, r.Err = client.Put(resourceURL(client, bandwidthID), b, &r.Body, &golangsdk.RequestOpts{ 55 OkCodes: []int{200}, 56 }) 57 return 58 } 59 60 func Get(client *golangsdk.ServiceClient, bandwidthID string) (r GetResult) { 61 _, r.Err = client.Get(resourceURL(client, bandwidthID), &r.Body, nil) 62 return 63 } 64 65 func List(client *golangsdk.ServiceClient) pagination.Pager { 66 return pagination.NewPager(client, rootURL(client), func(r pagination.PageResult) pagination.Page { 67 return BandwidthPage{pagination.SinglePageBase(r)} 68 }) 69 } 70 71 func Delete(client *golangsdk.ServiceClient, bandwidthID string) (r DeleteResult) { 72 _, r.Err = client.Delete(resourceURL(client, bandwidthID), nil) 73 return 74 } 75 76 type InsertOptsBuilder interface { 77 ToBandwidthInsertMap() (map[string]interface{}, error) 78 } 79 80 type InsertOpts struct { 81 PublicIpInfo []PublicIpInfoInsertOpts `json:"publicip_info" required:"true"` 82 } 83 84 type PublicIpInfoInsertOpts struct { 85 PublicIpID string `json:"publicip_id" required:"true"` 86 PublicIpType string `json:"publicip_type,omitempty"` 87 } 88 89 func (opts InsertOpts) ToBandwidthInsertMap() (map[string]interface{}, error) { 90 return golangsdk.BuildRequestBody(opts, "bandwidth") 91 } 92 93 func Insert(client *golangsdk.ServiceClient, bandwidthID string, opts InsertOptsBuilder) (r CreateResult) { 94 b, err := opts.ToBandwidthInsertMap() 95 if err != nil { 96 r.Err = err 97 return 98 } 99 100 _, r.Err = client.Post(insertURL(client, bandwidthID), b, &r.Body, &golangsdk.RequestOpts{ 101 OkCodes: []int{200, 201}, 102 }) 103 return 104 } 105 106 type RemoveOptsBuilder interface { 107 ToBandwidthRemoveMap() (map[string]interface{}, error) 108 } 109 110 type RemoveOpts struct { 111 ChargeMode string `json:"charge_mode" required:"true"` 112 Size int `json:"size" required:"true"` 113 PublicIpInfo []PublicIpInfoID `json:"publicip_info" required:"true"` 114 } 115 116 type PublicIpInfoID struct { 117 PublicIpID string `json:"publicip_id" required:"true"` 118 } 119 120 func (opts RemoveOpts) ToBandwidthRemoveMap() (map[string]interface{}, error) { 121 return golangsdk.BuildRequestBody(opts, "bandwidth") 122 } 123 124 func Remove(client *golangsdk.ServiceClient, bandwidthID string, opts RemoveOptsBuilder) (r DeleteResult) { 125 b, err := opts.ToBandwidthRemoveMap() 126 if err != nil { 127 r.Err = err 128 return 129 } 130 131 _, r.Err = client.Post(removeURL(client, bandwidthID), b, nil, &golangsdk.RequestOpts{ 132 OkCodes: []int{200, 204}, 133 }) 134 return 135 }