Files
warewulf/internal/app/wwctl/node/console/power.go
Jonathon Anderson 22910958b5 Replace all instances of wwlog.Printf
wwlog provides named loggers for each level, which requires
less code and is clearer than wwlog.Printf. The code has
included a mix of both, but this commit consolidates existing
code on the per-level functions.

Signed-off-by: Jonathon Anderson <janderson@ciq.co>
2022-09-11 08:00:23 -06:00

73 lines
1.4 KiB
Go

package console
import (
"fmt"
"os"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/power"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/hpcng/warewulf/pkg/hostlist"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var returnErr error = nil
nodeDB, err := node.New()
if err != nil {
wwlog.Error("Could not open node configuration: %s\n", err)
os.Exit(1)
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Error("Could not get node list: %s\n", err)
os.Exit(1)
}
args = hostlist.Expand(args)
if len(args) > 0 {
nodes = node.FilterByName(nodes, args)
} else {
//nolint:errcheck
cmd.Usage()
os.Exit(1)
}
if len(nodes) == 0 {
fmt.Printf("No nodes found\n")
os.Exit(1)
}
for _, node := range nodes {
if node.Ipmi.Ipaddr.Get() == "" {
wwlog.Error("%s: No IPMI IP address\n", node.Id.Get())
continue
}
ipmiCmd := power.IPMI{
NodeName: node.Id.Get(),
HostName: node.Ipmi.Ipaddr.Get(),
Port: node.Ipmi.Port.Get(),
User: node.Ipmi.UserName.Get(),
Password: node.Ipmi.Password.Get(),
AuthType: "MD5",
Interface: node.Ipmi.Interface.Get(),
}
err := ipmiCmd.Console()
if err != nil {
wwlog.Error("%s: Console problem\n", node.Id.Get())
returnErr = err
continue
}
}
return returnErr
}