Skip to content

Commit b19fe1a

Browse files
authored
WIP: feat: Implement api2/json/cluster/ceph/status endpoint (#186)
* Add ceph cluster type Signed-off-by: JustusBunsi <[email protected]> * Implement actual api endpoint Signed-off-by: JustusBunsi <[email protected]> * Add tests Signed-off-by: JustusBunsi <[email protected]> --------- Signed-off-by: JustusBunsi <[email protected]>
1 parent 481b57d commit b19fe1a

File tree

6 files changed

+14402
-0
lines changed

6 files changed

+14402
-0
lines changed

ceph.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package proxmox
2+
3+
import "context"
4+
5+
func (ce *Ceph) Status(ctx context.Context) (*ClusterCephStatus, error) {
6+
cephStatus := &ClusterCephStatus{}
7+
8+
if err := ce.client.Get(ctx, "/cluster/ceph/status", cephStatus); !IsNotAuthorized(err) {
9+
return cephStatus, err
10+
}
11+
12+
return cephStatus, nil
13+
}

ceph_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package proxmox
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
9+
"github.com/luthermonson/go-proxmox/tests/mocks"
10+
)
11+
12+
func TestClusterCeph_Status(t *testing.T) {
13+
mocks.ProxmoxVE8x(mockConfig)
14+
defer mocks.Off()
15+
client := mockClient()
16+
ctx := context.Background()
17+
ceph := Ceph{
18+
client: client,
19+
}
20+
21+
expectedOsdNearFullCheck := CephHealthCheck{
22+
Detail: []CephHealthCheckDetail{
23+
{
24+
Message: "osd.3 is near full",
25+
},
26+
{
27+
Message: "osd.8 is near full",
28+
},
29+
{
30+
Message: "osd.9 is near full",
31+
},
32+
},
33+
Muted: false,
34+
Severity: "HEALTH_WARN",
35+
Summary: CephHealthCheckSummary{
36+
Count: 3,
37+
Message: "3 nearfull osd(s)",
38+
},
39+
}
40+
41+
actual, err := ceph.Status(ctx)
42+
assert.Nil(t, err)
43+
assert.Equal(t, "HEALTH_WARN", actual.Health.Status)
44+
assert.Equal(t, []string{"proxmox-node01", "proxmox-node03", "proxmox-node02"}, actual.QuorumNames)
45+
assert.Equal(t, expectedOsdNearFullCheck, actual.Health.Checks["OSD_NEARFULL"])
46+
}

cluster.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,17 @@ func (cl *Cluster) Tasks(ctx context.Context) (Tasks, error) {
7979

8080
return tasks, nil
8181
}
82+
83+
func (cl *Cluster) Ceph(ctx context.Context) (*Ceph, error) {
84+
ceph := &Ceph{
85+
client: cl.client,
86+
}
87+
88+
// TODO?
89+
//// requires (/, Sys.Audit), do not error out if no access to still get the ceph
90+
//if err := ceph.Status(ctx); !IsNotAuthorized(err) {
91+
// return ceph, err
92+
//}
93+
94+
return ceph, nil
95+
}

0 commit comments

Comments
 (0)