Add bmc_subnet information to introspection.

And Consolidated BMC information retrieval logic into a single function _get_bmc_info().

Change-Id: If865e10f910d9e00a68106d97cc85bd53b4a86ed
This commit is contained in:
Maximilian Brandt 2024-05-06 21:12:40 +02:00 committed by Maximilian Brandt
parent af907322f6
commit f95b5db264
1 changed files with 34 additions and 12 deletions

View File

@ -943,6 +943,9 @@ class HardwareManager(object, metaclass=abc.ABCMeta):
def get_bmc_address(self):
raise errors.IncompatibleHardwareMethodError()
def get_bmc_subnet(self):
raise errors.IncompatibleHardwareMethodError()
def get_bmc_mac(self):
raise errors.IncompatibleHardwareMethodError()
@ -1082,6 +1085,7 @@ class HardwareManager(object, metaclass=abc.ABCMeta):
hardware_info['disks'] = self.list_block_devices()
hardware_info['memory'] = self.get_memory()
hardware_info['bmc_address'] = self.get_bmc_address()
hardware_info['bmc_subnet'] = self.get_bmc_subnet()
hardware_info['bmc_v6address'] = self.get_bmc_v6address()
hardware_info['system_vendor'] = self.get_system_vendor_info()
hardware_info['boot'] = self.get_boot_info()
@ -2288,21 +2292,20 @@ class GenericHardwareManager(HardwareManager):
msg = (("Failed to nvme format device {}: {}"
).format(block_device, e))
raise errors.BlockDeviceEraseError(msg)
def _get_bmc_address_info(self, type):
"""Attempt to detect BMC information
def get_bmc_address(self):
"""Attempt to detect BMC IP address
:return: IP address of lan channel or 0.0.0.0 in case none of them is
configured properly
:param keyword: Keyword to search for in IPMITool output (e.g., 'IP Address', 'Subnet Mask')
:return: BMC information (IP address or subnet mask) or default value if none found
"""
try:
# From all the channels 0-15, only 1-11 can be assigned to
# different types of communication media and protocols and
# effectively used
# From all the channels 0-15, only 1-11 can be assigned to
# different types of communication media and protocols and
# effectively used
for channel in range(1, 12):
out, e = il_utils.execute(
"ipmitool lan print {} | awk '/IP Address[ \\t]*:/"
" {{print $4}}'".format(channel), shell=True)
"ipmitool lan print {} | awk '/{}[ \\t]*:/ {{print $4}}'".format(channel, type), shell=True)
if e.startswith("Invalid channel"):
continue
out = out.strip()
@ -2310,7 +2313,7 @@ class GenericHardwareManager(HardwareManager):
try:
ipaddress.ip_address(out)
except ValueError as exc:
LOG.warning('Invalid IP address %(output)s: %(exc)s',
LOG.warning('Invalid IP or Subnet address %(output)s: %(exc)s',
{'output': out, 'exc': exc})
continue
@ -2321,11 +2324,30 @@ class GenericHardwareManager(HardwareManager):
except (processutils.ProcessExecutionError, OSError) as e:
# Not error, because it's normal in virtual environment
LOG.warning("Cannot get BMC address: %s", e)
LOG.warning("Cannot get BMC %s: %s", key, e)
return
return '0.0.0.0'
def get_bmc_address(self):
"""Attempt to detect BMC IP address
:return: IP address of LAN channel or 0.0.0.0 if none of them is configured properly
"""
return self._get_bmc_info("IP Address")
def get_bmc_subnet(self):
"""Attempt to detect BMC subnet mask
:return: Subnet mask of the first LAN channel or 255.255.255.255 if none of them is configured properly
"""
bmc_subnet = self._get_bmc_info("Subnet Mask")
if bmc_subnet == '0.0.0.0':
return '255.255.255.255'
return bmc_subnet
def get_bmc_mac(self):
"""Attempt to detect BMC MAC address