Example #1
0
    def get_boot_device(self, task):
        """Get the current boot device for a node.

        Provides the current boot device of the node. Be aware that not
        all drivers support this.

        :param task: a task from TaskManager.
        :raises: MissingParameterValue if a required parameter is missing
        :raises: CIMCException if there is an error from CIMC
        :returns: a dictionary containing:

            :boot_device:
                the boot device, one of :mod:`ironic.common.boot_devices` or
                None if it is unknown.
            :persistent:
                Whether the boot device will persist to all future boots or
                not, None if it is unknown.
        """

        with common.cimc_handle(task) as handle:
            method = imcsdk.ImcCore.ExternalMethod("ConfigResolveClass")
            method.Cookie = handle.cookie
            method.InDn = "sys/rack-unit-1"
            method.InHierarchical = "true"
            method.ClassId = "lsbootDef"

            try:
                resp = handle.xml_query(method, imcsdk.WriteXmlOption.DIRTY)
            except imcsdk.ImcException as e:
                raise exception.CIMCException(node=task.node.uuid, error=e)
            error = getattr(resp, 'error_code', None)
            if error:
                raise exception.CIMCException(node=task.node.uuid, error=error)

            bootDevs = resp.OutConfigs.child[0].child

            first_device = None
            for dev in bootDevs:
                try:
                    if int(dev.Order) == 1:
                        first_device = dev
                        break
                except (ValueError, AttributeError):
                    pass

            boot_device = (CIMC_TO_IRONIC_BOOT_DEVICE.get(first_device.Rn)
                           if first_device else None)

            # Every boot device in CIMC is persistent right now
            persistent = True if boot_device else None
            return {'boot_device': boot_device, 'persistent': persistent}
Example #2
0
    def set_boot_device(self, task, device, persistent=True):
        """Set the boot device for a 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
                       :mod:`ironic.common.boot_devices`.
        :param persistent: Every boot device in CIMC is persistent right now,
                           so this value is ignored.
        :raises: InvalidParameterValue if an invalid boot device is
                 specified.
        :raises: MissingParameterValue if a required parameter is missing
        :raises: CIMCException if there is an error from CIMC
        """

        with common.cimc_handle(task) as handle:
            dev = IRONIC_TO_CIMC_BOOT_DEVICE[device]

            method = imcsdk.ImcCore.ExternalMethod("ConfigConfMo")
            method.Cookie = handle.cookie
            method.Dn = "sys/rack-unit-1/boot-policy"
            method.InHierarchical = "true"

            config = imcsdk.Imc.ConfigConfig()

            bootMode = imcsdk.ImcCore.ManagedObject(dev[0])
            bootMode.set_attr("access", dev[3])
            bootMode.set_attr("type", dev[2])
            bootMode.set_attr("Rn", dev[1])
            bootMode.set_attr("order", "1")

            config.add_child(bootMode)
            method.InConfig = config

            try:
                resp = handle.xml_query(method, imcsdk.WriteXmlOption.DIRTY)
            except imcsdk.ImcException as e:
                raise exception.CIMCException(node=task.node.uuid, error=e)
            error = getattr(resp, 'error_code')
            if error:
                raise exception.CIMCException(node=task.node.uuid, error=error)
Example #3
0
def handle_login(task, handle, info):
    """Login to the CIMC handle.

    Run login on the CIMC handle, catching any ImcException and reraising
    it as an ironic CIMCException.

    :param handle: A CIMC handle.
    :param info: A list of driver info as produced by parse_driver_info.
    :raises: CIMCException if there error logging in.
    """
    try:
        handle.login(info['cimc_address'], info['cimc_username'],
                     info['cimc_password'])
    except imcsdk.ImcException as e:
        raise exception.CIMCException(node=task.node.uuid, error=e)
