From 1370932cd3208c59c64aaa62c3a33420cfe0f469 Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Sat, 23 Oct 2021 07:12:57 -0700 Subject: [PATCH] Introduction of `netname` functionality for network devices --- internal/app/wwctl/node/add/main.go | 118 +++++----- internal/app/wwctl/node/add/root.go | 3 +- internal/app/wwctl/node/list/main.go | 3 +- internal/app/wwctl/node/set/main.go | 115 ++++++---- internal/app/wwctl/node/set/root.go | 9 +- internal/app/wwctl/profile/list/main.go | 1 - internal/app/wwctl/profile/set/main.go | 206 ++++++++++-------- internal/app/wwctl/profile/set/root.go | 9 +- internal/pkg/node/constructors.go | 11 +- internal/pkg/node/datastructure.go | 8 +- internal/pkg/node/modifiers.go | 6 +- internal/pkg/overlay/overlay.go | 2 +- overlays/runtime/default/etc/hosts.ww | 2 +- .../etc/network/interfaces.d/default.ww | 7 + .../default/etc/network/interfaces.d/eth0.ww | 10 - .../network-scripts/ifcfg-default.ww | 13 ++ .../sysconfig/network-scripts/ifcfg-eth0.ww | 10 - .../systemd/network/10-persistent-net.link.ww | 2 +- ...ifcfg-eth0.xml.ww => ifcfg-default.xml.ww} | 6 +- 19 files changed, 301 insertions(+), 240 deletions(-) create mode 100644 overlays/system/default/etc/network/interfaces.d/default.ww delete mode 100644 overlays/system/default/etc/network/interfaces.d/eth0.ww create mode 100644 overlays/system/default/etc/sysconfig/network-scripts/ifcfg-default.ww delete mode 100644 overlays/system/default/etc/sysconfig/network-scripts/ifcfg-eth0.ww rename overlays/system/default/etc/wicked/ifconfig/{ifcfg-eth0.xml.ww => ifcfg-default.xml.ww} (75%) diff --git a/internal/app/wwctl/node/add/main.go b/internal/app/wwctl/node/add/main.go index 0902be93..3b33c3bd 100644 --- a/internal/app/wwctl/node/add/main.go +++ b/internal/app/wwctl/node/add/main.go @@ -34,102 +34,110 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } + if SetNetDev != "" { + if SetNetName == "" { + return errors.New("you must include the '--netname' option") + } + + if _, ok := n.NetDevs[SetNetName]; !ok { + var netdev node.NetDevEntry + n.NetDevs[SetNetName] = &netdev + } + + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Device to: %s\n", n.Id.Get(), SetNetName, SetNetDev) + + n.NetDevs[SetNetName].Device.Set(SetNetDev) + n.NetDevs[SetNetName].OnBoot.SetB(true) + + // err := nodeDB.NodeUpdate(n) + // if err != nil { + // return errors.Wrap(err, "failed to update nodedb") + // } + } + if SetIpaddr != "" { - if SetNetDev == "" { - return errors.New("you must include the '--netdev' option") + if SetNetName == "" { + return errors.New("you must include the '--netname' option") } NewIpaddr := util.IncrementIPv4(SetIpaddr, count) - if _, ok := n.NetDevs[SetNetDev]; !ok { + if _, ok := n.NetDevs[SetNetName]; !ok { var netdev node.NetDevEntry - n.NetDevs[SetNetDev] = &netdev + n.NetDevs[SetNetName] = &netdev } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Id.Get(), SetNetDev, NewIpaddr) + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Id.Get(), SetNetName, NewIpaddr) + + n.NetDevs[SetNetName].Ipaddr.Set(NewIpaddr) + n.NetDevs[SetNetName].OnBoot.SetB(true) - n.NetDevs[SetNetDev].Ipaddr.Set(NewIpaddr) - n.NetDevs[SetNetDev].Default.SetB(true) - err := nodeDB.NodeUpdate(n) - if err != nil { - return errors.Wrap(err, "failed to update nodedb") - } } + if SetNetmask != "" { - if SetNetDev == "" { - return errors.New("you must include the '--netdev' option") + if SetNetName == "" { + return errors.New("you must include the '--netname' option") } - if _, ok := n.NetDevs[SetNetDev]; !ok { - return errors.New("network device does not exist: " + SetNetDev) + if _, ok := n.NetDevs[SetNetName]; !ok { + return errors.New("network device does not exist: " + SetNetName) } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Id.Get(), SetNetDev, SetNetmask) + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Id.Get(), SetNetName, SetNetmask) - n.NetDevs[SetNetDev].Netmask.Set(SetNetmask) - err := nodeDB.NodeUpdate(n) - if err != nil { - return errors.Wrap(err, "failed to update nodedb") - } + n.NetDevs[SetNetName].Netmask.Set(SetNetmask) } + if SetGateway != "" { - if SetNetDev == "" { - return errors.New("you must include the '--netdev' option") + if SetNetName == "" { + return errors.New("you must include the '--netname' option") } - if _, ok := n.NetDevs[SetNetDev]; !ok { - return errors.New("network device does not exist: " + SetNetDev) + if _, ok := n.NetDevs[SetNetName]; !ok { + return errors.New("network device does not exist: " + SetNetName) } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Id.Get(), SetNetDev, SetGateway) + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Id.Get(), SetNetName, SetGateway) - n.NetDevs[SetNetDev].Gateway.Set(SetGateway) - err := nodeDB.NodeUpdate(n) - if err != nil { - return errors.Wrap(err, "failed to update nodedb") - } + n.NetDevs[SetNetName].Gateway.Set(SetGateway) } + if SetHwaddr != "" { - if SetNetDev == "" { - return errors.New("you must include the '--netdev' option") + if SetNetName == "" { + return errors.New("you must include the '--netname' option") } - if _, ok := n.NetDevs[SetNetDev]; !ok { - return errors.New("network device does not exist: " + SetNetDev) + if _, ok := n.NetDevs[SetNetName]; !ok { + return errors.New("network device does not exist: " + SetNetName) } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Id.Get(), SetNetDev, SetHwaddr) + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Id.Get(), SetNetName, SetHwaddr) - n.NetDevs[SetNetDev].Hwaddr.Set(SetHwaddr) - err := nodeDB.NodeUpdate(n) - if err != nil { - return errors.Wrap(err, "failed to update nodedb") - } + n.NetDevs[SetNetName].Hwaddr.Set(SetHwaddr) + n.NetDevs[SetNetName].OnBoot.SetB(true) } if SetType != "" { - if SetNetDev == "" { - return errors.New("you must include the '--netdev' option") + if SetNetName == "" { + return errors.New("you must include the '--netname' option") } - if _, ok := n.NetDevs[SetNetDev]; !ok { - return errors.New("network device does not exist: " + SetNetDev) + if _, ok := n.NetDevs[SetNetName]; !ok { + return errors.New("network device does not exist: " + SetNetName) } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Type to: %s\n", n.Id.Get(), SetNetDev, SetType) + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Type to: %s\n", n.Id.Get(), SetNetName, SetType) - n.NetDevs[SetNetDev].Type.Set(SetType) - err := nodeDB.NodeUpdate(n) - if err != nil { - return errors.Wrap(err, "failed to update nodedb") - } + n.NetDevs[SetNetName].Type.Set(SetType) } if SetDiscoverable { wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting node to discoverable\n", n.Id.Get()) n.Discoverable.SetB(true) - err := nodeDB.NodeUpdate(n) - if err != nil { - return errors.Wrap(err, "failed to update nodedb") - } } + + err = nodeDB.NodeUpdate(n) + if err != nil { + return errors.Wrap(err, "failed to update nodedb") + } + count++ } diff --git a/internal/app/wwctl/node/add/root.go b/internal/app/wwctl/node/add/root.go index c4c716b3..e748d582 100644 --- a/internal/app/wwctl/node/add/root.go +++ b/internal/app/wwctl/node/add/root.go @@ -11,6 +11,7 @@ var ( Args: cobra.MinimumNArgs(1), } SetClusterName string + SetNetName string SetNetDev string SetIpaddr string SetNetmask string @@ -22,6 +23,7 @@ var ( func init() { baseCmd.PersistentFlags().StringVarP(&SetClusterName, "cluster", "c", "", "Set the node's cluster name") + baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure") baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "eth0", "Define the network device to configure") 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") @@ -29,7 +31,6 @@ func init() { 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") - } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/node/list/main.go b/internal/app/wwctl/node/list/main.go index 31b81eba..ea9c6301 100644 --- a/internal/app/wwctl/node/list/main.go +++ b/internal/app/wwctl/node/list/main.go @@ -56,12 +56,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error { fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiInterface", node.IpmiInterface.Source(), node.IpmiInterface.Print()) for name, netdev := range node.NetDevs { + fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":DEVICE", netdev.Device.Source(), netdev.Device.Print()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":HWADDR", netdev.Hwaddr.Source(), netdev.Hwaddr.Print()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":IPADDR", netdev.Ipaddr.Source(), netdev.Ipaddr.Print()) 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()) + fmt.Printf("%-20s %-18s %-12s %t\n", node.Id.Get(), name+":ONBOOT", netdev.OnBoot.Source(), netdev.OnBoot.PrintB()) } for keyname, key := range node.Keys { diff --git a/internal/app/wwctl/node/set/main.go b/internal/app/wwctl/node/set/main.go index 7f066163..4fd0bd37 100644 --- a/internal/app/wwctl/node/set/main.go +++ b/internal/app/wwctl/node/set/main.go @@ -163,110 +163,129 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } - if SetNetDevDel { - if SetNetDev == "" { - wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") + if SetNetDev != "" { + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' 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) + if _, ok := n.NetDevs[SetNetName]; !ok { + var nd node.NetDevEntry + n.NetDevs[SetNetName] = &nd } - wwlog.Printf(wwlog.VERBOSE, "Node: %s, Deleting network device: %s\n", n.Id.Get(), SetNetDev) - delete(n.NetDevs, 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) } + if SetIpaddr != "" { - if SetNetDev == "" { - wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") os.Exit(1) } - if _, ok := n.NetDevs[SetNetDev]; !ok { + if _, ok := n.NetDevs[SetNetName]; !ok { var nd node.NetDevEntry - n.NetDevs[SetNetDev] = &nd + n.NetDevs[SetNetName] = &nd } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Id.Get(), SetNetDev, SetIpaddr) - n.NetDevs[SetNetDev].Ipaddr.Set(SetIpaddr) + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Id.Get(), SetNetName, SetIpaddr) + n.NetDevs[SetNetName].Ipaddr.Set(SetIpaddr) } + if SetNetmask != "" { - if SetNetDev == "" { - wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") os.Exit(1) } - if _, ok := n.NetDevs[SetNetDev]; !ok { + if _, ok := n.NetDevs[SetNetName]; !ok { var nd node.NetDevEntry - n.NetDevs[SetNetDev] = &nd + n.NetDevs[SetNetName] = &nd } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Id.Get(), SetNetDev, SetNetmask) - n.NetDevs[SetNetDev].Netmask.Set(SetNetmask) + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Id.Get(), SetNetName, SetNetmask) + n.NetDevs[SetNetName].Netmask.Set(SetNetmask) } + if SetGateway != "" { - if SetNetDev == "" { - wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") os.Exit(1) } - if _, ok := n.NetDevs[SetNetDev]; !ok { + if _, ok := n.NetDevs[SetNetName]; !ok { var nd node.NetDevEntry - n.NetDevs[SetNetDev] = &nd + n.NetDevs[SetNetName] = &nd } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Id.Get(), SetNetDev, SetGateway) - n.NetDevs[SetNetDev].Gateway.Set(SetGateway) + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Id.Get(), SetNetName, SetGateway) + n.NetDevs[SetNetName].Gateway.Set(SetGateway) } if SetHwaddr != "" { - if SetNetDev == "" { - wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") os.Exit(1) } - if _, ok := n.NetDevs[SetNetDev]; !ok { + if _, ok := n.NetDevs[SetNetName]; !ok { var nd node.NetDevEntry - n.NetDevs[SetNetDev] = &nd + n.NetDevs[SetNetName] = &nd } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Id.Get(), SetNetDev, SetHwaddr) - n.NetDevs[SetNetDev].Hwaddr.Set(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) } if SetType != "" { - if SetNetDev == "" { - wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") os.Exit(1) } - if _, ok := n.NetDevs[SetNetDev]; !ok { + if _, ok := n.NetDevs[SetNetName]; !ok { var nd node.NetDevEntry - n.NetDevs[SetNetDev] = &nd + n.NetDevs[SetNetName] = &nd } - wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Type %s\n", n.Id.Get(), SetNetDev, SetType) - n.NetDevs[SetNetDev].Type.Set(SetType) + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Type %s\n", n.Id.Get(), SetNetName, SetType) + n.NetDevs[SetNetName].Type.Set(SetType) } - if SetNetDevDefault { - if SetNetDev == "" { - wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") + if SetNetOnBoot != "" { + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") os.Exit(1) } - if _, ok := n.NetDevs[SetNetDev]; !ok { + if _, ok := n.NetDevs[SetNetName]; !ok { var nd node.NetDevEntry - n.NetDevs[SetNetDev] = &nd + n.NetDevs[SetNetName] = &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) + if SetNetOnBoot == "yes" || SetNetOnBoot == "y" || SetNetOnBoot == "1" || SetNetOnBoot == "true" { + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting ONBOOT\n", n.Id.Get(), SetNetName) + n.NetDevs[SetNetName].OnBoot.SetB(true) + } else { + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Unsetting ONBOOT\n", n.Id.Get(), SetNetName) + n.NetDevs[SetNetName].OnBoot.SetB(false) } - n.NetDevs[SetNetDev].Default.SetB(true) + } + + if SetNetDevDel { + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") + os.Exit(1) + } + + if _, ok := n.NetDevs[SetNetName]; !ok { + wwlog.Printf(wwlog.ERROR, "Network device name doesn't exist: %s\n", SetNetName) + os.Exit(1) + } + + wwlog.Printf(wwlog.VERBOSE, "Node: %s, Deleting network device: %s\n", n.Id.Get(), SetNetName) + delete(n.NetDevs, SetNetName) } if SetValue != "" { diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index 86ea559e..527e7d8d 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -36,14 +36,15 @@ var ( SetContainer string SetKernel string SetKernelArgs string + SetNetName string SetNetDev string SetIpaddr string SetNetmask string SetGateway string SetHwaddr string SetType string + SetNetOnBoot string SetNetDevDel bool - SetNetDevDefault bool SetClusterName string SetIpxe string SetRuntimeOverlay string @@ -126,14 +127,16 @@ func init() { }); err != nil { log.Println(err) } - baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Define the network device to configure") + baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure") + baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Define the network device") 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(&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().StringVar(&SetNetOnBoot, "onboot", "yes", "Enable/disable device (yes/no)") + 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().StringVarP(&SetKey, "key", "k", "", "Define custom key") baseCmd.PersistentFlags().BoolVar(&SetKeyDel, "keydel", false, "Delete custom key") diff --git a/internal/app/wwctl/profile/list/main.go b/internal/app/wwctl/profile/list/main.go index f43a2046..20e2dcd6 100644 --- a/internal/app/wwctl/profile/list/main.go +++ b/internal/app/wwctl/profile/list/main.go @@ -54,7 +54,6 @@ 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()) } for keyname, key := range profile.Keys { diff --git a/internal/app/wwctl/profile/set/main.go b/internal/app/wwctl/profile/set/main.go index 667111f7..2ef3b549 100644 --- a/internal/app/wwctl/profile/set/main.go +++ b/internal/app/wwctl/profile/set/main.go @@ -130,9 +130,119 @@ func CobraRunE(cmd *cobra.Command, args []string) error { p.Discoverable.SetB(false) } + if SetNetDev != "" { + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") + 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) + p.NetDevs[SetNetName].Device.Set(SetNetDev) + } + + if SetIpaddr != "" { + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") + 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) + p.NetDevs[SetNetName].Ipaddr.Set(SetIpaddr) + } + + if SetNetmask != "" { + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") + 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) + p.NetDevs[SetNetName].Netmask.Set(SetNetmask) + } + + if SetGateway != "" { + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") + 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) + p.NetDevs[SetNetName].Gateway.Set(SetGateway) + } + + if SetHwaddr != "" { + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") + 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) + p.NetDevs[SetNetName].Hwaddr.Set(SetHwaddr) + } + + if SetType != "" { + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") + 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) + p.NetDevs[SetNetName].Type.Set(SetType) + } + + if SetNetOnBoot != "" { + if SetNetName == "" { + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") + 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" { + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting ONBOOT\n", p.Id.Get(), SetNetName) + p.NetDevs[SetNetName].OnBoot.SetB(true) + } else { + wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Unsetting ONBOOT\n", p.Id.Get(), SetNetName) + p.NetDevs[SetNetName].OnBoot.SetB(false) + } + } + if SetNetDevDel { if SetNetDev == "" { - wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") + wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") os.Exit(1) } @@ -145,100 +255,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { delete(p.NetDevs, SetNetDev) } - if SetIpaddr != "" { - 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 IP address to: %s:%s\n", p.Id.Get(), SetNetDev, SetHwaddr) - p.NetDevs[SetNetDev].Ipaddr.Set(SetIpaddr) - } - - if SetNetmask != "" { - 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 netmask to: %s:%s\n", p.Id.Get(), SetNetDev, SetHwaddr) - p.NetDevs[SetNetDev].Netmask.Set(SetNetmask) - } - - if SetGateway != "" { - 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 gateway to: %s:%s\n", p.Id.Get(), SetNetDev, SetHwaddr) - p.NetDevs[SetNetDev].Gateway.Set(SetGateway) - } - - if SetHwaddr != "" { - 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, SetHwaddr) - 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 { - 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:%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) - } - if SetValue != "" { if SetKey == "" { wwlog.Printf(wwlog.ERROR, "You must include the '--key/-k' option\n") diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index cb0b765a..42e55403 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -48,14 +48,15 @@ var ( SetIpmiUsername string SetIpmiPassword string SetIpmiInterface string + SetNetName string SetNetDev string SetIpaddr string SetNetmask string SetGateway string SetHwaddr string SetType string + SetNetOnBoot string SetNetDevDel bool - SetNetDevDefault bool SetDiscoverable bool SetUndiscoverable bool SetInit string @@ -108,14 +109,16 @@ func init() { 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' if empty)") - baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Define the network device to configure") + baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure") + baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Define the network device") 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(&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().StringVar(&SetNetOnBoot, "onboot", "yes", "Enable/disable device (yes/no)") + 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().StringVarP(&SetKey, "key", "k", "", "Define custom key") baseCmd.PersistentFlags().BoolVar(&SetKeyDel, "keydel", false, "Delete custom key") diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index 596a6b43..e4e2ff8d 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -90,12 +90,14 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) { n.NetDevs[devname] = &netdev } + n.NetDevs[devname].Name.Set(devname) + n.NetDevs[devname].Device.Set(netdev.Device) n.NetDevs[devname].Ipaddr.Set(netdev.Ipaddr) n.NetDevs[devname].Netmask.Set(netdev.Netmask) n.NetDevs[devname].Hwaddr.Set(netdev.Hwaddr) n.NetDevs[devname].Gateway.Set(netdev.Gateway) n.NetDevs[devname].Type.Set(netdev.Type) - n.NetDevs[devname].Default.SetB(netdev.Default) + n.NetDevs[devname].OnBoot.SetB(netdev.OnBoot) } for keyname, key := range node.Keys { @@ -142,12 +144,13 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) { } wwlog.Printf(wwlog.DEBUG, "Updating profile (%s) netdev: %s\n", p, devname) + n.NetDevs[devname].Device.SetAlt(netdev.Device, p) n.NetDevs[devname].Ipaddr.SetAlt(netdev.Ipaddr, p) n.NetDevs[devname].Netmask.SetAlt(netdev.Netmask, p) n.NetDevs[devname].Hwaddr.SetAlt(netdev.Hwaddr, p) n.NetDevs[devname].Gateway.SetAlt(netdev.Gateway, p) n.NetDevs[devname].Type.SetAlt(netdev.Type, p) - n.NetDevs[devname].Default.SetAltB(netdev.Default, p) + n.NetDevs[devname].OnBoot.SetAltB(netdev.OnBoot, p) } for keyname, key := range config.NodeProfiles[p].Keys { @@ -213,12 +216,14 @@ func (config *nodeYaml) FindAllProfiles() ([]NodeInfo, error) { wwlog.Printf(wwlog.DEBUG, "Updating profile netdev: %s\n", devname) + p.NetDevs[devname].Name.Set(devname) + p.NetDevs[devname].Device.Set(netdev.Device) p.NetDevs[devname].Ipaddr.Set(netdev.Ipaddr) p.NetDevs[devname].Netmask.Set(netdev.Netmask) p.NetDevs[devname].Hwaddr.Set(netdev.Hwaddr) p.NetDevs[devname].Gateway.Set(netdev.Gateway) p.NetDevs[devname].Type.Set(netdev.Type) - p.NetDevs[devname].Default.SetB(netdev.Default) + p.NetDevs[devname].OnBoot.SetB(netdev.OnBoot) } for keyname, key := range profile.Keys { diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index a7f55ae6..5d605bf9 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -42,8 +42,10 @@ type NodeConf struct { } type NetDevs struct { + Name string Type string `yaml:"type,omitempty"` - Default bool `yaml:"default"` + OnBoot bool `yaml:"onboot"` + Device string `yaml:"device"` Hwaddr string Ipaddr string IpCIDR string @@ -93,8 +95,10 @@ type NodeInfo struct { } type NetDevEntry struct { + Name Entry Type Entry `yaml:"type,omitempty"` - Default Entry `yaml:"default"` + OnBoot Entry `yaml:"onboot"` + Device Entry `yaml:"device"` Hwaddr Entry Ipaddr Entry IpCIDR Entry diff --git a/internal/pkg/node/modifiers.go b/internal/pkg/node/modifiers.go index bdde2e9f..ea238d49 100644 --- a/internal/pkg/node/modifiers.go +++ b/internal/pkg/node/modifiers.go @@ -84,12 +84,13 @@ func (config *nodeYaml) NodeUpdate(node NodeInfo) error { var newdev NetDevs config.Nodes[nodeID].NetDevs[devname] = &newdev + config.Nodes[nodeID].NetDevs[devname].Device = netdev.Device.GetReal() config.Nodes[nodeID].NetDevs[devname].Ipaddr = netdev.Ipaddr.GetReal() config.Nodes[nodeID].NetDevs[devname].Netmask = netdev.Netmask.GetReal() config.Nodes[nodeID].NetDevs[devname].Hwaddr = netdev.Hwaddr.GetReal() config.Nodes[nodeID].NetDevs[devname].Gateway = netdev.Gateway.GetReal() config.Nodes[nodeID].NetDevs[devname].Type = netdev.Type.GetReal() - config.Nodes[nodeID].NetDevs[devname].Default = netdev.Default.GetRealB() + config.Nodes[nodeID].NetDevs[devname].OnBoot = netdev.OnBoot.GetRealB() } for keyname, key := range node.Keys { @@ -169,12 +170,13 @@ func (config *nodeYaml) ProfileUpdate(profile NodeInfo) error { var newdev NetDevs config.NodeProfiles[profileID].NetDevs[devname] = &newdev + config.NodeProfiles[profileID].NetDevs[devname].Device = netdev.Device.GetReal() config.NodeProfiles[profileID].NetDevs[devname].Ipaddr = netdev.Ipaddr.GetReal() config.NodeProfiles[profileID].NetDevs[devname].Netmask = netdev.Netmask.GetReal() config.NodeProfiles[profileID].NetDevs[devname].Hwaddr = netdev.Hwaddr.GetReal() config.NodeProfiles[profileID].NetDevs[devname].Gateway = netdev.Gateway.GetReal() config.NodeProfiles[profileID].NetDevs[devname].Type = netdev.Type.GetReal() - config.NodeProfiles[profileID].NetDevs[devname].Default = netdev.Default.GetRealB() + config.NodeProfiles[profileID].NetDevs[devname].OnBoot = netdev.OnBoot.GetRealB() } for keyname, key := range profile.Keys { diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index 9ba7625d..f865982b 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -160,12 +160,12 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error { for devname, netdev := range n.NetDevs { var nd node.NetDevs t.NetDevs[devname] = &nd + t.NetDevs[devname].Name = devname t.NetDevs[devname].Hwaddr = netdev.Hwaddr.Get() t.NetDevs[devname].Ipaddr = netdev.Ipaddr.Get() t.NetDevs[devname].Netmask = netdev.Netmask.Get() t.NetDevs[devname].Gateway = netdev.Gateway.Get() t.NetDevs[devname].Type = netdev.Type.Get() - t.NetDevs[devname].Default = netdev.Default.GetB() mask := net.IPMask(net.ParseIP(netdev.Netmask.Get()).To4()) ipaddr := net.ParseIP(netdev.Ipaddr.Get()).To4() netaddr := net.IPNet{IP: ipaddr, Mask: mask} diff --git a/overlays/runtime/default/etc/hosts.ww b/overlays/runtime/default/etc/hosts.ww index 12f61397..b4641eae 100644 --- a/overlays/runtime/default/etc/hosts.ww +++ b/overlays/runtime/default/etc/hosts.ww @@ -5,7 +5,7 @@ {{range $node := $.AllNodes}} # Entry for {{$node.Id.Get}} {{- range $devname, $netdev := $node.NetDevs}} -{{- if $netdev.Default}} +{{- if eq $netdev.Name.Get "default"}} {{$netdev.Ipaddr.Get}} {{$node.Id.Get}} {{- else}} {{$netdev.Ipaddr.Get}} {{$node.Id.Get}}-{{$devname}} diff --git a/overlays/system/default/etc/network/interfaces.d/default.ww b/overlays/system/default/etc/network/interfaces.d/default.ww new file mode 100644 index 00000000..851dfd21 --- /dev/null +++ b/overlays/system/default/etc/network/interfaces.d/default.ww @@ -0,0 +1,7 @@ +auto {{.NetDevs.default.Device}} +allow-hotplug {{.NetDevs.default.Device}} +iface {{.NetDevs.default.Device}} inet static + address {{.NetDevs.default.Ipaddr}} + netmask {{.NetDevs.default.Netmask}} + gateway {{.NetDevs.default.Gateway}} + up ifmetric {{.NetDevs.default.Device}} 30 diff --git a/overlays/system/default/etc/network/interfaces.d/eth0.ww b/overlays/system/default/etc/network/interfaces.d/eth0.ww deleted file mode 100644 index 8240b54f..00000000 --- a/overlays/system/default/etc/network/interfaces.d/eth0.ww +++ /dev/null @@ -1,10 +0,0 @@ -auto eth0 -allow-hotplug eth0 -iface eth0 inet static - address {{.NetDevs.eth0.Ipaddr}} - netmask {{.NetDevs.eth0.Netmask}} - gateway {{.NetDevs.eth0.Gateway}} - up ifmetric eth0 30 - - - diff --git a/overlays/system/default/etc/sysconfig/network-scripts/ifcfg-default.ww b/overlays/system/default/etc/sysconfig/network-scripts/ifcfg-default.ww new file mode 100644 index 00000000..ea81303e --- /dev/null +++ b/overlays/system/default/etc/sysconfig/network-scripts/ifcfg-default.ww @@ -0,0 +1,13 @@ +DEVICE={{.NetDevs.default.Device}} +NAME=default +BOOTPROTO=static +DEVTIMEOUT=10 +IPADDR={{$.NetDevs.default.Ipaddr}} +NETMASK={{$.NetDevs.default.Netmask}} +GATEWAY={{$.NetDevs.default.Gateway}} +HWADDR={{$.NetDevs.default.Hwaddr}} +{{if eq $.NetDevs.default.OnBoot "true"}} +ONBOOT=yes +{{else}} +ONBOOT=no +{{end}} \ No newline at end of file diff --git a/overlays/system/default/etc/sysconfig/network-scripts/ifcfg-eth0.ww b/overlays/system/default/etc/sysconfig/network-scripts/ifcfg-eth0.ww deleted file mode 100644 index a7e03bcf..00000000 --- a/overlays/system/default/etc/sysconfig/network-scripts/ifcfg-eth0.ww +++ /dev/null @@ -1,10 +0,0 @@ -DEVICE=eth0 -NAME=eth0 -IPADDR={{$.NetDevs.eth0.Ipaddr}} -NETMASK={{$.NetDevs.eth0.Netmask}} -GATEWAY={{$.NetDevs.eth0.Gateway}} -HWADDR={{$.NetDevs.eth0.Hwaddr}} -BOOTPROTO=static -ONBOOT=yes -DEVTIMEOUT=10 - diff --git a/overlays/system/default/etc/systemd/network/10-persistent-net.link.ww b/overlays/system/default/etc/systemd/network/10-persistent-net.link.ww index c2fa29ec..7dafb682 100644 --- a/overlays/system/default/etc/systemd/network/10-persistent-net.link.ww +++ b/overlays/system/default/etc/systemd/network/10-persistent-net.link.ww @@ -1,7 +1,7 @@ # /etc/systemd/network/10-persistent-net.link {{range $devname, $netdev := .NetDevs}} -{{- if $netdev.Default}} +{{- if eq $netdev.Name "default"}} [Match] MACAddress={{$netdev.Hwaddr}} [Link] diff --git a/overlays/system/default/etc/wicked/ifconfig/ifcfg-eth0.xml.ww b/overlays/system/default/etc/wicked/ifconfig/ifcfg-default.xml.ww similarity index 75% rename from overlays/system/default/etc/wicked/ifconfig/ifcfg-eth0.xml.ww rename to overlays/system/default/etc/wicked/ifconfig/ifcfg-default.xml.ww index 6e7f7600..f1aa84e8 100644 --- a/overlays/system/default/etc/wicked/ifconfig/ifcfg-eth0.xml.ww +++ b/overlays/system/default/etc/wicked/ifconfig/ifcfg-default.xml.ww @@ -1,5 +1,5 @@ - eth0 + {{.NetDevs.default.Device}} boot @@ -11,11 +11,11 @@
- {{$.NetDevs.eth0.IpCIDR}} + {{$.NetDevs.default.IpCIDR}}
- {{$.NetDevs.eth0.Gateway}} + {{$.NetDevs.default.Gateway}}