Files
warewulf/internal/pkg/configure/dhcp.go
Jonathon Anderson 70292276e2 Rename BaseConf.New to BaseConf.Get
Since BaseConf.New could return a cached BaseConf, rather than always
constructing a new struct, I've renamed it to Get to more accurately
reflect its use. A new New() method is called by Get and always
initializes a new struct.

Signed-off-by: Jonathon Anderson <janderson@ciq.co>
2023-04-19 14:02:43 -06:00

52 lines
1.2 KiB
Go

package configure
import (
"fmt"
"os"
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/hpcng/warewulf/internal/pkg/util"
warewulfconf "github.com/hpcng/warewulf/internal/pkg/config"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
)
/*
Configures the dhcpd server, when show is set to false, else the
dhcp configuration is checked.
*/
func Dhcp() (err error) {
controller := warewulfconf.Get()
if !controller.Dhcp.Enabled {
wwlog.Info("This system is not configured as a Warewulf DHCP controller")
os.Exit(1)
}
if controller.Dhcp.RangeStart == "" {
wwlog.Error("Configuration is not defined: `dhcpd range start`")
os.Exit(1)
}
if controller.Dhcp.RangeEnd == "" {
wwlog.Error("Configuration is not defined: `dhcpd range end`")
os.Exit(1)
}
if controller.Warewulf.EnableHostOverlay {
err = overlay.BuildHostOverlay()
if err != nil {
wwlog.Warn("host overlay could not be built: %s", err)
}
} else {
wwlog.Info("host overlays are disabled, did not modify/create dhcpd configuration")
}
fmt.Printf("Enabling and restarting the DHCP services\n")
err = util.SystemdStart(controller.Dhcp.SystemdName)
if err != nil {
return errors.Wrap(err, "failed to start")
}
return
}