def reboot(self, task, helper=None): """Cycles the power to a node. :param task: a TaskManager instance. :param helper: ucs helper instance. :raises: UcsOperationError on error from UCS Client. :raises: PowerStateFailure if the final state of the node is not POWER_ON. """ try: ucs_power_handle = ucs_power.UcsPower(helper) ucs_power_handle.reboot() except ucs_error.UcsOperationError as ucs_exception: LOG.error(_LE("%(driver)s: driver failed to reset node %(uuid)s " "power state."), {'driver': task.node.driver, 'uuid': task.node.uuid}) operation = _("rebooting") raise exception.UcsOperationError(operation=operation, error=ucs_exception, node=task.node.uuid) state = _wait_for_state_change(states.POWER_ON, ucs_power_handle) if state != states.POWER_ON: timeout = CONF.cisco_ucs.action_interval * CONF.cisco_ucs.max_retry LOG.error(_LE("%(driver)s: driver failed to reboot node %(uuid)s " "within %(timeout)s seconds."), {'driver': task.node.driver, 'uuid': task.node.uuid, 'timeout': timeout}) raise exception.PowerStateFailure(pstate=states.POWER_ON)
def get_power_state(self, task, helper=None): """Get the current power state. Poll the host for the current power state of the node. :param task: instance of `ironic.manager.task_manager.TaskManager`. :param helper: ucs helper instance :raises: MissingParameterValue if required CiscoDriver parameters are missing. :raises: UcsOperationError on error from UCS Client. :returns: power state. One of :class:`ironic.common.states`. """ try: power_handle = ucs_power.UcsPower(helper) power_status = power_handle.get_power_state() except ucs_error.UcsOperationError as ucs_exception: LOG.error(_LE("%(driver)s: get_power_state operation failed for " "node %(uuid)s with error: %(msg)s."), {'driver': task.node.driver, 'uuid': task.node.uuid, 'msg': ucs_exception}) operation = _('getting power status') raise exception.UcsOperationError(operation=operation, error=ucs_exception, node=task.node.uuid) return UCS_TO_IRONIC_POWER_STATE.get(power_status, states.ERROR)
def set_boot_device(self, task, device, persistent=False, helper=None): """Set the boot device for the task's node. Set the boot device to use on next reboot of the node. :param task: a task from TaskManager. :param device: the boot device, one of 'PXE, DISK or CDROM'. :param persistent: Boolean value. True if the boot device will persist to all future boots, False if not. Default: False. Ignored by this driver. :param helper: ucs helper instance. :raises: MissingParameterValue if required CiscoDriver parameters are missing. :raises: UcsOperationError on error from UCS client. setting the boot device. """ try: mgmt_handle = ucs_mgmt.BootDeviceHelper(helper) mgmt_handle.set_boot_device(device, persistent) except ucs_error.UcsOperationError as ucs_exception: LOG.error("%(driver)s: client failed to set boot device " "%(device)s for node %(uuid)s.", {'driver': task.node.driver, 'device': device, 'uuid': task.node.uuid}) operation = _('setting boot device') raise exception.UcsOperationError(operation=operation, error=ucs_exception, node=task.node.uuid) LOG.debug("Node %(uuid)s set to boot from %(device)s.", {'uuid': task.node.uuid, 'device': device})
def get_boot_device(self, task, helper=None): """Get the current boot device for the task's node. Provides the current boot device of the node. :param task: a task from TaskManager. :param helper: ucs helper instance. :returns: a dictionary containing: :boot_device: the boot device, one of :mod:`ironic.common.boot_devices` [PXE, DISK, CDROM] or None if it is unknown. :persistent: Whether the boot device will persist to all future boots or not, None if it is unknown. :raises: MissingParameterValue if a required UCS parameter is missing. :raises: UcsOperationError on error from UCS client, while setting the boot device. """ try: mgmt_handle = ucs_mgmt.BootDeviceHelper(helper) boot_device = mgmt_handle.get_boot_device() except ucs_error.UcsOperationError as ucs_exception: LOG.error("%(driver)s: client failed to get boot device for " "node %(uuid)s.", {'driver': task.node.driver, 'uuid': task.node.uuid}) operation = _('getting boot device') raise exception.UcsOperationError(operation=operation, error=ucs_exception, node=task.node.uuid) boot_device['boot_device'] = ( UCS_TO_IRONIC_BOOT_DEVICE[boot_device['boot_device']]) return boot_device
def set_power_state(self, task, pstate, helper=None): """Turn the power on or off. Set the power state of a node. :param task: instance of `ironic.manager.task_manager.TaskManager`. :param pstate: Either POWER_ON or POWER_OFF from :class: `ironic.common.states`. :param helper: ucs helper instance :raises: InvalidParameterValue if an invalid power state was specified. :raises: MissingParameterValue if required CiscoDriver parameters are missing. :raises: UcsOperationError on error from UCS Client. :raises: PowerStateFailure if the desired power state couldn't be set. """ if pstate not in (states.POWER_ON, states.POWER_OFF): msg = _("set_power_state called with invalid power state " "'%s'") % pstate raise exception.InvalidParameterValue(msg) try: ucs_power_handle = ucs_power.UcsPower(helper) power_status = ucs_power_handle.get_power_state() if UCS_TO_IRONIC_POWER_STATE.get(power_status) != pstate: ucs_power_handle.set_power_state( IRONIC_TO_UCS_POWER_STATE.get(pstate)) else: return except ucs_error.UcsOperationError as ucs_exception: LOG.error( _LE("%(driver)s: set_power_state operation failed for " "node %(uuid)s with error: %(msg)s."), { 'driver': task.node.driver, 'uuid': task.node.uuid, 'msg': ucs_exception }) operation = _("setting power status") raise exception.UcsOperationError(operation=operation, error=ucs_exception, node=task.node.uuid) state = _wait_for_state_change(pstate, ucs_power_handle) if state != pstate: timeout = CONF.cisco_ucs.action_interval * CONF.cisco_ucs.max_retry LOG.error( _LE("%(driver)s: driver failed to change node %(uuid)s " "power state to %(state)s within %(timeout)s " "seconds."), { 'driver': task.node.driver, 'uuid': task.node.uuid, 'state': pstate, 'timeout': timeout }) raise exception.PowerStateFailure(pstate=pstate)
def test_set_boot_device_fail(self, mock_mgmt, mock_helper): mc_mgmt = mock_mgmt.return_value mock_helper.generate_ucsm_handle.return_value = (True, mock.Mock()) side_effect = exception.UcsOperationError( operation='setting boot device', error='failed', node=self.node.uuid) mc_mgmt.set_boot_device.side_effect = side_effect with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: self.assertRaises(exception.IronicException, self.interface.set_boot_device, task, boot_devices.PXE) mc_mgmt.set_boot_device.assert_called_once_with( boot_devices.PXE, False)
def reboot(self, task, timeout=None, helper=None): """Cycles the power to a node. :param task: a TaskManager instance. :param timeout: timeout (in seconds). Unsupported by this interface. :param helper: ucs helper instance. :raises: UcsOperationError on error from UCS Client. :raises: PowerStateFailure if the final state of the node is not POWER_ON. """ # TODO(rloo): Support timeouts! if timeout is not None: LOG.warning( "The 'ucsm' Power Interface's 'reboot' method " "doesn't support the 'timeout' parameter. Ignoring " "timeout=%(timeout)s", {'timeout': timeout}) try: ucs_power_handle = ucs_power.UcsPower(helper) ucs_power_handle.reboot() except ucs_error.UcsOperationError as ucs_exception: LOG.error( "%(driver)s: driver failed to reset node %(uuid)s " "power state.", { 'driver': task.node.driver, 'uuid': task.node.uuid }) operation = _("rebooting") raise exception.UcsOperationError(operation=operation, error=ucs_exception, node=task.node.uuid) state = _wait_for_state_change(states.POWER_ON, ucs_power_handle) if state != states.POWER_ON: timeout = CONF.cisco_ucs.action_interval * CONF.cisco_ucs.max_retry LOG.error( "%(driver)s: driver failed to reboot node %(uuid)s " "within %(timeout)s seconds.", { 'driver': task.node.driver, 'uuid': task.node.uuid, 'timeout': timeout }) raise exception.PowerStateFailure(pstate=states.POWER_ON)