forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
requests.go
113 lines (92 loc) · 3.27 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
package stackresources
import (
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
)
// Find retrieves stack resources for the given stack name.
func Find(c *gophercloud.ServiceClient, stackName string) FindResult {
var res FindResult
// Send request to API
_, res.Err = c.Request("GET", findURL(c, stackName), gophercloud.RequestOpts{
JSONResponse: &res.Body,
})
return res
}
// ListOptsBuilder allows extensions to add additional parameters to the
// List request.
type ListOptsBuilder interface {
ToStackResourceListQuery() (string, error)
}
// ListOpts allows the filtering and sorting of paginated collections through
// the API. Marker and Limit are used for pagination.
type ListOpts struct {
// Include resources from nest stacks up to Depth levels of recursion.
Depth int `q:"nested_depth"`
}
// ToStackResourceListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToStackResourceListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
if err != nil {
return "", err
}
return q.String(), nil
}
// List makes a request against the API to list resources for the given stack.
func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager {
url := listURL(client, stackName, stackID)
if opts != nil {
query, err := opts.ToStackResourceListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
createPageFn := func(r pagination.PageResult) pagination.Page {
return ResourcePage{pagination.SinglePageBase(r)}
}
return pagination.NewPager(client, url, createPageFn)
}
// Get retreives data for the given stack resource.
func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) GetResult {
var res GetResult
// Send request to API
_, res.Err = c.Get(getURL(c, stackName, stackID, resourceName), &res.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return res
}
// Metadata retreives the metadata for the given stack resource.
func Metadata(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) MetadataResult {
var res MetadataResult
// Send request to API
_, res.Err = c.Get(metadataURL(c, stackName, stackID, resourceName), &res.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return res
}
// ListTypes makes a request against the API to list resource types.
func ListTypes(client *gophercloud.ServiceClient) pagination.Pager {
url := listTypesURL(client)
createPageFn := func(r pagination.PageResult) pagination.Page {
return ResourceTypePage{pagination.SinglePageBase(r)}
}
return pagination.NewPager(client, url, createPageFn)
}
// Schema retreives the schema for the given resource type.
func Schema(c *gophercloud.ServiceClient, resourceType string) SchemaResult {
var res SchemaResult
// Send request to API
_, res.Err = c.Get(schemaURL(c, resourceType), &res.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return res
}
// Template retreives the template representation for the given resource type.
func Template(c *gophercloud.ServiceClient, resourceType string) TemplateResult {
var res TemplateResult
// Send request to API
_, res.Err = c.Get(templateURL(c, resourceType), &res.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return res
}