@@ -0,0 +1,2 @@
|
||||
// Package ceph deals with ceph config
|
||||
package ceph
|
||||
@@ -0,0 +1,71 @@
|
||||
package ceph
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/netip"
|
||||
|
||||
"github.com/gofrs/uuid/v5"
|
||||
|
||||
"asciigoat.org/ini"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
func NewConfigFromReader(r io.Reader) (*Config, error) {
|
||||
var temp intermediateConfig
|
||||
|
||||
if err := ini.ReadInto(&temp, r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return temp.Export()
|
||||
}
|
||||
@@ -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 (
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
)
|
||||
|
||||
@@ -12,6 +14,7 @@ func (m *Zones) scan(opts *ScanOptions) error {
|
||||
m.scanZoneIDs,
|
||||
m.scanSort,
|
||||
m.scanGateways,
|
||||
m.scanCephMonitors,
|
||||
} {
|
||||
if err := fn(opts); err != nil {
|
||||
return err
|
||||
@@ -121,6 +124,19 @@ func (m *Zones) scanGateways(_ *ScanOptions) error {
|
||||
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 {
|
||||
// each directory is a machine
|
||||
entries, err := fs.ReadDir(z.zones.dir, z.Name)
|
||||
|
||||
Reference in New Issue
Block a user