Beispiel #1
0
    def set_boot_device(self, task, device, persistent=False):
        """Sets the boot device for a node.

        :param task: a task from TaskManager.
        :param device: the boot device, one of the supported devices
                       listed in :mod:`ironic.common.boot_devices`.
        :param persistent: Boolean value. True if the boot device will
                           persist to all future boots, False if not.
                           Default: False.
        :raises: InvalidParameterValue if an invalid boot device is
                 specified.
        :raises: XClarityError if the communication with XClarity fails
        """
        node = task.node
        xc_device = self._translate_ironic_to_xclarity(device)

        server_hardware_id = common.get_server_hardware_id(node)
        LOG.debug("Setting boot device to %(device)s for node %(node)s", {
            "device": device,
            "node": node.uuid
        })
        self._set_boot_device(task,
                              server_hardware_id,
                              xc_device,
                              singleuse=not persistent)
Beispiel #2
0
    def get_boot_device(self, task):
        """Get the current boot device for the task's node.

        :param task: a task from TaskManager.
        :returns: a dictionary containing:
            :boot_device: the boot device, one of [PXE, DISK, CDROM, BIOS]
            :persistent: Whether the boot device will persist or not
        :raises: InvalidParameterValue if the boot device is unknown
        :raises: XClarityError if the communication with XClarity fails
        """
        node = task.node
        client = common.get_xclarity_client(node)
        server_hardware_id = common.get_server_hardware_id(node)
        try:
            boot_info = (client.get_node_all_boot_info(server_hardware_id))
        except xclarity_client_exceptions.XClarityError as xclarity_exc:
            LOG.error(
                "Error getting boot device from XClarity for node %(node)s. "
                "Error: %(error)s", {
                    'node': node.uuid,
                    'error': xclarity_exc
                })
            raise exception.XClarityError(error=xclarity_exc)

        persistent = False
        primary = None
        boot_order = boot_info['bootOrder']['bootOrderList']
        for item in boot_order:
            current = item.get('currentBootOrderDevices', None)
            boot_type = item.get('bootType', None)
            if boot_type == "SingleUse":
                persistent = False
                primary = current[0]
                if primary != 'None':
                    boot_device = {
                        'boot_device': primary,
                        'persistent': persistent
                    }
                    self._validate_whether_supported_boot_device(primary)
                    return boot_device
            elif boot_type == "Permanent":
                persistent = True
                boot_device = {
                    'boot_device': current[0],
                    'persistent': persistent
                }
                self._validate_supported_boot_device(task, primary)
                return boot_device
Beispiel #3
0
    def set_power_state(self, task, power_state, timeout=None):
        """Turn the current power state on or off.

        :param task: a TaskManager instance.
        :param power_state: The desired power state POWER_ON, POWER_OFF or
                            REBOOT from :mod:`ironic.common.states`.
        :param timeout: timeout (in seconds). Unsupported by this interface.
        :raises: InvalidParameterValue if an invalid power state was specified.
        :raises: XClarityError if XClarity fails setting the power state.
        """
        # TODO(rloo): Support timeouts!
        if timeout is not None:
            LOG.warning(
                "The 'xclarity' Power Interface's 'set_power_state' method "
                "doesn't support the 'timeout' parameter. Ignoring "
                "timeout=%(timeout)s", {'timeout': timeout})

        if power_state == states.REBOOT:
            target_power_state = self.get_power_state(task)
            if target_power_state == states.POWER_OFF:
                power_state = states.POWER_ON

        node = task.node
        client = common.get_xclarity_client(node)
        server_hardware_id = common.get_server_hardware_id(node)
        LOG.debug(
            "Setting power state of node %(node_uuid)s to "
            "%(power_state)s", {
                'node_uuid': node.uuid,
                'power_state': power_state
            })

        try:
            client.set_node_power_status(server_hardware_id, power_state)
        except xclarity_client_exceptions.XClarityError as xclarity_exc:
            LOG.error(
                "Error setting power state of node %(node_uuid)s to "
                "%(power_state)s", {
                    'node_uuid': task.node.uuid,
                    'power_state': power_state
                })
            raise exception.XClarityError(error=xclarity_exc)
Beispiel #4
0
    def get_power_state(self, task):
        """Gets the current power state.

        :param task: a TaskManager instance.
        :returns: one of :mod:`ironic.common.states` POWER_OFF,
                  POWER_ON or ERROR.
        :raises: XClarityError if fails to retrieve power state of XClarity
                 resource
        """
        server_hardware_id = common.get_server_hardware_id(task.node)
        try:
            power_state = self.xclarity_client.get_node_power_status(
                server_hardware_id)
        except xclarity_client_exceptions.XClarityException as xclarity_exc:
            LOG.error(("Error getting power state for node %(node)s. Error: "
                       "%(error)s"), {
                           'node': task.node.uuid,
                           'error': xclarity_exc
                       })
            raise common.XClarityError(error=xclarity_exc)
        return common.translate_xclarity_power_state(power_state)
