added configureable ipmiinterface used by ipmitool

ipmitool is now searched from $PATH, so that self
compiled ipmitool can be used
This commit is contained in:
Christian Goll
2021-08-03 11:30:26 +02:00
parent 535563150c
commit c6b2fc5795
14 changed files with 91 additions and 42 deletions

View File

@@ -49,6 +49,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiNetmask", node.IpmiNetmask.Source(), node.IpmiNetmask.Print())
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiGateway", node.IpmiGateway.Source(), node.IpmiGateway.Print())
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiUserName", node.IpmiUserName.Source(), node.IpmiUserName.Print())
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiInterface", node.IpmiInterface.Source(), node.IpmiInterface.Print())
for name, netdev := range node.NetDevs {
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":HWADDR", netdev.Hwaddr.Source(), netdev.Hwaddr.Print())
@@ -79,11 +81,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
} else if ShowIpmi {
fmt.Printf("%-22s %-16s %-20s %-20s\n", "NODE NAME", "IPMI IPADDR", "IPMI USERNAME", "IPMI PASSWORD")
fmt.Printf("%-22s %-16s %-20s %-20s\n", "NODE NAME", "IPMI IPADDR", "IPMI USERNAME", "IPMI PASSWORD IPMI INTERFACE")
fmt.Println(strings.Repeat("=", 80))
for _, node := range node.FilterByName(nodes, args) {
fmt.Printf("%-22s %-16s %-20s %-20s\n", node.Id.Get(), node.IpmiIpaddr.Print(), node.IpmiUserName.Print(), node.IpmiPassword.Print())
fmt.Printf("%-22s %-16s %-20s %-20s\n", node.Id.Get(), node.IpmiIpaddr.Print(), node.IpmiUserName.Print(), node.IpmiPassword.Print(), node.IpmiInterface.Print())
}
} else if ShowLong {

View File

@@ -48,12 +48,16 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.Id.Get())
continue
}
var ipmiInterface = "lan"
if node.IpmiInterface.Get() != "" {
ipmiInterface = node.IpmiInterface.Get()
}
ipmiCmd := power.IPMI{
NodeName: node.Id.Get(),
HostName: node.IpmiIpaddr.Get(),
User: node.IpmiUserName.Get(),
Password: node.IpmiPassword.Get(),
NodeName: node.Id.Get(),
HostName: node.IpmiIpaddr.Get(),
User: node.IpmiUserName.Get(),
Password: node.IpmiPassword.Get(),
Interface: ipmiInterface,
AuthType: "MD5",
}

View File

@@ -175,6 +175,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
n.IpmiPassword.Set(SetIpmiPassword)
}
if SetIpmiInterface != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP interface to: %s\n", n.Id.Get(), SetIpmiInterface)
n.IpmiInterface.Set(SetIpmiInterface)
}
if SetDiscoverable == true {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting node to discoverable\n", n.Id.Get())
n.Discoverable.SetB(true)

View File

@@ -31,6 +31,7 @@ var (
SetIpmiGateway string
SetIpmiUsername string
SetIpmiPassword string
SetIpmiInterface string
SetNodeAll bool
SetYes bool
SetProfile string
@@ -63,6 +64,7 @@ func init() {
baseCmd.PersistentFlags().StringVar(&SetIpmiGateway, "ipmigateway", "", "Set the node's IPMI gateway")
baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username")
baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password")
baseCmd.PersistentFlags().StringVar(&SetIpmiInterface, "ipmiinterface", "", "Set the node's IPMI interface (defaults to lan if empty)")
baseCmd.PersistentFlags().StringSliceVar(&SetAddProfile, "addprofile", []string{}, "Add Profile(s) to node")
baseCmd.PersistentFlags().StringSliceVar(&SetDelProfile, "delprofile", []string{}, "Remove Profile(s) to node")

View File

@@ -48,12 +48,16 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.Id.Get())
continue
}
var ipmiInterface = "lan"
if node.IpmiInterface.Get() != "" {
ipmiInterface = node.IpmiInterface.Get()
}
ipmiCmd := power.IPMI{
NodeName: node.Id.Get(),
HostName: node.IpmiIpaddr.Get(),
User: node.IpmiUserName.Get(),
Password: node.IpmiPassword.Get(),
NodeName: node.Id.Get(),
HostName: node.IpmiIpaddr.Get(),
User: node.IpmiUserName.Get(),
Password: node.IpmiPassword.Get(),
Interface: ipmiInterface,
AuthType: "MD5",
}

View File

@@ -48,12 +48,16 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.Id.Get())
continue
}
var ipmiInterface = "lan"
if node.IpmiInterface.Get() != "" {
ipmiInterface = node.IpmiInterface.Get()
}
ipmiCmd := power.IPMI{
NodeName: node.Id.Get(),
HostName: node.IpmiIpaddr.Get(),
User: node.IpmiUserName.Get(),
Password: node.IpmiPassword.Get(),
NodeName: node.Id.Get(),
HostName: node.IpmiIpaddr.Get(),
User: node.IpmiUserName.Get(),
Password: node.IpmiPassword.Get(),
Interface: ipmiInterface,
AuthType: "MD5",
}

