Python keystoneauth1.exceptions.NotFound() Examples

The following are 30 code examples of keystoneauth1.exceptions.NotFound(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module keystoneauth1.exceptions , or try the search function .
Example #1
Source File: forms.py    From cloudkitty-dashboard with Apache License 2.0 6 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        super(CreateFieldForm, self).__init__(request, *args, **kwargs)
        service_id = kwargs['initial']['service_id']
        manager = api.cloudkittyclient(request).rating.hashmap
        service = manager.get_service(service_id=service_id)
        self.fields['service_name'].initial = service['name']

        try:
            fields = manager.get_field(service_id=service['name'])['fields']
        except exceptions.NotFound:
            fields = None
        if fields:
            fields = api.identify(fields)
            choices = sorted([(field, field) for field in fields['metadata']])
            self.fields['field'] = forms.DynamicChoiceField(
                label=_("Field"))
            self.fields['field'].choices = choices
        else:
            self.fields['field'] = forms.CharField(
                label=_("Field")) 
Example #2
Source File: api.py    From eclcli with Apache License 2.0 6 votes vote down vote up
def find_one(
        self,
        path,
        **kwargs
    ):
        """Find a resource by name or ID

        :param string path:
            The API-specific portion of the URL path
        :returns:
            resource dict
        """

        bulk_list = self.find_bulk(path, **kwargs)
        num_bulk = len(bulk_list)
        if num_bulk == 0:
            msg = "none found"
            raise exceptions.NotFound(msg)
        elif num_bulk > 1:
            msg = "many found"
            raise RuntimeError(msg)
        return bulk_list[0] 
Example #3
Source File: views.py    From cloudkitty-dashboard with Apache License 2.0 6 votes vote down vote up
def get_data(self):
        manager = api.cloudkittyclient(self.request)
        services = manager.rating.hashmap.get_service().get('services', [])
        services = sorted(services, key=lambda service: service['name'])
        list_services = []
        for s in services:
            try:
                service = manager.info.get_metric(metric_name=s['name'])
                unit = service['unit']
            except exceptions.NotFound:
                unit = "-"

            list_services.append({
                "id": s['service_id'],
                "name": s['name'],
                "unit": unit
            })
        return list_services 
Example #4
Source File: placement_client.py    From cyborg with Apache License 2.0 6 votes vote down vote up
def update_inventory(
            self, resource_provider_uuid, inventories,
            resource_provider_generation=None):
        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 exception.PlacementResourceProviderNotFound(
                resource_provider=resource_provider_uuid) 
Example #5
Source File: client.py    From neutron-lib with Apache License 2.0 6 votes vote down vote up
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 
Example #6
Source File: gnocchi.py    From aodh with Apache License 2.0 6 votes vote down vote up
def get_external_project_owner():
        kc = keystone_client.get_client(pecan.request.cfg)
        project_name = pecan.request.cfg.api.gnocchi_external_project_owner
        domain_name = pecan.request.cfg.api.gnocchi_external_domain_name
        try:
            domains = kc.domains.list(name=domain_name)
            project = kc.projects.find(
                name=project_name,
                domain_id=domains[0].id)
            return project.id
        except ka_exceptions.NotFound:
            LOG.warning("Unable to get domain or project information. "
                        "domain_name : %(domain_name)s, "
                        "project_name : %(project_name)s",
                        {'domain_name': domain_name,
                         'project_name': project_name})
            return None 
Example #7
Source File: client.py    From neutron-lib with Apache License 2.0 6 votes vote down vote up
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.
        :returns: None.
        """
        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 
Example #8
Source File: client.py    From neutron-lib with Apache License 2.0 6 votes vote down vote up
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']) 
Example #9
Source File: client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
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.
        """
        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) 
Example #10
Source File: client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def list_aggregates(self, resource_provider_uuid):
        """List resource provider aggregates.

        :param resource_provider_uuid: UUID of the resource provider.
        :raises PlacementAggregateNotFound: For failure to the aggregates of
                                            a resource provider.
        :returns: The list of aggregates together with the resource provider
                  generation.
        """
        url = '/resource_providers/%s/aggregates' % resource_provider_uuid
        try:
            return self._get(url).json()
        except ks_exc.NotFound:
            raise n_exc.PlacementAggregateNotFound(
                resource_provider=resource_provider_uuid) 
