Building set commands for nodes and groups and templating out CLI further

This commit is contained in:
Gregory Kurtzer
2020-11-21 01:48:38 -08:00
parent 982816b474
commit 1d1a02b305
14 changed files with 305 additions and 39 deletions

View File

@@ -0,0 +1,22 @@
package add
import (
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed opening node database: %s\n", err)
os.Exit(1)
}
nodeDB.AddGroup(args[0])
nodeDB.Persist()
return nil
}

View File

@@ -0,0 +1,25 @@
package add
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "add",
Short: "Add a new node group",
Long: "Add a new node group ",
RunE: CobraRunE,
}
SetVnfs string
SetKernel string
// SetGroupLevel bool
)
func init() {
baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)")
baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,8 @@
package list
import "github.com/spf13/cobra"
func CobraRunE(cmd *cobra.Command, args []string) error {
return nil
}

View File

@@ -0,0 +1,20 @@
package list
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "list",
Short: "List group configurations",
Long: "List group configurations ",
RunE: CobraRunE,
}
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,27 @@
package group
import (
"github.com/hpcng/warewulf/internal/app/wwctl/group/add"
"github.com/hpcng/warewulf/internal/app/wwctl/group/list"
"github.com/hpcng/warewulf/internal/app/wwctl/group/set"
"github.com/spf13/cobra"
)
var (
baseCmd = &cobra.Command{
Use: "group",
Short: "Group management",
Long: "Management of group settings and power management",
}
)
func init() {
baseCmd.AddCommand(list.GetCommand())
baseCmd.AddCommand(set.GetCommand())
baseCmd.AddCommand(add.GetCommand())
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,8 @@
package set
import "github.com/spf13/cobra"
func CobraRunE(cmd *cobra.Command, args []string) error {
return nil
}

View File

@@ -0,0 +1,25 @@
package set
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "set",
Short: "Set group configurations",
Long: "Set group configurations ",
RunE: CobraRunE,
}
SetVnfs string
SetKernel string
// SetGroupLevel bool
)
func init() {
baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)")
baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,22 @@
package add
import (
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed to open node database: %s\n", err)
os.Exit(1)
}
nodeDB.AddNode(args[0], args[1])
nodeDB.Persist()
return nil
}

View File

@@ -0,0 +1,20 @@
package add
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "add",
Short: "Add new node",
Long: "Add new node ",
RunE: CobraRunE,
}
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,6 +1,7 @@
package node
import (
"github.com/hpcng/warewulf/internal/app/wwctl/node/add"
"github.com/hpcng/warewulf/internal/app/wwctl/node/list"
"github.com/hpcng/warewulf/internal/app/wwctl/node/poweron"
"github.com/hpcng/warewulf/internal/app/wwctl/node/poweroff"
@@ -23,6 +24,7 @@ func init() {
baseCmd.AddCommand(powerstatus.GetCommand())
baseCmd.AddCommand(list.GetCommand())
baseCmd.AddCommand(set.GetCommand())
baseCmd.AddCommand(add.GetCommand())
}

View File

@@ -10,9 +10,10 @@ import (
func CobraRunE(cmd *cobra.Command, args []string) error {
var err error
var c int
var count int
var nodes []node.NodeInfo
n, err := node.New()
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
@@ -23,18 +24,35 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1)
}
if SetVnfs != "" {
fmt.Printf("Setting vnfs to: %s\n", SetVnfs)
c, err = n.SetNodeVal("n0000", "vnfs", SetVnfs)
if len(args) > 0 {
nodes, err = nodeDB.SearchByNameList(args)
} else {
cmd.Usage()
os.Exit(1)
}
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
for _, n := range nodes {
if SetVnfs != "" {
fmt.Printf("Setting vnfs to: %s\n", SetVnfs)
c, _ := nodeDB.SetNodeVal(n.Id, "vnfs", SetVnfs)
count += c
}
if SetKernel != "" {
fmt.Printf("Setting kernel to: %s\n", SetVnfs)
c, _ := nodeDB.SetNodeVal(n.Id, "kernel", SetKernel)
count += c
}
}
fmt.Printf("set count: %d\n", c)
fmt.Printf("set count: %d\n", count)
a, err := n.FindByHwaddr("00:0c:29:23:8b:48")
// nodeDB.AddGroup("moo")
nodeDB.AddNode("moo", "node01")
fmt.Printf("VNFS: %s\n", a.Vnfs)
//n.Persist()
nodeDB.Persist()
return nil
}

View File

@@ -10,11 +10,13 @@ var (
RunE: CobraRunE,
}
SetVnfs string
SetKernel string
// SetGroupLevel bool
)
func init() {
baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)")
baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -2,6 +2,7 @@ package wwctl
import (
"github.com/hpcng/warewulf/internal/app/wwctl/build"
"github.com/hpcng/warewulf/internal/app/wwctl/group"
"github.com/hpcng/warewulf/internal/app/wwctl/kernel"
"github.com/hpcng/warewulf/internal/app/wwctl/node"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay"
@@ -30,6 +31,7 @@ func init() {
rootCmd.AddCommand(vnfs.GetCommand())
rootCmd.AddCommand(node.GetCommand())
rootCmd.AddCommand(kernel.GetCommand())
rootCmd.AddCommand(group.GetCommand())
}