def test_get_xclarity_client(self, mock_xclarityclient): expected_call = mock.call(ip='1.2.3.4', password='******', port=443, username='******') common.get_xclarity_client(self.node) self.assertEqual(mock_xclarityclient.mock_calls, [expected_call])
def get_boot_device(self, task): """Get the current boot device for the task's node. :param task: a task from TaskManager. :returns: a dictionary containing: :boot_device: the boot device, one of [PXE, DISK, CDROM, BIOS] :persistent: Whether the boot device will persist or not :raises: InvalidParameterValue if the boot device is unknown :raises: XClarityError if the communication with XClarity fails """ node = task.node client = common.get_xclarity_client(node) server_hardware_id = common.get_server_hardware_id(node) try: boot_info = (client.get_node_all_boot_info(server_hardware_id)) except xclarity_client_exceptions.XClarityError as xclarity_exc: LOG.error( "Error getting boot device from XClarity for node %(node)s. " "Error: %(error)s", { 'node': node.uuid, 'error': xclarity_exc }) raise exception.XClarityError(error=xclarity_exc) persistent = False primary = None boot_order = boot_info['bootOrder']['bootOrderList'] for item in boot_order: current = item.get('currentBootOrderDevices', None) boot_type = item.get('bootType', None) if boot_type == "SingleUse": persistent = False primary = current[0] if primary != 'None': boot_device = { 'boot_device': primary, 'persistent': persistent } self._validate_whether_supported_boot_device(primary) return boot_device elif boot_type == "Permanent": persistent = True boot_device = { 'boot_device': current[0], 'persistent': persistent } self._validate_supported_boot_device(task, primary) return boot_device
def _set_boot_device(self, task, server_hardware_id, new_primary_boot_device, singleuse=False): """Set the current boot device for xclarity :param server_hardware_id: the uri of the server hardware in XClarity :param new_primary_boot_device: boot device to be set :param task: a TaskManager instance. :param singleuse: if this device will be used only once at next boot """ node = task.node client = common.get_xclarity_client(node) boot_info = client.get_node_all_boot_info(server_hardware_id) xclarity_boot_device = self._translate_ironic_to_xclarity( new_primary_boot_device) current = [] LOG.debug(("Setting boot device to %(device)s for XClarity " "node %(node)s"), { 'device': xclarity_boot_device, 'node': node.uuid }) for item in boot_info['bootOrder']['bootOrderList']: if singleuse and item['bootType'] == 'SingleUse': item['currentBootOrderDevices'][0] = xclarity_boot_device elif not singleuse and item['bootType'] == 'Permanent': current = item['currentBootOrderDevices'] if xclarity_boot_device == current[0]: return if xclarity_boot_device in current: current.remove(xclarity_boot_device) current.insert(0, xclarity_boot_device) item['currentBootOrderDevices'] = current try: client.set_node_boot_info(server_hardware_id, boot_info, xclarity_boot_device, singleuse) except xclarity_client_exceptions.XClarityError as xclarity_exc: LOG.error( ('Error setting boot device %(boot_device)s for the XClarity ' 'node %(node)s. Error: %(error)s'), { 'boot_device': xclarity_boot_device, 'node': node.uuid, 'error': xclarity_exc }) raise exception.XClarityError(error=xclarity_exc)
def _set_boot_device(self, task, server_hardware_id, new_primary_boot_device, singleuse=False): """Set the current boot device for xclarity :param server_hardware_id: the uri of the server hardware in XClarity :param new_primary_boot_device: boot device to be set :param task: a TaskManager instance. :param singleuse: if this device will be used only once at next boot """ node = task.node client = common.get_xclarity_client(node) boot_info = client.get_node_all_boot_info( server_hardware_id) current = [] LOG.debug( ("Setting boot device to %(device)s for XClarity " "node %(node)s"), {'device': new_primary_boot_device, 'node': node.uuid} ) for item in boot_info['bootOrder']['bootOrderList']: if singleuse and item['bootType'] == 'SingleUse': item['currentBootOrderDevices'][0] = new_primary_boot_device elif not singleuse and item['bootType'] == 'Permanent': current = item['currentBootOrderDevices'] if new_primary_boot_device == current[0]: return if new_primary_boot_device in current: current.remove(new_primary_boot_device) current.insert(0, new_primary_boot_device) item['currentBootOrderDevices'] = current try: client.set_node_boot_info(server_hardware_id, boot_info, new_primary_boot_device, singleuse) except xclarity_client_exceptions.XClarityError as xclarity_exc: LOG.error( ('Error setting boot device %(boot_device)s for the XClarity ' 'node %(node)s. Error: %(error)s'), {'boot_device': new_primary_boot_device, 'node': node.uuid, 'error': xclarity_exc} ) raise exception.XClarityError(error=xclarity_exc)
def set_power_state(self, task, power_state, timeout=None): """Turn the current power state on or off. :param task: a TaskManager instance. :param power_state: The desired power state POWER_ON, POWER_OFF or REBOOT from :mod:`ironic.common.states`. :param timeout: timeout (in seconds). Unsupported by this interface. :raises: InvalidParameterValue if an invalid power state was specified. :raises: XClarityError if XClarity fails setting the power state. """ # TODO(rloo): Support timeouts! if timeout is not None: LOG.warning( "The 'xclarity' Power Interface's 'set_power_state' method " "doesn't support the 'timeout' parameter. Ignoring " "timeout=%(timeout)s", {'timeout': timeout}) if power_state == states.REBOOT: target_power_state = self.get_power_state(task) if target_power_state == states.POWER_OFF: power_state = states.POWER_ON node = task.node client = common.get_xclarity_client(node) server_hardware_id = common.get_server_hardware_id(node) LOG.debug( "Setting power state of node %(node_uuid)s to " "%(power_state)s", { 'node_uuid': node.uuid, 'power_state': power_state }) try: client.set_node_power_status(server_hardware_id, power_state) except xclarity_client_exceptions.XClarityError as xclarity_exc: LOG.error( "Error setting power state of node %(node_uuid)s to " "%(power_state)s", { 'node_uuid': task.node.uuid, 'power_state': power_state }) raise exception.XClarityError(error=xclarity_exc)
def get_power_state(self, task): """Gets the current power state. :param task: a TaskManager instance. :returns: one of :mod:`ironic.common.states` POWER_OFF, POWER_ON or ERROR. :raises: XClarityError if fails to retrieve power state of XClarity resource """ node = task.node client = common.get_xclarity_client(node) server_hardware_id = common.get_server_hardware_id(node) try: power_state = client.get_node_power_status(server_hardware_id) except xclarity_client_exceptions.XClarityError as xclarity_exc: LOG.error(("Error getting power state for node %(node)s. Error: " "%(error)s"), { 'node': node.uuid, 'error': xclarity_exc }) raise exception.XClarityError(error=xclarity_exc) return common.translate_xclarity_power_state(power_state)
def get_power_state(self, task): """Gets the current power state. :param task: a TaskManager instance. :returns: one of :mod:`ironic.common.states` POWER_OFF, POWER_ON or ERROR. :raises: XClarityError if fails to retrieve power state of XClarity resource """ node = task.node client = common.get_xclarity_client(node) server_hardware_id = common.get_server_hardware_id(node) try: power_state = client.get_node_power_status(server_hardware_id) except xclarity_client_exceptions.XClarityError as xclarity_exc: LOG.error( ("Error getting power state for node %(node)s. Error: " "%(error)s"), {'node': node.uuid, 'error': xclarity_exc} ) raise exception.XClarityError(error=xclarity_exc) return common.translate_xclarity_power_state(power_state)
def set_power_state(self, task, power_state, timeout=None): """Turn the current power state on or off. :param task: a TaskManager instance. :param power_state: The desired power state POWER_ON, POWER_OFF or REBOOT from :mod:`ironic.common.states`. :param timeout: timeout (in seconds). Unsupported by this interface. :raises: InvalidParameterValue if an invalid power state was specified. :raises: XClarityError if XClarity fails setting the power state. """ # TODO(rloo): Support timeouts! if timeout is not None: LOG.warning( "The 'xclarity' Power Interface's 'set_power_state' method " "doesn't support the 'timeout' parameter. Ignoring " "timeout=%(timeout)s", {'timeout': timeout}) if power_state == states.REBOOT: target_power_state = self.get_power_state(task) if target_power_state == states.POWER_OFF: power_state = states.POWER_ON node = task.node client = common.get_xclarity_client(node) server_hardware_id = common.get_server_hardware_id(node) LOG.debug("Setting power state of node %(node_uuid)s to " "%(power_state)s", {'node_uuid': node.uuid, 'power_state': power_state}) try: client.set_node_power_status(server_hardware_id, power_state) except xclarity_client_exceptions.XClarityError as xclarity_exc: LOG.error( "Error setting power state of node %(node_uuid)s to " "%(power_state)s", {'node_uuid': task.node.uuid, 'power_state': power_state}) raise exception.XClarityError(error=xclarity_exc)
def get_boot_device(self, task): """Get the current boot device for the task's node. :param task: a task from TaskManager. :returns: a dictionary containing: :boot_device: the boot device, one of [PXE, DISK, CDROM, BIOS] :persistent: Whether the boot device will persist or not It returns None if boot device is unknown. :raises: InvalidParameterValue if the boot device is unknown :raises: XClarityError if the communication with XClarity fails """ node = task.node client = common.get_xclarity_client(node) server_hardware_id = common.get_server_hardware_id(node) try: boot_info = (client.get_node_all_boot_info(server_hardware_id)) except xclarity_client_exceptions.XClarityError as xclarity_exc: LOG.error( "Error getting boot device from XClarity for node %(node)s. " "Error: %(error)s", { 'node': node.uuid, 'error': xclarity_exc }) raise exception.XClarityError(error=xclarity_exc) persistent = False primary = None boot_order = boot_info['bootOrder']['bootOrderList'] for item in boot_order: current = item.get('currentBootOrderDevices') if current is None: LOG.warning( 'Current boot order is None from XClarity for ' 'node %(node)s. Please check the hardware and ' 'XClarity connection', { 'node': node.uuid, }) return {'boot_device': None, 'persistent': None} else: primary = current[0] boot_type = item.get('bootType') if boot_type.lower() == "singleuse": persistent = False if primary != 'None': self._validate_supported_boot_device(task, primary) boot_device = { 'boot_device': BOOT_DEVICE_MAPPING_FROM_XCLARITY.get(primary), 'persistent': persistent } return boot_device elif boot_type.lower() in ['permanent', 'bootorder']: # for System X servers, permanent boot type is 'Permanent' # for Purley servers, permanent boot type is 'BootOrder' persistent = True if primary != 'None': self._validate_supported_boot_device(task, primary) boot_device = { 'boot_device': BOOT_DEVICE_MAPPING_FROM_XCLARITY.get(primary), 'persistent': persistent } return boot_device else: return {'boot_device': None, 'persistent': None}
def __init__(self): super(XClarityPower, self).__init__() self.xclarity_client = common.get_xclarity_client()
def __init__(self): super(XClarityManagement, self).__init__() self.xclarity_client = common.get_xclarity_client()
def get_boot_device(self, task): """Get the current boot device for the task's node. :param task: a task from TaskManager. :returns: a dictionary containing: :boot_device: the boot device, one of [PXE, DISK, CDROM, BIOS] :persistent: Whether the boot device will persist or not It returns None if boot device is unknown. :raises: InvalidParameterValue if the boot device is unknown :raises: XClarityError if the communication with XClarity fails """ node = task.node client = common.get_xclarity_client(node) server_hardware_id = common.get_server_hardware_id(node) try: boot_info = ( client.get_node_all_boot_info( server_hardware_id) ) except xclarity_client_exceptions.XClarityError as xclarity_exc: LOG.error( "Error getting boot device from XClarity for node %(node)s. " "Error: %(error)s", {'node': node.uuid, 'error': xclarity_exc}) raise exception.XClarityError(error=xclarity_exc) persistent = False primary = None boot_order = boot_info['bootOrder']['bootOrderList'] for item in boot_order: current = item.get('currentBootOrderDevices') if current is None: LOG.warning( 'Current boot order is None from XClarity for ' 'node %(node)s. Please check the hardware and ' 'XClarity connection', {'node': node.uuid, }) return {'boot_device': None, 'persistent': None} else: primary = current[0] boot_type = item.get('bootType') if boot_type == "SingleUse": persistent = False if primary != 'None': self._validate_supported_boot_device(task, primary) boot_device = { 'boot_device': BOOT_DEVICE_MAPPING_FROM_XCLARITY.get(primary), 'persistent': persistent } return boot_device elif boot_type == "Permanent": persistent = True if primary != 'None': self._validate_supported_boot_device(task, primary) boot_device = { 'boot_device': BOOT_DEVICE_MAPPING_FROM_XCLARITY.get(primary), 'persistent': persistent } return boot_device else: return {'boot_device': None, 'persistent': None}