Browse Source

zones: FilterMachines() creates a Machines subset

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/3/head
Alejandro Mery 10 months ago
parent
commit
1885c76198
  1. 20
      pkg/zones/zones.go

20
pkg/zones/zones.go

@ -66,6 +66,26 @@ func (m Machines) Swap(i, j int) {
m[i], m[j] = m[j], m[i]
}
// FilterMachines produces a subset of the machines offered by the given
// iterator fulfilling a condition
func FilterMachines(m MachineIterator, cond func(*Machine) bool) (Machines, int) {
var out []*Machine
if cond == nil {
// unconditional
cond = func(*Machine) bool { return true }
}
m.ForEachMachine(func(p *Machine) bool {
if cond(p) {
out = append(out, p)
}
return false
})
return out, len(out)
}
// Zone represents one zone in a cluster
type Zone struct {
zones *Zones

Loading…
Cancel
Save