Params-->Keys

This commit is contained in:
Niko Kivel
2021-05-11 08:45:09 +02:00
parent c12f257428
commit 17f26e8bf1
10 changed files with 70 additions and 69 deletions

View File

@@ -59,8 +59,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Printf("%-20s %-18s %-12s %t\n", node.Id.Get(), name+":DEFAULT", netdev.Default.Source(), netdev.Default.PrintB())
}
for name, param := range node.Params {
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name, param.Source(), param.Print())
for name, key := range node.Keys {
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name, key.Source(), key.Print())
}
}

View File

@@ -326,33 +326,32 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if SetValue != "" {
if SetParam == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--param' option\n")
if SetKey == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--key/-k' option\n")
os.Exit(1)
}
if _, ok := n.Params[SetParam]; !ok {
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Value %s\n", n.Id.Get(), SetParam, SetValue)
if _, ok := n.Keys[SetKey]; !ok {
var nd node.Entry
n.Params[SetParam] = &nd
n.Keys[SetKey] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Value %s\n", n.Id.Get(), SetParam, SetValue)
n.Params[SetParam].Set(SetValue)
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Value %s\n", n.Id.Get(), SetKey, SetValue)
n.Keys[SetKey].Set(SetValue)
}
if SetParamDel == true {
if SetParam == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--param' option\n")
if SetKeyDel == true {
if SetKey == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--key/-k' option\n")
os.Exit(1)
}
if _, ok := n.Params[SetParam]; !ok {
wwlog.Printf(wwlog.ERROR, "Custom parameter doesn't exist: %s\n", SetParam)
if _, ok := n.Keys[SetKey]; !ok {
wwlog.Printf(wwlog.ERROR, "Custom parameter doesn't exist: %s\n", SetKey)
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Deleting custom parameter: %s\n", n.Id.Get(), SetNetDev)
delete(n.Params, SetParam)
delete(n.Keys, SetKey)
}
err := nodeDB.NodeUpdate(n)

View File

@@ -41,9 +41,9 @@ var (
SetDiscoverable bool
SetUndiscoverable bool
SetRoot string
SetParam string
SetKey string
SetValue string
SetParamDel bool
SetKeyDel bool
)
func init() {
@@ -77,9 +77,10 @@ func init() {
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device")
baseCmd.PersistentFlags().BoolVar(&SetNetDevDefault, "netdefault", false, "Set this network to be default")
baseCmd.PersistentFlags().StringVarP(&SetParam, "param", "p", "", "Define custom parameter")
baseCmd.PersistentFlags().StringVarP(&SetValue, "value", "", "", "Set custom parameter value")
baseCmd.PersistentFlags().BoolVar(&SetParamDel, "paramdel", false, "Delete custom parameter")
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().BoolVarP(&SetNodeAll, "all", "a", false, "Set all nodes")

View File

@@ -55,8 +55,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Printf("%-20s %-18s %t\n", profile.Id.Get(), name+":DEFAULT", netdev.Default.PrintB())
}
for name, param := range profile.Params {
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name, param.Print())
for name, key := range profile.Keys {
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name, key.Print())
}
}
} else {

View File

@@ -242,32 +242,32 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if SetValue != "" {
if SetParam == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--param' option\n")
if SetKey == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--key/-k' option\n")
os.Exit(1)
}
if _, ok := p.Params[SetParam]; !ok {
if _, ok := p.Keys[SetKey]; !ok {
var nd node.Entry
p.Params[SetParam] = &nd
p.Keys[SetKey] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Profile: %s:%s, Setting Value %s\n", p.Id.Get(), SetParam, SetValue)
p.Params[SetParam].Set(SetValue)
wwlog.Printf(wwlog.VERBOSE, "Profile: %s:%s, Setting Value %s\n", p.Id.Get(), SetKey, SetValue)
p.Keys[SetKey].Set(SetValue)
}
if SetParamDel == true {
if SetParam == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--param' option\n")
if SetKeyDel == true {
if SetKey == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--key/-k' option\n")
os.Exit(1)
}
if _, ok := p.Params[SetParam]; !ok {
wwlog.Printf(wwlog.ERROR, "Custom parameter doesn't exist: %s\n", SetParam)
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 parameter: %s\n", p.Id.Get(), SetNetDev)
delete(p.Params, SetParam)
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

@@ -35,9 +35,9 @@ var (
SetNetDevDefault bool
SetInit string
SetRoot string
SetParam string
SetKey string
SetValue string
SetParamDel bool
SetKeyDel bool
)
func init() {
@@ -66,9 +66,10 @@ func init() {
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device")
baseCmd.PersistentFlags().BoolVar(&SetNetDevDefault, "netdefault", false, "Set this network to be default")
baseCmd.PersistentFlags().StringVarP(&SetParam, "param", "p", "", "Define custom parameter")
baseCmd.PersistentFlags().StringVarP(&SetValue, "value", "", "", "Set custom parameter value")
baseCmd.PersistentFlags().BoolVar(&SetParamDel, "paramdel", false, "Delete custom parameter")
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().BoolVarP(&SetAll, "all", "a", false, "Set all profiles")
baseCmd.PersistentFlags().BoolVarP(&SetForce, "force", "f", false, "Force configuration (even on error)")