

@task_manager.require_exclusive_lock
@ucs_helper.requires_ucs_client
def set_power_state(self, task, pstate, helper=None):
    "Turn the power on or off.\n\n        Set the power state of a node.\n\n        :param task: instance of `ironic.manager.task_manager.TaskManager`.\n        :param pstate: Either POWER_ON or POWER_OFF from :class:\n            `ironic.common.states`.\n        :param helper: ucs helper instance\n        :raises: InvalidParameterValue if an invalid power state was specified.\n        :raises: MissingParameterValue if required CiscoDriver parameters\n            are missing.\n        :raises: UcsOperationError on error from UCS Client.\n        :raises: PowerStateFailure if the desired power state couldn't be set.\n        "
    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)

dataset/ETHPy150Open openstack/ironic/ironic/drivers/modules/ucs/power.py Power.set_power_state/original