This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
requests.go
167 lines (136 loc) · 5.58 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
158
159
160
161
162
163
164
165
166
167
package publicips
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
type PublicIPRequest struct {
// Specifies the type of the elastic IP address. The value can the
// 5_telcom, 5_union, 5_bgp, or 5_sbgp. China Northeast: 5_telcom and 5_union China
// South: 5_sbgp China East: 5_sbgp China North: 5_bgp and 5_sbgp The value must be a
// type supported by the system. The value can be 5_telcom, 5_union, or 5_bgp.
Type string `json:"type" required:"true"`
// Specifies the elastic IP address to be obtained. The value must
// be a valid IP address in the available IP address segment.
IpAddress string `json:"ip_address,omitempty"`
//Value range: 4, 6, respectively, to create ipv4 and ipv6, when not created ipv4 by default
IPVersion int `json:"ip_version,omitempty"`
}
type BandWidth struct {
// Specifies the bandwidth name. The value is a string of 1 to 64
// characters that can contain letters, digits, underscores (_), and hyphens (-). This
// parameter is mandatory when share_type is set to PER and is optional when share_type
// is set to WHOLE with an ID specified.
Name string `json:"name,omitempty"`
// Specifies the bandwidth size. The value ranges from 1 Mbit/s to
// 300 Mbit/s. This parameter is mandatory when share_type is set to PER and is optional
// when share_type is set to WHOLE with an ID specified.
Size int `json:"size,omitempty"`
// Specifies the ID of the bandwidth. You can specify an earlier
// shared bandwidth when applying for an elastic IP address for the bandwidth whose type
// is set to WHOLE. The bandwidth whose type is set to WHOLE exclusively uses its own
// ID. The value can be the ID of the bandwidth whose type is set to WHOLE.
ID string `json:"id,omitempty"`
// Specifies whether the bandwidth is shared or exclusive. The
// value can be PER or WHOLE.
ShareType string `json:"share_type" required:"true"`
// Specifies the charging mode (by traffic or by bandwidth). The
// value can be bandwidth or traffic. If the value is an empty character string or no
// value is specified, default value bandwidth is used.
ChargeMode string `json:"charge_mode,omitempty"`
}
type CreateOpts struct {
// Specifies the elastic IP address objects.
Publicip PublicIPRequest `json:"publicip" required:"true"`
// Specifies the bandwidth objects.
Bandwidth BandWidth `json:"bandwidth" required:"true"`
// Enterprise project ID. The maximum length is 36 bytes, with the U-ID format of the hyphen "-", or the string "0".
//When creating an elastic public IP address, bind the enterprise project ID to the elastic public network IP.
EnterpriseProjectId string `json:"enterprise_project_id,omitempty"`
}
type CreateOptsBuilder interface {
ToCreatePublicIPMap() (map[string]interface{}, error)
}
func (opts CreateOpts) ToCreatePublicIPMap() (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
return b, nil
}
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToCreatePublicIPMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(CreateURL(client), b, &r.Body, &gophercloud.RequestOpts{OkCodes: []int{200}})
return
}
func Delete(client *gophercloud.ServiceClient, publicipId string) (r DeleteResult) {
url := DeleteURL(client, publicipId)
_, r.Err = client.Delete(url, nil)
return
}
func Get(client *gophercloud.ServiceClient, publicipId string) (r GetResult) {
url := GetURL(client, publicipId)
_, r.Err = client.Get(url, &r.Body, &gophercloud.RequestOpts{})
return
}
type ListOpts struct {
// Specifies the resource ID of pagination query. If the parameter
// is left blank, only resources on the first page are queried.
Marker string `q:"marker"`
// Specifies the number of records returned on each page. The
// value ranges from 0 to intmax.
Limit int `q:"limit"`
//Value range: 4, 6, respectively, to create ipv4 and ipv6, when not created ipv4 by default
IPVersion int `q:"ip_version"`
// enterprise_project_id
// You can use this field to filter the elastic public IP under an enterprise project.
EnterpriseProjectId string `q:"enterprise_project_id"`
}
type ListOptsBuilder interface {
ToListPublicIPQuery() (string, error)
}
func (opts ListOpts) ToListPublicIPQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := ListURL(client)
if opts != nil {
query, err := opts.ToListPublicIPQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return PublicIPPage{pagination.LinkedPageBase{PageResult: r}}
})
}
type UpdateOpts struct {
// Specifies the port ID.
PortId string `json:"port_id,omitempty"`
//Value range: 4, 6, respectively, to create ipv4 and ipv6, when not created ipv4 by default
IPVersion int `json:"ip_version,omitempty"`
}
type UpdateOptsBuilder interface {
ToUpdatePublicIPMap() (map[string]interface{}, error)
}
func (opts UpdateOpts) ToUpdatePublicIPMap() (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(opts, "publicip")
if err != nil {
return nil, err
}
return b, nil
}
func Update(client *gophercloud.ServiceClient, publicipId string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToUpdatePublicIPMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Put(UpdateURL(client, publicipId), b, &r.Body, &gophercloud.RequestOpts{OkCodes: []int{200}})
return
}