Browse Source

zones: rename Machine.RingAddresses to Machine.Rings

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/1/head
Alejandro Mery 1 year ago
parent
commit
0f62ee2e53
  1. 2
      pkg/zones/env.go
  2. 5
      pkg/zones/machine.go
  3. 10
      pkg/zones/machine_rings.go
  4. 6
      pkg/zones/scan.go

2
pkg/zones/env.go

@ -86,7 +86,7 @@ func getRingZeroGatewayID(z *Zone) int {
firstNodeID = p.ID
}
if _, found := p.getRingInfo(0); found {
if _, ok := p.getRingInfo(0); ok {
gatewayID = p.ID
}

5
pkg/zones/machine.go

@ -6,19 +6,16 @@ import (
"net/netip"
"path/filepath"
"strings"
"sync"
)
// A Machine is a machine on a Zone
type Machine struct {
mu sync.Mutex
zone *Zone
ID int
Name string `toml:"name"`
PublicAddresses []netip.Addr `toml:"public,omitempty"`
RingAddresses []*RingInfo `toml:"rings,omitempty"`
Rings []*RingInfo `toml:"rings,omitempty"`
}
func (m *Machine) String() string {

10
pkg/zones/machine_rings.go

@ -123,9 +123,9 @@ func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error {
}
func (m *Machine) getRingInfo(ring int) (*RingInfo, bool) {
for _, ri := range m.RingAddresses {
for _, ri := range m.Rings {
if ri.Ring == ring {
return ri, true
return ri, ri.Enabled
}
}
@ -133,10 +133,10 @@ func (m *Machine) getRingInfo(ring int) (*RingInfo, bool) {
}
func (m *Machine) applyRingInfo(ring int, new *RingInfo) error {
cur, found := m.getRingInfo(ring)
if !found {
cur, _ := m.getRingInfo(ring)
if cur == nil {
// first, append
m.RingAddresses = append(m.RingAddresses, new)
m.Rings = append(m.Rings, new)
return nil
}

6
pkg/zones/scan.go

@ -102,9 +102,9 @@ func (m *Zones) scanSort() error {
})
m.ForEachMachine(func(p *Machine) bool {
sort.SliceStable(p.RingAddresses, func(i, j int) bool {
ri1 := p.RingAddresses[i]
ri2 := p.RingAddresses[j]
sort.SliceStable(p.Rings, func(i, j int) bool {
ri1 := p.Rings[i]
ri2 := p.Rings[j]
return ri1.Ring < ri2.Ring
})

Loading…
Cancel
Save