Browse Source

env: set ceph monitors variables

they indicate the ceph monitors on the specified zone

* MON{zoneID}_NAME
* MON{zoneID}_ID
* MON{zoneID}_IP

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/9/head
Alejandro Mery 1 year ago
parent
commit
fe081a4297
  1. 50
      pkg/zones/env.go

50
pkg/zones/env.go

@ -59,6 +59,15 @@ 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) {
@ -111,3 +120,44 @@ 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()
}

Loading…
Cancel
Save