Beispiel #5
0
    def set_boot_device(self, task, device, persistent=False):
        """Sets the boot device for a node.

        :param task: a task from TaskManager.
        :param device: the boot device, one of the supported devices
                       listed in :mod:`ironic.common.boot_devices`.
        :param persistent: Boolean value. True if the boot device will
                           persist to all future boots, False if not.
                           Default: False.
        :raises: InvalidParameterValue if an invalid boot device is
                 specified.
        :raises: XClarityError if the communication with XClarity fails
        """
        node = task.node
        xc_device = self._translate_ironic_to_xclarity(device)

        server_hardware_id = common.get_server_hardware_id(node)
        LOG.debug("Setting boot device to %(device)s for node %(node)s",
                  {"device": device, "node": node.uuid})
        self._set_boot_device(task, server_hardware_id, xc_device,
                              singleuse=not persistent)
Beispiel #6
0
    def get_power_state(self, task):
        """Gets the current power state.

        :param task: a TaskManager instance.
        :returns: one of :mod:`ironic.common.states` POWER_OFF,
                  POWER_ON or ERROR.
        :raises: XClarityError if fails to retrieve power state of XClarity
                 resource
        """
        node = task.node
        client = common.get_xclarity_client(node)
        server_hardware_id = common.get_server_hardware_id(node)
        try:
            power_state = client.get_node_power_status(server_hardware_id)
        except xclarity_client_exceptions.XClarityError as xclarity_exc:
            LOG.error(
                ("Error getting power state for node %(node)s. Error: "
                 "%(error)s"),
                {'node': node.uuid, 'error': xclarity_exc}
            )
            raise exception.XClarityError(error=xclarity_exc)
        return common.translate_xclarity_power_state(power_state)
Beispiel #7
0
    def set_power_state(self, task, power_state, timeout=None):
        """Turn the current power state on or off.

        :param task: a TaskManager instance.
        :param power_state: The desired power state POWER_ON, POWER_OFF or
                            REBOOT from :mod:`ironic.common.states`.
        :param timeout: timeout (in seconds). Unsupported by this interface.
        :raises: InvalidParameterValue if an invalid power state was specified.
        :raises: XClarityError if XClarity fails setting the power state.
        """
        # TODO(rloo): Support timeouts!
        if timeout is not None:
            LOG.warning(
                "The 'xclarity' Power Interface's 'set_power_state' method "
                "doesn't support the 'timeout' parameter. Ignoring "
                "timeout=%(timeout)s",
                {'timeout': timeout})

        if power_state == states.REBOOT:
            target_power_state = self.get_power_state(task)
            if target_power_state == states.POWER_OFF:
                power_state = states.POWER_ON

        node = task.node
        client = common.get_xclarity_client(node)
        server_hardware_id = common.get_server_hardware_id(node)
        LOG.debug("Setting power state of node %(node_uuid)s to "
                  "%(power_state)s",
                  {'node_uuid': node.uuid, 'power_state': power_state})

        try:
            client.set_node_power_status(server_hardware_id, power_state)
        except xclarity_client_exceptions.XClarityError as xclarity_exc:
            LOG.error(
                "Error setting power state of node %(node_uuid)s to "
                "%(power_state)s",
                {'node_uuid': task.node.uuid, 'power_state': power_state})
            raise exception.XClarityError(error=xclarity_exc)
