rebased for the use without NodeInfo
make fanout configureable via commanline Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
@@ -16,46 +16,47 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
|
||||
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 fmt.Errorf("could not open node configuration: %s", 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 fmt.Errorf("could not get node list: %s", err)
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterByName(nodes, hostlist.Expand(args))
|
||||
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.PowerCycle()
|
||||
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.PowerCycle()
|
||||
results <- ipmiCmd
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
type variables struct {
|
||||
Showcmd bool
|
||||
Fanout int
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
@@ -27,11 +28,12 @@ func GetCommand() *cobra.Command {
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
node_names = append(node_names, node.Id())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package powercycle
|
||||
package cycle
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
Reference in New Issue
Block a user