Compare commits
7 Commits
v0.5.0
..
f1c40aa03c
| Author | SHA1 | Date | |
|---|---|---|---|
| f1c40aa03c | |||
| 7344de0406 | |||
| 1984db9a8f | |||
| ddab51386d | |||
| 6ad6b4a855 | |||
| 77de40a8c0 | |||
| 7c111c66ec |
+2
-31
@@ -1,11 +1,8 @@
|
|||||||
package ceph
|
package ceph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gofrs/uuid/v5"
|
"github.com/gofrs/uuid/v5"
|
||||||
|
|
||||||
@@ -20,37 +17,11 @@ type Config struct {
|
|||||||
// GlobalConfig represents the [global] section of a ceph.conf file
|
// GlobalConfig represents the [global] section of a ceph.conf file
|
||||||
type GlobalConfig struct {
|
type GlobalConfig struct {
|
||||||
FSID uuid.UUID `ini:"fsid"`
|
FSID uuid.UUID `ini:"fsid"`
|
||||||
Monitors []string `ini:"mon_initial_members,comma"`
|
Monitors []string `ini:"mon_host,comma"`
|
||||||
MonitorsAddr []netip.Addr `ini:"mon_host,comma"`
|
MonitorsAddr []netip.Addr `ini:"mon_initial_members,comma"`
|
||||||
ClusterNetwork netip.Prefix `ini:"cluster_network"`
|
ClusterNetwork netip.Prefix `ini:"cluster_network"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteTo writes a Wireguard [Config] onto the provided [io.Writer]
|
|
||||||
func (cfg *Config) WriteTo(w io.Writer) (int64, error) {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
|
|
||||||
writeGlobalToBuffer(&buf, &cfg.Global)
|
|
||||||
return buf.WriteTo(w)
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeGlobalToBuffer(w *bytes.Buffer, c *GlobalConfig) {
|
|
||||||
_, _ = w.WriteString("[global]\n")
|
|
||||||
_, _ = fmt.Fprintf(w, "%s = %s\n", "fsid", c.FSID.String())
|
|
||||||
_, _ = fmt.Fprintf(w, "%s = %s\n", "mon_initial_members", strings.Join(c.Monitors, ", "))
|
|
||||||
_, _ = fmt.Fprintf(w, "%s = %s\n", "mon_host", joinAddrs(c.MonitorsAddr, ", "))
|
|
||||||
_, _ = fmt.Fprintf(w, "%s = %s\n", "cluster_network", c.ClusterNetwork.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func joinAddrs(addrs []netip.Addr, sep string) string {
|
|
||||||
s := make([]string, len(addrs))
|
|
||||||
|
|
||||||
for i, addr := range addrs {
|
|
||||||
s[i] = addr.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Join(s, sep)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewConfigFromReader parses the ceph.conf file
|
// NewConfigFromReader parses the ceph.conf file
|
||||||
func NewConfigFromReader(r io.Reader) (*Config, error) {
|
func NewConfigFromReader(r io.Reader) (*Config, error) {
|
||||||
doc, err := basic.Decode(r)
|
doc, err := basic.Decode(r)
|
||||||
|
|||||||
@@ -43,8 +43,6 @@ func loadGlobalConfField(cfg *GlobalConfig, field basic.Field) error {
|
|||||||
// revive:enable:cyclomatic
|
// revive:enable:cyclomatic
|
||||||
// revive:enable:cognitive-complexity
|
// revive:enable:cognitive-complexity
|
||||||
|
|
||||||
// TODO: refactor when asciigoat's ini parser learns to do reflection
|
|
||||||
|
|
||||||
switch field.Key {
|
switch field.Key {
|
||||||
case "fsid":
|
case "fsid":
|
||||||
if !core.IsZero(cfg.FSID) {
|
if !core.IsZero(cfg.FSID) {
|
||||||
|
|||||||
@@ -31,18 +31,6 @@ func (m *Zones) GetCephConfig() (*ceph.Config, error) {
|
|||||||
return ceph.NewConfigFromReader(r)
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenCephConfig prepares a ceph.Config using the cluster information
|
// GenCephConfig prepares a ceph.Config using the cluster information
|
||||||
func (m *Zones) GenCephConfig() (*ceph.Config, error) {
|
func (m *Zones) GenCephConfig() (*ceph.Config, error) {
|
||||||
fsid, err := m.GetCephFSID()
|
fsid, err := m.GetCephFSID()
|
||||||
|
|||||||
+14
-21
@@ -53,7 +53,7 @@ func (err CephMissingMonitorError) Error() string {
|
|||||||
|
|
||||||
func (err *CephMissingMonitorError) writeNames(w *strings.Builder) {
|
func (err *CephMissingMonitorError) writeNames(w *strings.Builder) {
|
||||||
if len(err.Names) > 0 {
|
if len(err.Names) > 0 {
|
||||||
_, _ = w.WriteString(" mon_initial_members:")
|
_, _ = w.WriteString(" mon_host:")
|
||||||
for i, name := range err.Names {
|
for i, name := range err.Names {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
_, _ = w.WriteRune(',')
|
_, _ = w.WriteRune(',')
|
||||||
@@ -64,14 +64,12 @@ func (err *CephMissingMonitorError) writeNames(w *strings.Builder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (err *CephMissingMonitorError) writeAddrs(w *strings.Builder) {
|
func (err *CephMissingMonitorError) writeAddrs(w *strings.Builder) {
|
||||||
if len(err.Addrs) > 0 {
|
_, _ = w.WriteString(" mon_initial_members:")
|
||||||
_, _ = w.WriteString(" mon_host:")
|
for i, addr := range err.Addrs {
|
||||||
for i, addr := range err.Addrs {
|
if i != 0 {
|
||||||
if i != 0 {
|
_, _ = w.WriteRune(',')
|
||||||
_, _ = w.WriteRune(',')
|
|
||||||
}
|
|
||||||
_, _ = w.WriteString(addr.String())
|
|
||||||
}
|
}
|
||||||
|
_, _ = w.WriteString(addr.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,19 +157,14 @@ func (m *Zones) scanCephMonitors(_ *ScanOptions) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg != nil {
|
// flag monitors based on config
|
||||||
// store FSID
|
todo := newCephScanTODO(cfg)
|
||||||
m.CephFSID = cfg.Global.FSID
|
m.ForEachMachine(func(p *Machine) bool {
|
||||||
|
p.CephMonitor = todo.checkMachine(p)
|
||||||
// flag monitors based on config
|
return false
|
||||||
todo := newCephScanTODO(cfg)
|
})
|
||||||
m.ForEachMachine(func(p *Machine) bool {
|
if err := todo.Missing(); err != nil {
|
||||||
p.CephMonitor = todo.checkMachine(p)
|
return core.Wrap(err, "ceph")
|
||||||
return false
|
|
||||||
})
|
|
||||||
if err := todo.Missing(); err != nil {
|
|
||||||
return core.Wrap(err, "ceph")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure every zone has one
|
// make sure every zone has one
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ package zones
|
|||||||
func (m *Zones) SyncAll() error {
|
func (m *Zones) SyncAll() error {
|
||||||
for _, fn := range []func() error{
|
for _, fn := range []func() error{
|
||||||
m.SyncAllWireguard,
|
m.SyncAllWireguard,
|
||||||
m.SyncAllCeph,
|
|
||||||
} {
|
} {
|
||||||
if err := fn(); err != nil {
|
if err := fn(); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -32,13 +31,3 @@ func (m *Zones) SyncAllWireguard() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SyncAllCeph updates the ceph.conf file
|
|
||||||
func (m *Zones) SyncAllCeph() error {
|
|
||||||
cfg, err := m.GenCephConfig()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return m.WriteCephConfig(cfg)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user