Merge pull request #419 from jcsiadal/nodefault

Renames instances of "Default" to "Primary" in netdev source code
This commit is contained in:
Christian Goll
2022-05-12 11:58:47 +02:00
committed by GitHub
15 changed files with 36 additions and 33 deletions

View File

@@ -71,7 +71,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
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 %s\n", node.Id.Get(), name+":ONBOOT", netdev.OnBoot.Source(), netdev.OnBoot.PrintB())
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":DEFAULT", netdev.Default.Source(), netdev.Default.PrintB())
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":PRIMARY", netdev.Primary.Source(), netdev.Primary.PrintB())
for keyname, key := range netdev.Tags {
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":TAG["+keyname+"]", key.Source(), key.Print())
}

View File

@@ -188,13 +188,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
SetNetOnBoot = "yes"
for _, n := range n.NetDevs {
if n.Default.GetB() {
if n.Primary.GetB() {
def = false
}
}
if def {
SetNetDefault = "yes"
SetNetPrimary = "yes"
}
}
@@ -276,24 +276,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
if SetNetDefault != "" {
if SetNetPrimary != "" {
if SetNetName == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n")
os.Exit(1)
}
if SetNetDefault == "yes" || SetNetDefault == "y" || SetNetDefault == "1" || SetNetDefault == "true" {
if SetNetPrimary == "yes" || SetNetPrimary == "y" || SetNetPrimary == "1" || SetNetPrimary == "true" {
// Set all other devices to non-default
for _, n := range n.NetDevs {
n.Default.SetB(false)
n.Primary.SetB(false)
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting PRIMARY\n", n.Id.Get(), SetNetName)
n.NetDevs[SetNetName].Default.SetB(true)
n.NetDevs[SetNetName].Primary.SetB(true)
} else {
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Unsetting PRIMARY\n", n.Id.Get(), SetNetName)
n.NetDevs[SetNetName].Default.SetB(false)
n.NetDevs[SetNetName].Primary.SetB(false)
}
}

View File

@@ -44,7 +44,7 @@ var (
SetHwaddr string
SetType string
SetNetOnBoot string
SetNetDefault string
SetNetPrimary string
SetNetDevDel bool
SetClusterName string
SetIpxe string
@@ -143,7 +143,7 @@ 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().StringVar(&SetNetOnBoot, "onboot", "", "Enable/disable device (yes/no)")
baseCmd.PersistentFlags().StringVar(&SetNetDefault, "primary", "", "Enable/disable device as primary (yes/no)")
baseCmd.PersistentFlags().StringVar(&SetNetPrimary, "primary", "", "Enable/disable device as primary (yes/no)")
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device")
baseCmd.PersistentFlags().StringSliceVar(&SetNetTags, "nettag", []string{}, "Define custom tag to network device (key=value)")

View File

@@ -62,7 +62,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
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 %s\n", profile.Id.Get(), name+":ONBOOT", netdev.OnBoot.PrintB())
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name+":DEFAULT", netdev.Default.PrintB())
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name+":PRIMARY", netdev.Primary.PrintB())
for keyname, key := range netdev.Tags {
fmt.Printf("%-20s %-18s %-12s %s\n", profile.Id.Get(), name+":TAG["+keyname+"]", key.Source(), key.Print())
}

View File

@@ -211,24 +211,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
if SetNetDefault != "" {
if SetNetPrimary != "" {
if SetNetName == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n")
os.Exit(1)
}
if SetNetDefault == "yes" || SetNetDefault == "y" || SetNetDefault == "1" || SetNetDefault == "true" {
if SetNetPrimary == "yes" || SetNetPrimary == "y" || SetNetPrimary == "1" || SetNetPrimary == "true" {
// Set all other networks to non-default
for _, n := range p.NetDevs {
n.Default.SetB(false)
n.Primary.SetB(false)
}
wwlog.Printf(wwlog.VERBOSE, "Profile: %s:%s, Setting PRIMARY\n", p.Id.Get(), SetNetName)
p.NetDevs[SetNetName].Default.SetB(true)
p.NetDevs[SetNetName].Primary.SetB(true)
} else {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s:%s, Unsetting PRIMARY\n", p.Id.Get(), SetNetName)
p.NetDevs[SetNetName].Default.SetB(false)
p.NetDevs[SetNetName].Primary.SetB(false)
}
}

View File

@@ -57,7 +57,7 @@ var (
SetGateway string
SetType string
SetNetOnBoot string
SetNetDefault string
SetNetPrimary string
SetNetDevDel bool
SetDiscoverable bool
SetUndiscoverable bool
@@ -118,7 +118,7 @@ func init() {
baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure")
baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Set the node's network device")
baseCmd.PersistentFlags().StringVar(&SetNetDefault, "primary", "", "Enable/disable device as primary (yes/no)")
baseCmd.PersistentFlags().StringVar(&SetNetPrimary, "primary", "", "Enable/disable device as primary (yes/no)")
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(&SetType, "type", "T", "", "Set the node's network device type")

View File

@@ -166,10 +166,11 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
n.NetDevs[devname].Gateway.Set(netdev.Gateway)
n.NetDevs[devname].Type.Set(netdev.Type)
n.NetDevs[devname].OnBoot.Set(netdev.OnBoot)
n.NetDevs[devname].Default.Set(netdev.Default)
// for just one netdev, it is always the default
n.NetDevs[devname].Primary.Set(netdev.Primary)
n.NetDevs[devname].Primary.Set(netdev.Default) // backwards compatibility
// for just one netdev, it is always the primary
if len(node.NetDevs) == 1 {
n.NetDevs[devname].Default.Set("true")
n.NetDevs[devname].Primary.Set("true")
}
n.NetDevs[devname].Tags = make(map[string]*Entry)
for keyname, key := range netdev.Tags {
@@ -253,7 +254,7 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
n.NetDevs[devname].Gateway.SetAlt(netdev.Gateway, p)
n.NetDevs[devname].Type.SetAlt(netdev.Type, p)
n.NetDevs[devname].OnBoot.SetAlt(netdev.OnBoot, p)
n.NetDevs[devname].Default.SetAlt(netdev.Default, p)
n.NetDevs[devname].Primary.SetAlt(netdev.Primary, p)
if len(netdev.Tags) != 0 {
for keyname, key := range netdev.Tags {
if _, ok := n.NetDevs[devname].Tags[keyname]; !ok {
@@ -376,7 +377,8 @@ func (config *nodeYaml) FindAllProfiles() ([]NodeInfo, error) {
p.NetDevs[devname].Gateway.Set(netdev.Gateway)
p.NetDevs[devname].Type.Set(netdev.Type)
p.NetDevs[devname].OnBoot.Set(netdev.OnBoot)
p.NetDevs[devname].Default.Set(netdev.Default)
p.NetDevs[devname].Primary.Set(netdev.Primary)
p.NetDevs[devname].Primary.Set(netdev.Default) // backwards compatibility
// The following should not be set in a profile.
if netdev.Ipaddr != "" {

View File

@@ -75,7 +75,8 @@ type NetDevs struct {
Prefix string `yaml:"prefix,omitempty"`
Netmask string `yaml:"netmask,omitempty"`
Gateway string `yaml:"gateway,omitempty"`
Default string `yaml:"primary,omitempty"`
Primary string `yaml:"primary,omitempty"`
Default string `yaml:"default,omitempty"` /* backward compatibility */
Tags map[string]string `yaml:"tags,omitempty"`
}
@@ -149,7 +150,7 @@ type NetDevEntry struct {
Prefix Entry
Netmask Entry
Gateway Entry
Default Entry
Primary Entry
Tags map[string]*Entry
}

View File

@@ -101,7 +101,7 @@ func (config *nodeYaml) NodeUpdate(node NodeInfo) error {
config.Nodes[nodeID].NetDevs[devname].Gateway = netdev.Gateway.GetReal()
config.Nodes[nodeID].NetDevs[devname].Type = netdev.Type.GetReal()
config.Nodes[nodeID].NetDevs[devname].OnBoot = netdev.OnBoot.GetReal()
config.Nodes[nodeID].NetDevs[devname].Default = netdev.Default.GetReal()
config.Nodes[nodeID].NetDevs[devname].Primary = netdev.Primary.GetReal()
config.Nodes[nodeID].NetDevs[devname].Tags = make(map[string]string)
for keyname, key := range netdev.Tags {
if key.GetReal() != "" {
@@ -207,7 +207,7 @@ func (config *nodeYaml) ProfileUpdate(profile NodeInfo) error {
config.NodeProfiles[profileID].NetDevs[devname].Gateway = netdev.Gateway.GetReal()
config.NodeProfiles[profileID].NetDevs[devname].Type = netdev.Type.GetReal()
config.NodeProfiles[profileID].NetDevs[devname].OnBoot = netdev.OnBoot.GetReal()
config.NodeProfiles[profileID].NetDevs[devname].Default = netdev.Default.GetReal()
config.NodeProfiles[profileID].NetDevs[devname].Primary = netdev.Primary.GetReal()
config.NodeProfiles[profileID].NetDevs[devname].Tags = make(map[string]string)
for key := range netdev.Tags {
config.NodeProfiles[profileID].NetDevs[devname].Tags[key] = netdev.Tags[key].GetReal()

View File

@@ -261,7 +261,7 @@ func BuildOverlayIndir(nodeInfo node.NodeInfo, overlayNames []string, outputDir
tstruct.NetDevs[devname].Gateway = netdev.Gateway.Get()
tstruct.NetDevs[devname].Type = netdev.Type.Get()
tstruct.NetDevs[devname].OnBoot = netdev.OnBoot.Get()
tstruct.NetDevs[devname].Default = netdev.Default.Get()
tstruct.NetDevs[devname].Primary = netdev.Primary.Get()
mask := net.IPMask(net.ParseIP(netdev.Netmask.Get()).To4())
ipaddr := net.ParseIP(netdev.Ipaddr.Get()).To4()
netaddr := net.IPNet{IP: ipaddr, Mask: mask}