Compare commits
3 Commits
v0.0.1
..
979324f151
| Author | SHA1 | Date | |
|---|---|---|---|
| 979324f151 | |||
| be9da490ff | |||
| 3599812072 |
@@ -1,7 +1,10 @@
|
|||||||
package zones
|
package zones
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -56,3 +59,25 @@ func (m *Machine) FullName() string {
|
|||||||
|
|
||||||
return m.Name
|
return m.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadFile reads a file from the machine's config directory
|
||||||
|
func (m *Machine) ReadFile(name string, args ...any) ([]byte, error) {
|
||||||
|
base := m.zone.zones.dir
|
||||||
|
fullName := m.getFilename(name, args...)
|
||||||
|
|
||||||
|
return fs.ReadFile(base, fullName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Machine) getFilename(name string, args ...any) string {
|
||||||
|
if len(args) > 0 {
|
||||||
|
name = fmt.Sprintf(name, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
s := []string{
|
||||||
|
m.zone.Name,
|
||||||
|
m.Name,
|
||||||
|
name,
|
||||||
|
}
|
||||||
|
|
||||||
|
return filepath.Join(s...)
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,6 +31,22 @@ type Zones struct {
|
|||||||
Zones []*Zone `toml:"zones"`
|
Zones []*Zone `toml:"zones"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ForEachMachine calls a function for each Machine in the cluster
|
||||||
|
func (m *Zones) ForEachMachine(fn func(*Machine)) {
|
||||||
|
for _, z := range m.Zones {
|
||||||
|
for _, p := range z.Machines {
|
||||||
|
fn(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ForEachZone calls a function for each Zone in the cluster
|
||||||
|
func (m *Zones) ForEachZone(fn func(*Zone)) {
|
||||||
|
for _, p := range m.Zones {
|
||||||
|
fn(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewFS builds a [Zones] tree using the given directory
|
// NewFS builds a [Zones] tree using the given directory
|
||||||
func NewFS(dir fs.FS, domain string) (*Zones, error) {
|
func NewFS(dir fs.FS, domain string) (*Zones, error) {
|
||||||
z := &Zones{
|
z := &Zones{
|
||||||
|
|||||||
Reference in New Issue
Block a user