Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4402555f04 | |||
| 6e7f24f491 | |||
| 54b302c6d5 | |||
| f62a47003d | |||
| c702d649e0 |
Vendored
+3
@@ -1,9 +1,12 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"asciigoat",
|
||||
"ceph",
|
||||
"cyclomatic",
|
||||
"darvaza",
|
||||
"gofrs",
|
||||
"jpictl",
|
||||
"Wrapf",
|
||||
"zerolog"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func newCephScanTODO(cfg *ceph.Config) *cephScanTODO {
|
||||
return todo
|
||||
}
|
||||
|
||||
func (m *Cluster) scanCephMonitors(_ *ScanOptions) error {
|
||||
func (m *Cluster) scanCephMonitors(opts *ScanOptions) error {
|
||||
cfg, err := m.GetCephConfig()
|
||||
switch {
|
||||
case os.IsNotExist(err):
|
||||
@@ -94,6 +94,10 @@ func (m *Cluster) scanCephMonitors(_ *ScanOptions) error {
|
||||
todo.LogMissing(m.log)
|
||||
}
|
||||
|
||||
return m.initCephMonitors(opts)
|
||||
}
|
||||
|
||||
func (m *Cluster) initCephMonitors(_ *ScanOptions) error {
|
||||
// make sure every zone has one
|
||||
m.ForEachZone(func(z *Zone) bool {
|
||||
_ = z.GetCephMonitors()
|
||||
|
||||
@@ -27,7 +27,8 @@ type Cluster struct {
|
||||
Domain string `json:"domain,omitempty" yaml:"domain,omitempty"`
|
||||
|
||||
CephFSID uuid.UUID `json:"ceph_fsid,omitempty" yaml:"ceph_fsid,omitempty"`
|
||||
Zones []*Zone `json:"zones,omitempty" yaml:"zones,omitempty"`
|
||||
Regions []Region `json:",omitempty" yaml:",omitempty"`
|
||||
Zones []*Zone `json:",omitempty" yaml:",omitempty"`
|
||||
}
|
||||
|
||||
// revive:enable:line-length-limit
|
||||
|
||||
@@ -14,6 +14,8 @@ func (m *Cluster) init(opts *ScanOptions) error {
|
||||
m.scanZoneIDs,
|
||||
m.scanSort,
|
||||
m.scanGateways,
|
||||
m.initCephMonitors,
|
||||
m.initRegions,
|
||||
} {
|
||||
if err := fn(opts); err != nil {
|
||||
return err
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package cluster
|
||||
|
||||
// Region represents a group of zones geographically related
|
||||
type Region struct {
|
||||
m *Cluster
|
||||
zones []*Zone
|
||||
|
||||
Name string
|
||||
Regions []string `json:",omitempty" yaml:",omitempty"`
|
||||
}
|
||||
|
||||
func (m *Cluster) initRegions(_ *ScanOptions) error {
|
||||
regions := make(map[string][]*Zone)
|
||||
|
||||
// first regions defined by zones
|
||||
m.ForEachZone(func(z *Zone) bool {
|
||||
for _, region := range z.Regions {
|
||||
regions[region] = append(regions[region], z)
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
// bind first level regions and their zones
|
||||
for name, zones := range regions {
|
||||
m.syncRegions(name, zones...)
|
||||
}
|
||||
|
||||
// and combine zones to produce larger regions
|
||||
for i := range m.Regions {
|
||||
r := &m.Regions[i]
|
||||
m.finishRegion(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Cluster) syncRegions(name string, zones ...*Zone) {
|
||||
for _, r := range m.Regions {
|
||||
if r.Name == name {
|
||||
// found
|
||||
r.m = m
|
||||
r.zones = zones
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// new
|
||||
m.Regions = append(m.Regions, Region{
|
||||
m: m,
|
||||
zones: zones,
|
||||
Name: name,
|
||||
})
|
||||
}
|
||||
|
||||
func (m *Cluster) finishRegion(r *Region) {
|
||||
if r.m != nil {
|
||||
// ready
|
||||
return
|
||||
}
|
||||
|
||||
r.m = m
|
||||
sub := []string{}
|
||||
for _, name := range r.Regions {
|
||||
r2, ok := m.getRegion(name)
|
||||
if !ok {
|
||||
m.warn(nil).WithField("region", name).Print("unknown region")
|
||||
continue
|
||||
}
|
||||
|
||||
sub = append(sub, r2.Name)
|
||||
r.zones = append(r.zones, r2.zones...)
|
||||
}
|
||||
r.Regions = sub
|
||||
}
|
||||
|
||||
func (m *Cluster) getRegion(name string) (*Region, bool) {
|
||||
for i := range m.Regions {
|
||||
r := &m.Regions[i]
|
||||
|
||||
if name == r.Name {
|
||||
m.finishRegion(r)
|
||||
return r, true
|
||||
}
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
||||
@@ -19,8 +19,9 @@ type Zone struct {
|
||||
zones *Cluster
|
||||
logger `json:"-" yaml:"-"`
|
||||
|
||||
ID int
|
||||
Name string
|
||||
ID int
|
||||
Name string
|
||||
Regions []string `json:",omitempty" yaml:",omitempty"`
|
||||
|
||||
Machines
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user