zones: add initial m/ scanner

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-21 17:51:44 +00:00
parent a3f8e2fee3
commit 1ea1ab4ac4
3 changed files with 137 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
package zones
import (
"strconv"
"sync"
)
// A Machine is a machine on a Zone
type Machine struct {
mu sync.Mutex
zone *Zone
id int
Name string
}
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
}