From 13ad67e56e79742dbc971295069a456f2ae011fd Mon Sep 17 00:00:00 2001 From: "Michael L. Young" Date: Tue, 24 Aug 2021 19:11:39 -0400 Subject: [PATCH] Add IPMI Port Configuration 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. --- internal/app/wwctl/node/list/main.go | 5 +++-- internal/app/wwctl/node/sensors/power.go | 5 +++++ internal/app/wwctl/node/set/main.go | 5 +++++ internal/app/wwctl/node/set/root.go | 4 +++- internal/app/wwctl/power/cycle/power.go | 5 +++++ internal/app/wwctl/power/off/power.go | 11 ++++++++++- internal/app/wwctl/power/on/power.go | 5 +++++ internal/app/wwctl/power/status/power.go | 5 +++++ internal/app/wwctl/profile/list/main.go | 1 + 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 | 2 ++ internal/pkg/power/ipmitool.go | 14 ++++++++++---- 15 files changed, 62 insertions(+), 9 deletions(-) diff --git a/internal/app/wwctl/node/list/main.go b/internal/app/wwctl/node/list/main.go index 1953fac2..fcb40985 100644 --- a/internal/app/wwctl/node/list/main.go +++ b/internal/app/wwctl/node/list/main.go @@ -47,6 +47,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Root", node.Root.Source(), node.Root.Print()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiIpaddr", node.IpmiIpaddr.Source(), node.IpmiIpaddr.Print()) 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(), "IpmiPort", node.IpmiPort.Source(), node.IpmiPort.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()) @@ -80,11 +81,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } else if ShowIpmi { - fmt.Printf("%-22s %-16s %-20s %-20s %-20s\n", "NODE NAME", "IPMI IPADDR", "IPMI USERNAME", "IPMI PASSWORD", "IPMI INTERFACE") + fmt.Printf("%-22s %-16s %-5s %-20s %-20s %-20s\n", "NODE NAME", "IPMI IPADDR", "IPMI PORT", "IPMI USERNAME", "IPMI PASSWORD", "IPMI INTERFACE") fmt.Println(strings.Repeat("=", 80)) for _, node := range node.FilterByName(nodes, args) { - fmt.Printf("%-22s %-16s %-20s %-20s %-20s\n", node.Id.Get(), node.IpmiIpaddr.Print(), node.IpmiUserName.Print(), node.IpmiPassword.Print(), node.IpmiInterface.Print()) + fmt.Printf("%-22s %-16s %-5s %-20s %-20s %-20s\n", node.Id.Get(), node.IpmiIpaddr.Print(), node.IpmiPort.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 96813079..2f684ff1 100644 --- a/internal/app/wwctl/node/sensors/power.go +++ b/internal/app/wwctl/node/sensors/power.go @@ -52,9 +52,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error { if node.IpmiInterface.Get() != "" { ipmiInterface = node.IpmiInterface.Get() } + var ipmiPort = "623" + if node.IpmiPort.Get() != "" { + ipmiPort = node.IpmiPort.Get() + } ipmiCmd := power.IPMI{ NodeName: node.Id.Get(), HostName: node.IpmiIpaddr.Get(), + Port: ipmiPort, User: node.IpmiUserName.Get(), Password: node.IpmiPassword.Get(), Interface: ipmiInterface, diff --git a/internal/app/wwctl/node/set/main.go b/internal/app/wwctl/node/set/main.go index fc16ba3d..29e0ad3c 100644 --- a/internal/app/wwctl/node/set/main.go +++ b/internal/app/wwctl/node/set/main.go @@ -160,6 +160,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error { n.IpmiNetmask.Set(SetIpmiNetmask) } + if SetIpmiPort != "" { + wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI port to: %s\n", n.Id.Get(), SetIpmiPort) + n.IpmiPort.Set(SetIpmiPort) + } + if SetIpmiGateway != "" { wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI gateway to: %s\n", n.Id.Get(), SetIpmiGateway) n.IpmiGateway.Set(SetIpmiGateway) diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index e4c84d24..dc4a8ce6 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -29,6 +29,7 @@ var ( SetSystemOverlay string SetIpmiIpaddr string SetIpmiNetmask string + SetIpmiPort string SetIpmiGateway string SetIpmiUsername string SetIpmiPassword string @@ -62,10 +63,11 @@ func init() { baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay") baseCmd.PersistentFlags().StringVar(&SetIpmiIpaddr, "ipmi", "", "Set the node's IPMI IP address") baseCmd.PersistentFlags().StringVar(&SetIpmiNetmask, "ipminetmask", "", "Set the node's IPMI netmask") + baseCmd.PersistentFlags().StringVar(&SetIpmiPort, "ipmiport", "", "Set the node's IPMI port") 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().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 016e9a4f..b798fb84 100644 --- a/internal/app/wwctl/power/cycle/power.go +++ b/internal/app/wwctl/power/cycle/power.go @@ -52,9 +52,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error { if node.IpmiInterface.Get() != "" { ipmiInterface = node.IpmiInterface.Get() } + var ipmiPort = "623" + if node.IpmiPort.Get() != "" { + ipmiPort = node.IpmiPort.Get() + } ipmiCmd := power.IPMI{ NodeName: node.Id.Get(), HostName: node.IpmiIpaddr.Get(), + Port: ipmiPort, User: node.IpmiUserName.Get(), Password: node.IpmiPassword.Get(), Interface: ipmiInterface, diff --git a/internal/app/wwctl/power/off/power.go b/internal/app/wwctl/power/off/power.go index 43d4b358..e499ab4f 100644 --- a/internal/app/wwctl/power/off/power.go +++ b/internal/app/wwctl/power/off/power.go @@ -48,12 +48,21 @@ 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() + } + var ipmiPort = "623" + if node.IpmiPort.Get() != "" { + ipmiPort = node.IpmiPort.Get() + } ipmiCmd := power.IPMI{ NodeName: node.Id.Get(), HostName: node.IpmiIpaddr.Get(), + Port: ipmiPort, 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 a8c01f94..abab8e0c 100644 --- a/internal/app/wwctl/power/on/power.go +++ b/internal/app/wwctl/power/on/power.go @@ -52,9 +52,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error { if node.IpmiInterface.Get() != "" { ipmiInterface = node.IpmiInterface.Get() } + var ipmiPort = "623" + if node.IpmiPort.Get() != "" { + ipmiPort = node.IpmiPort.Get() + } ipmiCmd := power.IPMI{ NodeName: node.Id.Get(), HostName: node.IpmiIpaddr.Get(), + Port: ipmiPort, User: node.IpmiUserName.Get(), Password: node.IpmiPassword.Get(), Interface: ipmiInterface, diff --git a/internal/app/wwctl/power/status/power.go b/internal/app/wwctl/power/status/power.go index 62e0698d..d162105d 100644 --- a/internal/app/wwctl/power/status/power.go +++ b/internal/app/wwctl/power/status/power.go @@ -52,9 +52,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error { if node.IpmiInterface.Get() != "" { ipmiInterface = node.IpmiInterface.Get() } + var ipmiPort = "623" + if node.IpmiPort.Get() != "" { + ipmiPort = node.IpmiPort.Get() + } ipmiCmd := power.IPMI{ NodeName: node.Id.Get(), HostName: node.IpmiIpaddr.Get(), + Port: ipmiPort, User: node.IpmiUserName.Get(), Password: node.IpmiPassword.Get(), Interface: ipmiInterface, diff --git a/internal/app/wwctl/profile/list/main.go b/internal/app/wwctl/profile/list/main.go index bf51ae63..54c11ea7 100644 --- a/internal/app/wwctl/profile/list/main.go +++ b/internal/app/wwctl/profile/list/main.go @@ -43,6 +43,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "Ipxe", profile.Ipxe.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "IpmiIpaddr", profile.IpmiIpaddr.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "IpmiNetmask", profile.IpmiNetmask.Print()) + fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "IpmiPort", profile.IpmiPort.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "IpmiGateway", profile.IpmiGateway.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "IpmiUserName", profile.IpmiUserName.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "IpmiInterface", profile.IpmiInterface.Print()) diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index 019ea904..d6c0f2c1 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -58,7 +58,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().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 35224eba..4209ba30 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -72,6 +72,7 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) { n.Init.Set(node.Init) n.IpmiIpaddr.Set(node.IpmiIpaddr) n.IpmiNetmask.Set(node.IpmiNetmask) + n.IpmiPort.Set(node.IpmiPort) n.IpmiGateway.Set(node.IpmiGateway) n.IpmiUserName.Set(node.IpmiUserName) n.IpmiPassword.Set(node.IpmiPassword) @@ -121,6 +122,7 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) { n.Init.SetAlt(config.NodeProfiles[p].Init, p) n.IpmiIpaddr.SetAlt(config.NodeProfiles[p].IpmiIpaddr, p) n.IpmiNetmask.SetAlt(config.NodeProfiles[p].IpmiNetmask, p) + n.IpmiPort.SetAlt(config.NodeProfiles[p].IpmiPort, p) n.IpmiGateway.SetAlt(config.NodeProfiles[p].IpmiGateway, p) n.IpmiUserName.SetAlt(config.NodeProfiles[p].IpmiUserName, p) n.IpmiPassword.SetAlt(config.NodeProfiles[p].IpmiPassword, p) @@ -187,6 +189,7 @@ func (config *nodeYaml) FindAllProfiles() ([]NodeInfo, error) { p.KernelVersion.Set(profile.KernelVersion) p.KernelArgs.Set(profile.KernelArgs) p.IpmiNetmask.Set(profile.IpmiNetmask) + p.IpmiPort.Set(profile.IpmiPort) p.IpmiGateway.Set(profile.IpmiGateway) p.IpmiUserName.Set(profile.IpmiUserName) p.IpmiPassword.Set(profile.IpmiPassword) diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index 738277a9..e47275e5 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -28,6 +28,7 @@ type NodeConf struct { IpmiPassword string `yaml:"ipmi password,omitempty"` IpmiIpaddr string `yaml:"ipmi ipaddr,omitempty"` IpmiNetmask string `yaml:"ipmi netmask,omitempty"` + IpmiPort string `yaml:"ipmi port,omitempty"` IpmiGateway string `yaml:"ipmi gateway,omitempty"` IpmiInterface string `yaml:"ipmi interface,omitempty"` RuntimeOverlay string `yaml:"runtime overlay,omitempty"` @@ -75,6 +76,7 @@ type NodeInfo struct { KernelArgs Entry IpmiIpaddr Entry IpmiNetmask Entry + IpmiPort Entry IpmiGateway Entry IpmiUserName Entry IpmiPassword Entry diff --git a/internal/pkg/node/modifiers.go b/internal/pkg/node/modifiers.go index 0260d598..7abdd7e5 100644 --- a/internal/pkg/node/modifiers.go +++ b/internal/pkg/node/modifiers.go @@ -63,6 +63,7 @@ func (config *nodeYaml) NodeUpdate(node NodeInfo) error { config.Nodes[nodeID].KernelArgs = node.KernelArgs.GetReal() config.Nodes[nodeID].IpmiIpaddr = node.IpmiIpaddr.GetReal() config.Nodes[nodeID].IpmiNetmask = node.IpmiNetmask.GetReal() + config.Nodes[nodeID].IpmiPort = node.IpmiPort.GetReal() config.Nodes[nodeID].IpmiGateway = node.IpmiGateway.GetReal() config.Nodes[nodeID].IpmiUserName = node.IpmiUserName.GetReal() config.Nodes[nodeID].IpmiPassword = node.IpmiPassword.GetReal() @@ -147,6 +148,7 @@ func (config *nodeYaml) ProfileUpdate(profile NodeInfo) error { config.NodeProfiles[profileID].KernelArgs = profile.KernelArgs.GetReal() config.NodeProfiles[profileID].IpmiIpaddr = profile.IpmiIpaddr.GetReal() config.NodeProfiles[profileID].IpmiNetmask = profile.IpmiNetmask.GetReal() + config.NodeProfiles[profileID].IpmiPort = profile.IpmiPort.GetReal() config.NodeProfiles[profileID].IpmiGateway = profile.IpmiGateway.GetReal() config.NodeProfiles[profileID].IpmiUserName = profile.IpmiUserName.GetReal() config.NodeProfiles[profileID].IpmiPassword = profile.IpmiPassword.GetReal() diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index 2575b0ed..34ede735 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -29,6 +29,7 @@ type TemplateStruct struct { Root string IpmiIpaddr string IpmiNetmask string + IpmiPort string IpmiGateway string IpmiUserName string IpmiPassword string @@ -149,6 +150,7 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error { t.Root = n.Root.Get() t.IpmiIpaddr = n.IpmiIpaddr.Get() t.IpmiNetmask = n.IpmiNetmask.Get() + t.IpmiPort = n.IpmiPort.Get() t.IpmiGateway = n.IpmiGateway.Get() t.IpmiUserName = n.IpmiUserName.Get() t.IpmiPassword = n.IpmiPassword.Get() diff --git a/internal/pkg/power/ipmitool.go b/internal/pkg/power/ipmitool.go index 5c70c11b..b9e489b0 100644 --- a/internal/pkg/power/ipmitool.go +++ b/internal/pkg/power/ipmitool.go @@ -13,6 +13,7 @@ type IPMIResult struct { type IPMI struct { NodeName string HostName string + Port string User string Password string AuthType string @@ -29,9 +30,12 @@ func (ipmi *IPMI) Command(ipmiArgs []string) ([]byte, error) { var args []string if ipmi.Interface == "" { - ipmi.Interface = "lanplus" + ipmi.Interface = "lan" } - args = append(args, "-I", ipmi.Interface, "-H", ipmi.HostName, "-U", ipmi.User, "-P", ipmi.Password) + 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() @@ -44,8 +48,10 @@ func (ipmi *IPMI) InteractiveCommand(ipmiArgs []string) error { if ipmi.Interface == "" { ipmi.Interface = "lan" } - - args = append(args, "-I", ipmi.Interface, "-H", ipmi.HostName, "-U", ipmi.User, "-P", ipmi.Password) + 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