Browse Source

cluster: add recursive RegionIterator to Zone

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/43/head
Alejandro Mery 8 months ago
parent
commit
0158dc3a3c
  1. 23
      pkg/cluster/regions.go

23
pkg/cluster/regions.go

@ -9,6 +9,7 @@ var (
_ MachineIterator = (*Region)(nil) _ MachineIterator = (*Region)(nil)
_ ZoneIterator = (*Region)(nil) _ ZoneIterator = (*Region)(nil)
_ RegionIterator = (*Zone)(nil)
_ RegionIterator = (*Cluster)(nil) _ RegionIterator = (*Cluster)(nil)
) )
@ -152,6 +153,28 @@ func (m *Cluster) appendRegionRegions(name string, subs ...string) {
}) })
} }
// ForEachRegion calls a function on all regions this zone belongs to.
func (z *Zone) ForEachRegion(fn func(*Region) bool) {
if fn == nil {
return
}
z.zones.ForEachRegion(func(r *Region) bool {
var match bool
r.ForEachZone(func(z2 *Zone) bool {
match = (z == z2)
return match
})
if match && fn(r) {
return true
}
return false
})
}
func (z *Zone) appendRegions(regions ...string) error { func (z *Zone) appendRegions(regions ...string) error {
for _, s := range regions { for _, s := range regions {
// TODO: validate // TODO: validate

Loading…
Cancel
Save