def set_power_state(self, task, power_state): driver_info = _parse_driver_info(task.node) driver_internal_info = task.node.driver_internal_info if power_state == states.POWER_ON: requested_dev = driver_internal_info.get('amt_boot_device') if requested_dev: state = _power_on(driver_info, device=BOOT_DEVICE_MAP[requested_dev]) if not driver_internal_info.get('amt_boot_persistent'): del(driver_internal_info['amt_boot_device']) del(driver_internal_info['amt_boot_persistent']) task.node.driver_internal_info = driver_internal_info else: state = _power_on(driver_info) elif power_state == states.POWER_OFF: state = _power_off(driver_info) else: raise exception.InvalidParameterValue( _("set_power_state called with " " invalid power state %s.") % power_state ) if state != power_state: raise exception.PowerStateFailure(pstate=power_state)
def set_power_state(self, task, pstate, timeout=None): """Turn the power on or off. Set the power state of a node. :param task: An instance of `ironic.manager.task_manager.TaskManager`. :param pstate: Either POWER_ON or POWER_OFF from :class: `ironic.common.states`. :param timeout: timeout (in seconds). Unsupported by this interface. :raises: MissingParameterValue if required SNMP parameters are missing. :raises: InvalidParameterValue if SNMP parameters are invalid or `pstate` is invalid. :raises: PowerStateFailure if the final power state of the node is not as requested after the timeout. :raises: SNMPFailure if an SNMP request fails. """ # TODO(rloo): Support timeouts! if timeout is not None: LOG.warning( "The 'snmp' Power Interface's 'set_power_state' method " "doesn't support the 'timeout' parameter. Ignoring " "timeout=%(timeout)s", {'timeout': timeout}) driver = _get_driver(task.node) if pstate == states.POWER_ON: state = driver.power_on() elif pstate == states.POWER_OFF: state = driver.power_off() else: raise exception.InvalidParameterValue(_("set_power_state called " "with invalid power " "state %s.") % str(pstate)) if state != pstate: raise exception.PowerStateFailure(pstate=pstate)
def reboot(self, task, timeout=None): """Cycles the power to the task's node. Power cycles a node. :param task: a TaskManager instance containing the node to act on. :param timeout: timeout (in seconds). Unsupported by this interface. :raises: InvalidParameterValue if any connection parameters are incorrect. :raises: MissingParameterValue when a required parameter is missing :raises: NodeNotFound if could not find a VM corresponding to any of the provided MACs. :raises: PowerStateFailure if it failed to set power state to POWER_ON. :raises: LibvirtError if failed to connect to the Libvirt uri. """ # TODO(rloo): Support timeouts! if timeout is not None: LOG.warning("The 'libvirt' Power Interface's 'reboot' method " "doesn't support the 'timeout' parameter. Ignoring " "timeout=%(timeout)s", {'timeout': timeout}) domain = _get_domain_by_macs(task) _power_cycle(domain) state = _get_power_state(domain) if state != states.POWER_ON: raise ir_exc.PowerStateFailure(pstate=states.POWER_ON)
def _power_off(driver_info): """Turn the power off for this node. :param driver_info: the bmc access info for a node. :returns: power state POWER_OFF, one of :class:`ironic.common.states`. :raises: IPMIFailure when the native ipmi call fails. :raises: PowerStateFailure when invalid power state is returned from ipmi. """ msg = _("IPMI power off failed for node %(node_id)s with the " "following error: %(error)s") try: ipmicmd = ipmi_command.Command(bmc=driver_info['address'], userid=driver_info['username'], password=driver_info['password']) wait = CONF.ipmi.retry_timeout ret = ipmicmd.set_power('off', wait) except pyghmi_exception.IpmiException as e: error = msg % {'node_id': driver_info['uuid'], 'error': e} LOG.error(error) raise exception.IPMIFailure(error) state = ret.get('powerstate') if state == 'off': return states.POWER_OFF else: error = _("bad response: %s") % ret LOG.error(msg, {'node_id': driver_info['uuid'], 'error': error}) raise exception.PowerStateFailure(pstate=states.POWER_OFF)
def set_power_state(self, task, pstate): """Turn the power on or off. :param task: a TaskManager instance containing the node to act on. :param pstate: The desired power state, one of ironic.common.states POWER_ON, POWER_OFF. :raises: InvalidParameterValue if an invalid power state was specified. :raises: MissingParameterValue if required ipmi parameters are missing :raises: PowerStateFailure if the power couldn't be set to pstate. """ driver_info = _parse_driver_info(task.node) if pstate == states.POWER_ON: driver_utils.ensure_next_boot_device(task, driver_info) state = _power_on(driver_info) elif pstate == states.POWER_OFF: state = _power_off(driver_info) else: raise exception.InvalidParameterValue( _("set_power_state called " "with invalid power state %s.") % pstate) if state != pstate: raise exception.PowerStateFailure(pstate=pstate)
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( "%(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)
def set_power_state(self, task, node, pstate): """Turn the power on or off. Set the power state of a node. :param task: A instance of `ironic.manager.task_manager.TaskManager`. :param node: A single node. :param pstate: Either POWER_ON or POWER_OFF from :class: `ironic.common.states`. :returns NOTHING: :raises: exception.IronicException or exception.PowerStateFailure. """ driver_info = _parse_driver_info(node) driver_info['macs'] = _get_nodes_mac_addresses(task, node) ssh_obj = _get_connection(node) if pstate == states.POWER_ON: state = _power_on(ssh_obj, driver_info) elif pstate == states.POWER_OFF: state = _power_off(ssh_obj, driver_info) else: raise exception.IronicException( _("set_power_state called with invalid power state.")) if state != pstate: raise exception.PowerStateFailure(pstate=pstate)
def set_power_state(self, task, pstate): """Set the power state of the node. Turn the node power on or off. :param task: a TaskManager instance contains the target node. :param pstate: The desired power state of the node. :raises: PowerStateFailure if the power cannot set to pstate. :raises: InvalidParameterValue """ client, blade_id = msftocs_common.get_client_info( task.node.driver_info) try: if pstate == states.POWER_ON: client.set_blade_on(blade_id) elif pstate == states.POWER_OFF: client.set_blade_off(blade_id) else: raise exception.InvalidParameterValue( _('Unsupported target_state: %s') % pstate) except exception.MSFTOCSClientApiException as ex: LOG.exception( _LE("Changing the power state to %(pstate)s failed. " "Error: %(err_msg)s"), { "pstate": pstate, "err_msg": ex }) raise exception.PowerStateFailure(pstate=pstate)
def set_power_state(self, task, pstate): """Turn the power on or off. Set the power state of the task's node. :param task: a TaskManager instance containing the node to act on. :param pstate: Either POWER_ON or POWER_OFF from :class: `ironic.common.states`. :raises: InvalidParameterValue if any connection parameters are incorrect, or if the desired power state is invalid. :raises: MissingParameterValue when a required parameter is missing :raises: NodeNotFound if could not find a VM corresponding to any of the provided MACs. :raises: PowerStateFailure if it failed to set power state to pstate. :raises: SSHCommandFailed on an error from ssh. :raises: SSHConnectFailed if ssh failed to connect to the node. """ driver_info = _parse_driver_info(task.node) driver_info['macs'] = driver_utils.get_node_mac_addresses(task) ssh_obj = _get_connection(task.node) if pstate == states.POWER_ON: state = _power_on(ssh_obj, driver_info) elif pstate == states.POWER_OFF: state = _power_off(ssh_obj, driver_info) else: raise exception.InvalidParameterValue( _("set_power_state called with invalid power state %s." ) % pstate) if state != pstate: raise exception.PowerStateFailure(pstate=pstate)
def node_wait_for_power_state(task, new_state, timeout=None): """Wait for node to be in new power state. :param task: a TaskManager instance. :param new_state: the desired new power state, one of the power states in :mod:`ironic.common.states`. :param timeout: number of seconds to wait before giving up. If not specified, uses the conductor.power_state_change_timeout config value. :raises: PowerStateFailure if timed out """ retry_timeout = (timeout or CONF.conductor.power_state_change_timeout) def _wait(): status = task.driver.power.get_power_state(task) if status == new_state: raise loopingcall.LoopingCallDone(retvalue=status) # NOTE(sambetts): Return False to trigger BackOffLoopingCall to start # backing off. return False try: timer = loopingcall.BackOffLoopingCall(_wait) return timer.start(initial_delay=1, timeout=retry_timeout).wait() except loopingcall.LoopingCallTimeOut: LOG.error( 'Timed out after %(retry_timeout)s secs waiting for power ' '%(state)s on node %(node_id)s.', { 'retry_timeout': retry_timeout, 'state': new_state, 'node_id': task.node.uuid }) raise exception.PowerStateFailure(pstate=new_state)
def set_power_state(self, task, node, pstate): """Turn the power on or off. Set the power state of a node. :param task: An instance of `ironic.manager.task_manager.TaskManager`. :param node: A single node. :param pstate: Either POWER_ON or POWER_OFF from :class: `ironic.common.states`. :raises: InvalidParameterValue if any connection parameters are incorrect, or if the desired power state is invalid. :raises: NodeNotFound. :raises: PowerStateFailure if it failed to set power state to pstate. :raises: SSHCommandFailed on an error from ssh. :raises: SSHConnectFailed if ssh failed to connect to the node. """ driver_info = _parse_driver_info(node) driver_info['macs'] = driver_utils.get_node_mac_addresses(task, node) ssh_obj = _get_connection(node) if pstate == states.POWER_ON: state = _power_on(ssh_obj, driver_info) elif pstate == states.POWER_OFF: state = _power_off(ssh_obj, driver_info) else: raise exception.InvalidParameterValue( _("set_power_state called " "with invalid power state %s.") % pstate) if state != pstate: raise exception.PowerStateFailure(pstate=pstate)
def reboot(self, task, node): """Cycles the power to a node. Power cycles a node. :param task: An instance of `ironic.manager.task_manager.TaskManager`. :param node: A single node. :raises: InvalidParameterValue if any connection parameters are incorrect. :raises: NodeNotFound. :raises: PowerStateFailure if it failed to set power state to POWER_ON. :raises: SSHCommandFailed on an error from ssh. :raises: SSHConnectFailed if ssh failed to connect to the node. """ driver_info = _parse_driver_info(node) driver_info['macs'] = driver_utils.get_node_mac_addresses(task, node) ssh_obj = _get_connection(node) current_pstate = _get_power_status(ssh_obj, driver_info) if current_pstate == states.POWER_ON: _power_off(ssh_obj, driver_info) state = _power_on(ssh_obj, driver_info) if state != states.POWER_ON: raise exception.PowerStateFailure(pstate=states.POWER_ON)
def set_power_state(self, task, pstate): """Turn the power on or off. :param task: a TaskManager instance containing the node to act on. :param pstate: The desired power state, one of ironic.common.states POWER_ON, POWER_OFF. :raises: IBootOperationError on an error from iBoot. :raises: InvalidParameterValue if iboot parameters are invalid or if an invalid power state was specified. :raises: MissingParameterValue if required iboot parameters are missing. :raises: PowerStateFailure if the power couldn't be set to pstate. """ driver_info = _parse_driver_info(task.node) if pstate == states.POWER_ON: _switch(driver_info, True) elif pstate == states.POWER_OFF: _switch(driver_info, False) else: raise exception.InvalidParameterValue( _("set_power_state called with invalid " "power state %s.") % pstate) state = _power_status(driver_info) if state != pstate: raise exception.PowerStateFailure(pstate=pstate)
def set_power_state(self, task, pstate): """Turn the power on or off. Set the power state of the task's node. :param task: a TaskManager instance containing the node to act on. :param pstate: Either POWER_ON or POWER_OFF from :class: `ironic.common.states`. :raises: InvalidParameterValue if any connection parameters are incorrect, or if the desired power state is invalid. :raises: MissingParameterValue when a required parameter is missing :raises: NodeNotFound if could not find a VM corresponding to any of the provided MACs. :raises: PowerStateFailure if it failed to set power state to pstate. :raises: LibvirtError if failed to connect to the Libvirt uri. """ domain = _get_domain_by_macs(task) if pstate == states.POWER_ON: state = _power_on(domain) elif pstate == states.POWER_OFF: state = _power_off(domain) else: raise ir_exc.InvalidParameterValue( _("set_power_state called with invalid power state %s.") % pstate) if state != pstate: raise ir_exc.PowerStateFailure(pstate=pstate)
def reboot(self, task): """Cycles the power to the task's node. Power cycles a node. :param task: a TaskManager instance containing the node to act on. :raises: InvalidParameterValue if any connection parameters are incorrect. :raises: MissingParameterValue when a required parameter is missing :raises: NodeNotFound. :raises: PowerStateFailure if it failed to set power state to POWER_ON. :raises: SSHCommandFailed on an error from ssh. :raises: SSHConnectFailed if ssh failed to connect to the node. """ driver_info = _parse_driver_info(task.node) driver_info['macs'] = driver_utils.get_node_mac_addresses(task) ssh_obj = _get_connection(task.node) current_pstate = _get_power_status(ssh_obj, driver_info) if current_pstate == states.POWER_ON: _power_off(ssh_obj, driver_info) state = _power_on(ssh_obj, driver_info) if state != states.POWER_ON: raise exception.PowerStateFailure(pstate=states.POWER_ON)
def _reboot(driver_info): """Reboot this node. If the power is off, turn it on. If the power is on, reset it. :param driver_info: the bmc access info for a node. :returns: power state POWER_ON, one of :class:`ironic.common.states`. :raises: IPMIFailure when the native ipmi call fails. :raises: PowerStateFailure when invalid power state is returned from ipmi. """ msg = _LW("IPMI power reboot failed for node %(node_id)s with the " "following error: %(error)s") try: ipmicmd = ipmi_command.Command(bmc=driver_info['address'], userid=driver_info['username'], password=driver_info['password']) wait = CONF.ipmi.retry_timeout ret = ipmicmd.set_power('boot', wait) except pyghmi_exception.IpmiException as e: LOG.warning(msg % {'node_id': driver_info['uuid'], 'error': str(e)}) raise exception.IPMIFailure(cmd=str(e)) state = ret.get('powerstate') if state == 'on': return states.POWER_ON else: LOG.warning(msg % {'node_id': driver_info['uuid'], 'error': ret}) raise exception.PowerStateFailure(pstate=state)
def set_power_state(self, task, node, pstate): """Turn the power on or off. :param task: a TaskManager instance. :param node: The Node. :param pstate: The desired power state, one of ironic.common.states POWER_ON, POWER_OFF. :raises: InvalidParameterValue if required ipmi parameters are missing or if an invalid power state was specified. :raises: PowerStateFailure if the power couldn't be set to pstate. """ driver_info = _parse_driver_info(node) if pstate == states.POWER_ON: state = _power_on(driver_info) elif pstate == states.POWER_OFF: state = _power_off(driver_info) else: raise exception.InvalidParameterValue( _("set_power_state called " "with invalid power state %s.") % pstate) if state != pstate: raise exception.PowerStateFailure(pstate=pstate)
def set_power_state(self, task, pstate): """Turn the power on or off. Set the power state of a node. :param task: A instance of `ironic.manager.task_manager.TaskManager`. :param pstate: Either POWER_ON or POWER_OFF from :class: `ironic.common.states`. :raises: MissingParameterValue if required SNMP parameters are missing. :raises: InvalidParameterValue if SNMP parameters are invalid or `pstate` is invalid. :raises: PowerStateFailure if the final power state of the node is not as requested after the timeout. :raises: SNMPFailure if an SNMP request fails. """ driver = _get_driver(task.node) if pstate == states.POWER_ON: state = driver.power_on() elif pstate == states.POWER_OFF: state = driver.power_off() else: raise exception.InvalidParameterValue(_("set_power_state called " "with invalid power " "state %s.") % str(pstate)) if state != pstate: raise exception.PowerStateFailure(pstate=pstate)
def reboot(self): """Cycles the power to a node.""" self._power_off() self._set_pxe_for_next_boot() self._power_on() if self.state != states.POWER_ON: raise exception.PowerStateFailure(pstate=states.POWER_ON)
def reboot(self, task, node): """Cycles the power to a node.""" driver_info = _parse_driver_info(node) _power_off(driver_info) state = _power_on(driver_info) if state != states.POWER_ON: raise exception.PowerStateFailure(pstate=states.POWER_ON)
def test_set_power_state_fail(self, mock_saw): with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: pstate = states.POWER_ON mock_saw.side_effect = iter([exception.PowerStateFailure('x')]) self.assertRaises(exception.PowerStateFailure, task.driver.power.set_power_state, task, pstate) mock_saw.assert_called_once_with(task, pstate)
def _set_and_wait(task, target_state): """Helper function for DynamicLoopingCall. This method changes the power state and polls AMT until the desired power state is reached. :param task: a TaskManager instance contains the target node. :param target_state: desired power state. :returns: one of ironic.common.states. :raises: PowerStateFailure if cannot set the node to target_state. :raises: AMTFailure. :raises: AMTConnectFailure :raises: InvalidParameterValue """ node = task.node driver = task.driver if target_state not in (states.POWER_ON, states.POWER_OFF): raise exception.InvalidParameterValue(_('Unsupported target_state: %s') % target_state) elif target_state == states.POWER_ON: boot_device = node.driver_internal_info.get('amt_boot_device') if boot_device and boot_device != amt_common.DEFAULT_BOOT_DEVICE: driver.management.ensure_next_boot_device(node, boot_device) def _wait(status): status['power'] = _power_status(node) if status['power'] == target_state: raise loopingcall.LoopingCallDone() if status['iter'] >= CONF.amt.max_attempts: status['power'] = states.ERROR LOG.warning(_LW("AMT failed to set power state %(state)s after " "%(tries)s retries on node %(node_id)s."), {'state': target_state, 'tries': status['iter'], 'node_id': node.uuid}) raise loopingcall.LoopingCallDone() try: _set_power_state(node, target_state) except Exception: # Log failures but keep trying LOG.warning(_LW("AMT set power state %(state)s for node %(node)s " "- Attempt %(attempt)s times of %(max_attempt)s " "failed."), {'state': target_state, 'node': node.uuid, 'attempt': status['iter'] + 1, 'max_attempt': CONF.amt.max_attempts}) status['iter'] += 1 status = {'power': None, 'iter': 0} timer = loopingcall.FixedIntervalLoopingCall(_wait, status) timer.start(interval=CONF.amt.action_wait).wait() if status['power'] != target_state: raise exception.PowerStateFailure(pstate=target_state) return status['power']
def _get_power_state(driver_info): """call out to client and return the power state. """ try: ps = POWER_MAP[amtctrl(driver_info, 'power_state')] except KeyError: # response isn't in our map so raise PowerStateFailure raise exception.PowerStateFailure(pstate=None) return ps
def _wait_for_reboot(self, task, timeout): wait = CONF.agent.post_deploy_get_power_state_retry_interval if not timeout: timeout = CONF.agent.post_deploy_get_power_state_retries * wait @tenacity.retry( stop=tenacity.stop_after_delay(timeout), retry=(tenacity.retry_if_result(lambda result: not result) | tenacity.retry_if_exception_type( exception.AgentConnectionFailed)), wait=tenacity.wait_fixed(wait), reraise=True) def _wait_until_rebooted(task): try: status = self._client.get_commands_status( task.node, retry_connection=False, expect_errors=True) except exception.AgentConnectionFailed: LOG.debug('Still waiting for the agent to come back on the ' 'node %s', task.node.uuid) raise if any(cmd['command_name'] == agent_client.REBOOT_COMMAND for cmd in status): LOG.debug('Still waiting for the agent to power off on the ' 'node %s', task.node.uuid) return False return True try: _wait_until_rebooted(task) except exception.AgentConnectionFailed as exc: msg = _('Agent failed to come back on %(node)s with the "agent" ' 'power interface: %(exc)s') % { 'node': task.node.uuid, 'exc': exc} LOG.error(msg) raise exception.PowerStateFailure(msg) except Exception as exc: LOG.error('Could not reboot node %(node)s with the "agent" power ' 'interface: %(exc)s', {'node': task.node.uuid, 'exc': exc}) raise exception.PowerStateFailure( _('Unexpected error when rebooting through the agent: %s') % exc)
def _check_power_state(driver_info, pstate): """Function to check power state is correct. Up to max retries.""" # always try once + number of retries for num in range(0, 1 + CONF.iboot.max_retry): state = _power_status(driver_info) if state == pstate: return if num < CONF.iboot.max_retry: time.sleep(CONF.iboot.retry_interval) raise exception.PowerStateFailure(pstate=pstate)
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 _set_power_state(task, target_state): """Turns the server power on/off or do a reboot. :param task: a TaskManager instance containing the node to act on. :param target_state: target state of the node. :raises: InvalidParameterValue if an invalid power state was specified. :raises: IloOperationError on an error from IloClient library. :raises: PowerStateFailure if the power couldn't be set to target_state. """ node = task.node ilo_object = ilo_common.get_ilo_object(node) # Trigger the operation based on the target state. try: if target_state == states.POWER_OFF: ilo_object.hold_pwr_btn() elif target_state == states.POWER_ON: _attach_boot_iso(task) ilo_object.set_host_power('ON') elif target_state == states.REBOOT: _attach_boot_iso(task) ilo_object.reset_server() target_state = states.POWER_ON else: msg = _("_set_power_state called with invalid power state " "'%s'") % target_state raise exception.InvalidParameterValue(msg) except ilo_client.IloError as ilo_exception: LOG.error( _LE("iLO set_power_state failed to set state to %(tstate)s " " for node %(node_id)s with error: %(error)s"), { 'tstate': target_state, 'node_id': node.uuid, 'error': ilo_exception }) operation = _('iLO set_power_state') raise exception.IloOperationError(operation=operation, error=ilo_exception) # Wait till the state change gets reflected. state = _wait_for_state_change(node, target_state) if state != target_state: timeout = (CONF.ilo.power_wait) * (CONF.ilo.power_retry) LOG.error( _LE("iLO failed to change state to %(tstate)s " "within %(timeout)s sec"), { 'tstate': target_state, 'timeout': timeout }) raise exception.PowerStateFailure(pstate=target_state)
def set_power_state(self, task, power_state, timeout=None): """Set the power state of the task's node. :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) positive integer (> 0) for any power state. ``None`` indicates to use default timeout. :raises: InvalidParameterValue if an invalid power state was specified. :raises: PowerStateFailure if the power couldn't be set to power_state. :raises: OneViewError if OneView fails setting the power state. """ client = common.get_hponeview_client() if deploy_utils.is_node_in_use_by_oneview(task.node): raise exception.PowerStateFailure(_( "Cannot set power state '%(power_state)s' to node %(node)s. " "The node is in use by OneView.") % {'power_state': power_state, 'node': task.node.uuid}) if power_state not in SET_POWER_STATE_MAP: raise exception.InvalidParameterValue( _("set_power_state called with invalid power state %s.") % power_state) LOG.debug('Setting power state of node %(node_uuid)s to ' '%(power_state)s', {'node_uuid': task.node.uuid, 'power_state': power_state}) server_hardware = task.node.driver_info.get('server_hardware_uri') timeout = (-1 if timeout is None else timeout) try: if power_state == states.POWER_ON: management.set_boot_device(task) client.server_hardware.update_power_state( SET_POWER_STATE_MAP.get(power_state), server_hardware, timeout=timeout) elif power_state == states.REBOOT: client.server_hardware.update_power_state( SET_POWER_STATE_MAP.get(states.POWER_OFF), server_hardware, timeout=timeout) management.set_boot_device(task) client.server_hardware.update_power_state( SET_POWER_STATE_MAP.get(states.POWER_ON), server_hardware, timeout=timeout) else: client.server_hardware.update_power_state( SET_POWER_STATE_MAP.get(power_state), server_hardware, timeout=timeout) except client_exception.HPOneViewException as exc: raise exception.OneViewError( _("Error setting power state: %s") % exc)
def reboot(self, task): """Cycles the power to the task's node. :param task: a TaskManager instance containing the node to act on. :raises: InvalidParameterValue if required seamicro parameters are missing. :raises: PowerStateFailure if the final state of the node is not POWER_ON. """ state = _reboot(task.node) if state != states.POWER_ON: raise exception.PowerStateFailure(pstate=states.POWER_ON)
def reboot(self, task): """Cycle the power of the node :param task: a TaskManager instance contains the target node. :raises: PowerStateFailure if failed to reboot. """ client, blade_id = msftocs_common.get_client_info( task.node.driver_info) try: client.set_blade_power_cycle(blade_id) except exception.MSFTOCSClientApiException as ex: LOG.exception(_LE("Reboot failed. Error: %(err_msg)s"), {"err_msg": ex}) raise exception.PowerStateFailure(pstate=states.REBOOT)