-
Notifications
You must be signed in to change notification settings - Fork 50
/
cluster.go
40 lines (34 loc) · 1.07 KB
/
cluster.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
package proxmox
import (
"net/url"
"strconv"
"strings"
)
func (c *Client) Cluster() (*Cluster, error) {
cluster := &Cluster{
client: c,
}
return cluster, c.Get("/cluster/status", cluster)
}
func (cl *Cluster) NextID() (int, error) {
var ret string
if err := cl.client.Get("/cluster/nextid", &ret); err != nil {
return 0, err
}
return strconv.Atoi(ret)
}
// Resources retrieves a summary list of all resources in the cluster.
// It calls /cluster/resources api v2 endpoint with an optional "type" parameter
// to filter searched values.
// It returns a list of ClusterResources.
func (cl *Cluster) Resources(filters ...string) (rs ClusterResources, err error) {
u := url.URL{Path: "/cluster/resources"}
// filters are variadic because they're optional, munging everything passed into one big string to make
// a good request and the api will error out if there's an issue
if f := strings.Replace(strings.Join(filters, ""), " ", "", -1); f != "" {
params := url.Values{}
params.Add("type", f)
u.RawQuery = params.Encode()
}
return rs, cl.client.Get(u.String(), &rs)
}