Example #11
Source File: client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def get_resource_class(self, name):
        """Show resource class.

        :param name: The name of the resource class to show
        :raises PlacementResourceClassNotFound: If the resource class
                                                is not found.
        :returns: The name of resource class and its set of links.
        """
        url = '/resource_classes/%s' % (name)
        try:
            return self._get(url).json()
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceClassNotFound(resource_class=name) 
Example #12
Source File: client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def delete_resource_class(self, name):
        """Delete a custom resource class.

        :param name: The name of the resource class to be deleted.
        :raises PlacementResourceClassNotFound: If the resource class
                                                is not found.
        :returns: None.
        """
        url = '/resource_classes/%s' % (name)
        try:
            self._delete(url)
        except ks_exc.NotFound:
            raise n_exc.PlacementResourceClassNotFound(resource_class=name) 
Example #13
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_get_resource_provider_no_resource_provider(self):
        self.placement_fixture.mock_get.side_effect = ks_exc.NotFound()
        self.assertRaises(n_exc.PlacementResourceProviderNotFound,
                          self.placement_api_client.get_resource_provider,
                          RESOURCE_PROVIDER_UUID) 
Example #14
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_update_resource_provider_inventories_no_rp(self):
        self.placement_fixture.mock_put.side_effect = ks_exc.NotFound()

        self.assertRaises(
            n_exc.PlacementResourceProviderNotFound,
            self.placement_api_client.update_resource_provider_inventories,
            RESOURCE_PROVIDER_UUID, INVENTORY, RESOURCE_PROVIDER_GENERATION) 
Example #15
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_get_inventory_no_resource_provider(self):
        _exception = ks_exc.NotFound()
        _exception.details = "No resource provider with uuid"
        self.placement_fixture.mock_get.side_effect = _exception
        self.assertRaises(n_exc.PlacementResourceProviderNotFound,
                          self.placement_api_client.get_inventory,
                          RESOURCE_PROVIDER_UUID, RESOURCE_CLASS_NAME) 
Example #16
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_get_inventory_no_inventory(self):
        _exception = ks_exc.NotFound()
        _exception.details = _("No inventory of class")
        self.placement_fixture.mock_get.side_effect = _exception
        self.assertRaises(n_exc.PlacementInventoryNotFound,
                          self.placement_api_client.get_inventory,
                          RESOURCE_PROVIDER_UUID, RESOURCE_CLASS_NAME) 
Example #17
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_get_inventory_not_found(self):
        _exception = ks_exc.NotFound()
        _exception.details = "Any other exception explanation"
        _exception.response = mock.Mock(text="Some error response body")
        self.placement_fixture.mock_get.side_effect = _exception
        self.assertRaises(n_exc.PlacementClientError,
                          self.placement_api_client.get_inventory,
                          RESOURCE_PROVIDER_UUID, RESOURCE_CLASS_NAME) 
Example #18
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_update_resource_provider_inventory_not_found(self):
        # Test the resource provider not found case
        self.placement_fixture.mock_put.side_effect = ks_exc.NotFound(
            details="No resource provider with uuid")
        self.assertRaises(
            n_exc.PlacementResourceNotFound,
            self.placement_api_client.update_resource_provider_inventory,
            RESOURCE_PROVIDER_UUID, INVENTORY,
            RESOURCE_CLASS_NAME, RESOURCE_PROVIDER_GENERATION) 
Example #19
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_list_aggregates_no_resource_provider(self):
        self.placement_fixture.mock_get.side_effect = ks_exc.NotFound()
        self.assertRaises(n_exc.PlacementAggregateNotFound,
                          self.placement_api_client.list_aggregates,
                          RESOURCE_PROVIDER_UUID) 
Example #20
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_update_resource_provider_traits_no_rp(self):
        traits = [TRAIT_NAME]
        self.placement_fixture.mock_put.side_effect = ks_exc.NotFound()
        self.assertRaises(
            n_exc.PlacementResourceProviderNotFound,
            self.placement_api_client.update_resource_provider_traits,
            RESOURCE_PROVIDER_UUID, traits, resource_provider_generation=0) 
Example #21
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_list_resource_provider_traits_no_rp(self):
        self.placement_fixture.mock_get.side_effect = ks_exc.NotFound()
        self.assertRaises(
            n_exc.PlacementResourceProviderNotFound,
            self.placement_api_client.list_resource_provider_traits,
            RESOURCE_PROVIDER_UUID) 
