@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.

        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)
dataset/ETHPy150Open openstack/ironic/ironic/drivers/modules/ucs/power.py/Power.set_power_state/original