zones: WIP

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-22 23:50:05 +00:00
parent 47d79f7576
commit b57a2dfd53
3 changed files with 44 additions and 1 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ func getRingZeroGatewayID(z *Zone) int {
firstNodeID = nodeID
}
if _, found := p.getRingInfo(0); found {
if p.Gateway() {
gatewayID = nodeID
}
+28
View File
@@ -47,6 +47,34 @@ func (m *Machine) ID() int {
return m.id
}
// Gateway tells if the Machine is a ring0 gateway
func (m *Machine) Gateway() bool {
m.mu.Lock()
defer m.mu.Unlock()
if ri, found := m.getRingInfo(0); found {
return ri.Enabled
}
return false
}
func (m *Machine) SetGateway(enable bool) error {
m.mu.Lock()
defer m.mu.Unlock()
ri, found := m.getRingInfo(0)
switch {
case !found && !enable:
return nil
case !found:
return m.createRingInfo(0, true)
default:
ri.Enabled = enable
return nil
}
}
// FullName returns the Name of the machine including domain name
func (m *Machine) FullName() string {
if domain := m.zone.zones.domain; domain != "" {
+15
View File
@@ -134,3 +134,18 @@ func (m *Machine) applyZoneNodeID(zoneID, nodeID int) error {
return nil
}
func (m *Machine) createRingInfo(ring int, enabled bool) error {
keys, err := wireguard.NewKeyPair()
if err != nil {
return err
}
ri := &RingInfo{
Ring: ring,
Enabled: enabled,
Keys: keys,
}
return m.applyRingInfo(ring, ri)
}