zones: FilterMachines() and Zone.GatewayIDs() #3

Merged
amery merged 3 commits from pr-amery-machines into main 2023-08-28 16:47:58 +02:00
Showing only changes of commit 1885c76198 - Show all commits
+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