Пример #1
0
 def test_ensure_create_resource_provider(self):
     self.placement_fixture.mock_put.side_effect = \
         n_exc.PlacementResourceProviderNotFound(
             resource_provider=RESOURCE_PROVIDER_UUID)
     self.placement_api_client.ensure_resource_provider(RESOURCE_PROVIDER)
     self.placement_fixture.mock_post.assert_called_once_with(
         '/resource_providers', RESOURCE_PROVIDER)
Пример #2
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)
Пример #3
0
    def get_inventory(self, resource_provider_uuid, resource_class):
        """Get resource provider inventory.

        :param resource_provider_uuid: UUID of the resource provider.
        :param resource_class: Resource class name of the inventory to be
                               returned.
        :raises PlacementResourceProviderNotFound: If the resource provider is
                                                   not found.
        :raises PlacementInventoryNotFound: For failure to find inventory
                                            for a resource provider.
        :returns: The inventory of the resource class as a dict.
        """
        url = '/resource_providers/%s/inventories/%s' % (
            resource_provider_uuid, resource_class)
        try:
            return self._get(url).json()
        except ks_exc.NotFound as e:
            if "No resource provider with uuid" in e.details:
                raise n_exc.PlacementResourceProviderNotFound(
                    resource_provider=resource_provider_uuid)
            elif _("No inventory of class") in e.details:
                raise n_exc.PlacementInventoryNotFound(
                    resource_provider=resource_provider_uuid,
                    resource_class=resource_class)
            else:
                raise
Пример #4
0
    def update_resource_provider(self, resource_provider):
        """Update the resource provider identified by uuid.

        :param resource_provider: The resource provider. A dict with
                                  the uuid (required),
                                  the name (required) and
                                  the parent_provider_uuid (optional).
        :raises PlacementResourceProviderNotFound: No such resource provider.
        :raises PlacementResourceProviderNameNotUnique: Conflict with another
                                                        resource provider with
                                                        the same name.
        :returns: The updated resource provider.
        """
        url = '/resource_providers/%s' % resource_provider['uuid']
        # update does not tolerate if the uuid is repeated in the body
        update_body = resource_provider.copy()
        update_body.pop('uuid')
        try:
            return self._put(url, update_body).json()
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceProviderNotFound(
                resource_provider=resource_provider['uuid'])
        except ks_exc.Conflict:
            raise n_exc.PlacementResourceProviderNameNotUnique(
                name=resource_provider['name'])
Пример #5
0
    def delete_resource_provider_inventory(self, resource_provider_uuid,
                                           resource_class):
        """Delete inventory of the resource class for a resource provider.

        :param resource_provider_uuid: UUID of the resource provider.
        :param resource_class: The name of the resource class
        :raises PlacementResourceProviderNotFound: If the resource provider
                                                   is not found.
        :raises PlacementInventoryNotFound: No inventory of class.
        :returns: None.
        """
        url = '/resource_providers/%s/inventories/%s' % (
            resource_provider_uuid, resource_class)
        try:
            self._delete(url)
        except ks_exc.NotFound as e:
            if "No resource provider with uuid" in e.details:
                raise n_exc.PlacementResourceProviderNotFound(
                    resource_provider=resource_provider_uuid)
            elif "No inventory of class" in e.details:
                raise n_exc.PlacementInventoryNotFound(
                    resource_provider=resource_provider_uuid,
                    resource_class=resource_class)
            else:
                raise
Пример #6
0
    def delete_resource_provider_traits(self, resource_provider_uuid):
        """Delete resource provider traits.

        :param resource_provider_uuid: The UUID of the resource provider for
                                       which to delete all the traits.
        """
        url = '/resource_providers/%s/traits' % (resource_provider_uuid)
        try:
            self._delete(url)
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceProviderNotFound(
                resource_provider=resource_provider_uuid)
Пример #7
0
    def get_resource_provider(self, resource_provider_uuid):
        """Get resource provider by UUID.

        :param resource_provider_uuid: UUID of the resource provider.
        :raises PlacementResourceProviderNotFound: For failure to find resource
        :returns: The Resource Provider matching the UUID.
        """
        url = '/resource_providers/%s' % resource_provider_uuid
        try:
            return self._get(url).json()
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceProviderNotFound(
                resource_provider=resource_provider_uuid)
