rebased for the use without NodeInfo

make fanout configureable via commanline

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Jonathon Anderson
2024-11-07 17:45:02 -07:00
parent 0490f4c9a5
commit 2e2a7d7de3
22 changed files with 304 additions and 250 deletions

View File

@@ -17,46 +17,47 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
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 fmt.Errorf("could not open node configuration: %s", err)
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
return fmt.Errorf("could not get nodeList: %s", err)
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
return fmt.Errorf("could not get nodeList: %s", 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.FilterNodeListByName(nodes, hostlist.Expand(args))
} else {
//nolint:errcheck
cmd.Usage()
os.Exit(1)
}
if len(nodes) == 0 {
return fmt.Errorf("no nodes found")
}
if len(nodes) == 0 {
return fmt.Errorf("no nodes found")
}
batchpool := batch.New(50)
batchpool := batch.New(vars.Fanout)
jobcount := len(nodes)
results := make(chan power.IPMI, jobcount)
for _, n := range nodes {
for _, node := range nodes {
if node.Ipmi.Ipaddr.IsUnspecified() {
wwlog.Error("%s: No IPMI IP address", node.Id())
continue
}
var conf node.NodeConf
conf.GetFrom(n)
ipmiCmd := power.IPMI{IpmiConf: *conf.Ipmi}
batchpool.Submit(func() {
//nolint:errcheck
ipmiCmd.PowerSoft()
results <- ipmiCmd
})
if node.Ipmi.Ipaddr.IsUnspecified() {
wwlog.Error("%s: No IPMI IP address", node.Id())
continue
}
ipmiCmd := power.IPMI{
IpmiConf: *node.Ipmi,
ShowOnly: vars.Showcmd,
}
batchpool.Submit(func() {
//nolint:errcheck
ipmiCmd.PowerSoft()
results <- ipmiCmd
})
}

View File

@@ -7,6 +7,7 @@ import (
type variables struct {
Showcmd bool
Fanout int
}
// GetRootCommand returns the root cobra.Command for the application.
@@ -16,7 +17,7 @@ func GetCommand() *cobra.Command {
DisableFlagsInUseLine: true,
Use: "soft",
Short: "Gracefully shuts down the given node(s)",
Long: "This command uses the operationg system to shut down the set of nodes specified by PATTERN.",
Long: "This command uses the operating system to shut down the set of nodes specified by PATTERN.",
RunE: CobraRunE(&vars),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
@@ -33,5 +34,6 @@ func GetCommand() *cobra.Command {
},
}
powerCmd.PersistentFlags().BoolVarP(&vars.Showcmd, "show", "s", false, "only show command which will be executed")
powerCmd.PersistentFlags().IntVar(&vars.Fanout, "fanout", 50, "how many command should be executed in parallel")
return powerCmd
}

View File

@@ -1,4 +1,4 @@
package powersoft
package soft
import (
"bytes"