@task_manager.require_exclusive_lock
    @ucs_helper.requires_ucs_client
    def set_power_state(self, task, pstate, helper=None):

        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)
Turn the power on or off.
dataset/ETHPy150Open openstack/ironic/ironic/drivers/modules/ucs/power.py/Power.set_power_state