Skip to content

Commit 82869ba

Browse files
committed
internal/services: Populate Ceph state struct
Signed-off-by: Mathias Gibbens <mathias.gibbens@futurfusion.io>
1 parent ed17046 commit 82869ba

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

incus-osd/internal/services/service_ceph.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
"path/filepath"
99
"strings"
1010

11+
"github.com/lxc/incus/v7/shared/subprocess"
12+
"go.yaml.in/yaml/v4"
13+
1114
"github.com/lxc/incus-os/incus-osd/api"
1215
"github.com/lxc/incus-os/incus-osd/internal/state"
1316
)
@@ -20,12 +23,35 @@ type Ceph struct {
2023
}
2124

2225
// Get returns the current service state.
23-
func (n *Ceph) Get(_ context.Context) (any, error) {
26+
func (n *Ceph) Get(ctx context.Context) (any, error) {
2427
// Initialize target list if missing.
2528
if n.state.Services.Ceph.Config.Clusters == nil {
2629
n.state.Services.Ceph.Config.Clusters = map[string]api.ServiceCephCluster{}
2730
}
2831

32+
// Get current Ceph cluster status. The JSON output is too verbose, while
33+
// the plain text output is almost valid yaml (missing quotation of values).
34+
output, err := subprocess.RunCommandContext(ctx, "ceph", "status")
35+
if err == nil {
36+
lines := strings.Split(output, "\n")
37+
38+
for i := range lines {
39+
parts := strings.SplitN(lines[i], ":", 2)
40+
41+
if len(parts) != 2 {
42+
continue
43+
}
44+
45+
if len(parts[1]) > 0 {
46+
parts[1] = ` "` + strings.TrimSpace(parts[1]) + `"`
47+
}
48+
49+
lines[i] = parts[0] + ":" + parts[1]
50+
}
51+
52+
_ = yaml.Load([]byte(strings.Join(lines, "\n")), &n.state.Services.Ceph.State)
53+
}
54+
2955
return n.state.Services.Ceph, nil
3056
}
3157

0 commit comments

Comments
 (0)