Skip to content

Commit a1d53c0

Browse files
authored
Merge pull request #8 from Starttoaster/ceph-status
Add ceph status endpoint
2 parents 4af77fc + 88f8033 commit a1d53c0

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
lines changed

cluster.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,31 @@ func (s *ClusterService) GetClusterResources() (*GetClusterResourcesResponse, *h
9696

9797
return d, resp, nil
9898
}
99+
100+
// GetClusterCephStatusResponse contains the response for the /cluster/ceph/status endpoint
101+
type GetClusterCephStatusResponse struct {
102+
Data GetClusterCephStatusData `json:"data"`
103+
}
104+
105+
// GetClusterCephStatusData contains data of a ceph cluster's status from GetClusterCephStatus
106+
type GetClusterCephStatusData struct {
107+
Health CephHealthStatus `json:"health"`
108+
}
109+
110+
// GetClusterCephStatus makes a GET request to the /cluster/resources endpoint
111+
// https://pve.proxmox.com/pve-docs/api-viewer/index.html#/cluster/resources
112+
func (s *ClusterService) GetClusterCephStatus() (*GetClusterCephStatusResponse, *http.Response, error) {
113+
u := "cluster/ceph/status"
114+
req, err := s.client.NewRequest(http.MethodGet, u, nil)
115+
if err != nil {
116+
return nil, nil, err
117+
}
118+
119+
d := new(GetClusterCephStatusResponse)
120+
resp, err := s.client.Do(req, d)
121+
if err != nil {
122+
return nil, resp, err
123+
}
124+
125+
return d, resp, nil
126+
}

cluster_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,33 @@ func testIntOrString(is IntOrString) *IntOrString {
2424
return &is
2525
}
2626

27+
func TestGetClusterCephStatus(t *testing.T) {
28+
mux, server, client := setup(t)
29+
defer teardown(server)
30+
31+
mux.HandleFunc("/api2/json/cluster/ceph/status", func(w http.ResponseWriter, r *http.Request) {
32+
w.Header().Set("Content-Type", "application/json")
33+
w.WriteHeader(http.StatusOK)
34+
_, err := fmt.Fprint(w, fixture("clusters/get_cluster_ceph_status.json"))
35+
if err != nil {
36+
return
37+
}
38+
})
39+
40+
want := GetClusterCephStatusResponse{
41+
Data: GetClusterCephStatusData{
42+
Health: CephHealthStatus{
43+
Status: "HEALTH_OK",
44+
},
45+
},
46+
}
47+
48+
r, resp, err := client.Cluster.GetClusterCephStatus()
49+
require.NoError(t, err)
50+
require.NotNil(t, resp)
51+
require.Equal(t, want, *r)
52+
}
53+
2754
func TestGetClusterResources(t *testing.T) {
2855
mux, server, client := setup(t)
2956
defer teardown(server)
@@ -101,3 +128,64 @@ func TestGetClusterResources(t *testing.T) {
101128
require.NotNil(t, resp)
102129
require.Equal(t, want, *r)
103130
}
131+
132+
func TestGetClusterStatus(t *testing.T) {
133+
mux, server, client := setup(t)
134+
defer teardown(server)
135+
136+
mux.HandleFunc("/api2/json/cluster/status", func(w http.ResponseWriter, r *http.Request) {
137+
w.Header().Set("Content-Type", "application/json")
138+
w.WriteHeader(http.StatusOK)
139+
_, err := fmt.Fprint(w, fixture("clusters/get_cluster_status.json"))
140+
if err != nil {
141+
return
142+
}
143+
})
144+
145+
want := GetClusterStatusResponse{
146+
Data: []GetClusterStatusData{
147+
{
148+
Type: "cluster",
149+
ID: "cluster",
150+
Version: testInt(5),
151+
Quorate: testInt(1),
152+
Name: "prd",
153+
},
154+
{
155+
NodeID: testInt(2),
156+
Type: "node",
157+
IP: testStr("10.0.1.2"),
158+
Name: "cmp2",
159+
Level: testStr(""),
160+
Online: testInt(1),
161+
ID: "node/cmp2",
162+
Local: testInt(0),
163+
},
164+
{
165+
NodeID: testInt(4),
166+
Type: "node",
167+
IP: testStr("10.0.1.3"),
168+
Name: "cmp3",
169+
Level: testStr(""),
170+
Online: testInt(1),
171+
ID: "node/cmp3",
172+
Local: testInt(0),
173+
},
174+
{
175+
NodeID: testInt(1),
176+
Type: "node",
177+
IP: testStr("10.0.1.1"),
178+
Name: "cmp1",
179+
Level: testStr(""),
180+
Online: testInt(1),
181+
ID: "node/cmp1",
182+
Local: testInt(1),
183+
},
184+
},
185+
}
186+
187+
r, resp, err := client.Cluster.GetClusterStatus()
188+
require.NoError(t, err)
189+
require.NotNil(t, resp)
190+
require.Equal(t, want, *r)
191+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"data": {
3+
"health": {
4+
"status": "HEALTH_OK"
5+
}
6+
}
7+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"data": [
3+
{
4+
"type": "cluster",
5+
"id": "cluster",
6+
"version": 5,
7+
"quorate": 1,
8+
"nodes": 3,
9+
"name": "prd"
10+
},
11+
{
12+
"nodeid": 2,
13+
"type": "node",
14+
"ip": "10.0.1.2",
15+
"name": "cmp2",
16+
"level": "",
17+
"online": 1,
18+
"id": "node/cmp2",
19+
"local": 0
20+
},
21+
{
22+
"nodeid": 4,
23+
"type": "node",
24+
"ip": "10.0.1.3",
25+
"name": "cmp3",
26+
"level": "",
27+
"online": 1,
28+
"id": "node/cmp3",
29+
"local": 0
30+
},
31+
{
32+
"name": "cmp1",
33+
"ip": "10.0.1.1",
34+
"level": "",
35+
"id": "node/cmp1",
36+
"online": 1,
37+
"local": 1,
38+
"nodeid": 1,
39+
"type": "node"
40+
}
41+
]
42+
}

types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ type Swap struct {
5959
Used int `json:"used"`
6060
}
6161

62+
// CephHealthStatus status of ceph health
63+
type CephHealthStatus struct {
64+
Status string `json:"status"`
65+
}
66+
6267
// IntOrString is an alias for some returns from the Proxmox API where we've identified that some versions return a string, and others return an integer
6368
// For example, LXC VMIDs were a string return in PVE 8.1.x, and are an integer in 8.2.x
6469
// Since it can be either depending on the version of Proxmox queried, we're going to return the looser type. String in this case.

0 commit comments

Comments
 (0)