adding netname option back
This commit is contained in:
@@ -12,16 +12,15 @@ import (
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
// OptionStrMap, netWithoutName := apinode.AddNetname(OptionStrMap)
|
||||
// if netWithoutName {
|
||||
// return errors.New("a netname must be given for any network related configuration")
|
||||
// }
|
||||
// realMap := make(map[string]string)
|
||||
// remove the default network as the all network values are assigned
|
||||
// to this network
|
||||
if NetName != "" {
|
||||
netDev := *NodeConf.NetDevs["default"]
|
||||
NodeConf.NetDevs[NetName] = &netDev
|
||||
delete(NodeConf.NetDevs, "default")
|
||||
|
||||
// for key, val := range OptionStrMap {
|
||||
// realMap[key] = *val
|
||||
// }
|
||||
buffer, err := yaml.Marshal(nodeConf)
|
||||
}
|
||||
buffer, err := yaml.Marshal(NodeConf)
|
||||
if err != nil {
|
||||
wwlog.Error("Cant marshall nodeInfo", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -19,12 +19,15 @@ var (
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
nodeConf node.NodeConf
|
||||
NodeConf node.NodeConf
|
||||
NetName string
|
||||
)
|
||||
|
||||
func init() {
|
||||
nodeConf := node.NewConf()
|
||||
nodeConf.CreateFlags(baseCmd, []string{})
|
||||
NodeConf = node.NewConf()
|
||||
NodeConf.CreateFlags(baseCmd, []string{})
|
||||
baseCmd.PersistentFlags().StringVar(&NetName, "netname", "", "Set network name for network options")
|
||||
|
||||
// register the command line completions
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("container", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
list, _ := container.ListSources()
|
||||
|
||||
@@ -13,16 +13,15 @@ import (
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
// OptionStrMap, netWithoutName := apinode.AddNetname(OptionStrMap)
|
||||
// if netWithoutName {
|
||||
// return errors.New("a netname must be given for any network related configuration")
|
||||
// }
|
||||
// realMap := make(map[string]string)
|
||||
// remove the default network as the all network values are assigned
|
||||
// to this network
|
||||
if NetName != "" {
|
||||
netDev := *NodeConf.NetDevs["default"]
|
||||
NodeConf.NetDevs[NetName] = &netDev
|
||||
delete(NodeConf.NetDevs, "default")
|
||||
|
||||
// for key, val := range OptionStrMap {
|
||||
// realMap[key] = *val
|
||||
// }
|
||||
buffer, err := yaml.Marshal(nodeConf)
|
||||
}
|
||||
buffer, err := yaml.Marshal(NodeConf)
|
||||
if err != nil {
|
||||
wwlog.Error("Cant marshall nodeInfo", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -33,16 +33,18 @@ var (
|
||||
},
|
||||
}
|
||||
SetNetDevDel string
|
||||
NetName string
|
||||
SetNodeAll bool
|
||||
SetYes bool
|
||||
SetForce bool
|
||||
nodeConf node.NodeConf
|
||||
NodeConf node.NodeConf
|
||||
)
|
||||
|
||||
func init() {
|
||||
nodeConf := node.NewConf()
|
||||
nodeConf.CreateFlags(baseCmd, []string{})
|
||||
NodeConf = node.NewConf()
|
||||
NodeConf.CreateFlags(baseCmd, []string{})
|
||||
baseCmd.PersistentFlags().StringVarP(&SetNetDevDel, "netdel", "D", "", "Delete the node's network device")
|
||||
baseCmd.PersistentFlags().StringVar(&NetName, "netname", "", "Set network name for network options")
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetNodeAll, "all", "a", false, "Set all nodes")
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetYes, "yes", "y", false, "Set 'yes' to all questions asked")
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetForce, "force", "f", false, "Force configuration (even on error)")
|
||||
|
||||
@@ -14,16 +14,15 @@ import (
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
// OptionStrMap, netWithoutName := apinode.AddNetname(OptionStrMap)
|
||||
// if netWithoutName {
|
||||
// return errors.New("a netname must be given for any network related configuration")
|
||||
// }
|
||||
// realMap := make(map[string]string)
|
||||
// remove the default network as the all network values are assigned
|
||||
// to this network
|
||||
if NetName != "" {
|
||||
netDev := *ProfileConf.NetDevs["default"]
|
||||
ProfileConf.NetDevs[NetName] = &netDev
|
||||
delete(ProfileConf.NetDevs, "default")
|
||||
|
||||
// for key, val := range OptionStrMap {
|
||||
// realMap[key] = *val
|
||||
// }
|
||||
buffer, err := yaml.Marshal(profileConf)
|
||||
}
|
||||
buffer, err := yaml.Marshal(ProfileConf)
|
||||
if err != nil {
|
||||
wwlog.Error("Cant marshall nodeInfo", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -23,14 +23,16 @@ var (
|
||||
SetNodeAll bool
|
||||
SetYes bool
|
||||
SetForce bool
|
||||
profileConf node.NodeConf
|
||||
NetName string
|
||||
ProfileConf node.NodeConf
|
||||
)
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
profileConf = node.NewConf()
|
||||
profileConf.CreateFlags(baseCmd,
|
||||
ProfileConf = node.NewConf()
|
||||
ProfileConf.CreateFlags(baseCmd,
|
||||
[]string{"ipaddr", "ipaddr6", "ipmiaddr", "profile"})
|
||||
baseCmd.PersistentFlags().StringVar(&NetName, "netname", "", "Set network name for network options")
|
||||
// register the command line completions
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("container", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
list, _ := container.ListSources()
|
||||
|
||||
@@ -13,11 +13,16 @@ import (
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
// OptionStrMap, netWithoutName := apinode.AddNetname(OptionStrMap)
|
||||
// if netWithoutName {
|
||||
// return errors.New("a netname must be given for any network related configuration")
|
||||
// }
|
||||
buffer, err := yaml.Marshal(profileConf)
|
||||
|
||||
// remove the default network as the all network values are assigned
|
||||
// to this network
|
||||
if NetName != "" {
|
||||
netDev := *ProfileConf.NetDevs["default"]
|
||||
ProfileConf.NetDevs[NetName] = &netDev
|
||||
delete(ProfileConf.NetDevs, "default")
|
||||
|
||||
}
|
||||
buffer, err := yaml.Marshal(ProfileConf)
|
||||
if err != nil {
|
||||
wwlog.Error("Cant marshall nodeInfo", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -36,13 +36,15 @@ var (
|
||||
SetNodeAll bool
|
||||
SetYes bool
|
||||
SetForce bool
|
||||
profileConf node.NodeConf
|
||||
NetName string
|
||||
ProfileConf node.NodeConf
|
||||
)
|
||||
|
||||
func init() {
|
||||
profileConf = node.NewConf()
|
||||
profileConf.CreateFlags(baseCmd,
|
||||
ProfileConf = node.NewConf()
|
||||
ProfileConf.CreateFlags(baseCmd,
|
||||
[]string{"ipaddr", "ipaddr6", "ipmiaddr", "profile"})
|
||||
baseCmd.PersistentFlags().StringVar(&NetName, "netname", "", "Set network name for network options")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetNetDevDel, "netdel", "D", "", "Delete the node's network device")
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetNodeAll, "all", "a", false, "Set all nodes")
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetYes, "yes", "y", false, "Set 'yes' to all questions asked")
|
||||
|
||||
@@ -49,8 +49,8 @@ type NodeConf struct {
|
||||
Profiles []string `yaml:"profiles,omitempty" lopt:"profile" sopt:"P" comment:"Set the node's profile members (comma separated)"`
|
||||
NetDevs map[string]*NetDevs `yaml:"network devices,omitempty"`
|
||||
Tags map[string]string `yaml:"tags,omitempty" lopt:"tagadd" comment:"base key"`
|
||||
TagsDel []string `lopt:"tagdel" comment:"remove this tags"` // does not go to disk only to wire
|
||||
Keys map[string]string `yaml:"keys,omitempty"` // Reverse compatibility
|
||||
TagsDel []string `yaml:"tagsdel,omitempty" lopt:"tagdel" comment:"remove this tags"` // should not go to disk only to wire
|
||||
Keys map[string]string `yaml:"keys,omitempty"` // Reverse compatibility
|
||||
}
|
||||
|
||||
type IpmiConf struct {
|
||||
@@ -63,7 +63,7 @@ type IpmiConf struct {
|
||||
Interface string `yaml:"interface,omitempty" lopt:"ipmiinterface" comment:"Set the node's IPMI interface (defaults: 'lan')"`
|
||||
Write string `yaml:"write,omitempty" lopt:"ipmiwrite" comment:"Enable the write of impi configuration (yes/no)"`
|
||||
Tags map[string]string `yaml:"tags,omitempty" lopt:"ipmitagadd" comment:"add ipmitags"`
|
||||
TagsDel []string `lopt:"ipmitagdel" comment:"remove ipmitags"` // does not go to disk only to wire
|
||||
TagsDel []string `yaml:"tagsdel,omitempty" lopt:"ipmitagdel" comment:"remove ipmitags"` // should not go to disk only to wire
|
||||
}
|
||||
type KernelConf struct {
|
||||
Version string `yaml:"version,omitempty"`
|
||||
@@ -85,7 +85,7 @@ type NetDevs struct {
|
||||
Primary string `yaml:"primary,omitempty" lopt:"primary" comment:"Enable/disable network device as primary (yes/no)"`
|
||||
Default string `yaml:"default,omitempty"` /* backward compatibility */
|
||||
Tags map[string]string `yaml:"tags,omitempty" lopt:"nettagadd" comment:"network tags"`
|
||||
TagsDel []string `lopt:"nettagdel" comment:"delete network tags"` // does not go to disk only to wire
|
||||
TagsDel []string `yaml:"tagsdel,omitempty" lopt:"nettagdel" comment:"delete network tags"` // should not go to disk only to wire
|
||||
}
|
||||
|
||||
/******
|
||||
|
||||
@@ -81,6 +81,8 @@ func (ent *Entry) SetB(val bool) {
|
||||
func (ent *Entry) SetSlice(val []string) {
|
||||
if len(val) == 0 {
|
||||
return
|
||||
} else if len(val) == 1 && val[0] == "" { // check also for an "empty" slice
|
||||
return
|
||||
}
|
||||
if val[0] == "UNDEF" || val[0] == "DELETE" || val[0] == "UNSET" || val[0] == "--" {
|
||||
ent.value = []string{}
|
||||
|
||||
@@ -142,12 +142,14 @@ func (nodeConf *NodeConf) CreateFlags(baseCmd *cobra.Command, excludeList []stri
|
||||
for i := 0; i < nodeInfoVal.Elem().NumField(); i++ {
|
||||
if nodeInfoType.Elem().Field(i).Tag.Get("comment") != "" &&
|
||||
!util.InSlice(excludeList, nodeInfoType.Elem().Field(i).Tag.Get("lopt")) {
|
||||
createFlags(baseCmd, excludeList, nodeInfoType.Elem().Field(i), nodeInfoVal.Elem().Field(i))
|
||||
field := nodeInfoVal.Elem().Field(i)
|
||||
createFlags(baseCmd, excludeList, nodeInfoType.Elem().Field(i), &field)
|
||||
} else if nodeInfoType.Elem().Field(i).Type.Kind() == reflect.Ptr {
|
||||
nestType := reflect.TypeOf(nodeInfoVal.Elem().Field(i).Interface())
|
||||
nestVal := reflect.ValueOf(nodeInfoVal.Elem().Field(i).Interface())
|
||||
for j := 0; j < nestType.Elem().NumField(); j++ {
|
||||
createFlags(baseCmd, excludeList, nestType.Elem().Field(j), nestVal.Elem().Field(j))
|
||||
field := nestVal.Elem().Field(j)
|
||||
createFlags(baseCmd, excludeList, nestType.Elem().Field(j), &field)
|
||||
}
|
||||
} else if nodeInfoType.Elem().Field(i).Type == reflect.TypeOf(map[string]*NetDevs(nil)) {
|
||||
netMap := nodeInfoVal.Elem().Field(i).Interface().(map[string]*NetDevs)
|
||||
@@ -156,7 +158,8 @@ func (nodeConf *NodeConf) CreateFlags(baseCmd *cobra.Command, excludeList []stri
|
||||
netType := reflect.TypeOf(netMap["default"])
|
||||
netVal := reflect.ValueOf(netMap["default"])
|
||||
for j := 0; j < netType.Elem().NumField(); j++ {
|
||||
createFlags(baseCmd, excludeList, netType.Elem().Field(j), netVal.Elem().Field(j))
|
||||
field := netVal.Elem().Field(j)
|
||||
createFlags(baseCmd, excludeList, netType.Elem().Field(j), &field)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,7 +169,7 @@ func (nodeConf *NodeConf) CreateFlags(baseCmd *cobra.Command, excludeList []stri
|
||||
Helper function to create the different PerisitantFlags() for different types.
|
||||
*/
|
||||
func createFlags(baseCmd *cobra.Command, excludeList []string,
|
||||
myType reflect.StructField, myVal reflect.Value) {
|
||||
myType reflect.StructField, myVal *reflect.Value) {
|
||||
if myType.Tag.Get("lopt") != "" {
|
||||
if myType.Type.Kind() == reflect.String {
|
||||
ptr := myVal.Addr().Interface().(*string)
|
||||
|
||||
Reference in New Issue
Block a user