You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
1.9 KiB
104 lines
1.9 KiB
1 year ago
|
package cluster
|
||
1 year ago
|
|
||
|
import (
|
||
|
"os"
|
||
|
|
||
1 year ago
|
"darvaza.org/slog"
|
||
1 year ago
|
"git.jpi.io/amery/jpictl/pkg/ceph"
|
||
|
)
|
||
|
|
||
|
type cephScanTODO struct {
|
||
|
names map[string]bool
|
||
|
addrs map[string]bool
|
||
|
}
|
||
|
|
||
|
func (todo *cephScanTODO) checkMachine(p *Machine) bool {
|
||
|
// on ceph all addresses are ring1
|
||
|
ring1, _ := RingOneAddress(p.Zone(), p.ID)
|
||
|
addr := ring1.String()
|
||
|
|
||
|
if _, found := todo.names[p.Name]; found {
|
||
|
// found on the TODO by name
|
||
|
todo.names[p.Name] = true
|
||
|
todo.addrs[addr] = true
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
if _, found := todo.addrs[addr]; found {
|
||
|
// found on the TODO by address
|
||
|
todo.names[p.Name] = true
|
||
|
todo.addrs[addr] = true
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
return false
|
||
|
}
|
||
|
|
||
1 year ago
|
func (todo *cephScanTODO) LogMissing(log slog.Logger) {
|
||
1 year ago
|
for name, found := range todo.names {
|
||
|
if !found {
|
||
1 year ago
|
log.Warn().
|
||
|
WithField("subsystem", "ceph").
|
||
|
WithField("monitor", name).
|
||
|
Print("unknown monitor")
|
||
1 year ago
|
}
|
||
|
}
|
||
|
|
||
|
for addr, found := range todo.addrs {
|
||
|
if !found {
|
||
1 year ago
|
log.Warn().
|
||
|
WithField("subsystem", "ceph").
|
||
|
WithField("monitor", addr).
|
||
|
Print("unknown monitor")
|
||
1 year ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func newCephScanTODO(cfg *ceph.Config) *cephScanTODO {
|
||
|
todo := &cephScanTODO{
|
||
|
names: make(map[string]bool),
|
||
|
addrs: make(map[string]bool),
|
||
|
}
|
||
|
|
||
|
for _, name := range cfg.Global.Monitors {
|
||
|
todo.names[name] = false
|
||
|
}
|
||
|
|
||
|
for _, addr := range cfg.Global.MonitorsAddr {
|
||
|
todo.addrs[addr.String()] = false
|
||
|
}
|
||
|
|
||
|
return todo
|
||
|
}
|
||
|
|
||
|
func (m *Zones) scanCephMonitors(_ *ScanOptions) error {
|
||
|
cfg, err := m.GetCephConfig()
|
||
|
switch {
|
||
|
case os.IsNotExist(err):
|
||
|
err = nil
|
||
|
case err != nil:
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
if cfg != nil {
|
||
1 year ago
|
// store FSID
|
||
|
m.CephFSID = cfg.Global.FSID
|
||
|
|
||
1 year ago
|
// flag monitors based on config
|
||
|
todo := newCephScanTODO(cfg)
|
||
|
m.ForEachMachine(func(p *Machine) bool {
|
||
|
p.CephMonitor = todo.checkMachine(p)
|
||
|
return false
|
||
|
})
|
||
1 year ago
|
|
||
|
todo.LogMissing(m.log)
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
// make sure every zone has one
|
||
|
m.ForEachZone(func(z *Zone) bool {
|
||
|
_ = z.GetCephMonitors()
|
||
|
return false
|
||
|
})
|
||
1 year ago
|
return nil
|
||
|
}
|