Browse Source

zones: finish scan sorting the content

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/1/head v0.0.3
Alejandro Mery 1 year ago
parent
commit
fdb0f0324f
  1. 33
      pkg/zones/scan.go

33
pkg/zones/scan.go

@ -2,6 +2,7 @@ package zones
import (
"io/fs"
"sort"
)
func (m *Zones) scan() error {
@ -9,6 +10,7 @@ func (m *Zones) scan() error {
m.scanDirectory,
m.scanMachines,
m.scanZoneIDs,
m.scanSort,
} {
if err := fn(); err != nil {
return err
@ -82,6 +84,37 @@ func (m *Zones) scanZoneIDs() error {
return nil
}
func (m *Zones) scanSort() error {
sort.SliceStable(m.Zones, func(i, j int) bool {
id1 := m.Zones[i].ID
id2 := m.Zones[j].ID
return id1 < id2
})
m.ForEachZone(func(z *Zone) bool {
sort.SliceStable(z.Machines, func(i, j int) bool {
id1 := z.Machines[i].ID()
id2 := z.Machines[j].ID()
return id1 < id2
})
return false
})
m.ForEachMachine(func(p *Machine) bool {
sort.SliceStable(p.RingAddresses, func(i, j int) bool {
ri1 := p.RingAddresses[i]
ri2 := p.RingAddresses[j]
return ri1.Ring < ri2.Ring
})
return false
})
return nil
}
func (z *Zone) scan() error {
// each directory is a machine
entries, err := fs.ReadDir(z.zones.dir, z.Name)

Loading…
Cancel
Save