Browse Source

zones: introduce Machine.getRingInfo()

and refactor Machine.applyRingInfo()

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/1/head
Alejandro Mery 1 year ago
parent
commit
b084e103b9
  1. 14
      pkg/zones/machine_rings.go

14
pkg/zones/machine_rings.go

@ -60,17 +60,19 @@ func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error {
return nil
}
func (m *Machine) applyRingInfo(ring int, new *RingInfo) error {
var cur *RingInfo
func (m *Machine) getRingInfo(ring int) (*RingInfo, bool) {
for _, ri := range m.RingAddresses {
if ri.Ring == ring {
cur = ri
break
return ri, true
}
}
if cur == nil {
return nil, false
}
func (m *Machine) applyRingInfo(ring int, new *RingInfo) error {
cur, found := m.getRingInfo(ring)
if !found {
// first, append
m.RingAddresses = append(m.RingAddresses, new)
return nil

Loading…
Cancel
Save