Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4200db12cb | |||
| 5e57fe5f30 | |||
| 75dee617ef | |||
| cc7526ceb5 | |||
| d8657770d5 | |||
| 564a6c8af2 | |||
| c083a144ea | |||
| 226d529223 | |||
| 7489b15c52 | |||
| d4757bebc2 |
+31
-2
@@ -1,8 +1,11 @@
|
||||
package ceph
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/netip"
|
||||
"strings"
|
||||
|
||||
"github.com/gofrs/uuid/v5"
|
||||
|
||||
@@ -17,11 +20,37 @@ type Config struct {
|
||||
// GlobalConfig represents the [global] section of a ceph.conf file
|
||||
type GlobalConfig struct {
|
||||
FSID uuid.UUID `ini:"fsid"`
|
||||
Monitors []string `ini:"mon_host,comma"`
|
||||
MonitorsAddr []netip.Addr `ini:"mon_initial_members,comma"`
|
||||
Monitors []string `ini:"mon_initial_members,comma"`
|
||||
MonitorsAddr []netip.Addr `ini:"mon_host,comma"`
|
||||
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
|
||||
func NewConfigFromReader(r io.Reader) (*Config, error) {
|
||||
doc, err := basic.Decode(r)
|
||||
|
||||
@@ -31,6 +31,18 @@ func (m *Zones) GetCephConfig() (*ceph.Config, error) {
|
||||
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
|
||||
func (m *Zones) GenCephConfig() (*ceph.Config, error) {
|
||||
fsid, err := m.GetCephFSID()
|
||||
|
||||
+11
-6
@@ -53,7 +53,7 @@ func (err CephMissingMonitorError) Error() string {
|
||||
|
||||
func (err *CephMissingMonitorError) writeNames(w *strings.Builder) {
|
||||
if len(err.Names) > 0 {
|
||||
_, _ = w.WriteString(" mon_host:")
|
||||
_, _ = w.WriteString(" mon_initial_members:")
|
||||
for i, name := range err.Names {
|
||||
if i != 0 {
|
||||
_, _ = w.WriteRune(',')
|
||||
@@ -64,12 +64,14 @@ func (err *CephMissingMonitorError) writeNames(w *strings.Builder) {
|
||||
}
|
||||
|
||||
func (err *CephMissingMonitorError) writeAddrs(w *strings.Builder) {
|
||||
_, _ = w.WriteString(" mon_initial_members:")
|
||||
for i, addr := range err.Addrs {
|
||||
if i != 0 {
|
||||
_, _ = w.WriteRune(',')
|
||||
if len(err.Addrs) > 0 {
|
||||
_, _ = w.WriteString(" mon_host:")
|
||||
for i, addr := range err.Addrs {
|
||||
if i != 0 {
|
||||
_, _ = w.WriteRune(',')
|
||||
}
|
||||
_, _ = w.WriteString(addr.String())
|
||||
}
|
||||
_, _ = w.WriteString(addr.String())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +159,9 @@ func (m *Zones) scanCephMonitors(_ *ScanOptions) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// store FSID
|
||||
m.CephFSID = cfg.Global.FSID
|
||||
|
||||
// flag monitors based on config
|
||||
todo := newCephScanTODO(cfg)
|
||||
m.ForEachMachine(func(p *Machine) bool {
|
||||
|
||||
@@ -4,6 +4,7 @@ package zones
|
||||
func (m *Zones) SyncAll() error {
|
||||
for _, fn := range []func() error{
|
||||
m.SyncAllWireguard,
|
||||
m.SyncAllCeph,
|
||||
} {
|
||||
if err := fn(); err != nil {
|
||||
return err
|
||||
@@ -31,3 +32,13 @@ func (m *Zones) SyncAllWireguard() error {
|
||||
|
||||
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