forked from huaweicloud/huaweicloud-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.go
157 lines (126 loc) · 4.2 KB
/
requests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package bandwidths
import (
"github.com/YoungPioneers/huaweicloud-sdk-go"
)
type UpdateOpts struct {
Bandwidth Bandwidth `json:"bandwidth" required:"true"`
ExtendParam *ExtendParam `json:"extendParam,omitempty"`
}
type Bandwidth struct {
Name string `json:"name,omitempty"`
Size int `json:"size,omitempty"`
}
type ExtendParam struct {
IsAutoPay string `json:"is_auto_pay,omitempty"`
}
func (opts UpdateOpts) ToBandWidthUpdateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "")
}
type CreateOptsBuilder interface {
ToBandWidthCreateMap() (map[string]interface{}, error)
}
type CreateOpts struct {
Name string `json:"name" required:"true"`
Size *int `json:"size" required:"true"`
EnterpriseProjectId string `json:"enterprise_project_id,omitempty"`
}
func (opts CreateOpts) ToBandWidthCreateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "bandwidth")
}
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToBandWidthCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(PostURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 201},
})
return
}
type BatchCreateOptsBuilder interface {
ToBandWidthBatchCreateMap() (map[string]interface{}, error)
}
type BatchCreateOpts struct {
Name string `json:"name" required:"true"`
Size *int `json:"size" required:"true"`
Count *int `json:"count" required:"true"`
}
func (opts BatchCreateOpts) ToBandWidthBatchCreateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "bandwidth")
}
type BandWidthInsertOptsBuilder interface {
ToBandWidthInsertMap() (map[string]interface{}, error)
}
type BandWidthRemoveOptsBuilder interface {
ToBandWidthBatchRemoveMap() (map[string]interface{}, error)
}
type BandWidthInsertOpts struct {
PublicipInfo []PublicIpInfoID `json:"publicip_info" required:"true"`
}
func (opts BandWidthInsertOpts) ToBandWidthInsertMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "bandwidth")
}
type BandWidthRemoveOpts struct {
ChargeMode string `json:"charge_mode" required:"true"`
Size *int `json:"size" required:"true"`
PublicipInfo []PublicIpInfoID `json:"publicip_info" required:"true"`
}
func (opts BandWidthRemoveOpts) ToBandWidthBatchRemoveMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "bandwidth")
}
type PublicIpInfoID struct {
PublicIPID string `json:"publicip_id" required:"true"`
}
func Insert(client *gophercloud.ServiceClient, bandwidthID string, opts BandWidthInsertOptsBuilder) (r CreateResult) {
b, err := opts.ToBandWidthInsertMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(InsertURL(client, bandwidthID), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 201},
})
return
}
func Remove(client *gophercloud.ServiceClient, bandwidthID string, opts BandWidthRemoveOptsBuilder) (r DeleteResult) {
b, err := opts.ToBandWidthBatchRemoveMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(RemoveURL(client, bandwidthID), b, nil, &gophercloud.RequestOpts{
OkCodes: []int{200, 204},
})
return
}
func BatchCreate(client *gophercloud.ServiceClient, opts BatchCreateOptsBuilder) (r BatchCreateResult) {
b, err := opts.ToBandWidthBatchCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(BatchPostURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 201},
})
return
}
func Delete(client *gophercloud.ServiceClient, bandwidthID string) (r DeleteResult) {
url := DeleteURL(client, bandwidthID)
_, r.Err = client.Delete(url, nil)
return
}
func Update(c *gophercloud.ServiceClient, bandwidthID string, opts UpdateOpts) (interface{}, error) {
var r UpdateResult
body, err := opts.ToBandWidthUpdateMap()
if err != nil {
return nil, err
}
_, r.Err = c.Put(UpdateURL(c, bandwidthID), body, &r.Body, &gophercloud.RequestOpts{OkCodes: []int{200}})
onDemandData, onDemandErr := r.Extract()
orderData, orderErr := r.ExtractOrderID()
if orderData.OrderID != "" {
return orderData, orderErr
}
return onDemandData, onDemandErr
}