zones: introduce Zone.GetCephMonitors()
returning the local ceph monitors and setting one if there is none. non-gateway nodes are preferred when setting a monitor automatically Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -2,6 +2,7 @@ package zones
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"darvaza.org/core"
|
"darvaza.org/core"
|
||||||
"github.com/gofrs/uuid/v5"
|
"github.com/gofrs/uuid/v5"
|
||||||
@@ -28,3 +29,47 @@ func (m *Zones) GetCephConfig() (*ceph.Config, error) {
|
|||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(data)
|
||||||
return ceph.NewConfigFromReader(r)
|
return ceph.NewConfigFromReader(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user