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 61960b6c8c
commit bb894df100
4 changed files with 17 additions and 13 deletions

View File

@@ -11,7 +11,6 @@ var (
Args: cobra.NoArgs,
Aliases: []string{"dfaults"},
}
Zsh bool
)
func init() {

View File

@@ -13,6 +13,7 @@ import (
"github.com/hpcng/warewulf/internal/app/wwctl/ssh"
"github.com/hpcng/warewulf/internal/app/wwctl/version"
"github.com/hpcng/warewulf/internal/pkg/help"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
)
@@ -27,9 +28,10 @@ var (
SilenceUsage: true,
SilenceErrors: true,
}
verboseArg bool
DebugFlag bool
LogLevel int
verboseArg bool
DebugFlag bool
LogLevel int
WarewulfConfArg string
)
func init() {
@@ -37,6 +39,7 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&DebugFlag, "debug", "d", false, "Run with debugging messages enabled.")
rootCmd.PersistentFlags().IntVar(&LogLevel, "loglevel", wwlog.INFO, "Set log level to given string")
_ = rootCmd.PersistentFlags().MarkHidden("loglevel")
rootCmd.PersistentFlags().StringVar(&WarewulfConfArg, "warewulfconf", "", "Set the warewulf configuration file")
rootCmd.SetUsageTemplate(help.UsageTemplate)
rootCmd.SetHelpTemplate(help.HelpTemplate)
@@ -69,5 +72,6 @@ func rootPersistentPreRunE(cmd *cobra.Command, args []string) error {
if LogLevel != wwlog.INFO {
wwlog.SetLogLevel(LogLevel)
}
warewulfconf.ConfigFile = WarewulfConfArg
return nil
}

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)
}
}