Beispiel #8
0
    def get_boot_device(self, task):
        """Get the current boot device for the task's node.

        :param task: a task from TaskManager.
        :returns: a dictionary containing:
            :boot_device: the boot device, one of [PXE, DISK, CDROM, BIOS]
            :persistent: Whether the boot device will persist or not
            It returns None if boot device is unknown.
        :raises: InvalidParameterValue if the boot device is unknown
        :raises: XClarityError if the communication with XClarity fails
        """
        node = task.node
        client = common.get_xclarity_client(node)
        server_hardware_id = common.get_server_hardware_id(node)
        try:
            boot_info = (client.get_node_all_boot_info(server_hardware_id))
        except xclarity_client_exceptions.XClarityError as xclarity_exc:
            LOG.error(
                "Error getting boot device from XClarity for node %(node)s. "
                "Error: %(error)s", {
                    'node': node.uuid,
                    'error': xclarity_exc
                })
            raise exception.XClarityError(error=xclarity_exc)

        persistent = False
        primary = None
        boot_order = boot_info['bootOrder']['bootOrderList']
        for item in boot_order:
            current = item.get('currentBootOrderDevices')
            if current is None:
                LOG.warning(
                    'Current boot order is None from XClarity for '
                    'node %(node)s. Please check the hardware and '
                    'XClarity connection', {
                        'node': node.uuid,
                    })
                return {'boot_device': None, 'persistent': None}
            else:
                primary = current[0]
            boot_type = item.get('bootType')
            if boot_type.lower() == "singleuse":
                persistent = False
                if primary != 'None':
                    self._validate_supported_boot_device(task, primary)
                    boot_device = {
                        'boot_device':
                        BOOT_DEVICE_MAPPING_FROM_XCLARITY.get(primary),
                        'persistent':
                        persistent
                    }
                    return boot_device
            elif boot_type.lower() in ['permanent', 'bootorder']:
                # for System X servers, permanent boot type is 'Permanent'
                # for Purley servers, permanent boot type is 'BootOrder'
                persistent = True
                if primary != 'None':
                    self._validate_supported_boot_device(task, primary)
                    boot_device = {
                        'boot_device':
                        BOOT_DEVICE_MAPPING_FROM_XCLARITY.get(primary),
                        'persistent':
                        persistent
                    }
                    return boot_device
                else:
                    return {'boot_device': None, 'persistent': None}
Beispiel #9
0
 def test_get_server_hardware_id(self):
     driver_info = self.node.driver_info
     driver_info['xclarity_hardware_id'] = 'test'
     self.node.driver_info = driver_info
     result = common.get_server_hardware_id(self.node)
     self.assertEqual(result, 'test')
Beispiel #10
0
 def test_validate(self, mock_validate_driver_info, mock_get_xc_client):
     with task_manager.acquire(self.context, self.node.uuid) as task:
         task.driver.power.validate(task)
     common.get_server_hardware_id(task.node)
     mock_validate_driver_info.assert_called_with(task.node)
Beispiel #11
0
 def test_get_server_hardware_id(self):
     driver_info = self.node.driver_info
     driver_info['xclarity_hardware_id'] = 'test'
     self.node.driver_info = driver_info
     result = common.get_server_hardware_id(self.node)
     self.assertEqual(result, 'test')
Beispiel #12
0
 def test_validate(self, mock_validate_driver_info, mock_get_xc_client):
     with task_manager.acquire(self.context, self.node.uuid) as task:
         task.driver.power.validate(task)
     common.get_server_hardware_id(task.node)
     mock_validate_driver_info.assert_called_with(task.node)
Beispiel #13
0
    def get_boot_device(self, task):
        """Get the current boot device for the task's node.

        :param task: a task from TaskManager.
        :returns: a dictionary containing:
            :boot_device: the boot device, one of [PXE, DISK, CDROM, BIOS]
            :persistent: Whether the boot device will persist or not
            It returns None if boot device is unknown.
        :raises: InvalidParameterValue if the boot device is unknown
        :raises: XClarityError if the communication with XClarity fails
        """
        node = task.node
        client = common.get_xclarity_client(node)
        server_hardware_id = common.get_server_hardware_id(node)
        try:
            boot_info = (
                client.get_node_all_boot_info(
                    server_hardware_id)
            )
        except xclarity_client_exceptions.XClarityError as xclarity_exc:
            LOG.error(
                "Error getting boot device from XClarity for node %(node)s. "
                "Error: %(error)s", {'node': node.uuid,
                                     'error': xclarity_exc})
            raise exception.XClarityError(error=xclarity_exc)

        persistent = False
        primary = None
        boot_order = boot_info['bootOrder']['bootOrderList']
        for item in boot_order:
            current = item.get('currentBootOrderDevices')
            if current is None:
                LOG.warning(
                    'Current boot order is None from XClarity for '
                    'node %(node)s. Please check the hardware and '
                    'XClarity connection', {'node': node.uuid, })
                return {'boot_device': None, 'persistent': None}
            else:
                primary = current[0]
            boot_type = item.get('bootType')
            if boot_type == "SingleUse":
                persistent = False
                if primary != 'None':
                    self._validate_supported_boot_device(task, primary)
                    boot_device = {
                        'boot_device':
                            BOOT_DEVICE_MAPPING_FROM_XCLARITY.get(primary),
                        'persistent': persistent
                    }
                    return boot_device
            elif boot_type == "Permanent":
                persistent = True
                if primary != 'None':
                    self._validate_supported_boot_device(task, primary)
                    boot_device = {
                        'boot_device':
                            BOOT_DEVICE_MAPPING_FROM_XCLARITY.get(primary),
                        'persistent': persistent
                    }
                    return boot_device
                else:
                    return {'boot_device': None, 'persistent': None}