-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.go
78 lines (67 loc) · 2.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
package flavor
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// ListOptsBuilder allows extensions to add additional parameters to the
// List request.
type ListOptsBuilder interface {
ToFlavorListMap() (string, error)
}
//ListOpts allows the filtering and sorting of paginated collections through the API.
type ListOpts struct {
// Specifies the AZ name.
AvailabilityZone string `q:"availability_zone"`
}
// ToFlavorListMap formats a ListOpts into a query string.
func (opts ListOpts) ToFlavorListMap() (string, error) {
s, err := gophercloud.BuildQueryString(opts)
if err != nil {
return "", err
}
return s.String(), err
}
// List returns a Pager which allows you to iterate over a collection of
// flavors.
func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := getListUrl(c)
if opts != nil {
queryString, err := opts.ToFlavorListMap()
if err != nil {
return pagination.Pager{Err: err}
}
url += queryString
}
return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
return FlavorsPage{pagination.LinkedPageBase{PageResult: r}}
})
}
// ResizeOpts represents options for modifying the specifications of an ecs.
type ResizeOpts struct {
// Specifies the specifications ID of the ECS after the modification.
FlavorRef string `json:"flavorRef" required:"true"`
// Specifies the new DeH ID, which is applicable only to the ECSs on DeHs.
DedicatedHostId string `json:"dedicated_host_id,omitempty"`
}
// ToResizeOptsMap builds a request body from ResizeOpts.
func (opts ResizeOpts) ToResizeOptsMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "resize")
}
// Resize is an operation which modifying the specifications of an ecs.
func Resize(client *gophercloud.ServiceClient,serverId string,opts ResizeOpts) (jobId string, err error) {
var r ResizeResult
reqBody, err := opts.ToResizeOptsMap()
if err != nil {
return
}
_, err = client.Post(resizeURL(client,serverId), reqBody, &r.Body, &gophercloud.RequestOpts{OkCodes: []int{200}})
if err != nil {
return
}
job, err := r.ExtractJob()
if err != nil {
return
}
jobId = job.Id
return
}