diff --git a/go/inventory/v1/types.go b/go/inventory/v1/types.go index fb026a26..f3a5dcd1 100644 --- a/go/inventory/v1/types.go +++ b/go/inventory/v1/types.go @@ -17,6 +17,7 @@ type ClusterStorage []Storage var _ sort.Interface = (*Nodes)(nil) var _ sort.Interface = (*GPUs)(nil) var _ sort.Interface = (*CPUInfoS)(nil) +var _ sort.Interface = (*GPUInfoS)(nil) var _ sort.Interface = (*ClusterStorage)(nil) func (s Nodes) Len() int { @@ -57,6 +58,32 @@ func (s CPUInfoS) Less(i, j int) bool { return false } +func (s GPUInfoS) Len() int { + return len(s) +} + +func (s GPUInfoS) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +func (s GPUInfoS) Less(i, j int) bool { + a, b := s[i], s[j] + + if a.Vendor != b.Vendor { + return a.Vendor < b.Vendor + } + + if a.Name != b.Name { + return a.Name < b.Name + } + + if a.MemorySize != b.MemorySize { + return a.MemorySize < b.MemorySize + } + + return false +} + func (s GPUs) Len() int { return len(s) }