add CIDR format to warewulf.conf parse

Signed-off-by: Xu Yang <xyang@ciq.com>
This commit is contained in:
Xu Yang
2024-03-28 18:54:12 -06:00
committed by Jonathon Anderson
parent a9b226b3dd
commit b3d8f9ccc5
2 changed files with 14 additions and 0 deletions

View File

@@ -101,6 +101,19 @@ func (conf *RootConf) Parse(data []byte) error {
if len(conf.TFTP.IpxeBinaries) == 0 {
conf.TFTP.IpxeBinaries = defIpxe
}
// check whether ip addr is CIDR type and configure related fields as required
if ip, network, err := net.ParseCIDR(conf.Ipaddr); err == nil {
conf.Ipaddr = ip.String()
if conf.Network == "" {
conf.Network = network.IP.String()
}
if conf.Netmask == "" {
mask := network.Mask
conf.Netmask = fmt.Sprintf("%d.%d.%d.%d", mask[0], mask[1], mask[2], mask[3])
}
}
return nil
}