use ipmi interface from node.NodeConf

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2023-12-05 12:06:57 +01:00
committed by Jonathon Anderson
parent 37bf90c588
commit 10ea0ac78d
11 changed files with 59 additions and 185 deletions

View File

@@ -44,20 +44,10 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Error("%s: No IPMI IP address", node.Id())
continue
}
ipmiCmd := power.IPMI{
NodeName: node.Id(),
HostName: node.Ipmi.Ipaddr.String(),
Port: node.Ipmi.Port,
User: node.Ipmi.UserName,
Password: node.Ipmi.Password,
AuthType: "MD5",
Interface: node.Ipmi.Interface,
EscapeChar: node.Ipmi.EscapeChar,
}
var conf node.NodeConf
conf.GetFrom(n)
ipmiCmd := power.IPMI{IpmiConf: *conf.Ipmi}
err := ipmiCmd.Console()
if err != nil {
wwlog.Error("%s: Console problem", node.Id())
returnErr = err

View File

@@ -49,26 +49,10 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Error("%s: No IPMI IP address", node.Id())
continue
}
var ipmiInterface = "lan"
if node.Ipmi.Interface != "" {
ipmiInterface = node.Ipmi.Interface
}
var ipmiPort = "623"
if node.Ipmi.Port != "" {
ipmiPort = node.Ipmi.Port
}
ipmiCmd := power.IPMI{
NodeName: node.Id(),
HostName: node.Ipmi.Ipaddr.String(),
Port: ipmiPort,
User: node.Ipmi.UserName,
Password: node.Ipmi.Password,
Interface: ipmiInterface,
AuthType: "MD5",
}
var conf node.NodeConf
conf.GetFrom(n)
ipmiCmd := power.IPMI{IpmiConf: *conf.Ipmi}
fullFlag := full
batchpool.Submit(func() {
if fullFlag {
//nolint:errcheck
@@ -90,12 +74,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
out, err := result.Result()
if err != nil {
wwlog.Error("%s: %s", result.NodeName, out)
wwlog.Error("%s: %s", result.Ipaddr, out)
returnErr = err
continue
}
fmt.Printf("%s:\n%s\n", result.NodeName, out)
fmt.Printf("%s:\n%s\n", result.Ipaddr, out)
}
return returnErr

View File

@@ -41,30 +41,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
jobcount := len(nodes)
results := make(chan power.IPMI, jobcount)
for _, node := range nodes {
for _, n := range nodes {
if node.Ipmi.Ipaddr.IsUnspecified() {
wwlog.Error("%s: No IPMI IP address", node.Id())
continue
}
var ipmiInterface = "lan"
if node.Ipmi.Interface != "" {
ipmiInterface = node.Ipmi.Interface
}
var ipmiPort = "623"
if node.Ipmi.Port != "" {
ipmiPort = node.Ipmi.Port
}
ipmiCmd := power.IPMI{
NodeName: node.Id(),
HostName: node.Ipmi.Ipaddr.String(),
Port: ipmiPort,
User: node.Ipmi.UserName,
Password: node.Ipmi.Password,
Interface: ipmiInterface,
AuthType: "MD5",
}
var conf node.NodeConf
conf.GetFrom(n)
ipmiCmd := power.IPMI{IpmiConf: *conf.Ipmi}
batchpool.Submit(func() {
//nolint:errcheck
ipmiCmd.PowerCycle()
@@ -82,12 +67,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
out, err := result.Result()
if err != nil {
wwlog.Error("%s: %s", result.NodeName, out)
wwlog.Error("%s: %s", result.Ipaddr, out)
returnErr = err
continue
}
fmt.Printf("%s: %s\n", result.NodeName, out)
fmt.Printf("%s: %s\n", result.Ipaddr, out)
}

View File

@@ -47,24 +47,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Error("%s: No IPMI IP address", node.Id())
continue
}
var ipmiInterface = "lan"
if node.Ipmi.Interface != "" {
ipmiInterface = node.Ipmi.Interface
}
var ipmiPort = "623"
if node.Ipmi.Port != "" {
ipmiPort = node.Ipmi.Port
}
ipmiCmd := power.IPMI{
NodeName: node.Id(),
HostName: node.Ipmi.Ipaddr.String(),
Port: ipmiPort,
User: node.Ipmi.UserName,
Password: node.Ipmi.Password,
Interface: ipmiInterface,
AuthType: "MD5",
}
var conf node.NodeConf
conf.GetFrom(n)
ipmiCmd := power.IPMI{IpmiConf: *conf.Ipmi}
batchpool.Submit(func() {
//nolint:errcheck
ipmiCmd.PowerOff()
@@ -82,12 +67,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
out, err := result.Result()
if err != nil {
wwlog.Error("%s: %s", result.NodeName, out)
wwlog.Error("%s: %s", result.Ipaddr, out)
returnErr = err
continue
}
fmt.Printf("%s: %s\n", result.NodeName, out)
fmt.Printf("%s: %s\n", result.Ipaddr, out)
}

View File

@@ -47,24 +47,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Error("%s: No IPMI IP address", node.Id())
continue
}
var ipmiInterface = "lan"
if node.Ipmi.Interface != "" {
ipmiInterface = node.Ipmi.Interface
}
var ipmiPort = "623"
if node.Ipmi.Port != "" {
ipmiPort = node.Ipmi.Port
}
ipmiCmd := power.IPMI{
NodeName: node.Id(),
HostName: node.Ipmi.Ipaddr.String(),
Port: ipmiPort,
User: node.Ipmi.UserName,
Password: node.Ipmi.Password,
Interface: ipmiInterface,
AuthType: "MD5",
}
var conf node.NodeConf
conf.GetFrom(n)
ipmiCmd := power.IPMI{IpmiConf: *conf.Ipmi}
batchpool.Submit(func() {
//nolint:errcheck
ipmiCmd.PowerOn()
@@ -82,12 +67,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
out, err := result.Result()
if err != nil {
wwlog.Error("%s: %s", result.NodeName, out)
wwlog.Error("%s: %s", result.Ipaddr, out)
returnErr = err
continue
}
fmt.Printf("%s: %s\n", result.NodeName, out)
fmt.Printf("%s: %s\n", result.Ipaddr, out)
}

View File

@@ -41,30 +41,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
jobcount := len(nodes)
results := make(chan power.IPMI, jobcount)
for _, node := range nodes {
for _, n := range nodes {
if node.Ipmi.Ipaddr.IsUnspecified() {
wwlog.Error("%s: No IPMI IP address", node.Id())
continue
}
var ipmiInterface = "lan"
if node.Ipmi.Interface != "" {
ipmiInterface = node.Ipmi.Interface
}
var ipmiPort = "623"
if node.Ipmi.Port != "" {
ipmiPort = node.Ipmi.Port
}
ipmiCmd := power.IPMI{
NodeName: node.Id(),
HostName: node.Ipmi.Ipaddr.String(),
Port: ipmiPort,
User: node.Ipmi.UserName,
Password: node.Ipmi.Password,
Interface: ipmiInterface,
AuthType: "MD5",
}
var conf node.NodeConf
conf.GetFrom(n)
ipmiCmd := power.IPMI{IpmiConf: *conf.Ipmi}
batchpool.Submit(func() {
//nolint:errcheck
ipmiCmd.PowerReset()
@@ -82,12 +67,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
out, err := result.Result()
if err != nil {
wwlog.Error("%s: %s", result.NodeName, out)
wwlog.Error("%s: %s", result.Ipaddr, out)
returnErr = err
continue
}
fmt.Printf("%s: %s\n", result.NodeName, out)
fmt.Printf("%s: %s\n", result.Ipaddr, out)
}

View File

@@ -41,30 +41,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
jobcount := len(nodes)
results := make(chan power.IPMI, jobcount)
for _, node := range nodes {
for _, n := range nodes {
if node.Ipmi.Ipaddr.IsUnspecified() {
wwlog.Error("%s: No IPMI IP address", node.Id())
continue
}
var ipmiInterface = "lan"
if node.Ipmi.Interface != "" {
ipmiInterface = node.Ipmi.Interface
}
var ipmiPort = "623"
if node.Ipmi.Port != "" {
ipmiPort = node.Ipmi.Port
}
ipmiCmd := power.IPMI{
NodeName: node.Id(),
HostName: node.Ipmi.Ipaddr.String(),
Port: ipmiPort,
User: node.Ipmi.UserName,
Password: node.Ipmi.Password,
Interface: ipmiInterface,
AuthType: "MD5",
}
var conf node.NodeConf
conf.GetFrom(n)
ipmiCmd := power.IPMI{IpmiConf: *conf.Ipmi}
batchpool.Submit(func() {
//nolint:errcheck
ipmiCmd.PowerSoft()
@@ -82,12 +67,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
out, err := result.Result()
if err != nil {
wwlog.Error("%s: %s", result.NodeName, out)
wwlog.Error("%s: %s", result.Ipaddr, out)
returnErr = err
continue
}
fmt.Printf("%s: %s\n", result.NodeName, out)
fmt.Printf("%s: %s\n", result.Ipaddr, out)
}

View File

@@ -41,30 +41,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
jobcount := len(nodes)
results := make(chan power.IPMI, jobcount)
for _, node := range nodes {
for _, n := range nodes {
if node.Ipmi.Ipaddr.IsUnspecified() {
wwlog.Error("%s: No IPMI IP address", node.Id())
continue
}
var ipmiInterface = "lan"
if node.Ipmi.Interface != "" {
ipmiInterface = node.Ipmi.Interface
}
var ipmiPort = "623"
if node.Ipmi.Port != "" {
ipmiPort = node.Ipmi.Port
}
ipmiCmd := power.IPMI{
NodeName: node.Id(),
HostName: node.Ipmi.Ipaddr.String(),
Port: ipmiPort,
User: node.Ipmi.UserName,
Password: node.Ipmi.Password,
Interface: ipmiInterface,
AuthType: "MD5",
}
var conf node.NodeConf
conf.GetFrom(n)
ipmiCmd := power.IPMI{IpmiConf: *conf.Ipmi}
batchpool.Submit(func() {
//nolint:errcheck
ipmiCmd.PowerStatus()
@@ -82,12 +67,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
out, err := result.Result()
if err != nil {
wwlog.Error("%s: %s", result.NodeName, out)
wwlog.Error("%s: %s", result.Ipaddr, out)
returnErr = err
continue
}
fmt.Printf("%s: %s\n", result.NodeName, out)
fmt.Printf("%s: %s\n", result.Ipaddr, out)
}

View File

@@ -59,16 +59,17 @@ type ProfileConf struct {
}
type IpmiConf struct {
UserName string `yaml:"username,omitempty" lopt:"ipmiuser" comment:"Set the IPMI username"`
Password string `yaml:"password,omitempty" lopt:"ipmipass" comment:"Set the IPMI password"`
Ipaddr net.IP `yaml:"ipaddr,omitempty" lopt:"ipmiaddr" comment:"Set the IPMI IP address" type:"IP"`
Gateway net.IP `yaml:"gateway,omitempty" lopt:"ipmigateway" comment:"Set the IPMI gateway" type:"IP"`
Netmask net.IP `yaml:"netmask,omitempty" lopt:"ipminetmask" comment:"Set the IPMI netmask" type:"IP"`
Port string `yaml:"port,omitempty" lopt:"ipmiport" comment:"Set the IPMI port"`
Interface string `yaml:"interface,omitempty" lopt:"ipmiinterface" comment:"Set the node's IPMI interface (defaults: 'lan')"`
EscapeChar string `yaml:"escapechar,omitempty" lopt:"ipmiescapechar" comment:"Set the IPMI escape character (defaults: '~')"`
Write wwtype.WWbool `yaml:"write,omitempty" lopt:"ipmiwrite" comment:"Enable the write of impi configuration (true/false)"`
Tags map[string]string `yaml:"tags,omitempty"`
UserName string `yaml:"username,omitempty" lopt:"ipmiuser" comment:"Set the IPMI username"`
Password string `yaml:"password,omitempty" lopt:"ipmipass" comment:"Set the IPMI password"`
Ipaddr net.IP `yaml:"ipaddr,omitempty" lopt:"ipmiaddr" comment:"Set the IPMI IP address" type:"IP"`
Gateway net.IP `yaml:"gateway,omitempty" lopt:"ipmigateway" comment:"Set the IPMI gateway" type:"IP"`
Netmask net.IP `yaml:"netmask,omitempty" lopt:"ipminetmask" comment:"Set the IPMI netmask" type:"IP"`
Port string `yaml:"port,omitempty" lopt:"ipmiport" comment:"Set the IPMI port"`
Interface string `yaml:"interface,omitempty" lopt:"ipmiinterface" comment:"Set the node's IPMI interface (defaults: 'lan')"`
EscapeChar string `yaml:"escapechar,omitempty" lopt:"ipmiescapechar" comment:"Set the IPMI escape character (defaults: '~')"`
Write wwtype.WWbool `yaml:"write,omitempty" lopt:"ipmiwrite" comment:"Enable the write of impi configuration (true/false)"`
BmcTemplate string `yaml:"template,omitempty" lopt:"ipmitemplate" comment:"template used for ipmi command"`
Tags map[string]string `yaml:"tags,omitempty"`
}
type KernelConf struct {

View File

@@ -4,6 +4,8 @@ import (
"os"
"os/exec"
"strings"
"github.com/hpcng/warewulf/internal/pkg/node"
)
type IPMIResult struct {
@@ -12,15 +14,8 @@ type IPMIResult struct {
}
type IPMI struct {
NodeName string
HostName string
Port string
User string
Password string
AuthType string
Interface string
EscapeChar string
result IPMIResult
node.IpmiConf
result IPMIResult
}
func (ipmi *IPMI) Result() (string, error) {
@@ -40,7 +35,7 @@ func (ipmi *IPMI) Command(ipmiArgs []string) ([]byte, error) {
if ipmi.EscapeChar == "" {
ipmi.EscapeChar = "~"
}
args = append(args, "-I", ipmi.Interface, "-H", ipmi.HostName, "-p", ipmi.Port, "-U", ipmi.User, "-P", ipmi.Password, "-e", ipmi.EscapeChar)
args = append(args, "-I", ipmi.Interface, "-H", ipmi.Ipaddr, "-p", ipmi.Port, "-U", ipmi.UserName, "-P", ipmi.Password, "-e", ipmi.EscapeChar)
args = append(args, ipmiArgs...)
ipmiCmd := exec.Command("ipmitool", args...)
return ipmiCmd.CombinedOutput()
@@ -59,7 +54,7 @@ func (ipmi *IPMI) InteractiveCommand(ipmiArgs []string) error {
if ipmi.EscapeChar == "" {
ipmi.EscapeChar = "~"
}
args = append(args, "-I", ipmi.Interface, "-H", ipmi.HostName, "-p", ipmi.Port, "-U", ipmi.User, "-P", ipmi.Password, "-e", ipmi.EscapeChar)
args = append(args, "-I", ipmi.Interface, "-H", ipmi.Ipaddr, "-p", ipmi.Port, "-U", ipmi.UserName, "-P", ipmi.Password, "-e", ipmi.EscapeChar)
args = append(args, ipmiArgs...)
ipmiCmd := exec.Command("ipmitool", args...)
ipmiCmd.Stdout = os.Stdout

View File

@@ -1,11 +1,5 @@
package power
//type PowerControl interface {
//PowerOn() (result string, err error)
//PowerOff() (result string, err error)
//PowerStatus() (result string, err error)
//}
type PowerOnInterface interface {
PowerOn() (result string, err error)
}