zones: SetGateway [WIP]

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-23 14:32:36 +00:00
parent 87258c7a9e
commit 61d1ea85ee
2 changed files with 41 additions and 0 deletions
+16
View File
@@ -70,6 +70,22 @@ func (m *Machine) IsGateway() bool {
return false
}
// SetGateway enables/disables a Machine ring0 integration
func (m *Machine) SetGateway(enabled bool) error {
m.mu.Lock()
defer m.mu.Unlock()
ri, found := m.getRingInfo(0)
switch {
case !found && !enabled:
return nil
case !found:
return m.createRingInfo(0, true)
default:
ri.Enabled = enabled
return m.writeRingInfo(ri)
}
}
func (m *Machine) getPeerByName(name string) (*Machine, bool) {
return m.zone.zones.GetMachineByName(name)
}
+25
View File
@@ -33,6 +33,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