zones: calculate Machine.ID on init

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-24 17:55:43 +00:00
parent 61374d4cc5
commit aca0a5e834
5 changed files with 25 additions and 31 deletions
+18
View File
@@ -3,6 +3,7 @@ package zones
import (
"context"
"net/netip"
"strconv"
"time"
)
@@ -26,6 +27,10 @@ func (m *Machine) updatePublicAddresses() error {
}
func (m *Machine) init() error {
if err := m.setID(); err != nil {
return err
}
for i := 0; i < RingsCount; i++ {
if err := m.tryReadWireguardKeys(i); err != nil {
return err
@@ -34,6 +39,19 @@ func (m *Machine) init() error {
return nil
}
func (m *Machine) setID() error {
zoneName := m.zone.Name
suffix := m.Name[len(zoneName)+1:]
id, err := strconv.ParseInt(suffix, 10, 8)
if err != nil {
return err
}
m.ID = int(id)
return nil
}
func (m *Machine) scan() error {
for i := 0; i < RingsCount; i++ {
if err := m.tryApplyWireguardConfig(i); err != nil {