use ipmitool created from template file

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2023-12-05 15:49:29 +01:00
committed by Jonathon Anderson
parent 10ea0ac78d
commit 4597fdfaa9
6 changed files with 135 additions and 121 deletions

View File

@@ -12,36 +12,37 @@ import (
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var returnErr error = nil
func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err error) {
return func(cmd *cobra.Command, args []string) error {
var returnErr error = nil
nodeDB, err := node.New()
if err != nil {
return fmt.Errorf("could not open node configuration: %s", err)
}
nodeDB, err := node.New()
if err != nil {
return err
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
return fmt.Errorf("could not get node list: %s", err)
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
return err
}
if len(args) > 0 {
nodes = node.FilterNodeListByName(nodes, hostlist.Expand(args))
} else {
//nolint:errcheck
cmd.Usage()
os.Exit(1)
}
if len(args) > 0 {
nodes = node.FilterByName(nodes, hostlist.Expand(args))
} else {
//nolint:errcheck
cmd.Usage()
os.Exit(1)
}
if len(nodes) == 0 {
return fmt.Errorf("no nodes found")
}
batchpool := batch.New(50)
jobcount := len(nodes)
results := make(chan power.IPMI, jobcount)
batchpool := batch.New(50)
jobcount := len(nodes)
results := make(chan power.IPMI, jobcount)
for _, n := range nodes {
for _, n := range nodes {
if node.Ipmi.Ipaddr.IsUnspecified() {
wwlog.Error("%s: No IPMI IP address", node.Id())
@@ -56,25 +57,26 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
results <- ipmiCmd
})
}
batchpool.Run()
close(results)
for result := range results {
out, err := result.Result()
if err != nil {
wwlog.Error("%s: %s", result.Ipaddr, out)
returnErr = err
continue
}
fmt.Printf("%s: %s\n", result.Ipaddr, out)
batchpool.Run()
close(results)
for result := range results {
out, err := result.Result()
if err != nil {
wwlog.Error("%s: %s", result.Ipaddr, out)
returnErr = err
continue
}
wwlog.Info("%s: %s\n", result.Ipaddr, out)
}
return returnErr
}
return returnErr
}

View File

@@ -5,13 +5,19 @@ import (
"github.com/warewulf/warewulf/internal/pkg/node"
)
var (
powerCmd = &cobra.Command{
type variables struct {
Showcmd bool
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
vars := variables{}
powerCmd := &cobra.Command{
DisableFlagsInUseLine: true,
Use: "status [OPTIONS] [PATTERN ...]",
Short: "Show power status for the given node(s)",
Long: "This command displays the power status of a set of nodes specified by PATTERN.",
RunE: CobraRunE,
RunE: CobraRunE(&vars),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
@@ -26,9 +32,6 @@ var (
return node_names, cobra.ShellCompDirectiveNoFileComp
},
}
)
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
powerCmd.PersistentFlags().BoolVarP(&vars.Showcmd, "show", "s", false, "only show command which will be executed")
return powerCmd
}