// Package cluster contains information about the cluster package cluster import ( "io/fs" "darvaza.org/resolver" "darvaza.org/slog" "github.com/gofrs/uuid/v5" ) var ( _ MachineIterator = (*Cluster)(nil) _ ZoneIterator = (*Cluster)(nil) ) // revive:disable:line-length-limit // Cluster represents all zones in a cluster type Cluster struct { dir fs.FS log slog.Logger resolver resolver.Resolver BaseDir string `json:"dir,omitempty" yaml:"dir,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` Domain string `json:"domain,omitempty" yaml:"domain,omitempty"` CephFSID uuid.UUID `json:"ceph_fsid,omitempty" yaml:"ceph_fsid,omitempty"` Regions []Region `json:",omitempty" yaml:",omitempty"` Zones []*Zone `json:",omitempty" yaml:",omitempty"` } // revive:enable:line-length-limit // ForEachMachine calls a function for each Machine in the cluster // until instructed to terminate the loop func (m *Cluster) ForEachMachine(fn func(*Machine) bool) { m.ForEachZone(func(z *Zone) bool { var term bool z.ForEachMachine(func(p *Machine) bool { term = fn(p) return term }) return term }) } // ForEachZone calls a function for each Zone in the cluster // until instructed to terminate the loop func (m *Cluster) ForEachZone(fn func(*Zone) bool) { for _, p := range m.Zones { if fn(p) { // terminate return } } } // GetMachineByName looks for a machine with the specified // name on any zone func (m *Cluster) GetMachineByName(name string) (*Machine, bool) { var out *Machine if name != "" { m.ForEachMachine(func(p *Machine) bool { if p.Name == name { out = p } return out != nil }) } return out, out != nil }