From c6b2fc579595b97201dda559a354c39f98037679 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 3 Aug 2021 11:30:26 +0200 Subject: [PATCH] added configureable ipmiinterface used by ipmitool ipmitool is now searched from $PATH, so that self compiled ipmitool can be used --- internal/app/wwctl/node/list/main.go | 6 ++++-- internal/app/wwctl/node/sensors/power.go | 14 ++++++++----- internal/app/wwctl/node/set/main.go | 5 +++++ internal/app/wwctl/node/set/root.go | 2 ++ internal/app/wwctl/power/cycle/power.go | 14 ++++++++----- internal/app/wwctl/power/on/power.go | 14 ++++++++----- internal/app/wwctl/power/status/power.go | 14 ++++++++----- internal/app/wwctl/profile/set/main.go | 5 +++++ internal/app/wwctl/profile/set/root.go | 2 ++ internal/pkg/node/constructors.go | 3 +++ internal/pkg/node/datastructure.go | 2 ++ internal/pkg/node/modifiers.go | 2 ++ internal/pkg/overlay/overlay.go | 24 ++++++++++++---------- internal/pkg/power/ipmitool.go | 26 ++++++++++++++++-------- 14 files changed, 91 insertions(+), 42 deletions(-) diff --git a/internal/app/wwctl/node/list/main.go b/internal/app/wwctl/node/list/main.go index 16954318..a11063e8 100644 --- a/internal/app/wwctl/node/list/main.go +++ b/internal/app/wwctl/node/list/main.go @@ -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 { diff --git a/internal/app/wwctl/node/sensors/power.go b/internal/app/wwctl/node/sensors/power.go index b0379dce..3f1dad88 100644 --- a/internal/app/wwctl/node/sensors/power.go +++ b/internal/app/wwctl/node/sensors/power.go @@ -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", } diff --git a/internal/app/wwctl/node/set/main.go b/internal/app/wwctl/node/set/main.go index 76973c86..fc16ba3d 100644 --- a/internal/app/wwctl/node/set/main.go +++ b/internal/app/wwctl/node/set/main.go @@ -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) diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index 48c1531d..fe41253a 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -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") diff --git a/internal/app/wwctl/power/cycle/power.go b/internal/app/wwctl/power/cycle/power.go index c3aa7c80..b76aebc9 100644 --- a/internal/app/wwctl/power/cycle/power.go +++ b/internal/app/wwctl/power/cycle/power.go @@ -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", } diff --git a/internal/app/wwctl/power/on/power.go b/internal/app/wwctl/power/on/power.go index 2dad58ea..013d1dbc 100644 --- a/internal/app/wwctl/power/on/power.go +++ b/internal/app/wwctl/power/on/power.go @@ -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", } diff --git a/internal/app/wwctl/power/status/power.go b/internal/app/wwctl/power/status/power.go index 35f815b1..98ecdf37 100644 --- a/internal/app/wwctl/power/status/power.go +++ b/internal/app/wwctl/power/status/power.go @@ -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", } diff --git a/internal/app/wwctl/profile/set/main.go b/internal/app/wwctl/profile/set/main.go index b7a2eda6..1a2b700b 100644 --- a/internal/app/wwctl/profile/set/main.go +++ b/internal/app/wwctl/profile/set/main.go @@ -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") diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index 2bc4b6e2..cf152aa8 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -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") diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index 7f90342c..f17ea167 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -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) diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index 406c656d..079434b5 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -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 diff --git a/internal/pkg/node/modifiers.go b/internal/pkg/node/modifiers.go index ce22dea1..1c6e42ac 100644 --- a/internal/pkg/node/modifiers.go +++ b/internal/pkg/node/modifiers.go @@ -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() diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index 7936e534..5ec7cd3c 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -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 { diff --git a/internal/pkg/power/ipmitool.go b/internal/pkg/power/ipmitool.go index aac1ca66..4ef21882 100644 --- a/internal/pkg/power/ipmitool.go +++ b/internal/pkg/power/ipmitool.go @@ -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