diff --git a/internal/app/wwctl/node/add/main.go b/internal/app/wwctl/node/add/main.go index c3f88fb0..807b33ac 100644 --- a/internal/app/wwctl/node/add/main.go +++ b/internal/app/wwctl/node/add/main.go @@ -103,6 +103,26 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } + if SetType != "" { + if SetNetDev == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") + os.Exit(1) + } + + if _, ok := n.NetDevs[SetNetDev]; !ok { + wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev) + os.Exit(1) + } + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Type to: %s\n", n.Id, SetNetDev, SetType) + + n.NetDevs[SetNetDev].Type.Set(SetType) + err := nodeDB.NodeUpdate(n) + if err != nil { + wwlog.Printf(wwlog.ERROR, "%s\n", err) + os.Exit(1) + } + } + if SetDiscoverable == true { wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting node to discoverable\n", n.Id.Get()) diff --git a/internal/app/wwctl/node/add/root.go b/internal/app/wwctl/node/add/root.go index fdc264d1..e7ba130a 100644 --- a/internal/app/wwctl/node/add/root.go +++ b/internal/app/wwctl/node/add/root.go @@ -17,6 +17,7 @@ var ( SetNetmask string SetGateway string SetHwaddr string + SetType string SetDiscoverable bool ) @@ -28,6 +29,7 @@ func init() { 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(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address") + baseCmd.PersistentFlags().StringVarP(&SetType, "type", "T", "", "Set the node's network device type") baseCmd.PersistentFlags().BoolVar(&SetDiscoverable, "discoverable", false, "Make this node discoverable") } diff --git a/internal/app/wwctl/node/set/main.go b/internal/app/wwctl/node/set/main.go index 6355d3f5..6628c01d 100644 --- a/internal/app/wwctl/node/set/main.go +++ b/internal/app/wwctl/node/set/main.go @@ -221,6 +221,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Id.Get(), SetNetDev, SetGateway) n.NetDevs[SetNetDev].Gateway.Set(SetGateway) } + if SetHwaddr != "" { if SetNetDev == "" { wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") @@ -235,6 +236,37 @@ 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 SetType != "" { + 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 HW address to: %s\n", n.Id.Get(), SetNetDev, SetType) + n.NetDevs[SetNetDev].Type.Set(SetType) + } + + if SetType != "" { + 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 Type %s\n", n.Id.Get(), SetNetDev, SetType) + n.NetDevs[SetNetDev].Type.Set(SetType) + } + if SetNetDevDefault == true { if SetNetDev == "" { wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index 7663a9b9..ff28b19d 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -19,6 +19,7 @@ var ( SetNetmask string SetGateway string SetHwaddr string + SetType string SetNetDevDel bool SetNetDevDefault bool SetClusterName string @@ -67,6 +68,7 @@ func init() { 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(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address") + baseCmd.PersistentFlags().StringVarP(&SetType, "type", "T", "", "Set the node's network device type") baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device") baseCmd.PersistentFlags().BoolVar(&SetNetDevDefault, "netdefault", false, "Set this network to be default") diff --git a/internal/app/wwctl/profile/set/main.go b/internal/app/wwctl/profile/set/main.go index 11547f42..c80bed74 100644 --- a/internal/app/wwctl/profile/set/main.go +++ b/internal/app/wwctl/profile/set/main.go @@ -215,6 +215,21 @@ func CobraRunE(cmd *cobra.Command, args []string) error { p.NetDevs[SetNetDev].Hwaddr.Set(SetHwaddr) } + if SetType != "" { + 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, "Profile '%s': Setting HW address to: %s:%s\n", p.Id.Get(), SetNetDev, SetType) + p.NetDevs[SetNetDev].Type.Set(SetType) + } + if SetNetDevDefault == true { if SetNetDev == "" { wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index 5562ccb3..9eadcb8f 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -29,6 +29,7 @@ var ( SetNetmask string SetGateway string SetHwaddr string + SetType string SetNetDevDel bool SetNetDevDefault bool SetInit string @@ -57,6 +58,7 @@ func init() { 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(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address") + baseCmd.PersistentFlags().StringVarP(&SetType, "type", "T", "", "Set the node's network device type") baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device") baseCmd.PersistentFlags().BoolVar(&SetNetDevDefault, "netdefault", false, "Set this network to be default")