add user defined keys for networks/netdev
Every network in the profile and for the nodes can have induvidual keys values
pairs, called Tags, which are propergated to the templates. So they can be used
for things like MTU size like
`wwct node set node01 --nettag mtu=9000`
and in in ifcfg.xml.ww
```
{{ if $netdev.Tags.mtu -}}
<mtu> {{ $netdev.Tags.mtu }} </mtu>
{{ end -}}
```
This commit is contained in:
committed by
Christian Goll
parent
16fa2518fa
commit
95050a44ce
@@ -71,6 +71,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":TYPE", netdev.Type.Source(), netdev.Type.Print())
|
||||
fmt.Printf("%-20s %-18s %-12s %t\n", node.Id.Get(), name+":ONBOOT", netdev.OnBoot.Source(), netdev.OnBoot.PrintB())
|
||||
fmt.Printf("%-20s %-18s %-12s %t\n", node.Id.Get(), name+":DEFAULT", netdev.Default.Source(), netdev.Default.PrintB())
|
||||
for keyname, key := range netdev.Tags {
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":TAG["+keyname+"]", key.Source(), key.Print())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -176,9 +176,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
if SetNetName != "" {
|
||||
if _, ok := n.NetDevs[SetNetName]; !ok {
|
||||
var nd node.NetDevEntry
|
||||
nd.Tags = make(map[string]*node.Entry)
|
||||
|
||||
n.NetDevs[SetNetName] = &nd
|
||||
|
||||
if SetNetDev == "" {
|
||||
n.NetDevs[SetNetName].Device.Set(SetNetName)
|
||||
}
|
||||
@@ -341,7 +341,34 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
delete(n.Tags, key)
|
||||
}
|
||||
}
|
||||
if len(SetNetTags) > 0 {
|
||||
for _, t := range SetNetTags {
|
||||
keyval := strings.SplitN(t, "=", 2)
|
||||
key := keyval[0]
|
||||
val := keyval[1]
|
||||
if _, ok := n.NetDevs[SetNetName].Tags[key]; !ok {
|
||||
var nd node.Entry
|
||||
n.NetDevs[SetNetName].Tags[key] = &nd
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting NETTAG '%s'='%s'\n", n.Id.Get(), SetNetName, key, val)
|
||||
n.NetDevs[SetNetName].Tags[key].Set(val)
|
||||
}
|
||||
|
||||
}
|
||||
if len(SetNetDelTags) > 0 {
|
||||
for _, t := range SetNetDelTags {
|
||||
keyval := strings.SplitN(t, "=", 1)
|
||||
key := keyval[0]
|
||||
if _, ok := n.NetDevs[SetNetName].Tags[key]; !ok {
|
||||
wwlog.Printf(wwlog.WARN, "Node: %s:%s Key %s does not exist\n", n.Id.Get(), SetNetName, key)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Deleting Tag %s\n", n.Id.Get(), SetNetName, key)
|
||||
delete(n.NetDevs[SetNetName].Tags, key)
|
||||
}
|
||||
}
|
||||
err := nodeDB.NodeUpdate(n)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
|
||||
@@ -72,6 +72,8 @@ var (
|
||||
SetTags []string
|
||||
SetDelTags []string
|
||||
SetAssetKey string
|
||||
SetNetTags []string
|
||||
SetNetDelTags []string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -144,6 +146,8 @@ func init() {
|
||||
baseCmd.PersistentFlags().StringVar(&SetNetDefault, "default", "", "Enable/disable device as default (yes/no)")
|
||||
|
||||
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device")
|
||||
baseCmd.PersistentFlags().StringSliceVar(&SetNetTags, "nettag", []string{}, "Define custom tag to network device (key=value)")
|
||||
baseCmd.PersistentFlags().StringSliceVar(&SetNetDelTags, "netdeltag", []string{}, "Delete tag for network device")
|
||||
|
||||
baseCmd.PersistentFlags().StringSliceVarP(&SetTags, "tag", "t", []string{}, "Define custom tag (key=value)")
|
||||
baseCmd.PersistentFlags().StringSliceVar(&SetDelTags, "tagdel", []string{}, "Delete tag")
|
||||
|
||||
Reference in New Issue
Block a user