Optimized sorting methods across nodes and profiles

This commit is contained in:
Gregory Kurtzer
2021-04-25 15:43:35 -07:00
parent a321709901
commit 4bc523a052
15 changed files with 266 additions and 234 deletions

View File

@@ -3,7 +3,6 @@ package node
import (
"fmt"
"io/ioutil"
"regexp"
"sort"
"strings"
@@ -264,35 +263,3 @@ func (config *nodeYaml) FindByIpaddr(ipaddr string) (NodeInfo, error) {
return ret, errors.New("No nodes found with IP Addr: " + ipaddr)
}
func (nodes *nodeYaml) SearchByName(search string) ([]NodeInfo, error) {
var ret []NodeInfo
n, _ := nodes.FindAllNodes()
for _, node := range n {
b, _ := regexp.MatchString(search, node.Id.Get())
if b {
ret = append(ret, node)
}
}
return ret, nil
}
func (nodes *nodeYaml) SearchByNameList(searchList []string) ([]NodeInfo, error) {
var ret []NodeInfo
n, _ := nodes.FindAllNodes()
for _, search := range searchList {
for _, node := range n {
b, _ := regexp.MatchString(search, node.Id.Get())
if b {
ret = append(ret, node)
}
}
}
return ret, nil
}

View File

@@ -1,5 +1,32 @@
package node
import "regexp"
/**********
*
* Filters
*
*********/
func FilterByName(set []NodeInfo, searchList []string) []NodeInfo {
var ret []NodeInfo
if len(searchList) > 0 {
for _, search := range searchList {
for _, entry := range set {
b, _ := regexp.MatchString(search, entry.Id.Get())
if b {
ret = append(ret, entry)
}
}
}
} else {
ret = set
}
return ret
}
/**********
*
* Sets