initial checkin of node IPMI power control
This commit is contained in:
58
internal/app/wwctl/node/poweron/power.go
Normal file
58
internal/app/wwctl/node/poweron/power.go
Normal 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
|
||||
}
|
||||
19
internal/app/wwctl/node/poweron/root.go
Normal file
19
internal/app/wwctl/node/poweron/root.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user