Properly configure a network device to be default
This commit is contained in:
@@ -61,6 +61,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":NETMASK", netdev.Netmask.Source(), netdev.Netmask.Print())
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":GATEWAY", netdev.Gateway.Source(), netdev.Gateway.Print())
|
||||
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+":DEFAULT", netdev.Default.Source(), netdev.Default.PrintB())
|
||||
}
|
||||
|
||||
// v := reflect.ValueOf(node)
|
||||
|
||||
@@ -233,6 +233,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Id.Get(), SetNetDev, SetHwaddr)
|
||||
n.NetDevs[SetNetDev].Hwaddr.Set(SetHwaddr)
|
||||
}
|
||||
if SetNetDevDefault == true {
|
||||
if SetNetDev == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, ok := n.NetDevs[SetNetDev]; !ok {
|
||||
var nd node.NetDevEntry
|
||||
n.NetDevs[SetNetDev] = &nd
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting device as default\n", n.Id.Get(), SetNetDev)
|
||||
for _, dev := range n.NetDevs {
|
||||
// First clear all other devices that might be configured as default
|
||||
dev.Default.SetB(false)
|
||||
}
|
||||
n.NetDevs[SetNetDev].Default.SetB(true)
|
||||
}
|
||||
|
||||
err := nodeDB.NodeUpdate(n)
|
||||
if err != nil {
|
||||
|
||||
@@ -19,6 +19,7 @@ var (
|
||||
SetGateway string
|
||||
SetHwaddr string
|
||||
SetNetDevDel bool
|
||||
SetNetDevDefault bool
|
||||
SetClusterName string
|
||||
SetIpxe string
|
||||
SetRuntimeOverlay string
|
||||
@@ -66,6 +67,8 @@ func init() {
|
||||
baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address")
|
||||
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device")
|
||||
baseCmd.PersistentFlags().BoolVar(&SetNetDevDefault, "netdefault", false, "Set this network to be default")
|
||||
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetNodeAll, "all", "a", false, "Set all nodes")
|
||||
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetYes, "yes", "y", false, "Set 'yes' to all questions asked")
|
||||
|
||||
@@ -49,7 +49,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name+":GATEWAY", netdev.Gateway.Print())
|
||||
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name+":HWADDR", netdev.Hwaddr.Print())
|
||||
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name+":TYPE", netdev.Hwaddr.Print())
|
||||
|
||||
fmt.Printf("%-20s %-18s %t\n", profile.Id.Get(), name+":DEFAULT", netdev.Default.PrintB())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,6 +213,25 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
p.NetDevs[SetNetDev].Hwaddr.Set(SetHwaddr)
|
||||
}
|
||||
|
||||
if SetNetDevDefault == true {
|
||||
if SetNetDev == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, ok := p.NetDevs[SetNetDev]; !ok {
|
||||
var nd node.NetDevEntry
|
||||
p.NetDevs[SetNetDev] = &nd
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting device as default\n", p.Id.Get(), SetNetDev)
|
||||
for _, dev := range p.NetDevs {
|
||||
// First clear all other devices that might be configured as default
|
||||
dev.Default.SetB(false)
|
||||
}
|
||||
p.NetDevs[SetNetDev].Default.SetB(true)
|
||||
}
|
||||
|
||||
err := nodeDB.ProfileUpdate(p)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
|
||||
@@ -29,6 +29,7 @@ var (
|
||||
SetGateway string
|
||||
SetHwaddr string
|
||||
SetNetDevDel bool
|
||||
SetNetDevDefault bool
|
||||
SetInit string
|
||||
SetRoot string
|
||||
)
|
||||
@@ -56,6 +57,7 @@ func init() {
|
||||
baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address")
|
||||
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device")
|
||||
baseCmd.PersistentFlags().BoolVar(&SetNetDevDefault, "netdefault", false, "Set this network to be default")
|
||||
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetAll, "all", "a", false, "Set all profiles")
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetForce, "force", "f", false, "Force configuration (even on error)")
|
||||
|
||||
Reference in New Issue
Block a user