|
|
|
@ -11,6 +11,7 @@ func (m *Zones) scan() error {
|
|
|
|
|
m.scanMachines, |
|
|
|
|
m.scanZoneIDs, |
|
|
|
|
m.scanSort, |
|
|
|
|
m.scanGateways, |
|
|
|
|
} { |
|
|
|
|
if err := fn(); err != nil { |
|
|
|
|
return err |
|
|
|
@ -115,6 +116,16 @@ func (m *Zones) scanSort() error {
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Zones) scanGateways() error { |
|
|
|
|
var err error |
|
|
|
|
|
|
|
|
|
m.ForEachZone(func(z *Zone) bool { |
|
|
|
|
_, _, err = z.GetGateway() |
|
|
|
|
return err != nil |
|
|
|
|
}) |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (z *Zone) scan() error { |
|
|
|
|
// each directory is a machine
|
|
|
|
|
entries, err := fs.ReadDir(z.zones.dir, z.Name) |
|
|
|
@ -139,3 +150,41 @@ func (z *Zone) scan() error {
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetGateway returns the first gateway found, if none
|
|
|
|
|
// files will be created to enable the first [Machine] to
|
|
|
|
|
// be one
|
|
|
|
|
func (z *Zone) GetGateway() (*Machine, bool, error) { |
|
|
|
|
var first *Machine |
|
|
|
|
var gateway *Machine |
|
|
|
|
|
|
|
|
|
z.zones.ForEachMachine(func(p *Machine) bool { |
|
|
|
|
switch { |
|
|
|
|
case p.IsGateway(): |
|
|
|
|
// found
|
|
|
|
|
gateway = p |
|
|
|
|
case first == nil: |
|
|
|
|
// remember
|
|
|
|
|
first = p |
|
|
|
|
default: |
|
|
|
|
// keep looking
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return gateway != nil |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
switch { |
|
|
|
|
case gateway != nil: |
|
|
|
|
// found one
|
|
|
|
|
return gateway, false, nil |
|
|
|
|
case first != nil: |
|
|
|
|
// make one
|
|
|
|
|
if err := first.SetGateway(true); err != nil { |
|
|
|
|
return first, false, err |
|
|
|
|
} |
|
|
|
|
return first, true, nil |
|
|
|
|
default: |
|
|
|
|
// Zone without nodes?
|
|
|
|
|
panic("unreachable") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|