zones: calculate Machine.ID on init
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
+1
-23
@@ -5,7 +5,6 @@ import (
|
||||
"io/fs"
|
||||
"net/netip"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
@@ -15,7 +14,7 @@ type Machine struct {
|
||||
mu sync.Mutex
|
||||
|
||||
zone *Zone
|
||||
id int
|
||||
ID int
|
||||
Name string `toml:"name"`
|
||||
|
||||
PublicAddresses []netip.Addr `toml:"public,omitempty"`
|
||||
@@ -26,27 +25,6 @@ func (m *Machine) String() string {
|
||||
return m.Name
|
||||
}
|
||||
|
||||
// ID return the index within the [Zone] associated to this [Machine]
|
||||
func (m *Machine) ID() int {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
if m.id == 0 {
|
||||
zoneName := m.zone.Name
|
||||
|
||||
s := m.Name[len(zoneName)+1:]
|
||||
|
||||
id, err := strconv.ParseInt(s, 10, 8)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
m.id = int(id)
|
||||
}
|
||||
|
||||
return m.id
|
||||
}
|
||||
|
||||
// FullName returns the Name of the machine including domain name
|
||||
func (m *Machine) FullName() string {
|
||||
if domain := m.zone.zones.domain; domain != "" {
|
||||
|
||||
Reference in New Issue
Block a user