예제 #1
0
    def set_power_state(self, task, power_state):
        """Turn the current power state on or off.

        :param task: a TaskManager instance.
        :param node: The Node.
        :param power_state: The desired power state POWER_ON, POWER_OFF or
                            REBOOT from :mod:`ironic.common.states`.
        :raises: InvalidParameterValue if an invalid power state was specified.
        :raises: PowerStateFailure if the power couldn't be set to power_state.
        :raises: OneViewError if OneView fails setting the power state.
        """
        oneview_info = common.get_oneview_info(task.node)

        oneview_client = common.get_oneview_client()

        LOG.debug('Setting power state of node %(node_uuid)s to '
                  '%(power_state)s',
                  {'node_uuid': task.node.uuid, 'power_state': power_state})

        try:
            if power_state == states.POWER_ON:
                oneview_client.power_on(oneview_info)
            elif power_state == states.POWER_OFF:
                oneview_client.power_off(oneview_info)
            elif power_state == states.REBOOT:
                oneview_client.power_off(oneview_info)
                oneview_client.power_on(oneview_info)
            else:
                raise exception.InvalidParameterValue(
                    _("set_power_state called with invalid power state %s.")
                    % power_state)
        except oneview_exceptions.OneViewException as exc:
            raise exception.OneViewError(
                _("Error setting power state: %s") % exc
            )
예제 #2
0
def _deallocate_server_hardware_from_ironic(node):
    """Deallocate Server Hardware from ironic.

    :param node: an ironic node object
    :raises OneViewError: if an error occurs while deallocating the Server
            Hardware to ironic

    """
    oneview_info = common.get_oneview_info(node)

    oneview_client = common.get_oneview_client()
    oneview_client.power_off(oneview_info)

    applied_sp_uuid = oneview_utils.get_uuid_from_uri(
        oneview_info.get('applied_server_profile_uri'))

    try:
        oneview_client.delete_server_profile(applied_sp_uuid)
        _del_applied_server_profile_uri_field(node)

        LOG.info(
            _LI("Server Profile %(server_profile_uuid)s was successfully"
                " deleted from node %(node_uuid)s."), {
                    "node_uuid": node.uuid,
                    "server_profile_uuid": applied_sp_uuid
                })
    except oneview_exception.OneViewException as e:

        msg = (_("Error while deleting applied Server Profile from node "
                 "%(node_uuid)s. Error: %(error)s") % {
                     'node_uuid': node.uuid,
                     'error': e
                 })

        raise exception.OneViewError(node=node.uuid, reason=msg)
예제 #3
0
파일: power.py 프로젝트: bacaldwell/ironic
    def set_power_state(self, task, power_state):
        """Turn the current power state on or off.

        :param task: a TaskManager instance.
        :param node: The Node.
        :param power_state: The desired power state POWER_ON, POWER_OFF or
                            REBOOT from :mod:`ironic.common.states`.
        :raises: InvalidParameterValue if an invalid power state was specified.
        :raises: PowerStateFailure if the power couldn't be set to power_state.
        :raises: OneViewError if OneView fails setting the power state.
        """

        oneview_info = common.get_oneview_info(task.node)
        oneview_client = common.get_oneview_client()

        LOG.debug(
            "Setting power state of node %(node_uuid)s to " "%(power_state)s",
            {"node_uuid": task.node.uuid, "power_state": power_state},
        )

        try:
            if power_state == states.POWER_ON:
                oneview_client.power_on(oneview_info)
            elif power_state == states.POWER_OFF:
                oneview_client.power_off(oneview_info)
            elif power_state == states.REBOOT:
                oneview_client.power_off(oneview_info)
                oneview_client.power_on(oneview_info)
            else:
                raise exception.InvalidParameterValue(
                    _("set_power_state called with invalid power state %s.") % power_state
                )
        except oneview_exceptions.OneViewException as exc:
            raise exception.OneViewError(_("Error setting power state: %s") % exc)
예제 #4
0
    def set_boot_device(self, task, device, persistent=False):
        """Sets the boot device for a node.

        Sets the boot device to use on next reboot of the 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: OperationNotPermitted if the server has no server profile or
                 if the server is already powered on.
        :raises: OneViewError if the communication with OneView fails
        """
        oneview_info = common.get_oneview_info(task.node)

        if device not in self.get_supported_boot_devices(task):
            raise exception.InvalidParameterValue(
                _("Invalid boot device %s specified.") % device)

        LOG.debug("Setting boot device to %(device)s for node %(node)s", {
            "device": device,
            "node": task.node.uuid
        })
        try:
            oneview_client = common.get_oneview_client()
            device_to_oneview = BOOT_DEVICE_MAPPING_TO_OV.get(device)
            oneview_client.set_boot_device(oneview_info, device_to_oneview)
        except oneview_exceptions.OneViewException as oneview_exc:
            msg = (_("Error setting boot device on OneView. Error: %s") %
                   oneview_exc)
            raise exception.OneViewError(error=msg)
