示例#1
0
文件: repo_groups.py 项目: omps/pulp
 def GET(self, repo_group_id):
     collection = RepoGroup.get_collection()
     group = collection.find_one({'id': repo_group_id})
     if group is None:
         raise pulp_exceptions.MissingResource(repo_group=repo_group_id)
     group.update(serialization.link.current_link_obj())
     return self.ok(group)
示例#2
0
文件: roles.py 项目: beav/pulp
    def GET(self, role_id):

        role = managers.role_query_manager().find_by_id(role_id)
        if role is None:
            raise exceptions.MissingResource(role_id)

        role['users'] = [
            u['login'] for u in managers.user_query_manager().
            find_users_belonging_to_role(role['id'])
        ]
        permissions_manager = managers.permission_manager()

        # isolate schema change
        resource_permission = {}
        for item in role['permissions']:
            resource = item['resource']
            operations = item.get('permission', [])
            resource_permission[resource] = [
                permissions_manager.operation_value_to_name(o)
                for o in operations
            ]
        role['permissions'] = resource_permission

        role.update(serialization.link.current_link_obj())
        return self.ok(role)
示例#3
0
    def DELETE(self, repo_id, importer_id, schedule_id):
        importer_manager = manager_factory.repo_importer_manager()
        schedule_list = importer_manager.list_sync_schedules(repo_id)
        if schedule_id not in schedule_list:
            raise exceptions.MissingResource(repo=repo_id,
                                             importer=importer_id,
                                             publish_schedule=schedule_id)

        schedule_manager = manager_factory.schedule_manager()
        resources = {
            dispatch_constants.RESOURCE_REPOSITORY_TYPE: {
                repo_id: dispatch_constants.RESOURCE_READ_OPERATION
            },
            dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE: {
                importer_id: dispatch_constants.RESOURCE_UPDATE_OPERATION
            },
            dispatch_constants.RESOURCE_SCHEDULE_TYPE: {
                schedule_id: dispatch_constants.RESOURCE_DELETE_OPERATION
            }
        }
        tags = [
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE,
                         importer_id),
            resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE,
                         schedule_id),
            action_tag('delete_sync_schedule')
        ]
        call_request = CallRequest(schedule_manager.delete_sync_schedule,
                                   [repo_id, importer_id, schedule_id],
                                   resources=resources,
                                   tags=tags,
                                   archive=True)
        result = execution.execute(call_request)
        return self.ok(result)
示例#4
0
    def PUT(self, repo_id, importer_id):
        # Raise a MissingResource exception if the repo or the importer doesn't exist
        importer_manager = manager_factory.repo_importer_manager()
        importer = importer_manager.get_importer(repo_id)
        if importer['id'] != importer_id:
            raise exceptions.MissingResource(importer_id=importer_id)

        if not plugin_api.is_valid_importer(importer_id):
            raise exceptions.PulpCodedValidationException(
                error_code=error_codes.PLP1008)

        params = self.params()
        importer_config = params.get('importer_config', None)

        if importer_config is None:
            _logger.error(
                'Missing configuration updating importer for repository [%s]' %
                repo_id)
            raise exceptions.MissingValue(['importer_config'])

        task_tags = [
            tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_IMPORTER_TYPE,
                              importer_id),
            tags.action_tag('update_importer')
        ]
        async_result = update_importer_config.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_TYPE,
            repo_id, [repo_id], {'importer_config': importer_config},
            tags=task_tags)
        raise exceptions.OperationPostponed(async_result)
示例#5
0
    def POST(self, repo_id):
        # Params
        params = self.params()
        query = params.get('criteria', None)

        repo_query_manager = manager_factory.repo_query_manager()
        repo = repo_query_manager.find_by_id(repo_id)
        if repo is None:
            raise exceptions.MissingResource(repo_id=repo_id)

        if query is None:
            raise exceptions.MissingValue(['criteria'])

        try:
            criteria = UnitAssociationCriteria.from_client_input(query)
        except:
            _logger.error('Error parsing association criteria [%s]' % query)
            raise exceptions.PulpDataException(), None, sys.exc_info()[2]

        # Data lookup
        manager = manager_factory.repo_unit_association_query_manager()
        if criteria.type_ids is not None and len(criteria.type_ids) == 1:
            type_id = criteria.type_ids[0]
            units = manager.get_units_by_type(repo_id,
                                              type_id,
                                              criteria=criteria)
        else:
            units = manager.get_units_across_types(repo_id, criteria=criteria)

        return self.ok(units)
