Fixed backwards compatibility with --netdev and cleanups

This commit is contained in:
Gregory Kurtzer
2021-12-28 16:07:19 -08:00
parent 3a699f7148
commit f5a9c0f933
4 changed files with 30 additions and 76 deletions

View File

@@ -165,17 +165,23 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
if SetNetName != "" {
if _, ok := n.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
n.NetDevs[SetNetName] = &nd
if SetNetDev == "" {
n.NetDevs[SetNetName].Device.Set(SetNetName)
}
}
}
if SetNetDev != "" { if SetNetDev != "" {
if SetNetName == "" { if SetNetName == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n")
os.Exit(1) os.Exit(1)
} }
if _, ok := n.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
n.NetDevs[SetNetName] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting net Device to: %s\n", n.Id.Get(), SetNetName, SetNetDev) wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting net Device to: %s\n", n.Id.Get(), SetNetName, SetNetDev)
n.NetDevs[SetNetName].Device.Set(SetNetDev) n.NetDevs[SetNetName].Device.Set(SetNetDev)
} }
@@ -186,11 +192,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := n.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
n.NetDevs[SetNetName] = &nd
}
NewIpaddr := util.IncrementIPv4(SetIpaddr, count) NewIpaddr := util.IncrementIPv4(SetIpaddr, count)
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Id.Get(), SetNetName, NewIpaddr) wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Id.Get(), SetNetName, NewIpaddr)
@@ -203,11 +204,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := n.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
n.NetDevs[SetNetName] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Id.Get(), SetNetName, SetNetmask) wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Id.Get(), SetNetName, SetNetmask)
n.NetDevs[SetNetName].Netmask.Set(SetNetmask) n.NetDevs[SetNetName].Netmask.Set(SetNetmask)
} }
@@ -218,11 +214,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := n.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
n.NetDevs[SetNetName] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Id.Get(), SetNetName, SetGateway) wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Id.Get(), SetNetName, SetGateway)
n.NetDevs[SetNetName].Gateway.Set(SetGateway) n.NetDevs[SetNetName].Gateway.Set(SetGateway)
} }
@@ -233,11 +224,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := n.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
n.NetDevs[SetNetName] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Id.Get(), SetNetName, SetHwaddr) wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Id.Get(), SetNetName, SetHwaddr)
n.NetDevs[SetNetName].Hwaddr.Set(SetHwaddr) n.NetDevs[SetNetName].Hwaddr.Set(SetHwaddr)
} }
@@ -248,11 +234,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := n.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
n.NetDevs[SetNetName] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Type %s\n", n.Id.Get(), SetNetName, SetType) wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Type %s\n", n.Id.Get(), SetNetName, SetType)
n.NetDevs[SetNetName].Type.Set(SetType) n.NetDevs[SetNetName].Type.Set(SetType)
} }
@@ -263,11 +244,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := n.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
n.NetDevs[SetNetName] = &nd
}
if SetNetOnBoot == "yes" || SetNetOnBoot == "y" || SetNetOnBoot == "1" || SetNetOnBoot == "true" { if SetNetOnBoot == "yes" || SetNetOnBoot == "y" || SetNetOnBoot == "1" || SetNetOnBoot == "true" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting ONBOOT\n", n.Id.Get(), SetNetName) wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting ONBOOT\n", n.Id.Get(), SetNetName)
n.NetDevs[SetNetName].OnBoot.SetB(true) n.NetDevs[SetNetName].OnBoot.SetB(true)

View File

@@ -13,8 +13,8 @@ import (
var ( var (
baseCmd = &cobra.Command{ baseCmd = &cobra.Command{
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
Use: "set [OPTIONS] PATTERN [PATTERN ...]", Use: "set [OPTIONS] PATTERN [PATTERN ...]",
Short: "Configure node properties", Short: "Configure node properties",
Long: "This command sets configuration properties for nodes matching PATTERN.\n\n" + Long: "This command sets configuration properties for nodes matching PATTERN.\n\n" +
"Note: use the string 'UNSET' to remove a configuration", "Note: use the string 'UNSET' to remove a configuration",
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
@@ -128,8 +128,9 @@ func init() {
}); err != nil { }); err != nil {
log.Println(err) log.Println(err)
} }
baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure") baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "", "Define the network name to configure")
baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Define the network device") baseCmd.PersistentFlags().StringVarP(&SetNetName, "netdev", "N", "", "Alias to --netname")
baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdevice", "D", "", "Define the network device")
baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address") baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address")
baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask") baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask")
baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway") baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway")

