diff --git a/internal/app/wwctl/node/set/main.go b/internal/app/wwctl/node/set/main.go index 877c9c57..83187b24 100644 --- a/internal/app/wwctl/node/set/main.go +++ b/internal/app/wwctl/node/set/main.go @@ -11,8 +11,8 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) (err error) { - OptionStrMap, haveNetname := apinode.AddNetname(OptionStrMap) - if !haveNetname { + OptionStrMap, netWithoutName := apinode.AddNetname(OptionStrMap) + if netWithoutName { return errors.New("a netname must be given for any network related configuration") } realMap := make(map[string]string) diff --git a/internal/pkg/node/methods.go b/internal/pkg/node/methods.go index cf805546..7627465f 100644 --- a/internal/pkg/node/methods.go +++ b/internal/pkg/node/methods.go @@ -307,9 +307,9 @@ func (ent *Entry) Defined() bool { Set the Entry trough an interface by trying to cast the interface */ func SetEntry(entryPtr interface{}, val interface{}) { + valKind := reflect.TypeOf(val) if reflect.TypeOf(entryPtr) == reflect.TypeOf((*Entry)(nil)) { entry := entryPtr.(*Entry) - valKind := reflect.TypeOf(val) if valKind.Kind() == reflect.String { entry.Set(val.(string)) } else if valKind.Kind() == reflect.Slice { @@ -319,6 +319,18 @@ func SetEntry(entryPtr interface{}, val interface{}) { panic("Got unknown slice type") } } + } else if reflect.TypeOf(entryPtr) == reflect.TypeOf((*[]string)(nil)) { + entry := entryPtr.(*[]string) + if valKind.Kind() == reflect.String { + // most likely we got a comma seperated string slice + *entry = strings.Split(val.(string), ",") + } else if valKind.Kind() == reflect.Slice { + if valKind.Elem().Kind() == reflect.String { + *entry = val.([]string) + } else { + panic("Got unknown slice type") + } + } } else { panic(fmt.Sprintf("Can't convert %s to *node.Entry to call Set\n", reflect.TypeOf(entryPtr))) } @@ -370,7 +382,7 @@ func DelEntry(entryMapInt interface{}, val interface{}) { } /* -Call SetEntry for given field (NodeInfo) +Call SetEntry for given field (NodeInfo). */ func (node *NodeInfo) SetField(fieldName string, val interface{}) { field := reflect.ValueOf(node).Elem().FieldByName(fieldName) @@ -378,6 +390,8 @@ func (node *NodeInfo) SetField(fieldName string, val interface{}) { if field.Addr().Type() == reflect.TypeOf((*Entry)(nil)) { //fmt.Println(reflect.TypeOf(field.Addr().Interface())) SetEntry(field.Addr().Interface(), val) + } else if field.Addr().Type() == reflect.TypeOf((*[]string)(nil)) { + SetEntry(field.Addr().Interface(), val) } /* else if field.Addr().Kind() == reflect.Map {