Changed "key" paramaters to tags and cleaned up interface
This commit is contained in:
@@ -57,6 +57,10 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiUserName", node.IpmiUserName.Source(), node.IpmiUserName.Print())
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiInterface", node.IpmiInterface.Source(), node.IpmiInterface.Print())
|
||||
|
||||
for keyname, key := range node.Tags {
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Tag["+keyname+"]", key.Source(), key.Print())
|
||||
}
|
||||
|
||||
for name, netdev := range node.NetDevs {
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":DEVICE", netdev.Device.Source(), netdev.Device.Print())
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":HWADDR", netdev.Hwaddr.Source(), netdev.Hwaddr.Print())
|
||||
@@ -68,9 +72,6 @@ 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 keyname, key := range node.Keys {
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Keys."+keyname, key.Source(), key.Print())
|
||||
}
|
||||
}
|
||||
|
||||
} else if ShowNet {
|
||||
|
||||
@@ -301,33 +301,34 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
delete(n.NetDevs, SetNetName)
|
||||
}
|
||||
|
||||
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 := n.Keys[SetKey]; !ok {
|
||||
var nd node.Entry
|
||||
n.Keys[SetKey] = &nd
|
||||
if _, ok := n.Tags[key]; !ok {
|
||||
var nd node.Entry
|
||||
n.Tags[key] = &nd
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting Tag '%s'='%s'\n", n.Id.Get(), key, val)
|
||||
n.Tags[key].Set(val)
|
||||
}
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Value %s\n", n.Id.Get(), SetKey, SetValue)
|
||||
n.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 := n.Tags[key]; !ok {
|
||||
wwlog.Printf(wwlog.WARN, "Key does not exist: %s\n", key)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Deleting tag: %s\n", n.Id.Get(), key)
|
||||
delete(n.Tags, key)
|
||||
}
|
||||
|
||||
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.Keys, SetKey)
|
||||
}
|
||||
|
||||
err := nodeDB.NodeUpdate(n)
|
||||
|
||||
@@ -68,9 +68,8 @@ var (
|
||||
SetDiscoverable bool
|
||||
SetUndiscoverable bool
|
||||
SetRoot string
|
||||
SetKey string
|
||||
SetValue string
|
||||
SetKeyDel bool
|
||||
SetTags []string
|
||||
SetDelTags []string
|
||||
SetAssetKey string
|
||||
)
|
||||
|
||||
@@ -144,10 +143,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(&SetNodeAll, "all", "a", false, "Set all nodes")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user