View File

@@ -135,17 +135,23 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
p.Discoverable.SetB(false) p.Discoverable.SetB(false)
} }
if SetNetName != "" {
if _, ok := p.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetName] = &nd
if SetNetDev == "" {
p.NetDevs[SetNetName].Device.Set(SetNetName)
}
}
}
if SetNetDev != "" { if SetNetDev != "" {
if SetNetName == "" { if SetNetName == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n")
os.Exit(1) os.Exit(1)
} }
if _, ok := p.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetName] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting net Device to: %s\n", p.Id.Get(), SetNetName, SetNetDev) wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting net Device to: %s\n", p.Id.Get(), SetNetName, SetNetDev)
p.NetDevs[SetNetName].Device.Set(SetNetDev) p.NetDevs[SetNetName].Device.Set(SetNetDev)
} }
@@ -156,11 +162,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := p.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetName] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting IP address to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting IP address to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr)
p.NetDevs[SetNetName].Ipaddr.Set(SetIpaddr) p.NetDevs[SetNetName].Ipaddr.Set(SetIpaddr)
} }
@@ -171,11 +172,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := p.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetName] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting netmask to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting netmask to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr)
p.NetDevs[SetNetName].Netmask.Set(SetNetmask) p.NetDevs[SetNetName].Netmask.Set(SetNetmask)
} }
@@ -186,11 +182,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := p.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetName] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting gateway to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting gateway to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr)
p.NetDevs[SetNetName].Gateway.Set(SetGateway) p.NetDevs[SetNetName].Gateway.Set(SetGateway)
} }
@@ -201,11 +192,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := p.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetName] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting HW address to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting HW address to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr)
p.NetDevs[SetNetName].Hwaddr.Set(SetHwaddr) p.NetDevs[SetNetName].Hwaddr.Set(SetHwaddr)
} }
@@ -216,11 +202,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := p.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetName] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting HW address to: %s:%s\n", p.Id.Get(), SetNetName, SetType) wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting HW address to: %s:%s\n", p.Id.Get(), SetNetName, SetType)
p.NetDevs[SetNetName].Type.Set(SetType) p.NetDevs[SetNetName].Type.Set(SetType)
} }
@@ -231,11 +212,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if _, ok := p.NetDevs[SetNetName]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetName] = &nd
}
if SetNetOnBoot == "yes" || SetNetOnBoot == "y" || SetNetOnBoot == "1" || SetNetOnBoot == "true" { if SetNetOnBoot == "yes" || SetNetOnBoot == "y" || SetNetOnBoot == "1" || SetNetOnBoot == "true" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting ONBOOT\n", p.Id.Get(), SetNetName) wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting ONBOOT\n", p.Id.Get(), SetNetName)
p.NetDevs[SetNetName].OnBoot.SetB(true) p.NetDevs[SetNetName].OnBoot.SetB(true)

View File

@@ -111,8 +111,9 @@ func init() {
baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password") baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password")
baseCmd.PersistentFlags().StringVar(&SetIpmiInterface, "ipmiinterface", "", "Set the node's IPMI interface (defaults to 'lan')") baseCmd.PersistentFlags().StringVar(&SetIpmiInterface, "ipmiinterface", "", "Set the node's IPMI interface (defaults to 'lan')")
baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure") baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "", "Define the network name to configure")
baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Define the network device") baseCmd.PersistentFlags().StringVarP(&SetNetName, "netdev", "N", "", "Alias to --netname")
baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdevice", "D", "", "Define the network device")
baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address") baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address")
baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask") baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask")
baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway") baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway")