diff --git a/internal/pkg/warewulfconf/constructors.go b/internal/pkg/warewulfconf/constructors.go index 93bce4d8..9d83271f 100644 --- a/internal/pkg/warewulfconf/constructors.go +++ b/internal/pkg/warewulfconf/constructors.go @@ -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 } diff --git a/internal/pkg/warewulfconf/datastructure.go b/internal/pkg/warewulfconf/datastructure.go index 55509bc4..ed15aa95 100644 --- a/internal/pkg/warewulfconf/datastructure.go +++ b/internal/pkg/warewulfconf/datastructure.go @@ -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"`