示例#6
0
    def DELETE(self, repo_id, distributor_id, schedule_id):
        distributor_manager = manager_factory.repo_distributor_manager()
        schedule_list = distributor_manager.list_publish_schedules(
            repo_id, distributor_id)
        if schedule_id not in schedule_list:
            raise exceptions.MissingResource(repo=repo_id,
                                             distributor=distributor_id,
                                             publish_schedule=schedule_id)

        schedule_manager = manager_factory.schedule_manager()
        tags = [
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            resource_tag(
                dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                distributor_id),
            resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE,
                         schedule_id),
            action_tag('delete_publish_schedule')
        ]
        call_request = CallRequest(schedule_manager.delete_publish_schedule,
                                   [repo_id, distributor_id, schedule_id],
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(
            dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        call_request.updates_resource(
            dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
            distributor_id)
        call_request.deletes_resource(
            dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id)
        result = execution.execute(call_request)
        return self.ok(result)
示例#7
0
    def GET(self, id):
        """
        Looks for query parameters 'importers' and 'distributors', and will add
        the corresponding fields to the repository returned. Query parameter
        'details' is equivalent to passing both 'importers' and 'distributors'.
        """
        query_params = web.input()
        query_manager = manager_factory.repo_query_manager()
        repo = query_manager.find_by_id(id)

        if repo is None:
            raise exceptions.MissingResource(repo=id)

        repo.update(serialization.link.current_link_obj())
        _convert_repo_dates_to_strings(repo)

        if query_params.get('details', False):
            query_params['importers'] = True
            query_params['distributors'] = True

        if query_params.get('importers', False):
            repo = _merge_related_objects(
                'importers', manager_factory.repo_importer_manager(),
                (repo, ))[0]
        if query_params.get('distributors', False):
            repo = _merge_related_objects(
                'distributors', manager_factory.repo_distributor_manager(),
                (repo, ))[0]

        return self.ok(repo)
示例#8
0
    def get(self, request, role_id):
        """
        Retrieve a specific role.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param role_id: id for the requested role
        :type role_id: str

        :return: Response containing the role
        :rtype: django.http.HttpResponse
        :raises: MissingResource if role ID does not exist
        """
        role = factory.role_query_manager().find_by_id(role_id)
        if role is None:
            raise pulp_exceptions.MissingResource(role_id)
        role['users'] = [u['login'] for u in
                         factory.user_query_manager().find_users_belonging_to_role(role['id'])]
        permissions_manager = factory.permission_manager()
        # isolate schema change
        resource_permission = {}
        for item in role['permissions']:
            resource = item['resource']
            operations = item.get('permission', [])
            resource_permission[resource] = [permissions_manager.operation_value_to_name(o)
                                             for o in operations]
        role['permissions'] = resource_permission

        link = {'_href': reverse('role_resource',
                kwargs={'role_id': role['id']})}
        role.update(link)
        return generate_json_response_with_pulp_encoder(role)
示例#9
0
def update(schedule_id, delta):
    """
    Updates the schedule with unique ID schedule_id. This only allows updating
    of fields in ScheduledCall.USER_UPDATE_FIELDS.

    :param schedule_id: a unique ID for a schedule
    :type  schedule_id: basestring
    :param delta:       a dictionary of keys with values that should be modified
                        on the schedule.
    :type  delta:       dict

    :return:    instance of ScheduledCall representing the post-update state
    :rtype      ScheduledCall

    :raise  exceptions.UnsupportedValue
    :raise  exceptions.MissingResource
    """
    unknown_keys = set(delta.keys()) - ScheduledCall.USER_UPDATE_FIELDS
    if unknown_keys:
        raise exceptions.UnsupportedValue(list(unknown_keys))

    delta['last_updated'] = time.time()

    try:
        spec = {'_id': ObjectId(schedule_id)}
    except InvalidId:
        raise exceptions.InvalidValue(['schedule_id'])
    schedule = ScheduledCall.get_collection().find_and_modify(
        query=spec, update={'$set': delta}, safe=True, new=True)
    if schedule is None:
        raise exceptions.MissingResource(schedule_id=schedule_id)
    return ScheduledCall.from_db(schedule)
示例#10
0
    def _get(self, schedule_id, resource_href):
        """
        Gets and returns a schedule by ID, in dict form suitable for json serialization and
        end-user presentation.

        :param resource_href: href of the schedule
        :type  resource_href: str
        :param schedule_id: unique ID of a schedule
        :type  schedule_id: basestring

        :return:    dictionary representing the schedule
        :rtype:     dict

        :raise pulp.server.exceptions.MissingResource: if schedule is not found
        """

        # If schedule_id is not a valid bson ObjectId, this will raise InvalidValue. If the
        # schedule_id is a valid bson ObjectId but doesn't exist it will raise StopIteration.
        # Either should be a 404.
        try:
            schedule = next(iter(schedule_utils.get([schedule_id])))
        except (StopIteration, pulp_exceptions.InvalidValue):
            raise pulp_exceptions.MissingResource(schedule_id=schedule_id)

        ret = schedule.for_display()
        ret['_href'] = resource_href
        return generate_json_response(ret)
示例#11
0
    def post(self, request, consumer_group_id):
        """
        Create a bind association between the consumers belonging to the given
        consumer group by id included in the URL path and a repo-distributor
        specified in the POST body: {repo_id:<str>, distributor_id:<str>}.
        Designed to be idempotent so only MissingResource is expected to
        be raised by manager.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_group_id: The consumer group ID to bind.
        :type consumer_group_id: str
        :raises: MissingResource if group id does not exist
        :raises: InvalidValue some parameters are invalid
        :raises: OperationPostponed when an async operation is performed
        """
        params = request.body_as_json
        repo_id = params.get('repo_id')
        distributor_id = params.get('distributor_id')
        binding_config = params.get('binding_config', None)
        options = params.get('options', {})
        notify_agent = params.get('notify_agent', True)
        missing_resources = verify_group_resources(consumer_group_id, repo_id,
                                                   distributor_id)
        if missing_resources:
            if 'group_id' in missing_resources:
                raise pulp_exceptions.MissingResource(**missing_resources)
            else:
                raise pulp_exceptions.InvalidValue(list(missing_resources))
        bind_args_tuple = (consumer_group_id, repo_id, distributor_id,
                           notify_agent, binding_config, options)
        async_task = bind.apply_async(bind_args_tuple)
        raise pulp_exceptions.OperationPostponed(async_task)
示例#12
0
def publish_history(start_date, end_date, repo_id, distributor_id):
    """
    Returns a cursor containing the publish history entries for the given repo and distributor.

    :param start_date: if specified, no events prior to this date will be returned.
    :type  start_date: iso8601 datetime string
    :param end_date: if specified, no events after this date will be returned.
    :type  end_date: iso8601 datetime string
    :param repo_id: identifies the repo
    :type  repo_id: str
    :param distributor_id: identifies the distributor to retrieve history for
    :type  distributor_id: str

    :return: object containing publish history results
    :rtype:  pymongo.cursor.Cursor

    :raise pulp_exceptions.MissingResource: if repo/distributor pair is invalid
    """
    model.Repository.objects.get_repo_or_missing_resource(repo_id)
    dist = RepoDistributor.get_collection().find_one({
        'repo_id': repo_id,
        'id': distributor_id
    })
    if dist is None:
        raise pulp_exceptions.MissingResource(distributor_id)

    search_params = {'repo_id': repo_id, 'distributor_id': distributor_id}
    date_range = {}
    if start_date:
        date_range['$gte'] = start_date
    if end_date:
        date_range['$lte'] = end_date
    if len(date_range) > 0:
        search_params['started'] = date_range
    return RepoPublishResult.get_collection().find(search_params)
示例#13
0
文件: cud.py 项目: taftsanders/pulp
    def create_repo_group(group_id, display_name=None, description=None, repo_ids=None, notes=None):
        """
        Create a new repo group.
        :param group_id: unique id of the repo group
        :param display_name: display name of the repo group
        :type  display_name: str or None
        :param description: description of the repo group
        :type  description: str or None
        :param repo_ids: list of ids for repos initially belonging to the repo group
        :type  repo_ids: list or None
        :param notes: notes for the repo group
        :type  notes: dict or None
        :return: SON representation of the repo group
        :rtype: bson.SON
        """
        # Check if ids in repo_ids belong to existing repositories
        existing_repos = model.Repository.objects(repo_id__in=repo_ids)
        if repo_ids and existing_repos.count() != len(repo_ids):
            existing_repo_ids = set([repo.repo_id for repo in existing_repos])
            non_existing_repo_ids = list(set(repo_ids) - existing_repo_ids)
            raise pulp_exceptions.MissingResource(repositories=non_existing_repo_ids)

        # Create repo group
        collection = RepoGroup.get_collection()
        repo_group = RepoGroup(group_id, display_name, description, repo_ids, notes)
        try:
            collection.insert(repo_group)
        except DuplicateKeyError:
            raise pulp_exceptions.DuplicateResource(group_id), None, sys.exc_info()[2]
        group = collection.find_one({'id': group_id})
        return group
示例#14
0
 def test_handle_missing_role(self, mock_find_u_with_role):
     """
     Test that if the role reqested does not exist, super_users is None.
     """
     user_man = managers.UserManager()
     mock_find_u_with_role.side_effect = exceptions.MissingResource()
     super_users = user_man.get_admins()
     self.assertTrue(super_users is None)
示例#15
0
def update(schedule_id, delta):
    """
    Updates the schedule with unique ID schedule_id. This only allows updating
    of fields in ScheduledCall.USER_UPDATE_FIELDS.

    :param schedule_id: a unique ID for a schedule
    :type  schedule_id: basestring
    :param delta:       a dictionary of keys with values that should be modified
                        on the schedule.
    :type  delta:       dict

    :return:    instance of ScheduledCall representing the post-update state
    :rtype      ScheduledCall

    :raise  exceptions.UnsupportedValue
    :raise  exceptions.MissingResource
    """
    unknown_keys = set(delta.keys()) - ScheduledCall.USER_UPDATE_FIELDS
    if unknown_keys:
        raise exceptions.UnsupportedValue(list(unknown_keys))

    delta['last_updated'] = time.time()

    # bz 1139703 - if we update iso_schedule, update the pickled object as well
    if 'iso_schedule' in delta:
        interval, start_time, occurrences = dateutils.parse_iso8601_interval(
            delta['iso_schedule'])
        delta['schedule'] = pickle.dumps(CelerySchedule(interval))

        # set first_run and next_run so that the schedule update will take effect
        new_schedule_call = ScheduledCall(delta['iso_schedule'],
                                          'dummytaskname')
        delta['first_run'] = new_schedule_call.first_run
        delta['next_run'] = new_schedule_call.next_run

    try:
        spec = {'_id': ObjectId(schedule_id)}
    except InvalidId:
        # During schedule update, MissingResource should be raised even if
        # schedule_id is invalid object_id.
        raise exceptions.MissingResource(schedule_id=schedule_id)
    schedule = ScheduledCall.get_collection().find_and_modify(
        query=spec, update={'$set': delta}, safe=True, new=True)
    if schedule is None:
        raise exceptions.MissingResource(schedule_id=schedule_id)
    return ScheduledCall.from_db(schedule)
示例#16
0
def sync(repo_id, sync_config_override=None, scheduled_call_id=None):
    """
    Performs a synchronize operation on the given repository and triggers publishes for
    distributors with auto-publish enabled.

    The given repo must have an importer configured. This method is intentionally limited to
    synchronizing a single repo. Performing multiple repository syncs concurrently will require a
    more global view of the server and must be handled outside the scope of this class.

    :param repo_id: identifies the repo to sync
    :type  repo_id: str
    :param sync_config_override: optional config containing values to use for this sync only
    :type  sync_config_override: dict
    :param scheduled_call_id: id of scheduled call that dispatched this task
    :type  scheduled_call_id: str

    :return: TaskResult containing sync results and a list of spawned tasks
    :rtype:  pulp.server.async.tasks.TaskResult

    :raise pulp_exceptions.MissingResource: if specified repo does not exist, or it does not have
                                            an importer and associated plugin
    :raise pulp_exceptions.PulpExecutionException: if the task fails.
    """

    repo_obj = model.Repository.objects.get_repo_or_missing_resource(repo_id)
    transfer_repo = repo_obj.to_transfer_repo()

    repo_importer = model.Importer.objects.get_or_404(repo_id=repo_id)
    try:
        importer, imp_config = plugin_api.get_importer_by_id(repo_importer.importer_type_id)
    except plugin_exceptions.PluginNotFound:
        raise pulp_exceptions.MissingResource(repository=repo_id)

    call_config = PluginCallConfiguration(imp_config, repo_importer.config, sync_config_override)
    transfer_repo.working_dir = common_utils.get_working_directory()
    conduit = RepoSyncConduit(repo_id, repo_importer.importer_type_id, repo_importer.id)
    sync_result_collection = RepoSyncResult.get_collection()

    # Fire an events around the call
    fire_manager = manager_factory.event_fire_manager()
    fire_manager.fire_repo_sync_started(repo_id)

    # Perform the sync
    sync_start_timestamp = _now_timestamp()
    sync_result = None

    try:
        # Replace the Importer's sync_repo() method with our register_sigterm_handler decorator,
        # which will set up cancel_sync_repo() as the target for the signal handler
        sync_repo = register_sigterm_handler(importer.sync_repo, importer.cancel_sync_repo)
        sync_report = sync_repo(transfer_repo, conduit, call_config)

    except Exception, e:
        sync_end_timestamp = _now_timestamp()
        sync_result = RepoSyncResult.error_result(
            repo_obj.repo_id, repo_importer['id'], repo_importer['importer_type_id'],
            sync_start_timestamp, sync_end_timestamp, e, sys.exc_info()[2])
        raise
示例#17
0
 def test_nonexisent_importer(self, mock_model):
     """
     Try to get an importer that doesn't exist.
     """
     mock_model.Importer.objects.get_or_404.side_effect = exceptions.MissingResource('foo')
     try:
         importer.get_valid_importer('mock_repo', 'mock_imp')
     except exceptions.MissingResource, result:
         pass
示例#18
0
文件: users.py 项目: sahwar/pulp
    def GET(self, login):

        user = managers.user_query_manager().find_by_login(login)
        if user is None:
            raise exceptions.MissingResource(login)

        user.update(serialization.link.current_link_obj())

        return self.ok(user)
示例#19
0
文件: utils.py 项目: taftsanders/pulp
def delete(schedule_id):
    """
    Deletes the schedule with unique ID schedule_id

    :param schedule_id: a unique ID for a schedule
    :type  schedule_id: basestring
    """

    try:
        spec = {'_id': ObjectId(schedule_id)}
    except InvalidId:
        # During schedule deletion, MissingResource should be raised even if
        # schedule_id is invalid object_id.
        raise exceptions.MissingResource(schedule_id=schedule_id)

    schedule = ScheduledCall.get_collection().find_and_modify(
        query=spec, remove=True)
    if schedule is None:
        raise exceptions.MissingResource(schedule_id=schedule_id)
示例#20
0
    def GET(self, login):

        user = managers.user_query_manager().find_by_login(login)
        if user is None:
            raise exceptions.MissingResource(login)

        user.update(serialization.link.current_link_obj())

        self.process_dictionary_against_whitelist(user, USER_WHITELIST)
        return self.ok(user)
示例#21
0
    def get_or_404(self, **kwargs):
        """
        Generally allow querysets to raise a MissingResource exception if getting an object that
        does not exist.

        :param kwargs: keyword arguments that specify field of the document and value it should be
        :raise pulp_exceptions.MissingResource: if no objects are found
        """
        try:
            return self.get(**kwargs)
        except DoesNotExist:
            raise pulp_exceptions.MissingResource(**kwargs)
示例#22
0
 def GET(self, repo_id, importer_id, schedule_id):
     importer_manager = manager_factory.repo_importer_manager()
     schedule_list = importer_manager.list_sync_schedules(repo_id)
     if schedule_id not in schedule_list:
         raise exceptions.MissingResource(repo=repo_id,
                                          importer=importer_id,
                                          publish_schedule=schedule_id)
     scheduler = dispatch_factory.scheduler()
     schedule = scheduler.get(schedule_id)
     obj = serialization.dispatch.scheduled_sync_obj(schedule)
     obj.update(serialization.link.current_link_obj())
     return self.ok(obj)
示例#23
0
def publish(repo_id,
            dist_id,
            publish_config_override=None,
            scheduled_call_id=None):
    """
    Uses the given distributor to publish the repository.

    The publish operation is executed synchronously in the caller's thread and will block until it
    is completed. The caller must take the necessary steps to address the fact that a publish call
    may be time intensive.

    :param repo_id: identifies the repo being published
    :type  repo_id: str
    :param dist_id: identifies the repo's distributor to publish
    :type  dist_id: str
    :param publish_config_override: optional config values to use for this publish call only
    :type  publish_config_override: dict, None
    :param scheduled_call_id: id of scheduled call that dispatched this task
    :type  scheduled_call_id: str

    :return: report of the details of the publish
    :rtype:  pulp.server.db.model.repository.RepoPublishResult

    :raises pulp_exceptions.MissingResource: if distributor/repo pair does not exist
    """
    distributor_coll = RepoDistributor.get_collection()
    repo_obj = model.Repository.objects.get_repo_or_missing_resource(repo_id)
    repo_distributor = distributor_coll.find_one({
        'repo_id': repo_id,
        'id': dist_id
    })
    if repo_distributor is None:
        raise pulp_exceptions.MissingResource(repository=repo_id,
                                              distributor=dist_id)

    dist_inst, dist_conf = _get_distributor_instance_and_config(
        repo_id, dist_id)

    # Assemble the data needed for the publish
    conduit = RepoPublishConduit(repo_id, dist_id)
    call_config = PluginCallConfiguration(dist_conf,
                                          repo_distributor['config'],
                                          publish_config_override)
    transfer_repo = repo_obj.to_transfer_repo()
    transfer_repo.working_dir = common_utils.get_working_directory()

    # Fire events describing the publish state
    fire_manager = manager_factory.event_fire_manager()
    fire_manager.fire_repo_publish_started(repo_id, dist_id)
    result = _do_publish(repo_obj, dist_id, dist_inst, transfer_repo, conduit,
                         call_config)
    fire_manager.fire_repo_publish_finished(result)
    return result
示例#24
0
    def remove(self, schedule_id):
        """
        Remove a scheduled call request
        @param schedule_id: id of the schedule for the call request
        @type  schedule_id: str
        """
        if isinstance(schedule_id, basestring):
            schedule_id = ObjectId(schedule_id)

        if ScheduledCall.get_collection().find_one(schedule_id) is None:
            raise pulp_exceptions.MissingResource(schedule=str(schedule_id))

        self.scheduled_call_collection.remove({'_id': schedule_id}, safe=True)
示例#25
0
    def PUT(self, repo_id, distributor_id, schedule_id):
        distributor_manager = manager_factory.repo_distributor_manager()
        schedule_list = distributor_manager.list_publish_schedules(
            repo_id, distributor_id)
        if schedule_id not in schedule_list:
            raise exceptions.MissingResource(repo=repo_id,
                                             distributor=distributor_id,
                                             publish_schedule=schedule_id)

        publish_update = {}
        schedule_update = self.params()
        if 'override_config' in schedule_update:
            publish_update['override_config'] = schedule_update.pop(
                'override_config')

        schedule_manager = manager_factory.schedule_manager()
        resources = {
            dispatch_constants.RESOURCE_REPOSITORY_TYPE: {
                repo_id: dispatch_constants.RESOURCE_READ_OPERATION
            },
            dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE: {
                distributor_id: dispatch_constants.RESOURCE_READ_OPERATION
            },
            dispatch_constants.RESOURCE_SCHEDULE_TYPE: {
                schedule_id: dispatch_constants.RESOURCE_UPDATE_OPERATION
            }
        }
        tags = [
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            resource_tag(
                dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                distributor_id),
            resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE,
                         schedule_id),
            action_tag('update_publish_schedule')
        ]
        call_request = CallRequest(schedule_manager.update_publish_schedule, [
            repo_id, distributor_id, schedule_id, publish_update,
            schedule_update
        ],
                                   resources=resources,
                                   tags=tags,
                                   archive=True)
        execution.execute(call_request)

        scheduler = dispatch_factory.scheduler()
        schedule = scheduler.get(schedule_id)
        obj = serialization.dispatch.scheduled_publish_obj(schedule)
        obj.update(serialization.link.current_link_obj())
        return self.ok(obj)
示例#26
0
def get_valid_importer(repo_id, importer_type_id):
    """
    Retrieves the importer for the specified repo and ensures that the provided importer type id
    matches the importer set on the repo.

    :param repo_id: id of the repo
    :type  repo_id: str
    :param importer_type_id: type of the importer
    :type  importer_type_id: str

    :return: key-value pairs describing the importer in use
    :rtype:  dict

    :raises pulp.server.exceptions.MissingResource: if repo/importer combination cannot be found
    """
    model.Repository.objects.get_repo_or_missing_resource(repo_id)
    try:
        importer = model.Importer.objects.get_or_404(repo_id=repo_id)
    except exceptions.MissingResource:
        raise exceptions.MissingResource(importer_id=importer_type_id)
    if importer.importer_type_id != importer_type_id:
        raise exceptions.MissingResource(importer_id=importer_type_id)
    return importer
示例#27
0
def find_users_belonging_to_role(role_id):
    """
    Get a list of users belonging to the given role

    :param role_id: get members of this role
    :type  role_id: str

    :return: list of users that are members of the given role
    :rtype:  list of pulp.server.db.model.User instances
    """
    role = Role.get_collection().find_one({'id': role_id})
    if role is None:
        raise pulp_exceptions.MissingResource(role_id)
    return [user for user in model.User.objects() if role_id in user.roles]
示例#28
0
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)
示例#29
0
文件: repo.py 项目: zjhuntin/pulp
    def validate_importer(repo_id, importer_id):
        """
        Validate that the importer exists for the specified repo

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param importer_id:     unique ID for an importer
        :type  importer_id:     basestring

        :raise: pulp.server.exceptions.MissingResource
        """
        # make sure the passed in importer id matches the current importer on the repo
        importer_manager = managers_factory.repo_importer_manager()
        importer = importer_manager.get_importer(repo_id)
        if importer_id != importer['id']:
            raise exceptions.MissingResource(importer=importer_id)
示例#30
0
    def get_repo_or_missing_resource(self, repo_id):
        """
        Allows a django-like get or 404.

        :param repo_id: identifies the repository to be returned
        :type  repo_id: str

        :return: repository object
        :rtype:  pulp.server.db.model.Repository

        :raises pulp_exceptions.MissingResource if repository is not found
        """
        try:
            return self.get(repo_id=repo_id)
        except DoesNotExist:
            raise pulp_exceptions.MissingResource(repository=repo_id)