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
+46
View File
@@ -0,0 +1,46 @@
// Package zones contains information about the cluster
package zones
import (
"io/fs"
"os"
)
// Zone represents one zone in a cluster
type Zone struct {
zones *Zones
ID int
Name string
Machines []*Machine `toml:"machines"`
}
func (z *Zone) String() string {
return z.Name
}
// Zones represents all zones in a cluster
type Zones struct {
dir fs.FS
Zones []*Zone `toml:"zones"`
}
// NewFS builds a [Zones] tree using the given directory
func NewFS(dir fs.FS) (*Zones, error) {
z := &Zones{
dir: dir,
}
if err := z.scan(); err != nil {
return nil, err
}
return z, nil
}
// New builds a [Zones] tree using the given directory
func New(dir string) (*Zones, error) {
return NewFS(os.DirFS(dir))
}