This commit adds the ability to configure the default IPMI port for a profile or per node. If the port is not set, we default to 623. Updated some areas to default to 'lan' for IPMI interface if it has not been set.
113 lines
2.5 KiB
Go
113 lines
2.5 KiB
Go
package power
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
type IPMIResult struct {
|
|
err error
|
|
out string
|
|
}
|
|
|
|
type IPMI struct {
|
|
NodeName string
|
|
HostName string
|
|
Port string
|
|
User string
|
|
Password string
|
|
AuthType string
|
|
Interface string
|
|
result IPMIResult
|
|
}
|
|
|
|
func (ipmi *IPMI) Result() (string, error) {
|
|
return ipmi.result.out, ipmi.result.err
|
|
}
|
|
|
|
func (ipmi *IPMI) Command(ipmiArgs []string) ([]byte, error) {
|
|
|
|
var args []string
|
|
|
|
if ipmi.Interface == "" {
|
|
ipmi.Interface = "lan"
|
|
}
|
|
if ipmi.Port == "" {
|
|
ipmi.Port = "623"
|
|
}
|
|
args = append(args, "-I", ipmi.Interface, "-H", ipmi.HostName, "-p", ipmi.Port, "-U", ipmi.User, "-P", ipmi.Password)
|
|
args = append(args, ipmiArgs...)
|
|
ipmiCmd := exec.Command("ipmitool", args...)
|
|
return ipmiCmd.CombinedOutput()
|
|
}
|
|
|
|
func (ipmi *IPMI) InteractiveCommand(ipmiArgs []string) error {
|
|
|
|
var args []string
|
|
|
|
if ipmi.Interface == "" {
|
|
ipmi.Interface = "lan"
|
|
}
|
|
if ipmi.Port == "" {
|
|
ipmi.Port = "623"
|
|
}
|
|
args = append(args, "-I", ipmi.Interface, "-H", ipmi.HostName, "-p", ipmi.Port, "-U", ipmi.User, "-P", ipmi.Password)
|
|
args = append(args, ipmiArgs...)
|
|
ipmiCmd := exec.Command("ipmitool", args...)
|
|
ipmiCmd.Stdout = os.Stdout
|
|
ipmiCmd.Stdin = os.Stdin
|
|
ipmiCmd.Stderr = os.Stderr
|
|
return ipmiCmd.Run()
|
|
}
|
|
|
|
func (ipmi *IPMI) IPMIInteractiveCommand(args ...string) error {
|
|
return ipmi.InteractiveCommand(args)
|
|
}
|
|
|
|
func (ipmi *IPMI) IPMICommand(args ...string) (string, error) {
|
|
ipmiOut, err := ipmi.Command(args)
|
|
ipmi.result.out = string(ipmiOut)
|
|
ipmi.result.err = err
|
|
return ipmi.result.out, ipmi.result.err
|
|
|
|
}
|
|
|
|
//func (ipmi IPMI) PowerOn() (string, error) {
|
|
//
|
|
// var args []string
|
|
//
|
|
// args = append(args, "chassis", "power", "on")
|
|
// ipmiOut, err := ipmi.Command(args)
|
|
// ipmi.result.out = string(ipmiOut)
|
|
// ipmi.result.err = err
|
|
// return ipmi.result.out, ipmi.result.err
|
|
//}
|
|
|
|
func (ipmi *IPMI) PowerOn() (string, error) {
|
|
return ipmi.IPMICommand("chassis", "power", "on")
|
|
}
|
|
|
|
func (ipmi *IPMI) PowerOff() (string, error) {
|
|
return ipmi.IPMICommand("chassis", "power", "off")
|
|
}
|
|
|
|
func (ipmi *IPMI) PowerCycle() (string, error) {
|
|
return ipmi.IPMICommand("chassis", "power", "cycle")
|
|
}
|
|
|
|
func (ipmi *IPMI) PowerStatus() (string, error) {
|
|
return ipmi.IPMICommand("chassis", "power", "status")
|
|
}
|
|
|
|
func (ipmi *IPMI) SDRList() (string, error) {
|
|
return ipmi.IPMICommand("sdr", "list")
|
|
}
|
|
|
|
func (ipmi *IPMI) SensorList() (string, error) {
|
|
return ipmi.IPMICommand("sensor", "list")
|
|
}
|
|
|
|
func (ipmi *IPMI) Console() error {
|
|
return ipmi.IPMIInteractiveCommand("sol", "activate")
|
|
}
|