From 3d638e9a85ed1aad52ccd114fa27d7a5b5c27828 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Fri, 25 Aug 2023 17:10:52 +0000 Subject: [PATCH] zones: add Zone.SetGateway() to set one by ID Signed-off-by: Alejandro Mery --- pkg/zones/zones.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pkg/zones/zones.go b/pkg/zones/zones.go index 15d55ea..f6924c7 100644 --- a/pkg/zones/zones.go +++ b/pkg/zones/zones.go @@ -50,6 +50,31 @@ func (z *Zone) ForEachMachine(fn func(*Machine) bool) { } } +// SetGateway configures a machine to be the zone's ring0 gateway +func (z *Zone) SetGateway(gatewayID int, enabled bool) error { + var err error + var found bool + + z.ForEachMachine(func(p *Machine) bool { + if p.ID == gatewayID { + found = true + err = p.SetGateway(enabled) + + return true + } + return false + }) + + switch { + case err != nil: + return err + case !found: + return fs.ErrNotExist + default: + return nil + } +} + // Zones represents all zones in a cluster type Zones struct { dir fs.FS