-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.go
98 lines (86 loc) · 3.09 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
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
package proxmox
import "net/http"
// ClusterService is the service that encapsulates node API methods
type ClusterService struct {
client *Client
}
// GetClusterStatusResponse contains the response for the /cluster/status endpoint
type GetClusterStatusResponse struct {
Data []GetClusterStatusData `json:"data"`
}
// GetClusterStatusData contains data of a cluster's status from GetClusterStatus
type GetClusterStatusData struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
IP *string `json:"ip"`
Level *string `json:"level"`
Local *int `json:"local"`
NodeID *int `json:"nodeid"`
Online *int `json:"online"`
Quorate *int `json:"quorate"`
Version *int `json:"version"`
}
// GetClusterStatus makes a GET request to the /cluster/status endpoint
// https://pve.proxmox.com/pve-docs/api-viewer/index.html#/cluster/status
func (s *ClusterService) GetClusterStatus() (*GetClusterStatusResponse, *http.Response, error) {
u := "cluster/status"
req, err := s.client.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, nil, err
}
d := new(GetClusterStatusResponse)
resp, err := s.client.Do(req, d)
if err != nil {
return nil, resp, err
}
return d, resp, nil
}
// GetClusterResourcesResponse contains the response for the /cluster/resources endpoint
type GetClusterResourcesResponse struct {
Data []GetClusterResourcesData `json:"data"`
}
// GetClusterResourcesData contains data of a cluster's resources from GetClusterResources
type GetClusterResourcesData struct {
ID string `json:"id"`
Node string `json:"node"`
Status string `json:"status"`
Type string `json:"type"`
CPU *float64 `json:"cpu"`
Disk *int `json:"disk"`
DiskRead *int `json:"diskread"`
DiskWrite *int `json:"diskwrite"`
MaxCPU *int `json:"maxcpu"`
MaxDisk *int `json:"maxdisk"`
MaxMem *int `json:"maxmem"`
Mem *int `json:"mem"`
Name *string `json:"name"`
NetIn *int `json:"netin"`
NetOut *int `json:"netout"`
Template *int `json:"template"`
Uptime *int `json:"uptime"`
VMID *IntOrString `json:"vmid"`
HAState *string `json:"hastate"`
CgroupMode *int `json:"cgroup-mode"`
Level *string `json:"level"`
Content *string `json:"content"`
PluginType *string `json:"plugintype"`
Shared *int `json:"shared"`
Storage *string `json:"storage"`
SDN *string `json:"sdn"`
}
// GetClusterResources makes a GET request to the /cluster/resources endpoint
// https://pve.proxmox.com/pve-docs/api-viewer/index.html#/cluster/resources
func (s *ClusterService) GetClusterResources() (*GetClusterResourcesResponse, *http.Response, error) {
u := "cluster/resources"
req, err := s.client.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, nil, err
}
d := new(GetClusterResourcesResponse)
resp, err := s.client.Do(req, d)
if err != nil {
return nil, resp, err
}
return d, resp, nil
}