From 32b4bb74cc62d7828bedd8e6e3e37f097450f402 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Fri, 3 Mar 2023 14:07:26 +0100 Subject: [PATCH] added `wwctl genconfig warewulfconf print` Signed-off-by: Christian Goll --- cmd/config_defaults/config_defaults.go | 26 ------------------ internal/app/wwctl/genconf/root.go | 2 ++ .../wwctl/genconf/warewulfconf/print/main.go | 19 +++++++++++++ .../wwctl/genconf/warewulfconf/print/root.go | 22 +++++++++++++++ .../app/wwctl/genconf/warewulfconf/root.go | 27 +++++++++++++++++++ internal/pkg/warewulfconf/datastructure.go | 2 +- 6 files changed, 71 insertions(+), 27 deletions(-) delete mode 100644 cmd/config_defaults/config_defaults.go create mode 100644 internal/app/wwctl/genconf/warewulfconf/print/main.go create mode 100644 internal/app/wwctl/genconf/warewulfconf/print/root.go create mode 100644 internal/app/wwctl/genconf/warewulfconf/root.go diff --git a/cmd/config_defaults/config_defaults.go b/cmd/config_defaults/config_defaults.go deleted file mode 100644 index 70068c90..00000000 --- a/cmd/config_defaults/config_defaults.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -// Regenerates the default configuration files -// Keeps the current content and adds missing default values -// Won't create a new file, but will update a blank file - -//TODO: Add nodes.conf - -import ( - "fmt" - "github.com/hpcng/warewulf/internal/pkg/warewulfconf" -) - -func main() { - tmpConf, err := warewulfconf.New() - if err != nil { - fmt.Println(err) - return - } - - err = tmpConf.Persist() - if err != nil { - fmt.Println(err) - return - } -} diff --git a/internal/app/wwctl/genconf/root.go b/internal/app/wwctl/genconf/root.go index 5f9a8a4b..1a979be4 100644 --- a/internal/app/wwctl/genconf/root.go +++ b/internal/app/wwctl/genconf/root.go @@ -5,6 +5,7 @@ import ( "github.com/hpcng/warewulf/internal/app/wwctl/genconf/dfaults" "github.com/hpcng/warewulf/internal/app/wwctl/genconf/man" "github.com/hpcng/warewulf/internal/app/wwctl/genconf/reference" + "github.com/hpcng/warewulf/internal/app/wwctl/genconf/warewulfconf" "github.com/spf13/cobra" ) @@ -25,6 +26,7 @@ func init() { baseCmd.AddCommand(man.GetCommand()) baseCmd.AddCommand(reference.GetCommand()) baseCmd.AddCommand(dfaults.GetCommand()) + baseCmd.AddCommand(warewulfconf.GetCommand()) } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/genconf/warewulfconf/print/main.go b/internal/app/wwctl/genconf/warewulfconf/print/main.go new file mode 100644 index 00000000..2efca477 --- /dev/null +++ b/internal/app/wwctl/genconf/warewulfconf/print/main.go @@ -0,0 +1,19 @@ +package print + +import ( + "fmt" + + "github.com/hpcng/warewulf/internal/pkg/warewulfconf" + "github.com/spf13/cobra" + "gopkg.in/yaml.v2" +) + +func CobraRunE(cmd *cobra.Command, args []string) (err error) { + conf := warewulfconf.New() + buffer, err := yaml.Marshal(&conf) + if err != nil { + return + } + fmt.Println(string(buffer)) + return +} diff --git a/internal/app/wwctl/genconf/warewulfconf/print/root.go b/internal/app/wwctl/genconf/warewulfconf/print/root.go new file mode 100644 index 00000000..8bd53f6f --- /dev/null +++ b/internal/app/wwctl/genconf/warewulfconf/print/root.go @@ -0,0 +1,22 @@ +package print + +import ( + "github.com/spf13/cobra" +) + +var ( + baseCmd = &cobra.Command{ + Use: "print", + Short: "print wareweulf.conf", + Long: "This command prints the actual used warewulf.conf, can be used to create an empty valid warewulf.conf", + RunE: CobraRunE, + Args: cobra.ExactArgs(0), + } +) + +func init() { +} + +func GetCommand() *cobra.Command { + return baseCmd +} diff --git a/internal/app/wwctl/genconf/warewulfconf/root.go b/internal/app/wwctl/genconf/warewulfconf/root.go new file mode 100644 index 00000000..856c2f70 --- /dev/null +++ b/internal/app/wwctl/genconf/warewulfconf/root.go @@ -0,0 +1,27 @@ +package warewulfconf + +import ( + "github.com/hpcng/warewulf/internal/app/wwctl/genconf/warewulfconf/print" + "github.com/spf13/cobra" +) + +var ( + baseCmd = &cobra.Command{ + Use: "warewulfconf", + Short: "access warewulf.conf", + Long: "Commands for accessing the actual used warewulf.conf", + Args: cobra.ExactArgs(0), + Aliases: []string{"cnf"}, + } + ListFull bool + WWctlRoot *cobra.Command +) + +func init() { + baseCmd.AddCommand(print.GetCommand()) +} + +// GetRootCommand returns the root cobra.Command for the application. +func GetCommand() *cobra.Command { + return baseCmd +} diff --git a/internal/pkg/warewulfconf/datastructure.go b/internal/pkg/warewulfconf/datastructure.go index ad0921a1..ff12e4cb 100644 --- a/internal/pkg/warewulfconf/datastructure.go +++ b/internal/pkg/warewulfconf/datastructure.go @@ -17,7 +17,7 @@ type ControllerConf struct { Dhcp *DhcpConf `yaml:"dhcp"` Tftp *TftpConf `yaml:"tftp"` Nfs *NfsConf `yaml:"nfs"` - MountsContainer []*MountEntry `yaml:"container mounts"` + MountsContainer []*MountEntry `yaml:"container mounts" default:"[{\"source\": \"/etc/resolv.conf\", \"dest\": \"/etc/resolv.conf\"}]"` current bool }