예제 #5
0
def set_boot_device(task):
    """Sets the boot device for a node.

    Sets the boot device to use on next reboot of the node.

    :param task: a task from TaskManager.
    :raises: InvalidParameterValue if an invalid boot device is
             specified.
    :raises: OperationNotPermitted if the server has no server profile or
             if the server is already powered on.
    :raises: OneViewError if the communication with OneView fails
    """
    oneview_client = common.get_oneview_client()
    common.has_server_profile(task, oneview_client)
    driver_internal_info = task.node.driver_internal_info
    next_boot_device = driver_internal_info.get('next_boot_device')

    if next_boot_device:
        boot_device = next_boot_device.get('boot_device')
        persistent = next_boot_device.get('persistent')

        if boot_device not in sorted(BOOT_DEVICE_MAPPING_TO_OV):
            raise exception.InvalidParameterValue(
                _("Invalid boot device %s specified.") % boot_device)

        LOG.debug(
            "Setting boot device to %(boot_device)s and "
            "persistent to %(persistent)s for node %(node)s", {
                "boot_device": boot_device,
                "persistent": persistent,
                "node": task.node.uuid
            })

        try:
            oneview_info = common.get_oneview_info(task.node)
            device_to_oneview = BOOT_DEVICE_MAPPING_TO_OV.get(boot_device)
            oneview_client.set_boot_device(oneview_info,
                                           device_to_oneview,
                                           onetime=not persistent)
            driver_internal_info.pop('next_boot_device', None)
            task.node.driver_internal_info = driver_internal_info
            task.node.save()
        except oneview_exceptions.OneViewException as oneview_exc:
            msg = (_("Error setting boot device on OneView. Error: %s") %
                   oneview_exc)
            raise exception.OneViewError(error=msg)

    else:
        LOG.debug(
            "Not going to set boot device because there is no "
            "'next_boot_device' on driver_internal_info "
            "for the %(node)s", {"node": task.node.uuid})
예제 #6
0
def set_boot_device(task):
    """Sets the boot device for a node.

    Sets the boot device to use on next reboot of the node.

    :param task: a task from TaskManager.
    :raises: InvalidParameterValue if an invalid boot device is
             specified.
    :raises: OperationNotPermitted if the server has no server profile or
             if the server is already powered on.
    :raises: OneViewError if the communication with OneView fails
    """
    oneview_client = common.get_oneview_client()
    common.has_server_profile(task, oneview_client)
    driver_internal_info = task.node.driver_internal_info
    next_boot_device = driver_internal_info.get('next_boot_device')

    if next_boot_device:
        boot_device = next_boot_device.get('boot_device')
        persistent = next_boot_device.get('persistent')

        if boot_device not in sorted(BOOT_DEVICE_MAPPING_TO_OV):
            raise exception.InvalidParameterValue(
                _("Invalid boot device %s specified.") % boot_device)

        LOG.debug("Setting boot device to %(boot_device)s and "
                  "persistent to %(persistent)s for node %(node)s",
                  {"boot_device": boot_device, "persistent": persistent,
                   "node": task.node.uuid})

        try:
            oneview_info = common.get_oneview_info(task.node)
            device_to_oneview = BOOT_DEVICE_MAPPING_TO_OV.get(boot_device)
            oneview_client.set_boot_device(oneview_info,
                                           device_to_oneview,
                                           onetime=not persistent)
            driver_internal_info.pop('next_boot_device', None)
            task.node.driver_internal_info = driver_internal_info
            task.node.save()
        except oneview_exceptions.OneViewException as oneview_exc:
            msg = (_(
                "Error setting boot device on OneView. Error: %s")
                % oneview_exc
            )
            raise exception.OneViewError(error=msg)

    else:
        LOG.debug("Not going to set boot device because there is no "
                  "'next_boot_device' on driver_internal_info "
                  "for the %(node)s",
                  {"node": task.node.uuid})
    def __init__(self):
        if not importutils.try_import('oneview_client.client'):
            raise exception.DriverLoadError(
                driver=self.__class__.__name__,
                reason=_("Unable to import python-oneviewclient library"))

        # Checks connectivity to OneView and version compatibility on driver
        # initialization
        oneview_client = oneview_common.get_oneview_client()
        oneview_client.verify_oneview_version()
        oneview_client.verify_credentials()
        self.power = oneview_power.OneViewPower()
        self.management = oneview_management.OneViewManagement()
        self.boot = fake.FakeBoot()
        self.deploy = fake.FakeDeploy()
