You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

77 lines
1.6 KiB

// 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"`
Zones []*Zone `json:"zones,omitempty" yaml:"zones,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
}