How to use the pulp.server.exceptions.MissingResource function in PuLP

To help you get started, we’ve selected a few PuLP examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulp / pulpcore / platform / src / pulp / server / managers / repo / group / distributor.py View on Github external
        @raise MissingResource: if either there is no distributor for the
        given group ID/distributor ID pair or the group itself does not exist
        """

        # Check the group's existence for the exception contract first
        manager_factory.repo_group_query_manager().get_group(repo_group_id)

        # Check for the distributor if we know the group exists
        spec = {
            'repo_group_id' : repo_group_id,
            'id' : distributor_id,
        }
        distributor = RepoGroupDistributor.get_collection().find_one(spec)

        if distributor is None:
            raise MissingResource(repo_group=repo_group_id, distributor=distributor_id)

        return distributor
github pulp / pulp / server / pulp / server / managers / consumer / group / cud.py View on Github external
def validate_existing_consumer_group(group_id):
    """
    Validate the existence of a consumer group, given its id.
    Returns the consumer group db collection upon successful validation,
    raises an exception upon failure
    @param group_id: unique id of the consumer group to validate
    @type  group_id: str
    @return: consumer group db collection
    @rtype:  L{pulp.server.db.connection.PulpCollection}
    @raise:  L{pulp.server.exceptions.MissingResource}
    """
    collection = ConsumerGroup.get_collection()
    consumer_group = collection.find_one({'id': group_id})
    if consumer_group is not None:
        return collection
    raise pulp_exceptions.MissingResource(consumer_group=group_id)
github pulp / pulpcore / server / pulp / server / managers / auth / role / cud.py View on Github external
        @param role_id: role identifier
        
        @type resource: str
        @param resource: resource path to grant permissions to
        
        @type operations: list of allowed operations being granted
        @param operations: list or tuple

        @raise MissingResource: if the given role does not exist
        """
        if role_id == self.super_user_role:
            raise PulpDataException(_('super-users role cannot be changed'))
        
        role = Role.get_collection().find_one({'id' : role_id})
        if role is None:
            raise MissingResource(role_id)
        
        current_ops = role['permissions'].setdefault(resource, [])
        for o in operations:
            if o in current_ops:
                continue
            current_ops.append(o)
            
        users = factory.user_query_manager().find_users_belonging_to_role(role_id)
        for user in users:
            factory.permission_manager().grant(resource, user['login'], operations)
            
        Role.get_collection().save(role, safe=True)
github pulp / pulpcore / server / pulp / server / webservices / views / task_groups.py View on Github external
    @auth_required(authorization.READ)
    def get(self, request, group_id):
        """
        Return a response containing a list of tasks for task group.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param group_id: The ID of the task group you wish to summarize
        :type  group_id: basestring

        :return: Response containing a list of the tasks in task group
        :rtype : django.http.HttpResponse
        :raises MissingResource: if group id is not found
        """
        raise MissingResource(group_id)
github pulp / pulpcore / platform / src / pulp / server / api / consumer_group.py View on Github external
Bind (subscribe) a consumer group to a repo.
        @param id: A consumer group id.
        @type id: str
        @param repoid: A repo id to bind.
        @type repoid: str
        @raise PulpException: When consumer group is not found.
        """
        consumergroup = self.consumergroup(id)
        if consumergroup is None:
            raise PulpException("No Consumer Group with id: %s found" % id)

# 
        repo_query_manager = manager_factory.repo_query_manager()
        repo = repo_query_manager.find_by_id(repoid)
        if repo is None:
            raise MissingResource(repoid)
# 

        consumerids = consumergroup['consumerids']
        for consumerid in consumerids:
            self.consumerApi.bind(consumerid, repoid)
github pulp / pulpcore / platform / src / pulp / server / managers / repo / importer.py View on Github external
def remove_sync_schedule(self, repo_id, schedule_id):
        """
        Removes a sync schedule for a repo from the importer.
        @param repo_id:
        @param schedule_id:
        @return:
        """
        collection = RepoImporter.get_collection()
        importer = collection.find_one({'repo_id': repo_id})
        if importer is None:
            raise MissingResource(importer=repo_id)
        if schedule_id not in importer['scheduled_syncs']:
            return
        collection.update({'_id': importer['_id']},
                          {'$pull': {'scheduled_syncs': schedule_id}},
                          safe=True)
github pulp / pulp / server / pulp / server / managers / consumer / profile.py View on Github external
try:
            profiler, config = plugin_api.get_profiler_by_type(content_type)
        except plugin_exceptions.PluginNotFound:
            # Not all profile types have a type specific profiler, so let's use the baseclass
            # Profiler
            profiler, config = (Profiler(), {})
        # Allow the profiler a chance to update the profile before we save it
        if profile is None:
            raise MissingValue('profile')
        profile = profiler.update_profile(consumer, content_type, profile, config)
        try:
            p = ProfileManager.get_profile(consumer_id, content_type)
            p['profile'] = profile
            # We store the profile's hash anytime the profile gets altered
            p['profile_hash'] = UnitProfile.calculate_hash(profile)
        except MissingResource:
            p = UnitProfile(consumer_id, content_type, profile)
        collection = UnitProfile.get_collection()
        collection.save(p)
        history_manager = factory.consumer_history_manager()
        history_manager.record_event(
            consumer_id,
            'unit_profile_changed', {'profile_content_type': content_type})
        return p
github pulp / pulp / server / pulp / server / webservices / views / content.py View on Github external
:type source_id: str

        :raises: MissingResource if source id does not exist
        :return: requested content source object.
        :rtype:  django.http.HttpResponse
        """
        container = ContentContainer()
        source = container.sources.get(source_id)
        if source:
            d = source.dict()
            link = {'_href': reverse('content_sources_resource',
                    kwargs={'source_id': source.id})}
            d.update(link)
            return generate_json_response_with_pulp_encoder(d)
        else:
            raise MissingResource(source_id=source_id)
github pulp / pulp / server / pulp / server / webservices / controllers / contents.py View on Github external
    @auth_required(READ)
    def GET(self, type_id, unit_id):
        """
        Return information about a content unit.
        """
        cqm = factory.content_query_manager()
        try:
            unit = cqm.get_content_unit_by_id(type_id, unit_id)
        except MissingResource:
            return self.not_found(_('No content unit resource: %(r)s') %
                                  {'r': unit_id})
        resource = serialization.content.content_unit_obj(unit)
        resource.update({'children': serialization.content.content_unit_child_link_objs(resource)})
        return self.ok(resource)
github pulp / pulp / platform / src / pulp / server / api / consumer.py View on Github external
        @return: dictionary containing details about the repo that will describe how
                 to use the bound repo; None if no binding took place
        @rtype:  dict
        @raise PulpException: if either the consumer or repo cannot be found
        '''

        # Parameter tests
        consumer = self.consumer(id)
        if consumer is None:
            raise PulpException('Consumer [%s] not found' % id)

# 
        repo_query_manager = manager_factory.repo_query_manager()
        repo = repo_query_manager.find_by_id(repoid)
        if repo is None:
            raise MissingResource(repoid)

#        repo = self.repoapi.repository(repoid)
#        if repo is None:
#            raise PulpException('Repo [%s] does not exist' % repoid)
# 

        # Short circuit if the repo is already bound
        repoids = consumer.setdefault('repoids', [])
        if repoid in repoids:
            return None

        log.info('Bind consumer:%s, repoid: %s', id, repoid)

        # Update the consumer with the new repo, adding an entry to its history
        repoids.append(repoid)
        self.collection.save(consumer, safe=True)