Added profile UI fixes

Related to #63 and #58.
This commit is contained in:
Gregory Kurtzer
2021-04-25 13:21:59 -07:00
parent 7941f0e23c
commit 663c31fc7e
2 changed files with 50 additions and 5 deletions

View File

@@ -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)
}
}

View File

@@ -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")