-
Notifications
You must be signed in to change notification settings - Fork 510
/
requests.go
49 lines (44 loc) · 1.44 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
package services
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// ListOptsBuilder allows extensions to add additional parameters to the List
// request.
type ListOptsBuilder interface {
ToServiceListQuery() (string, error)
}
// ListOpts holds options for listing Services.
type ListOpts struct {
// The pool name for the back end.
ProjectID string `json:"project_id,omitempty"`
// The service host name.
Host string `json:"host"`
// The service binary name. Default is the base name of the executable.
Binary string `json:"binary"`
// The availability zone.
Zone string `json:"zone"`
// The current state of the service. A valid value is up or down.
State string `json:"state"`
// The service status, which is enabled or disabled.
Status string `json:"status"`
}
// ToServiceListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToServiceListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
// List makes a request against the API to list services.
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := listURL(client)
if opts != nil {
query, err := opts.ToServiceListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return ServicePage{pagination.SinglePageBase(r)}
})
}