View File

@@ -48,12 +48,16 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.Id.Get())
continue
}
var ipmiInterface = "lan"
if node.IpmiInterface.Get() != "" {
ipmiInterface = node.IpmiInterface.Get()
}
ipmiCmd := power.IPMI{
NodeName: node.Id.Get(),
HostName: node.IpmiIpaddr.Get(),
User: node.IpmiUserName.Get(),
Password: node.IpmiPassword.Get(),
NodeName: node.Id.Get(),
HostName: node.IpmiIpaddr.Get(),
User: node.IpmiUserName.Get(),
Password: node.IpmiPassword.Get(),
Interface: ipmiInterface,
AuthType: "MD5",
}

View File

@@ -132,6 +132,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
p.IpmiPassword.Set(SetIpmiPassword)
}
if SetIpmiInterface != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting IPMI username to: %s\n", p.Id, SetIpmiInterface)
p.IpmiInterface.Set(SetIpmiInterface)
}
if SetNetDevDel == true {
if SetNetDev == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")

View File

@@ -25,6 +25,7 @@ var (
SetIpmiGateway string
SetIpmiUsername string
SetIpmiPassword string
SetIpmiInterface string
SetNetDev string
SetIpaddr string
SetNetmask string
@@ -56,6 +57,7 @@ func init() {
baseCmd.PersistentFlags().StringVar(&SetIpmiGateway, "ipmigateway", "", "Set the node's IPMI gateway")
baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username")
baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password")
baseCmd.PersistentFlags().StringVar(&SetIpmiInterface, "ipmiinterface", "", "Set the node's IPMI interface (defaults to lan if empty)")
baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Define the network device to configure")
baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address")

View File

@@ -75,6 +75,7 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
n.IpmiGateway.Set(node.IpmiGateway)
n.IpmiUserName.Set(node.IpmiUserName)
n.IpmiPassword.Set(node.IpmiPassword)
n.IpmiInterface.Set(node.IpmiInterface)
n.SystemOverlay.Set(node.SystemOverlay)
n.RuntimeOverlay.Set(node.RuntimeOverlay)
n.Root.Set(node.Root)
@@ -123,6 +124,7 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
n.IpmiGateway.SetAlt(config.NodeProfiles[p].IpmiGateway, p)
n.IpmiUserName.SetAlt(config.NodeProfiles[p].IpmiUserName, p)
n.IpmiPassword.SetAlt(config.NodeProfiles[p].IpmiPassword, p)
n.IpmiInterface.SetAlt(config.NodeProfiles[p].IpmiInterface, p)
n.SystemOverlay.SetAlt(config.NodeProfiles[p].SystemOverlay, p)
n.RuntimeOverlay.SetAlt(config.NodeProfiles[p].RuntimeOverlay, p)
n.Root.SetAlt(config.NodeProfiles[p].Root, p)
@@ -190,6 +192,7 @@ func (config *nodeYaml) FindAllProfiles() ([]NodeInfo, error) {
p.IpmiGateway.Set(profile.IpmiGateway)
p.IpmiUserName.Set(profile.IpmiUserName)
p.IpmiPassword.Set(profile.IpmiPassword)
p.IpmiInterface.Set(profile.IpmiInterface)
p.RuntimeOverlay.Set(profile.RuntimeOverlay)
p.SystemOverlay.Set(profile.SystemOverlay)
p.Root.Set(profile.Root)

View File

@@ -29,6 +29,7 @@ type NodeConf struct {
IpmiIpaddr string `yaml:"ipmi ipaddr,omitempty"`
IpmiNetmask string `yaml:"ipmi netmask,omitempty"`
IpmiGateway string `yaml:"ipmi gateway,omitempty"`
IpmiInterface string `yaml:"ipmi interface,omitempty"`
RuntimeOverlay string `yaml:"runtime overlay,omitempty"`
SystemOverlay string `yaml:"system overlay,omitempty"`
Init string `yaml:"init,omitempty"`
@@ -75,6 +76,7 @@ type NodeInfo struct {
IpmiGateway Entry
IpmiUserName Entry
IpmiPassword Entry
IpmiInterface Entry
RuntimeOverlay Entry
SystemOverlay Entry
Root Entry

View File

@@ -66,6 +66,7 @@ func (config *nodeYaml) NodeUpdate(node NodeInfo) error {
config.Nodes[nodeID].IpmiGateway = node.IpmiGateway.GetReal()
config.Nodes[nodeID].IpmiUserName = node.IpmiUserName.GetReal()
config.Nodes[nodeID].IpmiPassword = node.IpmiPassword.GetReal()
config.Nodes[nodeID].IpmiInterface = node.IpmiInterface.GetReal()
config.Nodes[nodeID].RuntimeOverlay = node.RuntimeOverlay.GetReal()
config.Nodes[nodeID].SystemOverlay = node.SystemOverlay.GetReal()
config.Nodes[nodeID].Root = node.Root.GetReal()
@@ -149,6 +150,7 @@ func (config *nodeYaml) ProfileUpdate(profile NodeInfo) error {
config.NodeProfiles[profileID].IpmiGateway = profile.IpmiGateway.GetReal()
config.NodeProfiles[profileID].IpmiUserName = profile.IpmiUserName.GetReal()
config.NodeProfiles[profileID].IpmiPassword = profile.IpmiPassword.GetReal()
config.NodeProfiles[profileID].IpmiInterface = profile.IpmiInterface.GetReal()
config.NodeProfiles[profileID].RuntimeOverlay = profile.RuntimeOverlay.GetReal()
config.NodeProfiles[profileID].SystemOverlay = profile.SystemOverlay.GetReal()
config.NodeProfiles[profileID].Root = profile.Root.GetReal()

View File

@@ -19,17 +19,18 @@ import (
)
type TemplateStruct struct {
Id string
Hostname string
ClusterName string
Container string
Init string
Root string
IpmiIpaddr string
IpmiNetmask string
IpmiGateway string
IpmiUserName string
IpmiPassword string
Id string
Hostname string
ClusterName string
Container string
Init string
Root string
IpmiIpaddr string
IpmiNetmask string
IpmiGateway string
IpmiUserName string
IpmiPassword string
IpmiInterface string
NetDevs map[string]*node.NetDevs
Keys map[string]string
AllNodes []node.NodeInfo
@@ -149,6 +150,7 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error {
t.IpmiGateway = n.IpmiGateway.Get()
t.IpmiUserName = n.IpmiUserName.Get()
t.IpmiPassword = n.IpmiPassword.Get()
t.IpmiInterface = n.IpmiInterface.Get()
t.NetDevs = make(map[string]*node.NetDevs)
t.Keys = make(map[string]string)
for devname, netdev := range n.NetDevs {

View File

@@ -11,11 +11,12 @@ type IPMIResult struct {
}
type IPMI struct {
NodeName string
HostName string
User string
Password string
AuthType string
NodeName string
HostName string
User string
Password string
AuthType string
Interface string
result IPMIResult
}
@@ -27,9 +28,12 @@ func (ipmi *IPMI) Command(ipmiArgs []string) ([]byte, error) {
var args []string
args = append(args, "-I", "lan", "-H", ipmi.HostName, "-U", ipmi.User, "-P", ipmi.Password)
if ipmi.Interface == "" {
ipmi.Interface = "lanplus"
}
args = append(args, "-I", ipmi.Interface, "-H", ipmi.HostName, "-U", ipmi.User, "-P", ipmi.Password)
args = append(args, ipmiArgs...)
ipmiCmd := exec.Command("/usr/bin/ipmitool", args...)
ipmiCmd := exec.Command("ipmitool", args...)
return ipmiCmd.CombinedOutput()
}
@@ -37,9 +41,13 @@ func (ipmi *IPMI) InteractiveCommand(ipmiArgs []string) error {
var args []string
args = append(args, "-I", "lanplus", "-H", ipmi.HostName, "-U", ipmi.User, "-P", ipmi.Password)
if ipmi.Interface == "" {
ipmi.Interface = "lan"
}
args = append(args, "-I", ipmi.Interface, "-H", ipmi.HostName, "-U", ipmi.User, "-P", ipmi.Password)
args = append(args, ipmiArgs...)
ipmiCmd := exec.Command("/usr/bin/ipmitool", args...)
ipmiCmd := exec.Command("ipmitool", args...)
ipmiCmd.Stdout = os.Stdout
ipmiCmd.Stdin = os.Stdin
ipmiCmd.Stderr = os.Stderr