Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7dc3b36777 | |||
| 9e8a19d00d | |||
| 1037ed4bae | |||
| 3014212bc9 | |||
| f1a0b1d644 |
@@ -2,7 +2,6 @@ package zones
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"sort"
|
|
||||||
|
|
||||||
"git.jpi.io/amery/jpictl/pkg/ceph"
|
"git.jpi.io/amery/jpictl/pkg/ceph"
|
||||||
)
|
)
|
||||||
@@ -29,47 +28,3 @@ func (m *Zones) WriteCephConfig(cfg *ceph.Config) error {
|
|||||||
_, err = cfg.WriteTo(f)
|
_, err = cfg.WriteTo(f)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCephMonitors returns the set of Ceph monitors on
|
|
||||||
// the zone
|
|
||||||
func (z *Zone) GetCephMonitors() Machines {
|
|
||||||
var mons Machines
|
|
||||||
var first, second *Machine
|
|
||||||
|
|
||||||
z.ForEachMachine(func(p *Machine) bool {
|
|
||||||
switch {
|
|
||||||
case p.CephMonitor:
|
|
||||||
// it is a monitor
|
|
||||||
mons = append(mons, p)
|
|
||||||
case len(mons) > 0:
|
|
||||||
// zone has a monitor
|
|
||||||
case first == nil && !p.IsGateway():
|
|
||||||
// first option for monitor
|
|
||||||
first = p
|
|
||||||
case second == nil:
|
|
||||||
// second option for monitor
|
|
||||||
second = p
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case len(mons) > 0:
|
|
||||||
// ready
|
|
||||||
case first != nil:
|
|
||||||
// make first option our monitor
|
|
||||||
first.CephMonitor = true
|
|
||||||
mons = append(mons, first)
|
|
||||||
case second != nil:
|
|
||||||
// make second option our monitor
|
|
||||||
second.CephMonitor = true
|
|
||||||
mons = append(mons, second)
|
|
||||||
default:
|
|
||||||
// zone without machines??
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Sort(mons)
|
|
||||||
return mons
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -167,10 +167,5 @@ func (m *Zones) scanCephMonitors(_ *ScanOptions) error {
|
|||||||
return core.Wrap(err, "ceph")
|
return core.Wrap(err, "ceph")
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure every zone has one
|
|
||||||
m.ForEachZone(func(z *Zone) bool {
|
|
||||||
_ = z.GetCephMonitors()
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,15 +59,6 @@ func (m *Env) writeEnvZone(w io.Writer, z *Zone) {
|
|||||||
// ZONE{zoneID}_GW
|
// ZONE{zoneID}_GW
|
||||||
gateways, _ := z.GatewayIDs()
|
gateways, _ := z.GatewayIDs()
|
||||||
m.writeEnvVarInts(w, gateways, "ZONE%v_%s", zoneID, "GW")
|
m.writeEnvVarInts(w, gateways, "ZONE%v_%s", zoneID, "GW")
|
||||||
|
|
||||||
// Ceph
|
|
||||||
monitors := z.GetCephMonitors()
|
|
||||||
// MON{zoneID}_NAME
|
|
||||||
m.writeEnvVar(w, genEnvZoneCephMonNames(monitors), "MON%v_%s", zoneID, "NAME")
|
|
||||||
// MON{zoneID}_IP
|
|
||||||
m.writeEnvVar(w, genEnvZoneCephMonIPs(monitors), "MON%v_%s", zoneID, "IP")
|
|
||||||
// MON{zoneID}_ID
|
|
||||||
m.writeEnvVar(w, genEnvZoneCephMonIDs(monitors), "MON%v_%s", zoneID, "ID")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Env) writeEnvVarInts(w io.Writer, value []int, name string, args ...any) {
|
func (m *Env) writeEnvVarInts(w io.Writer, value []int, name string, args ...any) {
|
||||||
@@ -120,44 +111,3 @@ func genEnvZoneNodes(z *Zone) string {
|
|||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func genEnvZoneCephMonNames(m Machines) string {
|
|
||||||
var buf strings.Builder
|
|
||||||
m.ForEachMachine(func(p *Machine) bool {
|
|
||||||
if buf.Len() > 0 {
|
|
||||||
_, _ = buf.WriteRune(' ')
|
|
||||||
}
|
|
||||||
_, _ = buf.WriteString(p.Name)
|
|
||||||
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func genEnvZoneCephMonIPs(m Machines) string {
|
|
||||||
var buf strings.Builder
|
|
||||||
m.ForEachMachine(func(p *Machine) bool {
|
|
||||||
addr, _ := RingOneAddress(p.Zone(), p.ID)
|
|
||||||
|
|
||||||
if buf.Len() > 0 {
|
|
||||||
_, _ = buf.WriteRune(' ')
|
|
||||||
}
|
|
||||||
_, _ = buf.WriteString(addr.String())
|
|
||||||
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func genEnvZoneCephMonIDs(m Machines) string {
|
|
||||||
var buf strings.Builder
|
|
||||||
m.ForEachMachine(func(p *Machine) bool {
|
|
||||||
if buf.Len() > 0 {
|
|
||||||
_, _ = buf.WriteRune(' ')
|
|
||||||
}
|
|
||||||
_, _ = fmt.Fprintf(&buf, "%v", p.ID)
|
|
||||||
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user