Browse Source

zones: introduce Zone.ForEachMachine()

and refactor Zones.ForEachMachine() using it

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/1/head
Alejandro Mery 1 year ago
parent
commit
223edf846b
  1. 30
      pkg/zones/zones.go

30
pkg/zones/zones.go

@ -22,6 +22,16 @@ func (z *Zone) String() string {
return z.Name
}
// ForEachMachine calls a function for each Machine in the zone
// until instructed to terminate the loop
func (z *Zone) ForEachMachine(fn func(*Machine) bool) {
for _, p := range z.Machines {
if fn(p) {
return
}
}
}
// Zones represents all zones in a cluster
type Zones struct {
dir fs.FS
@ -32,18 +42,22 @@ type Zones struct {
}
// ForEachMachine calls a function for each Machine in the cluster
// until instructed to terminate the loop
func (m *Zones) ForEachMachine(fn func(*Machine) bool) {
for _, z := range m.Zones {
for _, p := range z.Machines {
if fn(p) {
// terminate
return
}
}
}
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 *Zones) ForEachZone(fn func(*Zone) bool) {
for _, p := range m.Zones {
if fn(p) {

Loading…
Cancel
Save