예제 #8
0
    def __init__(self):
        if not importutils.try_import('oneview_client.client'):
            raise exception.DriverLoadError(
                driver=self.__class__.__name__,
                reason=_("Unable to import python-oneviewclient library"))

        # Checks connectivity to OneView and version compatibility on driver
        # initialization
        oneview_client = oneview_common.get_oneview_client()
        oneview_client.verify_oneview_version()
        oneview_client.verify_credentials()
        self.power = oneview_power.OneViewPower()
        self.management = oneview_management.OneViewManagement()
        self.boot = fake.FakeBoot()
        self.deploy = fake.FakeDeploy()
예제 #9
0
def is_node_in_use_by_oneview(node):
    """Check if node is in use by OneView user.

    :param node: an ironic node object
    :returns: Boolean value. True if node is in use by OneView,
              False otherwise.
    :raises OneViewError: if not possible to get OneView's informations
             for the given node, if not possible to retrieve Server Hardware
             from OneView.

    """
    oneview_info = common.get_oneview_info(node)

    oneview_client = common.get_oneview_client()

    sh_uuid = oneview_utils.get_uuid_from_uri(
        oneview_info.get("server_hardware_uri"))

    try:
        server_hardware = oneview_client.get_server_hardware_by_uuid(sh_uuid)
    except oneview_exception.OneViewResourceNotFoundError as e:
        msg = (_("Error while obtaining Server Hardware from node "
                 "%(node_uuid)s. Error: %(error)s") % {
                     'node_uuid': node.uuid,
                     'error': e
                 })
        raise exception.OneViewError(error=msg)

    applied_sp_uri = (node.driver_info.get('applied_server_profile_uri'))

    # Check if Profile exists in Oneview and it is different of the one
    # applied by ironic
    if (server_hardware.server_profile_uri not in (None, '')
            and applied_sp_uri != server_hardware.server_profile_uri):

        LOG.warning(_LW("Node %s is already in use by OneView."), node.uuid)

        return True

    else:
        LOG.debug(
            _("Hardware %(hardware_uri)s is free for use by "
              "ironic on node %(node_uuid)s."), {
                  "hardware_uri": server_hardware.uri,
                  "node_uuid": node.uuid
              })

        return False
예제 #10
0
    def __init__(self):
        if not importutils.try_import('oneview_client.client'):
            raise exception.DriverLoadError(
                driver=self.__class__.__name__,
                reason=_("Unable to import python-oneviewclient library"))

        # Checks connectivity to OneView and version compatibility on driver
        # initialization
        oneview_client = common.get_oneview_client()
        oneview_client.verify_oneview_version()
        oneview_client.verify_credentials()
        self.power = power.OneViewPower()
        self.management = management.OneViewManagement()
        self.boot = pxe.PXEBoot()
        self.deploy = deploy.OneViewIscsiDeploy()
        self.inspect = inspect.OneViewInspect.create_if_enabled(
            'ISCSIPXEOneViewDriver')
예제 #11
0
파일: oneview.py 프로젝트: Tehsmash/ironic
    def __init__(self):
        if not importutils.try_import('oneview_client.client'):
            raise exception.DriverLoadError(
                driver=self.__class__.__name__,
                reason=_("Unable to import python-oneviewclient library"))

        # Checks connectivity to OneView and version compatibility on driver
        # initialization
        oneview_client = common.get_oneview_client()
        oneview_client.verify_oneview_version()
        oneview_client.verify_credentials()
        self.power = power.OneViewPower()
        self.management = management.OneViewManagement()
        self.boot = pxe.PXEBoot()
        self.deploy = deploy.OneViewIscsiDeploy()
        self.inspect = inspect.OneViewInspect.create_if_enabled(
            'ISCSIPXEOneViewDriver')
