custom paramters

This commit is contained in:
Niko Kivel
2021-05-10 00:12:13 +02:00
parent dd4c075f50
commit 54b2164c4e
9 changed files with 92 additions and 22 deletions

View File

@@ -60,7 +60,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for name, param := range node.Params {
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":VALUE", param.Value.Source(), param.Value.Print())
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name, param.Source(), param.Print())
}
}

View File

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

View File

@@ -43,6 +43,7 @@ var (
SetRoot string
SetParam string
SetValue string
SetParamDel bool
)
func init() {
@@ -78,6 +79,7 @@ func init() {
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().BoolVarP(&SetNodeAll, "all", "a", false, "Set all nodes")