added make_defaults to wwctl genconfig defaults

Signed-off-by: Christian Goll <cgoll@suse.de>
This commit is contained in:
Christian Goll
2023-03-02 19:44:48 +01:00
parent 1a19cfda63
commit 29a6d39a24
4 changed files with 17 additions and 13 deletions

View File

@@ -19,7 +19,13 @@ var cachedConf ControllerConf
var ConfigFile string
/*
Get the configFile location from the os.ev if set
*/
func init() {
if ConfigFile == "" {
ConfigFile = os.Getenv("WARWULFCONF")
}
if ConfigFile == "" {
ConfigFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/warewulf.conf")
}
@@ -51,7 +57,7 @@ func New() (ControllerConf, error) {
wwlog.Debug("Opening Warewulf configuration file: %s", ConfigFile)
data, err := os.ReadFile(ConfigFile)
if err != nil {
wwlog.Warn("Error reading Warewulf configuration file")
wwlog.Warn("Error reading Warewulf configuration file, falling back on defaults")
}
wwlog.Debug("Unmarshaling the Warewulf configuration")
@@ -71,12 +77,12 @@ func New() (ControllerConf, error) {
localIp := conn.LocalAddr().(*net.UDPAddr)
if ret.Ipaddr == "" {
ret.Ipaddr = localIp.IP.String()
wwlog.Warn("IP address is not configured in warewulfd.conf, using %s", ret.Ipaddr)
wwlog.Verbose("IP address is not configured in warewulfd.conf, using %s", ret.Ipaddr)
}
if ret.Netmask == "" {
mask := localIp.IP.DefaultMask()
ret.Netmask = fmt.Sprintf("%d.%d.%d.%d", mask[0], mask[1], mask[2], mask[3])
wwlog.Warn("Netmask address is not configured in warewulfd.conf, using %s", ret.Netmask)
wwlog.Verbose("Netmask address is not configured in warewulfd.conf, using %s", ret.Netmask)
}
}

View File

@@ -2,7 +2,6 @@ package warewulfconf
import (
"github.com/creasty/defaults"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
)
@@ -80,13 +79,9 @@ func (s *NfsConf) Unmarshal(unmarshal func(interface{}) error) error {
}
func init() {
if !util.IsFile(ConfigFile) {
wwlog.Error("Configuration file not found: %s", ConfigFile)
// fail silently as this also called by bash_completion
}
_, err := New()
if err != nil {
wwlog.Error("Could not read Warewulf configuration file: %s", err)
wwlog.Warn("Could not get any Warewulf configuration: %s", err)
}
}