diff --git a/internal/app/wwctl/node/export/main.go b/internal/app/wwctl/node/export/main.go new file mode 100644 index 00000000..1645683c --- /dev/null +++ b/internal/app/wwctl/node/export/main.go @@ -0,0 +1,26 @@ +package export + +import ( + "fmt" + + apinode "github.com/hpcng/warewulf/internal/pkg/api/node" + "github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1" + "github.com/spf13/cobra" +) + +func CobraRunE(cmd *cobra.Command, args []string) error { + if len(args) == 0 { + args = append(args, ".*") + } + filterList := wwapiv1.NodeList{ + Output: args, + } + nodeListMsg := apinode.FilteredNodes(&filterList) + /* + nodeMap := make(map[string]*node.NodeConf) + // got proper yaml back + _ = yaml.Unmarshal([]byte(nodeListMsg.NodeConfMapYaml), nodeMap) + */ + fmt.Println(nodeListMsg.NodeConfMapYaml) + return nil +} diff --git a/internal/app/wwctl/node/export/root.go b/internal/app/wwctl/node/export/root.go new file mode 100644 index 00000000..ce423830 --- /dev/null +++ b/internal/app/wwctl/node/export/root.go @@ -0,0 +1,38 @@ +package export + +import ( + "github.com/hpcng/warewulf/internal/pkg/node" + "github.com/spf13/cobra" +) + +var ( + baseCmd = &cobra.Command{ + DisableFlagsInUseLine: true, + Use: "export NODENAME", + Short: "Export nodes as yaml to stdout", + Long: "This command exports the given nodes as yaml to stdout.", + RunE: CobraRunE, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) != 0 { + return nil, cobra.ShellCompDirectiveNoFileComp + } + + nodeDB, _ := node.New() + nodes, _ := nodeDB.FindAllNodes() + var node_names []string + for _, node := range nodes { + node_names = append(node_names, node.Id.Get()) + } + return node_names, cobra.ShellCompDirectiveNoFileComp + }, + } + NoHeader bool +) + +func init() { +} + +// GetRootCommand returns the root cobra.Command for the application. +func GetCommand() *cobra.Command { + return baseCmd +} diff --git a/internal/app/wwctl/node/root.go b/internal/app/wwctl/node/root.go index 27ca7a92..ffc1f80b 100644 --- a/internal/app/wwctl/node/root.go +++ b/internal/app/wwctl/node/root.go @@ -5,6 +5,7 @@ import ( "github.com/hpcng/warewulf/internal/app/wwctl/node/console" "github.com/hpcng/warewulf/internal/app/wwctl/node/delete" "github.com/hpcng/warewulf/internal/app/wwctl/node/edit" + "github.com/hpcng/warewulf/internal/app/wwctl/node/export" "github.com/hpcng/warewulf/internal/app/wwctl/node/imprt" "github.com/hpcng/warewulf/internal/app/wwctl/node/list" "github.com/hpcng/warewulf/internal/app/wwctl/node/sensors" @@ -34,6 +35,7 @@ func init() { baseCmd.AddCommand(nodestatus.GetCommand()) baseCmd.AddCommand(edit.GetCommand()) baseCmd.AddCommand(imprt.GetCommand()) + baseCmd.AddCommand(export.GetCommand()) } // GetRootCommand returns the root cobra.Command for the application.