Example #22
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_delete_trait_no_trait(self):
        self.placement_fixture.mock_delete.side_effect = ks_exc.NotFound()
        self.assertRaises(
            n_exc.PlacementTraitNotFound,
            self.placement_api_client.delete_trait,
            TRAIT_NAME) 
Example #23
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_delete_resource_provider_traits_no_rp(self):
        self.placement_fixture.mock_delete.side_effect = ks_exc.NotFound()
        self.assertRaises(
            n_exc.PlacementResourceProviderNotFound,
            self.placement_api_client.delete_resource_provider_traits,
            RESOURCE_PROVIDER_UUID) 
Example #24
Source File: test_client.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_get_resource_class_no_resource_class(self):
        self.placement_fixture.mock_get.side_effect = ks_exc.NotFound()
        self.assertRaises(
            n_exc.PlacementResourceClassNotFound,
            self.placement_api_client.get_resource_class,
            RESOURCE_CLASS_NAME
        ) 
Example #25
Source File: keystone_client.py    From aodh with Apache License 2.0 5 votes vote down vote up
def delete_trust_id(conf, trust_id, auth_plugin):
    """Delete a trust previously setup for the aodh user."""
    client = get_client_on_behalf_user(conf, auth_plugin)
    try:
        client.trusts.delete(trust_id)
    except ka_exception.NotFound:
        pass 
Example #26
Source File: keystone_init.py    From monasca-docker with Apache License 2.0 5 votes vote down vote up
def ensure_user_in_group(client, user, group):
    """Ensure user is in the specified group

    :type client: keystoneclient.v3.client.Client
    :type user: keystoneclient.v3.users.User
    :type group: keystoneclient.v3.groups.Group
    :return:
    """
    try:
        client.users.check_in_group(user, group)
        logger.info('user %s is already in group %s', user.name, group.name)
    except NotFound:
        client.users.add_to_group(user, group)
        logger.info('added user %s to group %s', user.name, group.name) 
Example #27
Source File: api.py    From eclcli with Apache License 2.0 5 votes vote down vote up
def find(
        self,
        path,
        value=None,
        attr=None,
    ):
        """Find a single resource by name or ID

        :param string path:
            The API-specific portion of the URL path
        :param string search:
            search expression
        :param string attr:
            name of attribute for secondary search
        """

        try:
            ret = self._request('GET', "/%s/%s" % (path, value)).json()
        except ks_exceptions.NotFound:
            kwargs = {attr: value}
            try:
                ret = self.find_one("/%s/detail" % (path), **kwargs)
            except ks_exceptions.NotFound:
                msg = "%s not found" % value
                raise exceptions.NotFound(msg)

        return ret 
Example #28
Source File: keystone.py    From vdi-broker with Apache License 2.0 5 votes vote down vote up
def delete_trust(trust_id):
    LOG.debug("Deleting trust id: %s", trust_id)

    auth = _get_trusts_auth_plugin(trust_id)
    session = ks_session.Session(
        auth=auth, verify=not CONF.keystone.allow_untrusted)
    client = kc_v3.Client(session=session)
    try:
        client.trusts.delete(trust_id)
    except ks_exceptions.NotFound:
        LOG.debug("Trust id not found: %s", trust_id) 
Example #29
Source File: keystone_client.py    From vitrage with Apache License 2.0 5 votes vote down vote up
def delete_trust_id(trust_id, auth_plugin):
    """Delete a trust previously setup for the vitrage user."""
    client = get_client_on_behalf_user(auth_plugin)
    try:
        client.trusts.delete(trust_id)
    except ka_exception.NotFound:
        pass 
Example #30
Source File: keystone.py    From coriolis with GNU Affero General Public License v3.0 5 votes vote down vote up
def delete_trust(ctxt):
    if ctxt.trust_id:
        LOG.debug("Deleting trust id: %s", ctxt.trust_id)

        auth = _get_trusts_auth_plugin(ctxt.trust_id)
        session = ks_session.Session(
            auth=auth, verify=not CONF.keystone.allow_untrusted)
        client = kc_v3.Client(session=session)
        try:
            client.trusts.delete(ctxt.trust_id)
        except ks_exceptions.NotFound:
            LOG.debug("Trust id not found: %s", ctxt.trust_id)
        ctxt.trust_id = None