From f5a9c0f933fd62f9b18378c92e1237cf02c1456b Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Tue, 28 Dec 2021 16:07:19 -0800 Subject: [PATCH] Fixed backwards compatibility with --netdev and cleanups --- internal/app/wwctl/node/set/main.go | 46 ++++++-------------------- internal/app/wwctl/node/set/root.go | 9 ++--- internal/app/wwctl/profile/set/main.go | 46 ++++++-------------------- internal/app/wwctl/profile/set/root.go | 5 +-- 4 files changed, 30 insertions(+), 76 deletions(-) diff --git a/internal/app/wwctl/node/set/main.go b/internal/app/wwctl/node/set/main.go index 75b07aaa..33a1bc97 100644 --- a/internal/app/wwctl/node/set/main.go +++ b/internal/app/wwctl/node/set/main.go @@ -165,17 +165,23 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } + if SetNetName != "" { + if _, ok := n.NetDevs[SetNetName]; !ok { + var nd node.NetDevEntry + n.NetDevs[SetNetName] = &nd + + if SetNetDev == "" { + n.NetDevs[SetNetName].Device.Set(SetNetName) + } + } + } + if SetNetDev != "" { if SetNetName == "" { wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") os.Exit(1) } - if _, ok := n.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - n.NetDevs[SetNetName] = &nd - } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting net Device to: %s\n", n.Id.Get(), SetNetName, SetNetDev) n.NetDevs[SetNetName].Device.Set(SetNetDev) } @@ -186,11 +192,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := n.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - n.NetDevs[SetNetName] = &nd - } - NewIpaddr := util.IncrementIPv4(SetIpaddr, count) wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Id.Get(), SetNetName, NewIpaddr) @@ -203,11 +204,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := n.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - n.NetDevs[SetNetName] = &nd - } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Id.Get(), SetNetName, SetNetmask) n.NetDevs[SetNetName].Netmask.Set(SetNetmask) } @@ -218,11 +214,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := n.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - n.NetDevs[SetNetName] = &nd - } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Id.Get(), SetNetName, SetGateway) n.NetDevs[SetNetName].Gateway.Set(SetGateway) } @@ -233,11 +224,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := n.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - n.NetDevs[SetNetName] = &nd - } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Id.Get(), SetNetName, SetHwaddr) n.NetDevs[SetNetName].Hwaddr.Set(SetHwaddr) } @@ -248,11 +234,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := n.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - n.NetDevs[SetNetName] = &nd - } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Type %s\n", n.Id.Get(), SetNetName, SetType) n.NetDevs[SetNetName].Type.Set(SetType) } @@ -263,11 +244,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := n.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - n.NetDevs[SetNetName] = &nd - } - if SetNetOnBoot == "yes" || SetNetOnBoot == "y" || SetNetOnBoot == "1" || SetNetOnBoot == "true" { wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting ONBOOT\n", n.Id.Get(), SetNetName) n.NetDevs[SetNetName].OnBoot.SetB(true) diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index fb6c3b5c..f8885462 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -13,8 +13,8 @@ import ( var ( baseCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "set [OPTIONS] PATTERN [PATTERN ...]", - Short: "Configure node properties", + Use: "set [OPTIONS] PATTERN [PATTERN ...]", + Short: "Configure node properties", Long: "This command sets configuration properties for nodes matching PATTERN.\n\n" + "Note: use the string 'UNSET' to remove a configuration", Args: cobra.MinimumNArgs(1), @@ -128,8 +128,9 @@ func init() { }); err != nil { log.Println(err) } - baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure") - baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Define the network device") + baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "", "Define the network name to configure") + baseCmd.PersistentFlags().StringVarP(&SetNetName, "netdev", "N", "", "Alias to --netname") + baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdevice", "D", "", "Define the 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") diff --git a/internal/app/wwctl/profile/set/main.go b/internal/app/wwctl/profile/set/main.go index 45f8ed61..cf88a9e1 100644 --- a/internal/app/wwctl/profile/set/main.go +++ b/internal/app/wwctl/profile/set/main.go @@ -135,17 +135,23 @@ func CobraRunE(cmd *cobra.Command, args []string) error { p.Discoverable.SetB(false) } + if SetNetName != "" { + if _, ok := p.NetDevs[SetNetName]; !ok { + var nd node.NetDevEntry + p.NetDevs[SetNetName] = &nd + + if SetNetDev == "" { + p.NetDevs[SetNetName].Device.Set(SetNetName) + } + } + } + if SetNetDev != "" { if SetNetName == "" { wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") os.Exit(1) } - if _, ok := p.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - p.NetDevs[SetNetName] = &nd - } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting net Device to: %s\n", p.Id.Get(), SetNetName, SetNetDev) p.NetDevs[SetNetName].Device.Set(SetNetDev) } @@ -156,11 +162,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := p.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - p.NetDevs[SetNetName] = &nd - } - wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting IP address to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) p.NetDevs[SetNetName].Ipaddr.Set(SetIpaddr) } @@ -171,11 +172,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := p.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - p.NetDevs[SetNetName] = &nd - } - wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting netmask to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) p.NetDevs[SetNetName].Netmask.Set(SetNetmask) } @@ -186,11 +182,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := p.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - p.NetDevs[SetNetName] = &nd - } - wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting gateway to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) p.NetDevs[SetNetName].Gateway.Set(SetGateway) } @@ -201,11 +192,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := p.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - p.NetDevs[SetNetName] = &nd - } - wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting HW address to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) p.NetDevs[SetNetName].Hwaddr.Set(SetHwaddr) } @@ -216,11 +202,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := p.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - p.NetDevs[SetNetName] = &nd - } - wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting HW address to: %s:%s\n", p.Id.Get(), SetNetName, SetType) p.NetDevs[SetNetName].Type.Set(SetType) } @@ -231,11 +212,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if _, ok := p.NetDevs[SetNetName]; !ok { - var nd node.NetDevEntry - p.NetDevs[SetNetName] = &nd - } - if SetNetOnBoot == "yes" || SetNetOnBoot == "y" || SetNetOnBoot == "1" || SetNetOnBoot == "true" { wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting ONBOOT\n", p.Id.Get(), SetNetName) p.NetDevs[SetNetName].OnBoot.SetB(true) diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index c3f61bbc..270f01a1 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -111,8 +111,9 @@ func init() { baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password") baseCmd.PersistentFlags().StringVar(&SetIpmiInterface, "ipmiinterface", "", "Set the node's IPMI interface (defaults to 'lan')") - baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure") - baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Define the network device") + baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "", "Define the network name to configure") + baseCmd.PersistentFlags().StringVarP(&SetNetName, "netdev", "N", "", "Alias to --netname") + baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdevice", "D", "", "Define the 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")