/
compute_host_cluster.go
86 lines (72 loc) · 2.23 KB
/
compute_host_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
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
package client
import "context"
type HostClusterClient struct {
c *Client
}
func (c *ComputeClient) HostCluster() *HostClusterClient {
return &HostClusterClient{c.c}
}
type HostCluster struct {
ID string `terraform:"id"`
Name string `terraform:"name"`
Moref string `terraform:"moref"`
Hosts []HostClusterHostStub `terraform:"hosts"`
Metrics HostClusterMetrics `terraform:"metrics"`
VirtualMachinesNumber int `terraform:"virtual_machines_number"`
MachineManagerId string `terraform:"machine_manager_id"`
}
type HostClusterFilter struct {
Name string `filter:"name"`
MachineManagerId string `filter:"machineManagerId"`
DatacenterId string `filter:"datacenterId"`
DatastoreId string `filter:"datastoreId"`
}
type HostClusterHostStub struct {
ID string `terraform:"id"`
Type string `terraform:"type"`
}
type HostClusterMetrics struct {
TotalCpu int `terraform:"total_cpu"`
TotalMemory int `terraform:"total_memory"`
TotalStorage int `terraform:"total_storage"`
CpuUsed int `terraform:"cpu_used"`
MemoryUsed int `terraform:"memory_used"`
StorageUsed int `terraform:"storage_used"`
}
func (h *HostClusterClient) List(
ctx context.Context,
filter *HostClusterFilter) ([]*HostCluster, error) {
// TODO: filters
r := h.c.newRequest("GET", "/compute/v1/vcenters/host_clusters")
r.addFilter(filter)
resp, err := h.c.doRequest(ctx, r)
if err != nil {
return nil, err
}
defer closeResponseBody(resp)
if err := requireOK(resp); err != nil {
return nil, err
}
var out []*HostCluster
if err := decodeBody(resp, &out); err != nil {
return nil, err
}
return out, nil
}
func (h *HostClusterClient) Read(ctx context.Context, id string) (*HostCluster, error) {
r := h.c.newRequest("GET", "/compute/v1/vcenters/host_clusters/%s", id)
resp, err := h.c.doRequest(ctx, r)
if err != nil {
return nil, err
}
defer closeResponseBody(resp)
found, err := requireNotFoundOrOK(resp, 403)
if err != nil || !found {
return nil, err
}
var out HostCluster
if err := decodeBody(resp, &out); err != nil {
return nil, err
}
return &out, nil
}