A bunch of changes including reworking the assets -> node API

This commit is contained in:
Gregory Kurtzer
2020-11-20 17:59:06 -08:00
parent dd2d83788a
commit 221e71b384
28 changed files with 367 additions and 291 deletions

View File

@@ -0,0 +1,59 @@
package list
import (
"fmt"
"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 {
var err error
var nodes []node.NodeInfo
n, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
if len(args) > 0 {
nodes, err = n.SearchByNameList(args)
} else {
nodes, err = n.FindAllNodes()
}
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
if ShowNet == true {
fmt.Printf("%-22s %-10s %-20s %-16s %-16s %-16s %s\n", "NODE NAME", "DEVICE", "HWADDR", "IPADDR", "NETMASK", "GATEWAY", "TYPE")
for _, node := range nodes {
for name, dev := range node.NetDevs {
fmt.Printf("%-22s %-10s %-20s %-16s %-16s %-16s %s\n", node.Fqdn, name, dev.Hwaddr, dev.Ipaddr, dev.Netmask, dev.Gateway, dev.Type)
}
}
} else if ShowIpmi == true {
fmt.Printf("%-22s %-16s %-20s %-20s\n", "NODE NAME", "IPMI IPADDR", "IPMI USERNAME", "IPMI PASSWORD")
for _, node := range nodes {
fmt.Printf("%-22s %-16s %-20s %-20s\n", node.Fqdn, node.IpmiIpaddr, node.IpmiUserName, node.IpmiPassword)
}
} else {
fmt.Printf("%-22s %-30s %-30s %-16s %-16s\n", "NODE NAME", "KERNEL NAME", "VNFS IMAGE", "SYSTEM OVERLAY", "RUNTIME OVERLAY")
for _, node := range nodes {
fmt.Printf("%-22s %-30s %-30s %-16s %-16s\n", node.Fqdn, node.KernelVersion, node.Vnfs, node.SystemOverlay, node.RuntimeOverlay)
}
}
return nil
}

View File

@@ -0,0 +1,25 @@
package list
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "list",
Short: "List all nodes",
Long: "List all nodes",
RunE: CobraRunE,
}
ShowNet bool
ShowIpmi bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&ShowNet, "net", "n", false, "Show node network configurations")
baseCmd.PersistentFlags().BoolVarP(&ShowIpmi, "ipmi", "i", false, "Show node IPMI configurations")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,7 +1,7 @@
package poweroff
import (
"github.com/hpcng/warewulf/internal/pkg/assets"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/power"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
@@ -9,14 +9,17 @@ import (
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var returnErr error = nil
var nodeList []node.NodeInfo
var nodeList []assets.NodeInfo
n, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
if len(args) >= 1 {
//nodeList, _ = assets.SearchByName(args[0])
nodeList, _ = assets.SearchByNameList(args)
nodeList, _ = n.SearchByNameList(args)
} else {
wwlog.Printf(wwlog.ERROR, "No requested nodes\n")
os.Exit(255)

View File

@@ -1,7 +1,7 @@
package poweron
import (
"github.com/hpcng/warewulf/internal/pkg/assets"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/power"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
@@ -9,14 +9,17 @@ import (
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var returnErr error = nil
var nodeList []node.NodeInfo
var nodeList []assets.NodeInfo
n, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
if len(args) >= 1 {
//nodeList, _ = assets.SearchByName(args[0])
nodeList, _ = assets.SearchByNameList(args)
nodeList, _ = n.SearchByNameList(args)
} else {
wwlog.Printf(wwlog.ERROR, "No requested nodes\n")
os.Exit(255)

View File

@@ -1,7 +1,7 @@
package powerstatus
import (
"github.com/hpcng/warewulf/internal/pkg/assets"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/power"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
@@ -9,14 +9,17 @@ import (
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var returnErr error = nil
var nodeList []node.NodeInfo
var nodeList []assets.NodeInfo
n, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
if len(args) >= 1 {
//nodeList, _ = assets.SearchByName(args[0])
nodeList, _ = assets.SearchByNameList(args)
nodeList, _ = n.SearchByNameList(args)
} else {
wwlog.Printf(wwlog.ERROR, "No requested nodes\n")
os.Exit(255)

View File

@@ -1,6 +1,7 @@
package node
import (
"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"
"github.com/hpcng/warewulf/internal/app/wwctl/node/powerstatus"
@@ -19,6 +20,8 @@ func init() {
baseCmd.AddCommand(poweron.GetCommand())
baseCmd.AddCommand(poweroff.GetCommand())
baseCmd.AddCommand(powerstatus.GetCommand())
baseCmd.AddCommand(list.GetCommand())
}
// GetRootCommand returns the root cobra.Command for the application.