Changed "key" paramaters to tags and cleaned up interface

This commit is contained in:
Gregory Kurtzer
2022-02-11 05:52:46 +00:00
parent 7381efb0fc
commit ffaf794a42
10 changed files with 89 additions and 90 deletions

View File

@@ -3,6 +3,7 @@ package set
import (
"fmt"
"os"
"strings"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
@@ -269,33 +270,34 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
delete(p.NetDevs, SetNetDev)
}
if SetValue != "" {
if SetKey == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--key/-k' option\n")
os.Exit(1)
}
if len(SetTags) > 0 {
for _, t := range SetTags {
keyval := strings.SplitN(t, "=", 2)
key := keyval[0]
val := keyval[1]
if _, ok := p.Keys[SetKey]; !ok {
var nd node.Entry
p.Keys[SetKey] = &nd
if _, ok := p.Tags[key]; !ok {
var nd node.Entry
p.Tags[key] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting Tag '%s'='%s'\n", p.Id.Get(), key, val)
p.Tags[key].Set(val)
}
wwlog.Printf(wwlog.VERBOSE, "Profile: %s:%s, Setting Value %s\n", p.Id.Get(), SetKey, SetValue)
p.Keys[SetKey].Set(SetValue)
}
if len(SetDelTags) > 0 {
for _, t := range SetDelTags {
keyval := strings.SplitN(t, "=", 1)
key := keyval[0]
if SetKeyDel {
if SetKey == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--key/-k' option\n")
os.Exit(1)
if _, ok := p.Tags[key]; !ok {
wwlog.Printf(wwlog.WARN, "Key does not exist: %s\n", key)
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Deleting tag: %s\n", p.Id.Get(), key)
delete(p.Tags, key)
}
if _, ok := p.Keys[SetKey]; !ok {
wwlog.Printf(wwlog.ERROR, "Custom key doesn't exist: %s\n", SetKey)
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Deleting custom key: %s\n", p.Id.Get(), SetNetDev)
delete(p.Keys, SetKey)
}
err := nodeDB.ProfileUpdate(p)

View File

@@ -65,8 +65,8 @@ var (
SetInit string
SetRoot string
SetKey string
SetValue string
SetKeyDel bool
SetTags []string
SetDelTags []string
SetAssetKey string
)
@@ -126,10 +126,8 @@ func init() {
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device")
baseCmd.PersistentFlags().StringVarP(&SetKey, "key", "k", "", "Define custom key")
baseCmd.PersistentFlags().BoolVar(&SetKeyDel, "keydel", false, "Delete custom key")
baseCmd.PersistentFlags().StringVarP(&SetValue, "value", "", "", "Set value")
baseCmd.PersistentFlags().StringSliceVarP(&SetTags, "tag", "t", []string{}, "Define custom tag (key=value)")
baseCmd.PersistentFlags().StringSliceVar(&SetDelTags, "tagdel", []string{}, "Delete tag")
baseCmd.PersistentFlags().BoolVarP(&SetAll, "all", "a", false, "Set all profiles")
baseCmd.PersistentFlags().BoolVarP(&SetForce, "force", "f", false, "Force configuration (even on error)")