Пример #8
0
    def list_resource_provider_traits(self, resource_provider_uuid):
        """List all traits associated with a resource provider

        :param resource_provider_uuid: UUID of the resource provider for which
                                       the traits will be listed
        :raises PlacementResourceProviderNotFound: If the resource provider
                                                   is not found.
        """
        url = '/resource_providers/%s/traits' % (resource_provider_uuid)
        try:
            return self._get(url).json()
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceProviderNotFound(
                resource_provider=resource_provider_uuid)
Пример #9
0
    def get_resource_provider(self, resource_provider_uuid):
        """Get resource provider by UUID.

        :param resource_provider_uuid: UUID of the resource provider.
        :raises PlacementResourceProviderNotFound: If the resource provider is
                                                   not present.
        :returns: The Resource Provider matching the UUID.
        :raises PlacementResourceProviderNotFound: For failure to find resource
        """
        url = '/resource_providers/%s' % resource_provider_uuid
        try:
            return self._get(url, headers={API_VERSION_REQUEST_HEADER:
                                           self._openstack_api_version}).json()
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceProviderNotFound(
                resource_provider=resource_provider_uuid)
Пример #10
0
    def delete_resource_provider_inventories(self, resource_provider_uuid):
        """Delete all inventory records for the resource provider.

        :param resource_provider_uuid: UUID of the resource provider.
        :raises PlacementResourceProviderNotFound: If the resource provider
                                                   is not found.
        """
        url = '/resource_providers/%s/inventories' % (resource_provider_uuid)
        try:
            self._delete(url)
        except ks_exc.NotFound as e:
            if "No resource provider with uuid" in e.details:
                raise n_exc.PlacementResourceProviderNotFound(
                    resource_provider=resource_provider_uuid)
            else:
                raise
Пример #11
0
    def delete_resource_provider_traits(self, resource_provider_uuid):
        """Delete resource provider traits.

        :param resource_provider_uuid: The UUID of the resource provider for
                                       which to delete all the traits.
        :raises PlacementResourceProviderNotFound: If the resource provider
                                                   is not found.
        :returns: None.
        """
        # pylint: disable=raise-missing-from
        url = '/resource_providers/%s/traits' % (resource_provider_uuid)
        try:
            self._delete(url)
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceProviderNotFound(
                resource_provider=resource_provider_uuid)
Пример #12
0
    def update_resource_provider_inventories(
            self,
            resource_provider_uuid,
            inventories,
            resource_provider_generation=None):
        """Replaces the set of inventory records for a resource provider.

        :param resource_provider_uuid: UUID of the resource provider.
        :param inventories: The inventories. A dict in the format (see:
                            Placement API ref: https://goo.gl/F22mtk)
                            {resource_class(required):
                            {allocation_ratio(required):
                            total(required):
                            max_unit(required):
                            min_unit(required):
                            reserved(required):
                            step_size(required):
                            }}
        :param resource_provider_generation: The generation of the resource
                                             provider. Optional.
        :raises PlacementResourceProviderNotFound: if the resource provider
                                                   is not found.
        :raises PlacementResourceProviderGenerationConflict: if the generation
                                                             of the resource
                                                             provider does not
                                                             match with the
                                                             server side.
        :returns: The updated set of inventory records.
        """
        if resource_provider_generation is None:
            resource_provider_generation = self.get_resource_provider(
                resource_provider_uuid=resource_provider_uuid)['generation']
        url = '/resource_providers/%s/inventories' % resource_provider_uuid
        body = {
            'resource_provider_generation': resource_provider_generation,
            'inventories': inventories
        }
        try:
            return self._put(url, body).json()
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceProviderNotFound(
                resource_provider=resource_provider_uuid)
        except ks_exc.Conflict:
            raise n_exc.PlacementResourceProviderGenerationConflict(
                resource_provider=resource_provider_uuid,
                generation=resource_provider_generation)
Пример #13
0
    def list_resource_provider_traits(self, resource_provider_uuid):
        """List all traits associated with a resource provider

        :param resource_provider_uuid: UUID of the resource provider for which
                                       the traits will be listed
        :raises PlacementResourceProviderNotFound: If the resource provider
                                                   is not found.
        :returns: The associated traits of the resource provider together
                  with the resource provider generation.
        """
        # pylint: disable=raise-missing-from
        url = '/resource_providers/%s/traits' % (resource_provider_uuid)
        try:
            return self._get(url).json()
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceProviderNotFound(
                resource_provider=resource_provider_uuid)
Пример #14
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)