From 8902f08c8748e0518f31f6f0da3522f2990e12a1 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Mon, 4 Jul 2022 19:59:03 +0200 Subject: [PATCH] added hangling of map[string]*struct --- internal/app/wwctl/node/set/root.go | 2 -- internal/pkg/node/datastructure.go | 2 +- internal/pkg/node/methods.go | 14 ++++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index e63048ef..50904cbd 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -36,7 +36,6 @@ var ( SetKernelOverride string SetNetName string SetNetDev string - SetIpaddr string SetNetmask string SetGateway string SetHwaddr string @@ -138,7 +137,6 @@ func init() { } baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure") baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Set the node's network device") - baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address") baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask") baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway") baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address") diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index f5745a6a..54f51e3b 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -69,7 +69,7 @@ type NetDevs struct { OnBoot string `yaml:"onboot,omitempty"` Device string `yaml:"device,omitempty"` Hwaddr string `yaml:"hwaddr,omitempty"` - Ipaddr string `yaml:"ipaddr,omitempty"` + Ipaddr string `yaml:"ipaddr,omitempty" comment:"IPv4 address" sopt:"I" lopt:"ipaddr"` IpCIDR string `yaml:"ipcidr,omitempty"` Ipaddr6 string `yaml:"ip6addr,omitempty"` Prefix string `yaml:"prefix,omitempty"` diff --git a/internal/pkg/node/methods.go b/internal/pkg/node/methods.go index d6d62262..3039ac28 100644 --- a/internal/pkg/node/methods.go +++ b/internal/pkg/node/methods.go @@ -424,14 +424,24 @@ func (baseCmd *CobraCommand) CreateFlags(theStruct interface{}) map[string]*stri fmt.Printf("%s: field.Kind() == %s\n", field.Name, field.Type.Kind()) if field.Type.Kind() == reflect.Ptr { a := structVal.Field(i).Elem().Interface() + fmt.Println(structVal.Field(i).Elem()) subStruct := baseCmd.CreateFlags(a) for key, val := range subStruct { optionsMap[field.Name+"."+key] = val } } else if field.Type.Kind() == reflect.Map { - // Just check for network map - fmt.Println(reflect.TypeOf(structVal.Field(i).Elem())) + // check the type of map + mapType := field.Type.Elem() + if mapType.Kind() == reflect.Ptr { + //a := reflect.ValueOf((mapType.Elem())) node.NetDevs + subMap := baseCmd.CreateFlags(reflect.New(mapType.Elem()).Elem().Interface()) + for key, val := range subMap { + optionsMap[field.Name+"."+key] = val + } + } else { + fmt.Println(mapType) + } } else if field.Tag.Get("comment") != "" { var newStr string