forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
requests.go
87 lines (74 loc) · 2.42 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
package volumetypes
import (
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
)
// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToVolumeTypeCreateMap() (map[string]interface{}, error)
}
// CreateOpts are options for creating a volume type.
type CreateOpts struct {
// OPTIONAL. See VolumeType.
ExtraSpecs map[string]interface{}
// OPTIONAL. See VolumeType.
Name string
}
// ToVolumeTypeCreateMap casts a CreateOpts struct to a map.
func (opts CreateOpts) ToVolumeTypeCreateMap() (map[string]interface{}, error) {
vt := make(map[string]interface{})
if opts.ExtraSpecs != nil {
vt["extra_specs"] = opts.ExtraSpecs
}
if opts.Name != "" {
vt["name"] = opts.Name
}
return map[string]interface{}{"volume_type": vt}, nil
}
// Create will create a new volume. To extract the created volume type object,
// call the Extract method on the CreateResult.
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
var res CreateResult
reqBody, err := opts.ToVolumeTypeCreateMap()
if err != nil {
res.Err = err
return res
}
_, res.Err = perigee.Request("POST", createURL(client), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
OkCodes: []int{200, 201},
ReqBody: &reqBody,
Results: &res.Body,
})
return res
}
// Delete will delete the volume type with the provided ID.
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
var res DeleteResult
_, res.Err = perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
OkCodes: []int{202},
})
return res
}
// Get will retrieve the volume type with the provided ID. To extract the volume
// type from the result, call the Extract method on the GetResult.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var res GetResult
_, err := perigee.Request("GET", getURL(client, id), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
OkCodes: []int{200},
Results: &res.Body,
})
res.Err = err
return res
}
// List returns all volume types.
func List(client *gophercloud.ServiceClient) pagination.Pager {
createPage := func(r pagination.PageResult) pagination.Page {
return ListResult{pagination.SinglePageBase(r)}
}
return pagination.NewPager(client, listURL(client), createPage)
}