Exemplo n.º 1
0
    def update_resource_provider_traits(
            self, resource_provider_uuid, traits,
            resource_provider_generation=None):
        """Update resource provider traits

        :param resource_provider_uuid: UUID of the resource provider for which
                                       to set the traits
        :param traits: a list of traits.
        :param resource_provider_generation: The generation of the resource
                                             provider. Optional.
        :raises PlacementResourceProviderNotFound: If the resource provider
                                                   is not found.
        :raises PlacementTraitNotFound: If any of the specified traits are not
                                        valid.
        """
        if resource_provider_generation is None:
            resource_provider_generation = self.get_resource_provider(
                resource_provider_uuid=resource_provider_uuid)['generation']
        url = '/resource_providers/%s/traits' % (resource_provider_uuid)
        body = {
            'resource_provider_generation': resource_provider_generation,
            'traits': traits
        }
        try:
            return self._put(url, body).json()
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceProviderNotFound(
                resource_provider=resource_provider_uuid)
        except ks_exc.BadRequest:
            raise n_exc.PlacementTraitNotFound(trait=traits)
Exemplo n.º 2
0
    def delete_trait(self, name):
        """Delete the specified trait.

        :param name: the name of the trait to be deleted.
        """
        url = '/traits/%s' % (name)
        try:
            self._delete(url)
        except ks_exc.NotFound:
            raise n_exc.PlacementTraitNotFound(trait=name)
Exemplo n.º 3
0
    def get_trait(self, name):
        """Check if a given trait exists

        :param name: name of the trait to check.
        :raises PlacementTraitNotFound: If the trait name not found.
        """
        url = '/traits/%s' % name
        try:
            return self._get(url)
        except ks_exc.NotFound:
            raise n_exc.PlacementTraitNotFound(trait=name)
Exemplo n.º 4
0
    def delete_trait(self, name):
        """Delete the specified trait.

        :param name: the name of the trait to be deleted.
        :raises PlacementTraitNotFound: If the trait did not exist.
        :returns: None.
        """
        # pylint: disable=raise-missing-from
        url = '/traits/%s' % (name)
        try:
            self._delete(url)
        except ks_exc.NotFound:
            raise n_exc.PlacementTraitNotFound(trait=name)
Exemplo n.º 5
0
    def get_trait(self, name):
        """Check if a given trait exists

        :param name: name of the trait to check.
        :raises PlacementTraitNotFound: If the trait name not found.
        :returns: Evaluates to True if the trait exists.
        """
        # pylint: disable=raise-missing-from
        url = '/traits/%s' % name
        try:
            return self._get(url)
        except ks_exc.NotFound:
            raise n_exc.PlacementTraitNotFound(trait=name)
Exemplo n.º 6
0
    def update_resource_provider_traits(self,
                                        resource_provider_uuid,
                                        traits,
                                        resource_provider_generation=None):
        """Replace all associated traits of a resource provider.

        :param resource_provider_uuid: UUID of the resource provider for which
                                       to set the traits
        :param traits: a list of traits.
        :param resource_provider_generation: The generation of the resource
                                             provider. Optional. If not
                                             supplied by the caller, handle
                                             potential generation conflict
                                             by retrying the call. If supplied
                                             we assume the caller handles
                                             generation conflict.
        :raises PlacementResourceProviderNotFound: If the resource provider
                                                   is not found.
        :raises PlacementTraitNotFound: If any of the specified traits are not
                                        valid.
        :raises PlacementResourceProviderGenerationConflict: For concurrent
                                                             conflicting
                                                             updates detected.
        :returns: The new traits of the resource provider together with the
                  resource provider generation.
        """
        url = '/resource_providers/%s/traits' % (resource_provider_uuid)
        body = {
            'resource_provider_generation': resource_provider_generation,
            'traits': traits
        }

        try:
            return self._put_with_retry_for_generation_conflict(
                url, body, resource_provider_uuid,
                resource_provider_generation)
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceProviderNotFound(
                resource_provider=resource_provider_uuid)
        except ks_exc.BadRequest:
            raise n_exc.PlacementTraitNotFound(trait=traits)