Example #4
0
    def set_power_state(self, task, pstate, timeout=None):
        """Set the power state of the task's node.

        :param task: a TaskManager instance containing the node to act on.
        :param pstate: Any power state from :mod:`ironic.common.states`.
        :param timeout: timeout (in seconds). Unsupported by this interface.
        :raises: MissingParameterValue if a required parameter is missing.
        :raises: InvalidParameterValue if an invalid power state is passed
        :raises: CIMCException if there is an error communicating with CIMC
        """
        # TODO(rloo): Support timeouts!
        if timeout is not None:
            LOG.warning(
                "The 'cimc' Power Interface's 'set_power_state' method "
                "doesn't support the 'timeout' parameter. Ignoring "
                "timeout=%(timeout)s", {'timeout': timeout})

        if pstate not in IRONIC_TO_CIMC_POWER_STATE:
            msg = _("set_power_state called for %(node)s with "
                    "invalid state %(state)s")
            raise exception.InvalidParameterValue(msg % {
                "node": task.node.uuid,
                "state": pstate
            })
        with common.cimc_handle(task) as handle:
            try:
                handle.set_imc_managedobject(
                    None,
                    class_id="ComputeRackUnit",
                    params={
                        imcsdk.ComputeRackUnit.ADMIN_POWER:
                        IRONIC_TO_CIMC_POWER_STATE[pstate],
                        imcsdk.ComputeRackUnit.DN:
                        "sys/rack-unit-1"
                    })
            except imcsdk.ImcException as e:
                raise exception.CIMCException(node=task.node.uuid, error=e)

        if pstate is states.REBOOT:
            pstate = states.POWER_ON

        state = _wait_for_state_change(pstate, task)
        if state != pstate:
            raise exception.PowerStateFailure(pstate=pstate)
Example #5
0
    def get_power_state(self, task):
        """Return the power state of the task's node.

        :param task: a TaskManager instance containing the node to act on.
        :raises: MissingParameterValue if a required parameter is missing.
        :returns: a power state. One of :mod:`ironic.common.states`.
        :raises: CIMCException if there is an error communicating with CIMC
        """
        current_power_state = None
        with common.cimc_handle(task) as handle:
            try:
                rack_unit = handle.get_imc_managedobject(
                    None, None, params={"Dn": "sys/rack-unit-1"})
            except imcsdk.ImcException as e:
                raise exception.CIMCException(node=task.node.uuid, error=e)
            else:
                current_power_state = rack_unit[0].get_attr("OperPower")
        return CIMC_TO_IRONIC_POWER_STATE.get(current_power_state,
                                              states.ERROR)
Example #6
0
    def _wait(store):

        current_power_state = None
        with common.cimc_handle(task) as handle:
            try:
                rack_unit = handle.get_imc_managedobject(
                    None, None, params={"Dn": "sys/rack-unit-1"})
            except imcsdk.ImcException as e:
                raise exception.CIMCException(node=task.node.uuid, error=e)
            else:
                current_power_state = rack_unit[0].get_attr("OperPower")
        store['state'] = CIMC_TO_IRONIC_POWER_STATE.get(current_power_state)

        if store['state'] == target_state:
            raise loopingcall.LoopingCallDone()

        store['retries'] -= 1
        if store['retries'] <= 0:
            store['state'] = states.ERROR
            raise loopingcall.LoopingCallDone()
Example #7
0
    def set_power_state(self, task, pstate):
        """Set the power state of the task's node.

        :param task: a TaskManager instance containing the node to act on.
        :param pstate: Any power state from :mod:`ironic.common.states`.
        :raises: MissingParameterValue if a required parameter is missing.
        :raises: InvalidParameterValue if an invalid power state is passed
        :raises: CIMCException if there is an error communicating with CIMC
        """
        if pstate not in IRONIC_TO_CIMC_POWER_STATE:
            msg = _("set_power_state called for %(node)s with "
                    "invalid state %(state)s")
            raise exception.InvalidParameterValue(msg % {
                "node": task.node.uuid,
                "state": pstate
            })
        with common.cimc_handle(task) as handle:
            try:
                handle.set_imc_managedobject(
                    None,
                    class_id="ComputeRackUnit",
                    params={
                        imcsdk.ComputeRackUnit.ADMIN_POWER:
                        IRONIC_TO_CIMC_POWER_STATE[pstate],
                        imcsdk.ComputeRackUnit.DN:
                        "sys/rack-unit-1"
                    })
            except imcsdk.ImcException as e:
                raise exception.CIMCException(node=task.node.uuid, error=e)

        if pstate is states.REBOOT:
            pstate = states.POWER_ON

        state = _wait_for_state_change(pstate, task)
        if state != pstate:
            raise exception.PowerStateFailure(pstate=pstate)