From dbd747788f137e702bce4445fe055be25fc31769 Mon Sep 17 00:00:00 2001 From: jcsiadal Date: Tue, 19 Apr 2022 21:59:34 +0000 Subject: [PATCH] wwctl profile fixes Signed-off-by: jcsiadal --- internal/app/wwctl/node/set/main.go | 4 ++-- internal/app/wwctl/node/set/root.go | 2 +- internal/app/wwctl/profile/set/main.go | 16 ++++++++-------- internal/app/wwctl/profile/set/root.go | 1 + internal/pkg/node/datastructure.go | 2 +- internal/pkg/node/methods.go | 5 +++++ 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/internal/app/wwctl/node/set/main.go b/internal/app/wwctl/node/set/main.go index c41900d8..6460313e 100644 --- a/internal/app/wwctl/node/set/main.go +++ b/internal/app/wwctl/node/set/main.go @@ -289,10 +289,10 @@ func CobraRunE(cmd *cobra.Command, args []string) error { n.Default.SetB(false) } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting DEFAULT\n", n.Id.Get(), SetNetName) + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting PRIMARY\n", n.Id.Get(), SetNetName) n.NetDevs[SetNetName].Default.SetB(true) } else { - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Unsetting DEFAULT\n", n.Id.Get(), SetNetName) + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Unsetting PRIMARY\n", n.Id.Get(), SetNetName) n.NetDevs[SetNetName].Default.SetB(false) } } diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index 1470cafb..d6eb7bf7 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -143,7 +143,7 @@ func init() { baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address") baseCmd.PersistentFlags().StringVarP(&SetType, "type", "T", "", "Set the node's network device type") baseCmd.PersistentFlags().StringVar(&SetNetOnBoot, "onboot", "", "Enable/disable device (yes/no)") - baseCmd.PersistentFlags().StringVar(&SetNetDefault, "default", "", "Enable/disable device as default (yes/no)") + baseCmd.PersistentFlags().StringVar(&SetNetDefault, "primary", "", "Enable/disable device as primary (yes/no)") baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device") baseCmd.PersistentFlags().StringSliceVar(&SetNetTags, "nettag", []string{}, "Define custom tag to network device (key=value)") diff --git a/internal/app/wwctl/profile/set/main.go b/internal/app/wwctl/profile/set/main.go index f14df079..e217ed4c 100644 --- a/internal/app/wwctl/profile/set/main.go +++ b/internal/app/wwctl/profile/set/main.go @@ -219,32 +219,32 @@ func CobraRunE(cmd *cobra.Command, args []string) error { if SetNetDefault == "yes" || SetNetDefault == "y" || SetNetDefault == "1" || SetNetDefault == "true" { - // Set all other devices to non-default + // Set all other networks to non-default for _, n := range p.NetDevs { n.Default.SetB(false) } - wwlog.Printf(wwlog.VERBOSE, "Profile: %s:%s, Setting DEFAULT\n", p.Id.Get(), SetNetName) + wwlog.Printf(wwlog.VERBOSE, "Profile: %s:%s, Setting PRIMARY\n", p.Id.Get(), SetNetName) p.NetDevs[SetNetName].Default.SetB(true) } else { - wwlog.Printf(wwlog.VERBOSE, "Profile: %s:%s, Unsetting DEFAULT\n", p.Id.Get(), SetNetName) + wwlog.Printf(wwlog.VERBOSE, "Profile: %s:%s, Unsetting PRIMARY\n", p.Id.Get(), SetNetName) p.NetDevs[SetNetName].Default.SetB(false) } } if SetNetDevDel { - if SetNetDev == "" { + if SetNetName == "" { wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") os.Exit(1) } - if _, ok := p.NetDevs[SetNetDev]; !ok { - wwlog.Printf(wwlog.ERROR, "Profile '%s': network Device doesn't exist: %s\n", p.Id.Get(), SetNetDev) + if _, ok := p.NetDevs[SetNetName]; !ok { + wwlog.Printf(wwlog.ERROR, "Profile '%s': network name doesn't exist: %s\n", p.Id.Get(), SetNetName) os.Exit(1) } - wwlog.Printf(wwlog.VERBOSE, "Profile %s: Deleting network device: %s\n", p.Id.Get(), SetNetDev) - delete(p.NetDevs, SetNetDev) + wwlog.Printf(wwlog.VERBOSE, "Profile %s: Deleting network: %s\n", p.Id.Get(), SetNetName) + delete(p.NetDevs, SetNetName) } if len(SetTags) > 0 { diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index eb2a6b6e..e586314c 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -118,6 +118,7 @@ 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().StringVar(&SetNetDefault, "primary", "", "Enable/disable device as primary (yes/no)") 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(&SetType, "type", "T", "", "Set the node's network device type") diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index 11f83c60..d78ee910 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -75,7 +75,7 @@ type NetDevs struct { Prefix string `yaml:"prefix,omitempty"` Netmask string `yaml:"netmask,omitempty"` Gateway string `yaml:"gateway,omitempty"` - Default string `yaml:"default,omitempty"` + Default string `yaml:"primary,omitempty"` Tags map[string]string `yaml:"tags,omitempty"` } diff --git a/internal/pkg/node/methods.go b/internal/pkg/node/methods.go index 20960b1c..2e0546af 100644 --- a/internal/pkg/node/methods.go +++ b/internal/pkg/node/methods.go @@ -68,6 +68,8 @@ Set bool func (ent *Entry) SetB(val bool) { if val { ent.value = []string{"true"} + } else { + ent.value = []string{"false"} } } @@ -100,6 +102,9 @@ func (ent *Entry) SetAltB(val bool, from string) { if val { ent.altvalue = []string{"true"} ent.from = from + } else { + ent.altvalue = []string{"false"} + ent.from = from } }