2019-08-09 12:08:11 +02:00
|
|
|
import logging
|
|
|
|
import subprocess
|
|
|
|
|
2020-04-19 12:28:49 +02:00
|
|
|
from netaddr import IPNetwork
|
|
|
|
|
2019-08-09 12:08:11 +02:00
|
|
|
|
2024-10-21 12:55:54 +02:00
|
|
|
class IPMI:
|
2019-08-09 12:08:11 +02:00
|
|
|
"""
|
|
|
|
Parse IPMI output
|
|
|
|
ie:
|
|
|
|
|
|
|
|
Set in Progress : Set Complete
|
|
|
|
Auth Type Support :
|
|
|
|
Auth Type Enable : Callback :
|
|
|
|
: User :
|
|
|
|
: Operator :
|
|
|
|
: Admin :
|
|
|
|
: OEM :
|
|
|
|
IP Address Source : DHCP Address
|
|
|
|
IP Address : 10.192.2.1
|
|
|
|
Subnet Mask : 255.255.240.0
|
|
|
|
MAC Address : 98:f2:b3:f0:ee:1e
|
|
|
|
SNMP Community String :
|
|
|
|
BMC ARP Control : ARP Responses Enabled, Gratuitous ARP Disabled
|
|
|
|
Default Gateway IP : 10.192.2.254
|
|
|
|
802.1q VLAN ID : Disabled
|
|
|
|
802.1q VLAN Priority : 0
|
|
|
|
RMCP+ Cipher Suites : 0,1,2,3
|
|
|
|
Cipher Suite Priv Max : XuuaXXXXXXXXXXX
|
|
|
|
: X=Cipher Suite Unused
|
|
|
|
: c=CALLBACK
|
|
|
|
: u=USER
|
|
|
|
: o=OPERATOR
|
|
|
|
: a=ADMIN
|
|
|
|
: O=OEM
|
|
|
|
Bad Password Threshold : Not Available
|
|
|
|
"""
|
2020-02-02 20:08:56 +01:00
|
|
|
|
2019-08-09 12:08:11 +02:00
|
|
|
def __init__(self):
|
2024-10-21 12:55:54 +02:00
|
|
|
self.ret, self.output = subprocess.getstatusoutput("ipmitool lan print")
|
2019-08-09 12:08:11 +02:00
|
|
|
if self.ret != 0:
|
2024-10-21 12:55:54 +02:00
|
|
|
logging.error("Cannot get ipmi info: {}".format(self.output))
|
2019-08-09 12:08:11 +02:00
|
|
|
|
|
|
|
def parse(self):
|
2020-04-19 12:28:49 +02:00
|
|
|
_ipmi = {}
|
2019-08-09 12:08:11 +02:00
|
|
|
if self.ret != 0:
|
2020-04-19 12:28:49 +02:00
|
|
|
return _ipmi
|
|
|
|
|
2019-08-09 13:26:51 +02:00
|
|
|
for line in self.output.splitlines():
|
2024-10-21 12:55:54 +02:00
|
|
|
key = line.split(":")[0].strip()
|
|
|
|
if key not in [
|
|
|
|
"802.1q VLAN ID",
|
|
|
|
"IP Address",
|
|
|
|
"Subnet Mask",
|
|
|
|
"MAC Address",
|
|
|
|
]:
|
2020-04-19 12:28:49 +02:00
|
|
|
continue
|
2024-10-21 12:55:54 +02:00
|
|
|
value = ":".join(line.split(":")[1:]).strip()
|
2020-04-19 12:28:49 +02:00
|
|
|
_ipmi[key] = value
|
|
|
|
|
|
|
|
ret = {}
|
2024-10-21 12:55:54 +02:00
|
|
|
ret["name"] = "IPMI"
|
2023-02-14 23:32:26 +01:00
|
|
|
ret["mtu"] = 1500
|
2024-10-21 12:55:54 +02:00
|
|
|
ret["bonding"] = False
|
|
|
|
ret["mac"] = _ipmi["MAC Address"]
|
|
|
|
ret["vlan"] = (
|
|
|
|
int(_ipmi["802.1q VLAN ID"])
|
|
|
|
if _ipmi["802.1q VLAN ID"] != "Disabled"
|
|
|
|
else None
|
|
|
|
)
|
|
|
|
ip = _ipmi["IP Address"]
|
|
|
|
netmask = _ipmi["Subnet Mask"]
|
|
|
|
address = str(IPNetwork("{}/{}".format(ip, netmask)))
|
2020-04-19 12:28:49 +02:00
|
|
|
|
2024-10-21 12:55:54 +02:00
|
|
|
ret["ip"] = [address]
|
|
|
|
ret["ipmi"] = True
|
2019-08-09 12:08:11 +02:00
|
|
|
return ret
|