Merge pull request #1762 from anderbubble/wwbool-default-true
Add WWbool.BoolDefaultTrue()
This commit is contained in:
@@ -52,6 +52,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
- Don't use DHCP for interfaces attached to a bond. #1743
|
||||
- Wait until ignition has completed before trying to mount.
|
||||
- Fix timeout problem for wwclient. #1741
|
||||
- Fixed default "true" state of NetDev.OnBoot. #1754
|
||||
|
||||
### Removed
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwtype"
|
||||
)
|
||||
|
||||
@@ -74,7 +73,7 @@ func check(infoType reflect.Type, infoVal reflect.Value) (err error) {
|
||||
}
|
||||
|
||||
func checker(value string, valType string) (niceValue string, err error) {
|
||||
if valType == "" || value == "" || util.InSlice(wwtype.GetUnsetVerbs(), value) {
|
||||
if valType == "" || value == "" || wwtype.IsUnsetVerb(value) {
|
||||
return "", nil
|
||||
}
|
||||
switch valType {
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
package wwtype
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||
)
|
||||
|
||||
func GetUnsetVerbs() []string {
|
||||
return []string{"UNSET", "DELETE", "UNDEF", "undef", "--", "nil", "0.0.0.0"}
|
||||
return []string{"unset", "delete", "undef", "--", "nil", "0.0.0.0"}
|
||||
}
|
||||
|
||||
func IsUnsetVerb(value string) bool {
|
||||
return util.InSlice(GetUnsetVerbs(), strings.ToLower(value))
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||
)
|
||||
|
||||
// Simple string which can be converted to bool. Backend storage
|
||||
@@ -16,17 +14,38 @@ type WWbool string
|
||||
Transform the underlying string value to bool
|
||||
*/
|
||||
func (val WWbool) Bool() bool {
|
||||
str := string(val)
|
||||
if util.InSlice(GetUnsetVerbs(), str) {
|
||||
str := strings.ToLower(string(val))
|
||||
if IsUnsetVerb(str) {
|
||||
return false
|
||||
}
|
||||
if strings.ToLower(str) == "yes" {
|
||||
switch str {
|
||||
case "yes":
|
||||
return true
|
||||
case "no", "":
|
||||
return false
|
||||
}
|
||||
bval, err := strconv.ParseBool(str)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return bval
|
||||
}
|
||||
|
||||
func (val WWbool) BoolDefaultTrue() bool {
|
||||
str := strings.ToLower(string(val))
|
||||
if IsUnsetVerb(str) {
|
||||
return false
|
||||
}
|
||||
switch str {
|
||||
case "yes", "":
|
||||
return true
|
||||
case "no":
|
||||
return false
|
||||
}
|
||||
bval, err := strconv.ParseBool(str)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
if strings.ToLower(str) == "no" {
|
||||
return false
|
||||
}
|
||||
bval, _ := strconv.ParseBool(str)
|
||||
return bval
|
||||
}
|
||||
|
||||
@@ -34,7 +53,7 @@ func (val WWbool) Bool() bool {
|
||||
Set the string, only accept bool values like true, false, but also UNDEF
|
||||
*/
|
||||
func (val *WWbool) Set(str string) error {
|
||||
if util.InSlice(GetUnsetVerbs(), str) {
|
||||
if IsUnsetVerb(str) {
|
||||
// run the unset verb trough, will be filtered out later
|
||||
*val = WWbool(str)
|
||||
return nil
|
||||
|
||||
@@ -256,6 +256,7 @@ Filename: warewulf-bond0.conf
|
||||
id=bond0
|
||||
interface-name=bond0
|
||||
type=bond
|
||||
autoconnect=true
|
||||
[bond]
|
||||
downdelay=0
|
||||
miimon=100
|
||||
@@ -282,6 +283,7 @@ interface-name=en1
|
||||
type=ethernet
|
||||
master=bond0
|
||||
slave-type=bond
|
||||
autoconnect=true
|
||||
[ethernet]
|
||||
mac-address=e6:92:39:49:7b:03
|
||||
[ipv4]
|
||||
@@ -300,6 +302,7 @@ interface-name=en2
|
||||
type=ethernet
|
||||
master=bond0
|
||||
slave-type=bond
|
||||
autoconnect=true
|
||||
[ethernet]
|
||||
mac-address=9a:77:29:73:14:f1
|
||||
[ipv4]
|
||||
|
||||
@@ -10,9 +10,7 @@ type={{ default "ethernet" (lower $netdev.Type) }}
|
||||
master={{ $netdev.Tags.master }}
|
||||
slave-type=bond
|
||||
{{- end }}
|
||||
{{- if $netdev.OnBoot }}
|
||||
autoconnect=true
|
||||
{{- end }}
|
||||
autoconnect={{ $netdev.OnBoot.BoolDefaultTrue }}
|
||||
|
||||
{{- if eq (lower $netdev.Type) "bond" }}
|
||||
[bond]
|
||||
|
||||
@@ -54,6 +54,7 @@ writeFile: true
|
||||
Filename: default
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
auto wwnet0
|
||||
allow-hotplug wwnet0
|
||||
iface wwnet0 inet static
|
||||
address 192.168.3.21
|
||||
@@ -65,6 +66,7 @@ backupFile: true
|
||||
writeFile: true
|
||||
Filename: secondary
|
||||
# This file is autogenerated by warewulf
|
||||
auto wwnet1
|
||||
allow-hotplug wwnet1
|
||||
iface wwnet1 inet static
|
||||
address 192.168.3.22
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{- range $devname, $netdev := .ThisNode.NetDevs }}
|
||||
{{ file $devname }}
|
||||
# This file is autogenerated by warewulf
|
||||
{{- if $netdev.OnBoot }}
|
||||
{{- if $netdev.OnBoot.BoolDefaultTrue }}
|
||||
auto {{ $netdev.Device }}
|
||||
{{- end }}
|
||||
allow-hotplug {{ $netdev.Device }}
|
||||
|
||||
@@ -169,7 +169,7 @@ node methods in addition to its fields.
|
||||
- Tags:
|
||||
- NetDevs[default]:
|
||||
- Type:
|
||||
- OnBoot: true
|
||||
- OnBoot: true (true)
|
||||
- Device: wwnet0
|
||||
- Hwaddr: e6:92:39:49:7b:03
|
||||
- Ipaddr: 192.168.3.21
|
||||
@@ -182,7 +182,7 @@ node methods in addition to its fields.
|
||||
- Tags:
|
||||
- NetDevs[secondary]:
|
||||
- Type:
|
||||
- OnBoot: true
|
||||
- OnBoot: true (true)
|
||||
- Device: wwnet1
|
||||
- Hwaddr: 9a:77:29:73:14:f1
|
||||
- Ipaddr: 192.168.3.22
|
||||
|
||||
@@ -114,7 +114,7 @@ node methods in addition to its fields.
|
||||
{{- range $index, $netdev := .NetDevs }}
|
||||
- NetDevs[{{ $index }}]:
|
||||
- Type: {{ $netdev.Type }}
|
||||
- OnBoot: {{ $netdev.OnBoot }}
|
||||
- OnBoot: {{ $netdev.OnBoot }} ({{ $netdev.OnBoot.BoolDefaultTrue }})
|
||||
- Device: {{ $netdev.Device }}
|
||||
- Hwaddr: {{ $netdev.Hwaddr }}
|
||||
- Ipaddr: {{ $netdev.Ipaddr }}
|
||||
|
||||
@@ -57,6 +57,7 @@ IPADDR=192.168.3.21
|
||||
NETMASK=255.255.255.0
|
||||
GATEWAY=192.168.3.1
|
||||
HWADDR=e6:92:39:49:7b:03
|
||||
ONBOOT=true
|
||||
IPV6INIT=yes
|
||||
IPV6_AUTOCONF=yes
|
||||
IPV6_DEFROUTE=yes
|
||||
@@ -77,6 +78,7 @@ IPADDR=192.168.3.22
|
||||
NETMASK=255.255.255.0
|
||||
GATEWAY=192.168.3.1
|
||||
HWADDR=9a:77:29:73:14:f1
|
||||
ONBOOT=true
|
||||
IPV6INIT=yes
|
||||
IPV6_AUTOCONF=yes
|
||||
IPV6_DEFROUTE=yes
|
||||
@@ -202,6 +204,7 @@ BOOTPROTO=static
|
||||
DEVTIMEOUT=10
|
||||
IPADDR=192.168.3.110
|
||||
NETMASK=255.255.255.0
|
||||
ONBOOT=true
|
||||
IPV6INIT=yes
|
||||
IPV6_AUTOCONF=yes
|
||||
IPV6_DEFROUTE=yes
|
||||
@@ -217,6 +220,7 @@ NAME=en1
|
||||
BOOTPROTO=static
|
||||
DEVTIMEOUT=10
|
||||
HWADDR=e6:92:39:49:7b:03
|
||||
ONBOOT=true
|
||||
IPV6INIT=yes
|
||||
IPV6_AUTOCONF=yes
|
||||
IPV6_DEFROUTE=yes
|
||||
@@ -232,6 +236,7 @@ NAME=en2
|
||||
BOOTPROTO=static
|
||||
DEVTIMEOUT=10
|
||||
HWADDR=9a:77:29:73:14:f1
|
||||
ONBOOT=true
|
||||
IPV6INIT=yes
|
||||
IPV6_AUTOCONF=yes
|
||||
IPV6_DEFROUTE=yes
|
||||
@@ -266,6 +271,54 @@ backupFile: true
|
||||
writeFile: true
|
||||
Filename: route-untagged.conf
|
||||
# This file is autogenerated by warewulf
|
||||
`,
|
||||
},
|
||||
"ifcfg:ifcfg.ww (onBoot)": {
|
||||
nodes_conf: `
|
||||
nodes:
|
||||
node1:
|
||||
primary network: untagged
|
||||
network devices:
|
||||
untagged:
|
||||
onboot: false
|
||||
device: eth0
|
||||
tagged:
|
||||
onboot: true
|
||||
type: vlan
|
||||
device: eth0.902
|
||||
tags:
|
||||
route1: "192.168.1.0/24,192.168.2.254"
|
||||
`,
|
||||
args: []string{"--render", "node1", "ifcfg", "etc/sysconfig/network-scripts/ifcfg.ww"},
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: ifcfg-tagged.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
VLAN=yes
|
||||
DEVICE=eth0.902
|
||||
NAME=tagged
|
||||
BOOTPROTO=static
|
||||
DEVTIMEOUT=10
|
||||
ONBOOT=true
|
||||
IPV6INIT=yes
|
||||
IPV6_AUTOCONF=yes
|
||||
IPV6_DEFROUTE=yes
|
||||
IPV6_FAILURE_FATAL=no
|
||||
backupFile: true
|
||||
writeFile: true
|
||||
Filename: ifcfg-untagged.conf
|
||||
# This file is autogenerated by warewulf
|
||||
TYPE=Ethernet
|
||||
DEVICE=eth0
|
||||
NAME=untagged
|
||||
BOOTPROTO=static
|
||||
DEVTIMEOUT=10
|
||||
ONBOOT=false
|
||||
IPV6INIT=yes
|
||||
IPV6_AUTOCONF=yes
|
||||
IPV6_DEFROUTE=yes
|
||||
IPV6_FAILURE_FATAL=no
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -28,9 +28,7 @@ GATEWAY={{ $netdev.Gateway }}
|
||||
{{- if $netdev.Hwaddr }}
|
||||
HWADDR={{ $netdev.Hwaddr }}
|
||||
{{- end }}
|
||||
{{- if $netdev.OnBoot }}
|
||||
ONBOOT=true
|
||||
{{- end }}
|
||||
ONBOOT={{ $netdev.OnBoot.BoolDefaultTrue }}
|
||||
IPV6INIT=yes
|
||||
IPV6_AUTOCONF=yes
|
||||
IPV6_DEFROUTE=yes
|
||||
|
||||
@@ -66,7 +66,7 @@ This file is autogenerated by warewulf
|
||||
<name>wwnet0</name>
|
||||
<link-type>ethernet</link-type>
|
||||
<control>
|
||||
<mode>manual</mode>
|
||||
<mode>boot</mode>
|
||||
</control>
|
||||
<firewall/>
|
||||
<link/>
|
||||
@@ -101,7 +101,7 @@ This file is autogenerated by warewulf
|
||||
<name>wwnet1</name>
|
||||
<link-type>ethernet</link-type>
|
||||
<control>
|
||||
<mode>manual</mode>
|
||||
<mode>boot</mode>
|
||||
</control>
|
||||
<firewall/>
|
||||
<link/>
|
||||
|
||||
@@ -18,7 +18,7 @@ This file is autogenerated by warewulf
|
||||
<mtu>{{ $netdev.MTU }}</mtu>
|
||||
{{- end }}
|
||||
<control>
|
||||
<mode>{{ if $netdev.OnBoot }}boot{{ else }}manual{{ end }}</mode>
|
||||
<mode>{{ if $netdev.OnBoot.BoolDefaultTrue }}boot{{ else }}manual{{ end }}</mode>
|
||||
</control>
|
||||
<firewall/>
|
||||
<link/>
|
||||
|
||||
@@ -7,4 +7,4 @@ WWIPMI_NETMASK="{{$.Ipmi.Netmask}}"
|
||||
WWIPMI_GATEWAY="{{$.Ipmi.Gateway}}"
|
||||
WWIPMI_USER="{{$.Ipmi.UserName}}"
|
||||
WWIPMI_PASSWORD="{{$.Ipmi.Password}}"
|
||||
WWIPMI_WRITE="{{$.Ipmi.Write}}"
|
||||
WWIPMI_WRITE="{{$.Ipmi.Write.Bool}}"
|
||||
|
||||
Reference in New Issue
Block a user