예제 #12
0
    def get_boot_device(self, task):
        """Get the current boot device for the task's node.

        Provides the current boot device of the node.

        :param task: a task from TaskManager.
        :returns: a dictionary containing:
            :boot_device: the boot device, one of
                :mod:`ironic.common.boot_devices` [PXE, DISK, CDROM]
            :persistent: Whether the boot device will persist to all
                future boots or not, None if it is unknown.
        :raises: OperationNotPermitted if no Server Profile is associated with
        the node
        :raises: InvalidParameterValue if the boot device is unknown
        :raises: OneViewError if the communication with OneView fails
        """

        oneview_info = common.get_oneview_info(task.node)

        try:
            oneview_client = common.get_oneview_client()
            boot_order = oneview_client.get_boot_order(oneview_info)
        except oneview_exceptions.OneViewException as oneview_exc:
            msg = (_(
                "Error getting boot device from OneView. Error: %s")
                % oneview_exc
            )
            LOG.error(msg)
            raise exception.OneViewError(msg)

        primary_device = boot_order[0]
        if primary_device not in BOOT_DEVICE_OV_TO_GENERIC:
            raise exception.InvalidParameterValue(
                _("Unsupported boot Device %(device)s for Node: %(node)s")
                % {"device": primary_device, "node": task.node.uuid}
            )

        boot_device = {
            'boot_device': BOOT_DEVICE_OV_TO_GENERIC.get(primary_device),
            'persistent': True,
        }

        return boot_device
예제 #13
0
def _check_applied_server_profile(node, predicate, positive, negative):
    """Check if node is in use by ironic in OneView.

    :param node: an ironic node object
    :returns: Boolean value. True if node is in use by ironic,
              False otherwise.
    :raises OneViewError: if not possible to get OneView's information
             for the given node, if not possible to retrieve Server Hardware
             from OneView.

    """
    oneview_info = common.get_oneview_info(node)

    oneview_client = common.get_oneview_client()

    sh_uuid = oneview_utils.get_uuid_from_uri(
        oneview_info.get("server_hardware_uri")
    )

    try:
        server_hardware = oneview_client.get_server_hardware_by_uuid(
            sh_uuid
        )
    except oneview_exception.OneViewResourceNotFoundError as e:
        msg = (_("Error while obtaining Server Hardware from node "
                 "%(node_uuid)s. Error: %(error)s") %
               {'node_uuid': node.uuid, 'error': e})
        raise exception.OneViewError(error=msg)

    applied_sp_uri = (
        node.driver_info.get('applied_server_profile_uri')
    )

    result = predicate(server_hardware, applied_sp_uri)

    if result:
        LOG.debug(positive)
    else:
        LOG.debug(negative)

    return result
예제 #14
0
파일: power.py 프로젝트: bacaldwell/ironic
    def get_power_state(self, task):
        """Gets the current power state.

        :param task: a TaskManager instance.
        :param node: The Node.
        :returns: one of :mod:`ironic.common.states` POWER_OFF,
                  POWER_ON or ERROR.
        :raises: OneViewError if fails to retrieve power state of OneView
                 resource
        """

        oneview_info = common.get_oneview_info(task.node)
        oneview_client = common.get_oneview_client()
        try:
            power_state = oneview_client.get_node_power_state(oneview_info)
        except oneview_exceptions.OneViewException as oneview_exc:
            LOG.error(
                _LE("Error getting power state for node %(node)s. Error:" "%(error)s"),
                {"node": task.node.uuid, "error": oneview_exc},
            )
            raise exception.OneViewError(error=oneview_exc)
        return common.translate_oneview_power_state(power_state)
예제 #15
0
    def get_power_state(self, task):
        """Gets the current power state.

        :param task: a TaskManager instance.
        :param node: The Node.
        :returns: one of :mod:`ironic.common.states` POWER_OFF,
                  POWER_ON or ERROR.
        :raises: OneViewError if fails to retrieve power state of OneView
                 resource
        """
        oneview_info = common.get_oneview_info(task.node)

        oneview_client = common.get_oneview_client()
        try:
            power_state = oneview_client.get_node_power_state(oneview_info)
        except oneview_exceptions.OneViewException as oneview_exc:
            LOG.error(
                _LE("Error getting power state for node %(node)s. Error:"
                    "%(error)s"),
                {'node': task.node.uuid, 'error': oneview_exc}
            )
            raise exception.OneViewError(error=oneview_exc)
        return common.translate_oneview_power_state(power_state)
예제 #16
0
    def set_boot_device(self, task, device, persistent=False):
        """Sets the boot device for a node.

        Sets the boot device to use on next reboot of the 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: OperationNotPermitted if the server has no server profile or
                 if the server is already powered on.
        :raises: OneViewError if the communication with OneView fails
        """

        oneview_info = common.get_oneview_info(task.node)

        if device not in self.get_supported_boot_devices(task):
            raise exception.InvalidParameterValue(
                _("Invalid boot device %s specified.") % device)

        LOG.debug("Setting boot device to %(device)s for node %(node)s",
                  {"device": device, "node": task.node.uuid})
        try:
            oneview_client = common.get_oneview_client()
            device_to_oneview = BOOT_DEVICE_MAPPING_TO_OV.get(device)
            oneview_client.set_boot_device(oneview_info, device_to_oneview)
        except oneview_exceptions.OneViewException as oneview_exc:
            msg = (_(
                "Error setting boot device on OneView. Error: %s")
                % oneview_exc
            )
            LOG.error(msg)
            raise exception.OneViewError(error=msg)
