Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-24 21:48:00 +00:00
parent 568fd71d89
commit a454938bd7
4 changed files with 151 additions and 17 deletions
+23
View File
@@ -3,10 +3,12 @@ package zones
import (
"net/netip"
"strings"
"sync"
)
// A Machine is a machine on a Zone
type Machine struct {
mu sync.Mutex
zone *Zone
ID int
Name string `toml:"name"`
@@ -39,6 +41,27 @@ func (m *Machine) IsGateway() bool {
return ok
}
// 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:
var err error
if ri, err = m.createRingInfo(0, false); err != nil {
return err
}
}
ri.Enabled = enabled
return m.syncRingConfig(0)
}
func (m *Machine) getPeerByName(name string) (*Machine, bool) {
return m.zone.zones.GetMachineByName(name)
}