add simple node export
This commit is contained in:
26
internal/app/wwctl/node/export/main.go
Normal file
26
internal/app/wwctl/node/export/main.go
Normal file
@@ -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
|
||||
}
|
||||
38
internal/app/wwctl/node/export/root.go
Normal file
38
internal/app/wwctl/node/export/root.go
Normal file
@@ -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
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user