Fix Nodeadd with ipaddr count

This commit is contained in:
Christian Goll
2022-07-20 15:14:30 +02:00
parent 99e9316011
commit d252b974bf
5 changed files with 49 additions and 43 deletions

View File

@@ -1,6 +1,8 @@
package apinode
import (
"strings"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
"github.com/pkg/errors"
@@ -23,3 +25,37 @@ func DbSave(nodeDB *node.NodeYaml) (err error) {
}
return
}
/*
Add the netname to the options map, as its only known after the
command line options have been read out, but its needing for setting
the values. Returns the manipulated map and a bool which is true if
networks specific values were set, but no netname was given.
*/
func AddNetname(theMap map[string]*string) (map[string]*string, bool) {
netname := ""
netvalues := false
retMap := make(map[string]*string)
for key, val := range theMap {
if key == "NetDevs" && *val != "" {
netname = *val
}
}
for key, val := range theMap {
keys := strings.Split(key, ".")
myVal := *val
if len(keys) >= 2 && keys[0] == "NetDevs" {
if *val != "" {
netvalues = true
}
if netname != "" {
retMap[keys[0]+"."+netname+"."+strings.Join(keys[1:], ".")] = &myVal
}
} else {
retMap[key] = &myVal
}
}
return retMap, netvalues && netname == ""
}