How to use the pulp.server.managers.factory 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 / server / pulp / plugins / conduits / mixins.py View on Github external
def do_get_repo_units(repo_id, criteria, exception_class, as_generator=False):
    """
    Performs a repo unit association query. This is split apart so we can have
    custom mixins with different signatures.
    """
    try:
        association_query_manager = manager_factory.repo_unit_association_query_manager()
        # Use a get_units as_generator here and cast to a list later, if necessary.
        units = association_query_manager.get_units(repo_id, criteria=criteria, as_generator=True)

        # Load all type definitions so we don't hammer the database.
        type_defs = dict((t['id'], t) for t in types_db.all_type_definitions())

        # Transfer object generator.
        def _transfer_object_generator():
            for u in units:
                type_id = u['unit_type_id']
                type_def = type_defs[type_id]
                yield common_utils.to_plugin_associated_unit(u, type_id, type_def['unit_key'])

        if as_generator:
            return _transfer_object_generator()
github pulp / pulpcore / platform / src / pulp / server / webservices / controllers / permissions.py View on Github external
def POST(self):

        # Params
        params = self.params()
        login = params.get('login', None)
        resource = params.get('resource', None)
        operation_names = params.get('operations', None)
        
        _check_invalid_params({'login':login,
                               'resource':resource,
                               'operation_names':operation_names})
            
        operations = _get_operations(operation_names)
        
        # Grant permission synchronously
        permission_manager = managers.permission_manager()
        tags = [resource_tag(dispatch_constants.RESOURCE_PERMISSION_TYPE, resource),
                resource_tag(dispatch_constants.RESOURCE_USER_TYPE, login),
                action_tag('grant_permission_to_user')]

        call_request = CallRequest(permission_manager.grant,
                                   [resource, login, operations],
                                   tags=tags)
        call_request.reads_resource(dispatch_constants.RESOURCE_USER_TYPE, login)
        call_request.updates_resource(dispatch_constants.RESOURCE_PERMISSION_TYPE, resource)
        
        return self.ok(execution.execute_sync(call_request))
