initial checkin of node IPMI power control

This commit is contained in:
Shannon V. Davidson
2020-11-19 17:51:57 -06:00
parent 744126572c
commit 6b9fc7dc92
11 changed files with 317 additions and 40 deletions

View File

@@ -0,0 +1,58 @@
package poweron
import (
"github.com/hpcng/warewulf/internal/pkg/assets"
"github.com/hpcng/warewulf/internal/pkg/power"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var returnErr error = nil
var nodeList []assets.NodeInfo
if len(args) >= 1 {
//nodeList, _ = assets.SearchByName(args[0])
nodeList, _ = assets.SearchByNameList(args)
} else {
wwlog.Printf(wwlog.ERROR, "No requested nodes\n")
os.Exit(255)
}
if len(nodeList) == 0 {
wwlog.Printf(wwlog.ERROR, "No nodes found matching: '%s'\n", args[0])
os.Exit(255)
} else {
wwlog.Printf(wwlog.VERBOSE, "Found %d matching nodes for power command\n", len(nodeList))
}
for _, node := range nodeList {
if node.IpmiIpaddr == "" {
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.HostName)
continue
}
ipmiCmd := power.IPMI{
HostName: node.IpmiIpaddr,
User: "ADMIN",
Password: "ADMIN",
AuthType: "MD5",
}
out, err := ipmiCmd.PowerOn()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s: %s\n", node.HostName, out)
returnErr = err
continue
}
wwlog.Printf(wwlog.INFO, "%s: %s\n", node.HostName, out)
}
return returnErr
}

View File

@@ -0,0 +1,19 @@
package poweron
import (
"github.com/spf13/cobra"
)
var (
powerCmd = &cobra.Command{
Use: "poweron",
Short: "power on node(s)",
Long: "turn power on for one or more nodes",
RunE: CobraRunE,
}
)
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return powerCmd
}