Add network as part of the warewulfconf (figure it out if undef)

This commit is contained in:
Gregory Kurtzer
2020-12-19 21:03:01 -08:00
parent 154f90a972
commit 5e8ef337d0
2 changed files with 19 additions and 0 deletions

View File

@@ -2,9 +2,11 @@ package warewulfconf
import (
"fmt"
"github.com/brotherpowers/ipsubnet"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"gopkg.in/yaml.v2"
"io/ioutil"
"net"
)
func New() (ControllerConf, error) {
@@ -23,6 +25,22 @@ func New() (ControllerConf, error) {
return ret, err
}
if ret.Ipaddr == "" {
wwlog.Printf(wwlog.WARN, "IP address is not configured in warewulfd.conf\n")
}
if ret.Netmask == "" {
wwlog.Printf(wwlog.WARN, "Netmask is not configured in warewulfd.conf\n")
}
if ret.Network == "" {
mask := net.IPMask(net.ParseIP(ret.Netmask).To4())
size, _ := mask.Size()
sub := ipsubnet.SubnetCalculator(ret.Ipaddr, size)
ret.Network = sub.GetNetworkPortion()
}
if ret.Warewulf.Port == 0 {
ret.Warewulf.Port = 9873
}

View File

@@ -12,6 +12,7 @@ type ControllerConf struct {
Comment string `yaml:"comment"`
Ipaddr string `yaml:"ipaddr"`
Netmask string `yaml:"netmask"`
Network string `yaml:"network,omitempty"`
Fqdn string `yaml:"fqdn,omitempty"`
Warewulf *WarewulfConf `yaml:"warewulf"`
Dhcp *DhcpConf `yaml:"dhcp"`