diff --git a/internal/app/wwctl/node/console/main.go b/internal/app/wwctl/node/console/main.go index bbc2d319..3361d4a5 100644 --- a/internal/app/wwctl/node/console/main.go +++ b/internal/app/wwctl/node/console/main.go @@ -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 diff --git a/internal/app/wwctl/node/sensors/main.go b/internal/app/wwctl/node/sensors/main.go index 00e382d4..436c4528 100644 --- a/internal/app/wwctl/node/sensors/main.go +++ b/internal/app/wwctl/node/sensors/main.go @@ -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 diff --git a/internal/app/wwctl/power/cycle/main.go b/internal/app/wwctl/power/cycle/main.go index 0018f857..38ac38e6 100644 --- a/internal/app/wwctl/power/cycle/main.go +++ b/internal/app/wwctl/power/cycle/main.go @@ -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) } diff --git a/internal/app/wwctl/power/off/main.go b/internal/app/wwctl/power/off/main.go index 278c08f2..939d9a66 100644 --- a/internal/app/wwctl/power/off/main.go +++ b/internal/app/wwctl/power/off/main.go @@ -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) } diff --git a/internal/app/wwctl/power/on/main.go b/internal/app/wwctl/power/on/main.go index 9bf926d5..4e517ea7 100644 --- a/internal/app/wwctl/power/on/main.go +++ b/internal/app/wwctl/power/on/main.go @@ -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) } diff --git a/internal/app/wwctl/power/reset/main.go b/internal/app/wwctl/power/reset/main.go index b3550944..89b0e5bb 100644 --- a/internal/app/wwctl/power/reset/main.go +++ b/internal/app/wwctl/power/reset/main.go @@ -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) } diff --git a/internal/app/wwctl/power/soft/main.go b/internal/app/wwctl/power/soft/main.go index 9eede24a..955a9b63 100644 --- a/internal/app/wwctl/power/soft/main.go +++ b/internal/app/wwctl/power/soft/main.go @@ -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) } diff --git a/internal/app/wwctl/power/status/main.go b/internal/app/wwctl/power/status/main.go index 6bfe4d15..c5d79ca6 100644 --- a/internal/app/wwctl/power/status/main.go +++ b/internal/app/wwctl/power/status/main.go @@ -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) } diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index 44597ad2..de593f95 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -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 { diff --git a/internal/pkg/power/ipmitool.go b/internal/pkg/power/ipmitool.go index 73a5b913..945d83a8 100644 --- a/internal/pkg/power/ipmitool.go +++ b/internal/pkg/power/ipmitool.go @@ -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 diff --git a/internal/pkg/power/power.go b/internal/pkg/power/power.go index 2faa3e67..5702e2d1 100644 --- a/internal/pkg/power/power.go +++ b/internal/pkg/power/power.go @@ -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) }