예제 #17
0
파일: deploy.py 프로젝트: namnh68/ironic
 def __init__(self):
     super(OneViewIscsiDeploy, self).__init__()
     self.oneview_client = common.get_oneview_client()
예제 #18
0
파일: inspect.py 프로젝트: stackhpc/ironic
 def __init__(self):
     super(OneViewInspect, self).__init__()
     self.oneview_client = common.get_oneview_client()
예제 #19
0
 def __init__(self):
     super(OneViewManagement, self).__init__()
     self.oneview_client = common.get_oneview_client()
예제 #20
0
파일: deploy.py 프로젝트: Tehsmash/ironic
 def __init__(self):
     super(OneViewAgentDeploy, self).__init__()
     self.oneview_client = common.get_oneview_client()
예제 #21
0
def allocate_server_hardware_to_ironic(node, server_profile_name):
    """Allocate Server Hardware to ironic.

    :param node: an ironic node object
    :param server_profile_name: a formatted string with the Server Profile
           name
    :raises OneViewError: if an error occurs while allocating the Server
            Hardware to ironic

    """
    node_in_use_by_oneview = is_node_in_use_by_oneview(node)

    if not node_in_use_by_oneview:

        oneview_info = common.get_oneview_info(node)

        applied_sp_uri = node.driver_info.get('applied_server_profile_uri')

        sh_uuid = oneview_utils.get_uuid_from_uri(
            oneview_info.get("server_hardware_uri")
        )
        spt_uuid = oneview_utils.get_uuid_from_uri(
            oneview_info.get("server_profile_template_uri")
        )
        oneview_client = common.get_oneview_client()
        server_hardware = oneview_client.get_server_hardware_by_uuid(sh_uuid)

        # Don't have Server Profile on OneView but has
        # `applied_server_profile_uri` on driver_info
        if (server_hardware.server_profile_uri in (None, '') and
                applied_sp_uri is not (None, '')):

            _del_applied_server_profile_uri_field(node)
            LOG.info(_LI(
                "Inconsistent 'applied_server_profile_uri' parameter "
                "value in driver_info. There is no Server Profile "
                "applied to node %(node_uuid)s. Value deleted."),
                {"node_uuid": node.uuid}
            )

        # applied_server_profile_uri exists and is equal to Server profile
        # applied on Hardware. Do not apply again.
        if (applied_sp_uri and server_hardware.server_profile_uri and
            server_hardware.server_profile_uri == applied_sp_uri):
            LOG.info(_LI(
                "The Server Profile %(applied_sp_uri)s was already applied "
                "by ironic on node %(node_uuid)s. Reusing."),
                {"node_uuid": node.uuid, "applied_sp_uri": applied_sp_uri}
            )
            return

        try:
            applied_profile = oneview_client.clone_template_and_apply(
                server_profile_name, sh_uuid, spt_uuid
            )
            _add_applied_server_profile_uri_field(node, applied_profile)

            LOG.info(
                _LI("Server Profile %(server_profile_uuid)s was successfully"
                    " applied to node %(node_uuid)s."),
                {"node_uuid": node.uuid,
                 "server_profile_uuid": applied_profile.uri}
            )

        except oneview_exception.OneViewServerProfileAssignmentError as e:
            LOG.error(_LE("An error occurred during allocating server "
                          "hardware to ironic during prepare: %s"), e)
            raise exception.OneViewError(error=e)
    else:
        msg = (_("Node %s is already in use by OneView.") %
               node.uuid)

        raise exception.OneViewError(error=msg)
예제 #22
0
 def __init__(self):
     super(OneViewInspect, self).__init__()
     self.oneview_client = common.get_oneview_client()
예제 #23
0
파일: deploy.py 프로젝트: tiansen87/ironic
 def __init__(self):
     super(OneViewAgentDeploy, self).__init__()
     self.client = common.get_hponeview_client()
     self.oneview_client = common.get_oneview_client()
예제 #24
0
 def __init__(self):
     super(OneViewPower, self).__init__()
     self.client = common.get_hponeview_client()
     self.oneview_client = common.get_oneview_client()
예제 #25
0
 def __init__(self):
     super(OneViewManagement, self).__init__()
     self.oneview_client = common.get_oneview_client()