Пример #1
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)
Пример #2
0
def delete_vnic(task, name):
    name = name[0:31]
    with common.cimc_handle(task) as handle:
        rackunit = handle.get_imc_managedobject(
            None, imcsdk.ComputeRackUnit.class_id())
        adaptorunits = handle.get_imc_managedobject(
            in_mo=rackunit, class_id=imcsdk.AdaptorUnit.class_id())
        vic = {
            "Dn": "%s/host-eth-%s" % (adaptorunits[0].Dn, name),
        }
        handle.remove_imc_managedobject(
            None, class_id="adaptorHostEthIf", params=vic)
Пример #3
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}
Пример #4
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}
Пример #5
0
    def test_cimc_handle(self, mock_login, mock_handle):
        mo_hand = mock.MagicMock()
        mo_hand.username = self.node.driver_info.get('cimc_username')
        mo_hand.password = self.node.driver_info.get('cimc_password')
        mo_hand.name = self.node.driver_info.get('cimc_address')
        mock_handle.return_value = mo_hand
        info = cimc_common.parse_driver_info(self.node)

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=False) as task:
            with cimc_common.cimc_handle(task) as handle:
                self.assertEqual(handle, mock_handle.return_value)

        mock_login.assert_called_once_with(task, mock_handle.return_value,
                                           info)
        mock_handle.return_value.logout.assert_called_once_with()
Пример #6
0
    def test_cimc_handle(self, mock_login, mock_handle):
        mo_hand = mock.MagicMock()
        mo_hand.username = self.node.driver_info.get('cimc_username')
        mo_hand.password = self.node.driver_info.get('cimc_password')
        mo_hand.name = self.node.driver_info.get('cimc_address')
        mock_handle.return_value = mo_hand
        info = cimc_common.parse_driver_info(self.node)

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=False) as task:
            with cimc_common.cimc_handle(task) as handle:
                self.assertEqual(handle, mock_handle.return_value)

        mock_login.assert_called_once_with(task, mock_handle.return_value,
                                           info)
        mock_handle.return_value.logout.assert_called_once_with()
Пример #7
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)
Пример #8
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)
Пример #9
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)
Пример #10
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()
Пример #11
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)
Пример #12
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)
Пример #13
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()
Пример #14
0
def add_vnic(task, name, mac, vlan, pxe=False):
    name = name[0:31]
    with common.cimc_handle(task) as handle:
        rackunit = handle.get_imc_managedobject(
            None, imcsdk.ComputeRackUnit.class_id())
        adaptorunits = handle.get_imc_managedobject(
            in_mo=rackunit, class_id=imcsdk.AdaptorUnit.class_id())

        dn = "%s/host-eth-%s" % (adaptorunits[0].Dn, name)

        method = imcsdk.ImcCore.ExternalMethod("ConfigConfMo")
        method.Cookie = handle.cookie
        method.Dn = dn

        config = imcsdk.Imc.ConfigConfig()

        newVic = imcsdk.ImcCore.ManagedObject("adaptorHostEthIf")
        newVic.set_attr("name", name)
        newVic.set_attr("mtu", "1500")
        newVic.set_attr("pxeBoot", "enabled" if pxe else "disabled")
        newVic.set_attr("Dn", dn)
        newVic.set_attr("mac", mac)
        newVic.set_attr("uplinkPort", "1")

        vlanProfile = imcsdk.ImcCore.ManagedObject("adaptorEthGenProfile")
        vlanProfile.set_attr("vlanMode", "ACCESS")
        vlanProfile.set_attr("vlan", str(vlan))
        vlanProfile.set_attr("Dn", dn)

        newVic.add_child(vlanProfile)
        config.add_child(newVic)
        method.InConfig = config

        resp = handle.xml_query(
            method, imcsdk.WriteXmlOption.DIRTY)
        error = getattr(resp, 'error_code', None)
        if error:
            raise imcsdk.ImcException(node=task.node.uuid, error=error)
Пример #15
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)