Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-24 17:03:31 +00:00
parent 568fd71d89
commit 114372b4c6
5 changed files with 170 additions and 16 deletions
+24
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,28 @@ 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)
}