3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from ironic_python_agent import hardware
19 from ironic_python_agent import utils
21 from oslo_log import log
22 from oslo_concurrency import processutils
28 class BMCHardwareManager(hardware.GenericHardwareManager):
29 HARDWARE_MANAGER_NAME = 'BMCHardwareManager'
30 HARDWARE_MANAGER_VERSION = '1'
32 def evaluate_hardware_support(self):
33 """Declare level of hardware support provided."""
35 LOG.info('Running in BMC environment')
36 return hardware.HardwareSupport.SERVICE_PROVIDER
38 def list_network_interfaces(self):
39 network_interfaces_list = []
41 bmc_mac = self.get_ipmi_info().get('MAC Address', False)
43 LOG.info("Adding MAC address net interfaces %s", bmc_mac)
44 bmc_address = self.get_bmc_address()
45 network_interfaces_list.append(hardware.NetworkInterface(
48 ipv4_address=bmc_address,
54 network_interfaces_list = super(BMCHardwareManager, self).list_network_interfaces()
55 return network_interfaces_list
57 def get_ipmi_info(self):
58 # These modules are rarely loaded automatically
59 utils.try_execute('modprobe', 'ipmi_msghandler')
60 utils.try_execute('modprobe', 'ipmi_devintf')
61 utils.try_execute('modprobe', 'ipmi_si')
64 out, _e = utils.execute(
65 "ipmitool lan print", shell=True, attempts=2)
66 except (processutils.ProcessExecutionError, OSError) as e:
67 # Not error, because it's normal in virtual environment
68 LOG.warning("Cannot get BMC info: %s", e)
72 for line in out.split('\n'):
77 key = line[0:spl].strip()
80 info[line[0:spl].strip()] = line[spl+1:].strip()