rebased for the use without NodeInfo
make fanout configureable via commanline Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
@@ -12,75 +12,77 @@ import (
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
func CobraRunE(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)
|
||||
}
|
||||
|
||||
nodes, err := nodeDB.FindAllNodes()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get node list: %s", err)
|
||||
}
|
||||
|
||||
args = hostlist.Expand(args)
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterNodeListByName(nodes, args)
|
||||
} else {
|
||||
//nolint:errcheck
|
||||
cmd.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
wwlog.Info("No nodes found")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
batchpool := batch.New(50)
|
||||
jobcount := len(nodes)
|
||||
results := make(chan power.IPMI, jobcount)
|
||||
|
||||
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}
|
||||
fullFlag := full
|
||||
batchpool.Submit(func() {
|
||||
if fullFlag {
|
||||
//nolint:errcheck
|
||||
ipmiCmd.SensorList()
|
||||
} else {
|
||||
//nolint:errcheck
|
||||
ipmiCmd.SDRList()
|
||||
}
|
||||
results <- ipmiCmd
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
batchpool.Run()
|
||||
|
||||
close(results)
|
||||
|
||||
for result := range results {
|
||||
out, err := result.Result()
|
||||
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 {
|
||||
wwlog.Error("%s: %s", result.Ipaddr, out)
|
||||
returnErr = err
|
||||
continue
|
||||
return fmt.Errorf("could not open node configuration: %s", err)
|
||||
}
|
||||
|
||||
fmt.Printf("%s:\n%s\n", result.Ipaddr, out)
|
||||
}
|
||||
nodes, err := nodeDB.FindAllNodes()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get node list: %s", err)
|
||||
}
|
||||
|
||||
return returnErr
|
||||
args = hostlist.Expand(args)
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes = node.FilterNodeListByName(nodes, args)
|
||||
} else {
|
||||
//nolint:errcheck
|
||||
cmd.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
wwlog.Info("No nodes found")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
batchpool := batch.New(50)
|
||||
jobcount := len(nodes)
|
||||
results := make(chan power.IPMI, jobcount)
|
||||
|
||||
for _, node := range nodes {
|
||||
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() {
|
||||
if vars.Full {
|
||||
//nolint:errcheck
|
||||
ipmiCmd.SensorList()
|
||||
} else {
|
||||
//nolint:errcheck
|
||||
ipmiCmd.SDRList()
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
wwlog.Info("%s:\n%s\n", result.Ipaddr, out)
|
||||
}
|
||||
|
||||
return returnErr
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,22 @@ import (
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
)
|
||||
|
||||
var (
|
||||
powerCmd = &cobra.Command{
|
||||
type variables struct {
|
||||
Showcmd bool
|
||||
Full bool
|
||||
Fanout int
|
||||
}
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
vars := variables{}
|
||||
|
||||
powerCmd := &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "sensors [OPTIONS] PATTERN",
|
||||
Short: "Show node IPMI sensor information",
|
||||
Long: "Show IPMI sensor information for nodes matching PATTERN.",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
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
|
||||
@@ -27,14 +35,8 @@ var (
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
}
|
||||
full bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
powerCmd.PersistentFlags().BoolVarP(&full, "full", "F", false, "show detailed output.")
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
powerCmd.PersistentFlags().BoolVarP(&vars.Full, "full", "F", false, "show detailed output.")
|
||||
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
|
||||
}
|
||||
|
||||
42
internal/app/wwctl/node/sensors/root_test.go
Normal file
42
internal/app/wwctl/node/sensors/root_test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package sensors
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
func Test_Power_Status(t *testing.T) {
|
||||
env := testenv.New(t)
|
||||
defer env.RemoveAll(t)
|
||||
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf", `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default:
|
||||
ipmi:
|
||||
username: admin
|
||||
password: admin
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
ipmi:
|
||||
ipaddr: 10.10.10.10`)
|
||||
warewulfd.SetNoDaemon()
|
||||
t.Run("ipmitool status test", func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
buf := new(bytes.Buffer)
|
||||
baseCmd.SetOut(buf)
|
||||
baseCmd.SetErr(buf)
|
||||
wwlog.SetLogWriter(buf)
|
||||
baseCmd.SetArgs([]string{"--show", "n01"})
|
||||
err := baseCmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "10.10.10.10:\nipmitool -I lan -H 10.10.10.10 -p 623 -U admin -P admin -e ~ sdr list", strings.TrimSpace(buf.String()))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user