Merge pull request #816 from JasonYangShadow/hotfix/patch_node_list_test

add sort support for returned entry slice
This commit is contained in:
Christian Goll
2023-05-12 08:15:51 +02:00
committed by GitHub
2 changed files with 10 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The network device "OnBoot" parameter correctly configures the ONBOOT ifcfg
parameter. (#644)
- Add support for listing profile/node via comma-separated values. #739
- Sort the node list returned entries by name.
### Changed

View File

@@ -4,12 +4,19 @@ import (
"fmt"
"reflect"
"regexp"
"sort"
"strings"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
)
type sortByName []NodeInfo
func (a sortByName) Len() int { return len(a) }
func (a sortByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a sortByName) Less(i, j int) bool { return a[i].Id.Print() < a[j].Id.Print() }
func GetUnsetVerbs() []string {
return []string{"UNSET", "DELETE", "UNDEF", "undef", "--", "nil", "0.0.0.0"}
}
@@ -43,6 +50,7 @@ func FilterByName(set []NodeInfo, searchList []string) []NodeInfo {
ret = set
}
sort.Sort(sortByName(ret))
return ret
}
@@ -58,7 +66,6 @@ func FilterMapByName(inputMap map[string]*NodeConf, searchList []string) (retMap
retMap[name] = nConf
}
}
}
}
return retMap
@@ -156,7 +163,6 @@ func (ent *Entry) SetDefault(val string) {
return
}
ent.def = []string{val}
}
/*
@@ -167,7 +173,6 @@ func (ent *Entry) SetDefaultSlice(val []string) {
return
}
ent.def = val
}
/*
@@ -328,7 +333,7 @@ per profile. Else -- is returned.
func (ent *Entry) Source() string {
if len(ent.value) != 0 && len(ent.altvalue) != 0 {
return "SUPERSEDED"
//return fmt.Sprintf("[%s]", ent.from)
// return fmt.Sprintf("[%s]", ent.from)
} else if ent.from == "" {
return "--"
}