From 663c31fc7e4696507b317c2ef57d7f5052501aa2 Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Sun, 25 Apr 2021 13:21:59 -0700 Subject: [PATCH] Added profile UI fixes Related to #63 and #58. --- internal/app/wwctl/node/set/main.go | 47 +++++++++++++++++++++++++++-- internal/app/wwctl/node/set/root.go | 8 +++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/internal/app/wwctl/node/set/main.go b/internal/app/wwctl/node/set/main.go index d84a7945..4d11f393 100644 --- a/internal/app/wwctl/node/set/main.go +++ b/internal/app/wwctl/node/set/main.go @@ -3,6 +3,7 @@ package set import ( "fmt" "os" + "strings" "github.com/hpcng/warewulf/internal/pkg/container" "github.com/hpcng/warewulf/internal/pkg/node" @@ -16,6 +17,7 @@ import ( func CobraRunE(cmd *cobra.Command, args []string) error { var err error var nodes []node.NodeInfo + var SetProfiles []string nodeDB, err := node.New() if err != nil { @@ -63,6 +65,42 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } + if SetProfile != "" { + profiles, _ := nodeDB.FindAllProfiles() + for _, r := range strings.Split(SetProfile, ",") { + var match bool + + for _, p := range profiles { + if p.Id.Get() == r || SetForce { + match = true + SetProfiles = append(SetProfiles, r) + } + } + + if !match { + wwlog.Printf(wwlog.WARN, "Requested profile is undefined: %s\n", r) + } + } + } + + if len(SetAddProfile) > 0 { + profiles, _ := nodeDB.FindAllProfiles() + for _, r := range SetAddProfile { + var match bool + + for _, p := range profiles { + if p.Id.Get() == r || SetForce { + match = true + } + } + + if !match { + wwlog.Printf(wwlog.WARN, "Requested profile is undefined: %s\n", r) + SetAddProfile = util.SliceRemoveElement(SetAddProfile, r) + } + } + } + for _, n := range nodes { wwlog.Printf(wwlog.VERBOSE, "Evaluating node: %s\n", n.Id.Get()) @@ -151,16 +189,21 @@ func CobraRunE(cmd *cobra.Command, args []string) error { n.Discoverable.SetB(false) } + if len(SetProfiles) > 0 { + wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting profiles to: %s\n", n.Id.Get(), strings.Join(SetProfiles, ",")) + n.Profiles = SetProfiles + } + if len(SetAddProfile) > 0 { for _, p := range SetAddProfile { - wwlog.Printf(wwlog.VERBOSE, "Node: %s, adding profile to '%s'\n", n.Id.Get(), p) + wwlog.Printf(wwlog.VERBOSE, "Node: %s, adding profile '%s'\n", n.Id.Get(), p) n.Profiles = util.SliceAddUniqueElement(n.Profiles, p) } } if len(SetDelProfile) > 0 { for _, p := range SetDelProfile { - wwlog.Printf(wwlog.VERBOSE, "Node: %s, deleting profile from '%s'\n", n.Id.Get(), p) + wwlog.Printf(wwlog.VERBOSE, "Node: %s, deleting profile '%s'\n", n.Id.Get(), p) n.Profiles = util.SliceRemoveElement(n.Profiles, p) } } diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index ff28b19d..0a7747d2 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -33,6 +33,7 @@ var ( SetIpmiPassword string SetNodeAll bool SetYes bool + SetProfile string SetAddProfile []string SetDelProfile []string SetForce bool @@ -48,7 +49,7 @@ func init() { baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes") baseCmd.PersistentFlags().StringVarP(&SetKernelArgs, "kernelargs", "A", "", "Set Kernel argument for nodes") baseCmd.PersistentFlags().StringVarP(&SetClusterName, "cluster", "c", "", "Set the node's cluster group") - baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name") + baseCmd.PersistentFlags().StringVar(&SetIpxe, "ipxe", "", "Set the node's iPXE template name") baseCmd.PersistentFlags().StringVarP(&SetInit, "init", "i", "", "Define the init process to boot the container") baseCmd.PersistentFlags().StringVar(&SetRoot, "root", "", "Define the rootfs") @@ -60,8 +61,9 @@ func init() { baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username") baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password") - baseCmd.PersistentFlags().StringSliceVarP(&SetAddProfile, "addprofile", "p", []string{}, "Add Profile(s) to node") - baseCmd.PersistentFlags().StringSliceVarP(&SetDelProfile, "delprofile", "r", []string{}, "Remove Profile(s) to node") + baseCmd.PersistentFlags().StringSliceVar(&SetAddProfile, "addprofile", []string{}, "Add Profile(s) to node") + baseCmd.PersistentFlags().StringSliceVar(&SetDelProfile, "delprofile", []string{}, "Remove Profile(s) to node") + baseCmd.PersistentFlags().StringVarP(&SetProfile, "profile", "P", "", "Set the node's profile members (comma separated)") baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Define the network device to configure") baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address")