You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
857 B
60 lines
857 B
package zones |
|
|
|
import ( |
|
"io/fs" |
|
) |
|
|
|
func (m *Zones) scan() error { |
|
// each directory is a zone |
|
entries, err := fs.ReadDir(m.dir, ".") |
|
if err != nil { |
|
return err |
|
} |
|
|
|
for _, e := range entries { |
|
if e.IsDir() { |
|
z := &Zone{ |
|
zones: m, |
|
Name: e.Name(), |
|
} |
|
|
|
if err := z.scan(); err != nil { |
|
return err |
|
} |
|
|
|
m.Zones = append(m.Zones, z) |
|
} |
|
} |
|
|
|
return m.scanMachines() |
|
} |
|
|
|
func (m *Zones) scanMachines() error { |
|
var err error |
|
m.ForEachMachine(func(p *Machine) bool { |
|
err = p.scan() |
|
return err != nil |
|
}) |
|
return err |
|
} |
|
|
|
func (z *Zone) scan() error { |
|
// each directory is a machine |
|
entries, err := fs.ReadDir(z.zones.dir, z.Name) |
|
if err != nil { |
|
return err |
|
} |
|
|
|
for _, e := range entries { |
|
if e.IsDir() { |
|
m := &Machine{ |
|
zone: z, |
|
Name: e.Name(), |
|
} |
|
|
|
z.Machines = append(z.Machines, m) |
|
} |
|
} |
|
|
|
return nil |
|
}
|
|
|