github pulp / pulpcore / server / pulp / server / webservices / controllers / contents.py View on Github external
:type  units:   list of dicts
        :param type_id: content type id
        :type  type_id: str
        :return:    same list of units that was passed in, only for convenience.
                    units are modified in-place
        """
        # quick return if there is nothing to do
        if not units:
            return units

        unit_ids = [unit['_id'] for unit in units]
        criteria = Criteria(
            filters={'unit_id': {'$in': unit_ids}, 'unit_type_id': type_id},
            fields=('repo_id', 'unit_id')
        )
        associations = factory.repo_unit_association_query_manager().find_by_criteria(criteria)
        unit_ids = None
        criteria = None
        association_map = {}
        for association in associations:
            association_map.setdefault(association['unit_id'], set()).add(
                association['repo_id'])

        for unit in units:
            unit['repository_memberships'] = list(association_map.get(unit['_id'], []))
        return units
github pulp / pulp / platform / src / pulp / server / webservices / controllers / consumer_groups.py View on Github external
def GET(self, consumer_group_id, repo_id=None):
        """
        Fetch all bind objects referencing the
        specified I{consumer_group_id}.
        @param consumer_group_id: The specified consumer.
        @type consumer_group_id: str
        @return: A list of bind dict:
            {consumer_group_id:,
             repo_id:,
             distributor_id:,
             href:,
             type_id:,
             details:}
        @rtype: dict
        """
        manager = managers_factory.consumer_bind_manager()
        bindings = manager.find_by_consumer(consumer_group_id, repo_id)
        bindings = [serialization.binding.serialize(b) for b in bindings]
        return self.ok(bindings)
github pulp / pulpcore / server / pulp / server / webservices / views / users.py View on Github external
def get(self, resuest, login):
        """
        Retrieve a specific user.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param login: login for the requested user
        :type login: str

        :return: Response containing the user
        :rtype: django.http.HttpResponse
        :raises: MissingResource if login does not exist
        """
        user = factory.user_query_manager().find_by_login(login)
        if user is None:
            raise pulp_exceptions.MissingResource(login)

        user = serialize(user)
        return generate_json_response_with_pulp_encoder(user)
github pulp / pulp / platform / src / pulp / server / webservices / application.py View on Github external
try:
        plugin_api.initialize()
    except Exception, e:
        msg  = 'One or more plugins failed to initialize. If a new type has '
        msg += 'been added, run pulp-manage-db to load the type into the '
        msg += 'database and restart the application. '
        msg += 'Error message: %s' % str(e)
        raise InitializationException(msg), None, sys.exc_info()[2]

    # There's a significantly smaller chance the following calls will fail.
    # The previous two are likely user errors, but the remainder represent
    # something gone horribly wrong. As such, I'm not going to account for each
    # and instead simply let the exception itself bubble up.

    # Load the mappings of manager type to managers
    manager_factory.initialize()

    # Initialize the tasking subsystem
    dispatch_factory.initialize()

    # Ensure the minimal auth configuration
    role_manager = manager_factory.role_manager()
    role_manager.ensure_super_user_role()
    user_manager = manager_factory.user_manager()
    user_manager.ensure_admin()

    # database document reaper
    reaper.initialize()

    # agent services
    AgentServices.start()
github pulp / pulpcore / platform / src / pulp / server / webservices / controllers / permissions.py View on Github external
def POST(self):

        # Params
        params = self.params()
        role_id = params.get('role_id', None)
        resource = params.get('resource', None)
        operation_names = params.get('operations', None)
        
        _check_invalid_params({'role_id':role_id,
                               'resource':resource,
                               'operation_names':operation_names})

        operations = _get_operations(operation_names)
        
        # Grant permission synchronously
        role_manager = managers.role_manager()
        
        tags = [resource_tag(dispatch_constants.RESOURCE_ROLE_TYPE, role_id),
                action_tag('grant_permission_to_role')]

        call_request = CallRequest(role_manager.add_permissions_to_role,
                                   [role_id, resource, operations],
                                   tags=tags)
        call_request.updates_resource(dispatch_constants.RESOURCE_ROLE_TYPE, role_id)

        return self.ok(execution.execute_sync(call_request))
github pulp / pulp / server / pulp / server / webservices / views / content.py View on Github external
:type  units:   list of dicts
        :param type_id: content type id
        :type  type_id: str
        :return:    same list of units that was passed in, only for convenience.
                    units are modified in-place
        """
        # quick return if there is nothing to do
        if not units:
            return units

        unit_ids = [unit['_id'] for unit in units]
        criteria = Criteria(
            filters={'unit_id': {'$in': unit_ids}, 'unit_type_id': type_id},
            fields=('repo_id', 'unit_id')
        )
        associations = factory.repo_unit_association_query_manager().find_by_criteria(criteria)
        unit_ids = None
        criteria = None
        association_map = {}
        for association in associations:
            association_map.setdefault(association['unit_id'], set()).add(
                association['repo_id'])

        for unit in units:
            unit['repository_memberships'] = list(association_map.get(unit['_id'], []))
        return units
github pulp / pulpcore / server / pulp / server / managers / auth / user / cud.py View on Github external
    @staticmethod
    def get_admins():
        """
        Get a list of users with the super-user role.

        :return: list of users who are admins.
        :rtype:  list of User
        """
        user_query_manager = factory.user_query_manager()

        try:
            super_users = user_query_manager.find_users_belonging_to_role(SUPER_USER_ROLE)
            return super_users
        except MissingResource:
            return None
github pulp / pulpcore / platform / src / pulp / server / webservices / controllers / repo_groups.py View on Github external
def POST(self, repo_group_id):
        # Params (validation will occur in the manager)
        params = self.params()
        distributor_type_id = params.get('distributor_type_id', None)
        distributor_config = params.get('distributor_config', None)
        distributor_id = params.get('distributor_id', None)

        distributor_manager = managers_factory.repo_group_distributor_manager()

        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
                action_tag('add_distributor')]
        if distributor_id is not None:
            tags.append(resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id))

        call_request = CallRequest(distributor_manager.add_distributor,
                                   [repo_group_id, distributor_type_id, distributor_config, distributor_id],
                                   weight=weight,
                                   tags=tags)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
        created = execution.execute(call_request)

        href = serialization.link.child_link_obj(created['id'])
        created.update(href)