Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 29b53e7172 | |||
| b1077de728 | |||
| 6f34e042d8 | |||
| fe2d843c1e | |||
| 5272ba8455 | |||
| 0da72f364e | |||
| 20e3ec7a13 | |||
| 61a7c8ca99 | |||
| e65c96ee33 |
@@ -5,7 +5,7 @@ go 1.19
|
|||||||
replace asciigoat.org/ini => ../../../asciigoat.org/ini
|
replace asciigoat.org/ini => ../../../asciigoat.org/ini
|
||||||
|
|
||||||
require (
|
require (
|
||||||
asciigoat.org/ini v0.2.5
|
asciigoat.org/ini v0.2.4
|
||||||
darvaza.org/core v0.9.8
|
darvaza.org/core v0.9.8
|
||||||
darvaza.org/resolver v0.5.4
|
darvaza.org/resolver v0.5.4
|
||||||
darvaza.org/sidecar v0.0.2
|
darvaza.org/sidecar v0.0.2
|
||||||
|
|||||||
+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)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package zones
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"net/netip"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"darvaza.org/core"
|
"darvaza.org/core"
|
||||||
@@ -31,48 +30,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
|
|
||||||
func (m *Zones) GenCephConfig() (*ceph.Config, error) {
|
|
||||||
fsid, err := m.GetCephFSID()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg := &ceph.Config{
|
|
||||||
Global: ceph.GlobalConfig{
|
|
||||||
FSID: fsid,
|
|
||||||
ClusterNetwork: netip.PrefixFrom(
|
|
||||||
netip.AddrFrom4([4]byte{10, 0, 0, 0}),
|
|
||||||
8,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
m.ForEachZone(func(z *Zone) bool {
|
|
||||||
for _, p := range z.GetCephMonitors() {
|
|
||||||
addr, _ := RingOneAddress(z.ID, p.ID)
|
|
||||||
|
|
||||||
cfg.Global.Monitors = append(cfg.Global.Monitors, p.Name)
|
|
||||||
cfg.Global.MonitorsAddr = append(cfg.Global.MonitorsAddr, addr)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
|
|
||||||
return cfg, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCephMonitors returns the set of Ceph monitors on
|
// GetCephMonitors returns the set of Ceph monitors on
|
||||||
// the zone
|
// the zone
|
||||||
func (z *Zone) GetCephMonitors() Machines {
|
func (z *Zone) GetCephMonitors() Machines {
|
||||||
|
|||||||
+6
-11
@@ -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,9 +157,6 @@ func (m *Zones) scanCephMonitors(_ *ScanOptions) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// store FSID
|
|
||||||
m.CephFSID = cfg.Global.FSID
|
|
||||||
|
|
||||||
// flag monitors based on config
|
// flag monitors based on config
|
||||||
todo := newCephScanTODO(cfg)
|
todo := newCephScanTODO(cfg)
|
||||||
m.ForEachMachine(func(p *Machine) bool {
|
m.ForEachMachine(func(p *Machine) bool {
|
||||||
|
|||||||
@@ -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