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 ( import (
"io/fs" "io/fs"
"sort"
) )
func (m *Zones) scan() error { func (m *Zones) scan() error {
@ -9,6 +10,7 @@ func (m *Zones) scan() error {
m.scanDirectory, m.scanDirectory,
m.scanMachines, m.scanMachines,
m.scanZoneIDs, m.scanZoneIDs,
m.scanSort,
} { } {
if err := fn(); err != nil { if err := fn(); err != nil {
return err return err
@ -82,6 +84,37 @@ func (m *Zones) scanZoneIDs() error {
return nil 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 { func (z *Zone) scan() error {
// each directory is a machine // each directory is a machine
entries, err := fs.ReadDir(z.zones.dir, z.Name) entries, err := fs.ReadDir(z.zones.dir, z.Name)

Loading…
Cancel
Save