@@ -14,6 +14,7 @@ require (
|
|||||||
darvaza.org/sidecar v0.0.0-20230721122716-b9c54b8adbaf
|
darvaza.org/sidecar v0.0.0-20230721122716-b9c54b8adbaf
|
||||||
darvaza.org/slog v0.5.2
|
darvaza.org/slog v0.5.2
|
||||||
github.com/burntSushi/toml v0.3.1
|
github.com/burntSushi/toml v0.3.1
|
||||||
|
github.com/gofrs/uuid/v5 v5.0.0
|
||||||
github.com/hack-pad/hackpadfs v0.2.1
|
github.com/hack-pad/hackpadfs v0.2.1
|
||||||
github.com/mgechev/revive v1.3.3
|
github.com/mgechev/revive v1.3.3
|
||||||
github.com/spf13/cobra v1.7.0
|
github.com/spf13/cobra v1.7.0
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBD
|
|||||||
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
|
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
|
||||||
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
|
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/gofrs/uuid/v5 v5.0.0 h1:p544++a97kEL+svbcFbCQVM9KFu0Yo25UoISXGNNH9M=
|
||||||
|
github.com/gofrs/uuid/v5 v5.0.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
|
||||||
github.com/hack-pad/hackpadfs v0.2.1 h1:FelFhIhv26gyjujoA/yeFO+6YGlqzmc9la/6iKMIxMw=
|
github.com/hack-pad/hackpadfs v0.2.1 h1:FelFhIhv26gyjujoA/yeFO+6YGlqzmc9la/6iKMIxMw=
|
||||||
github.com/hack-pad/hackpadfs v0.2.1/go.mod h1:khQBuCEwGXWakkmq8ZiFUvUZz84ZkJ2KNwKvChs4OrU=
|
github.com/hack-pad/hackpadfs v0.2.1/go.mod h1:khQBuCEwGXWakkmq8ZiFUvUZz84ZkJ2KNwKvChs4OrU=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// Package ceph deals with ceph config
|
||||||
|
package ceph
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package ceph
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"net/netip"
|
||||||
|
|
||||||
|
"github.com/gofrs/uuid/v5"
|
||||||
|
|
||||||
|
"asciigoat.org/ini/basic"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config represents a ceph.conf file
|
||||||
|
type Config struct {
|
||||||
|
Global GlobalConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteTo writes a Wireguard [Config] onto the provided [io.Writer]
|
||||||
|
func (*Config) WriteTo(w io.Writer) (int64, error) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
|
||||||
|
return buf.WriteTo(w)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalConfig represents the [global] section of a ceph.conf file
|
||||||
|
type GlobalConfig struct {
|
||||||
|
FSID uuid.UUID
|
||||||
|
Monitors []string
|
||||||
|
MonitorsAddr []netip.Addr
|
||||||
|
}
|
||||||
|
|
||||||
|
type intermediateConfig struct {
|
||||||
|
Global intermediateGlobalConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p intermediateConfig) Export() (*Config, error) {
|
||||||
|
var out Config
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// [global]
|
||||||
|
out.Global, err = p.Global.Export()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type intermediateGlobalConfig struct {
|
||||||
|
FSID uuid.UUID
|
||||||
|
MonInitialMembers string
|
||||||
|
MonHost string
|
||||||
|
ClusterNetwork string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (intermediateGlobalConfig) Export() (GlobalConfig, error) {
|
||||||
|
var out GlobalConfig
|
||||||
|
var err error
|
||||||
|
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewConfigFromReader parses the ceph.conf file
|
||||||
|
func NewConfigFromReader(r io.Reader) (*Config, error) {
|
||||||
|
doc, err := basic.Decode(r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg, err := newConfigFromDocument(doc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package zones
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
|
||||||
|
"git.jpi.io/amery/jpictl/pkg/ceph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetCephConfig reads the ceph.conf file
|
||||||
|
func (m *Zones) GetCephConfig() (*ceph.Config, error) {
|
||||||
|
data, err := m.ReadFile("ceph.conf")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
r := bytes.NewReader(data)
|
||||||
|
return ceph.NewConfigFromReader(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteCephConfig writes the ceph.conf file
|
||||||
|
func (m *Zones) WriteCephConfig(cfg *ceph.Config) error {
|
||||||
|
f, err := m.CreateTruncFile("ceph.conf")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
_, err = cfg.WriteTo(f)
|
||||||
|
return err
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ package zones
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,6 +14,7 @@ func (m *Zones) scan(opts *ScanOptions) error {
|
|||||||
m.scanZoneIDs,
|
m.scanZoneIDs,
|
||||||
m.scanSort,
|
m.scanSort,
|
||||||
m.scanGateways,
|
m.scanGateways,
|
||||||
|
m.scanCephMonitors,
|
||||||
} {
|
} {
|
||||||
if err := fn(opts); err != nil {
|
if err := fn(opts); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -121,6 +124,19 @@ func (m *Zones) scanGateways(_ *ScanOptions) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Zones) scanCephMonitors(_ *ScanOptions) error {
|
||||||
|
cfg, err := m.GetCephConfig()
|
||||||
|
switch {
|
||||||
|
case os.IsNotExist(err):
|
||||||
|
err = nil
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Print(cfg)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (z *Zone) scan() error {
|
func (z *Zone) scan() error {
|
||||||
// each directory is a machine
|
// each directory is a machine
|
||||||
entries, err := fs.ReadDir(z.zones.dir, z.Name)
|
entries, err := fs.ReadDir(z.zones.dir, z.Name)
|
||||||
|
|||||||
Reference in New Issue
Block a user