zones: FilterMachines() creates a Machines subset

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-27 16:25:11 +00:00
parent 2224e70638
commit 1885c76198
+20
View File
@@ -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