Exemple #1
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()
        resources = {
            dispatch_constants.RESOURCE_REPOSITORY_TYPE: {repo_id: dispatch_constants.RESOURCE_READ_OPERATION},
            dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE: {
                distributor_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_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],
            resources=resources,
            tags=tags,
            archive=True,
        )
        return execution.execute_ok(self, call_request)
Exemple #2
0
    def PUT(self, repo_id, distributor_id):

        # Params (validation will occur in the manager)
        params = self.params()
        distributor_config = params.get("distributor_config", None)

        if distributor_config is None:
            _LOG.exception(
                "Missing configuration when updating distributor [%s] on repository [%s]" % (distributor_id, repo_id)
            )
            raise exceptions.MissingValue(["distributor_config"])

        distributor_manager = manager_factory.repo_distributor_manager()
        resources = {
            dispatch_constants.RESOURCE_REPOSITORY_TYPE: {repo_id: dispatch_constants.RESOURCE_UPDATE_OPERATION},
            dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE: {
                distributor_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),
            action_tag("update_distributor"),
        ]
        call_request = CallRequest(
            distributor_manager.update_distributor_config,
            [repo_id, distributor_id, distributor_config],
            resources=resources,
            tags=tags,
            archive=True,
        )
        return execution.execute_ok(self, call_request)
Exemple #3
0
    def test_bind(self, *mocks):

        mock_agent = mocks[0]
        mock_context = mocks[1]
        mock_factory = mocks[2]
        mock_bindings = mocks[3]
        mock_task_status = mocks[4]
        mock_uuid = mocks[5]

        consumer = {'id': '1234'}
        mock_consumer_manager = Mock()
        mock_consumer_manager.get_consumer = Mock(return_value=consumer)
        mock_factory.consumer_manager = Mock(return_value=mock_consumer_manager)

        binding = {}
        mock_bind_manager = Mock()
        mock_bind_manager.get_bind = Mock(return_value=binding)
        mock_bind_manager.action_pending = Mock()
        mock_factory.consumer_bind_manager = Mock(return_value=mock_bind_manager)

        agent_bindings = []
        mock_bindings.return_value = agent_bindings

        task_id = '2345'
        mock_context.return_value = {}
        mock_uuid.return_value = task_id

        # test manager

        repo_id = '100'
        distributor_id = '200'
        options = {}
        agent_manager = AgentManager()
        agent_manager.bind(consumer['id'], repo_id, distributor_id, options)

        # validations

        task_tags = [
            tags.resource_tag(tags.RESOURCE_CONSUMER_TYPE, consumer['id']),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
            tags.action_tag(tags.ACTION_AGENT_BIND)
        ]

        mock_consumer_manager.get_consumer.assert_called_with(consumer['id'])
        mock_bind_manager.get_bind.assert_called_with(consumer['id'], repo_id, distributor_id)
        mock_bindings.assert_called_with([binding])

        mock_context.assert_called_with(
            consumer,
            task_id=task_id,
            action='bind',
            consumer_id=consumer['id'],
            repo_id=repo_id,
            distributor_id=distributor_id)

        mock_task_status.assert_called_with(task_id=task_id, worker_name='agent', tags=task_tags)
        mock_agent.bind.assert_called_with(mock_context.return_value, agent_bindings, options)
        mock_bind_manager.action_pending.assert_called_with(
            consumer['id'], repo_id, distributor_id, Bind.Action.BIND, task_id)
Exemple #4
0
    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))
Exemple #5
0
def queue_update(distributor, config, delta):
    """
    Dispatch a task to update a distributor.

    :param distributor: distributor to be updated
    :type  distributor: pulp.server.db.model.Distributor
    :param config: A configuration dictionary for a distributor instance. The contents of this dict
                   depends on the type of distributor. Values of None will remove they key from the
                   config. Keys ommited from this dictionary will remain unchanged.
    :type  config: dict
    :param delta: A dictionary used to change conf values for a distributor instance. This currently
                  only supports the 'auto_publish' keyword, which should have a value of type bool
    :type  delta: dict or None

    :return: An AsyncResult instance as returned by Celery's apply_async
    :rtype:  celery.result.AsyncResult
    """
    task_tags = [
        tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, distributor.repo_id),
        tags.resource_tag(tags.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor.distributor_id),
        tags.action_tag('update_distributor')
    ]
    async_result = update.apply_async_with_reservation(
        tags.RESOURCE_REPOSITORY_TYPE, distributor.repo_id,
        [distributor.repo_id, distributor.distributor_id, config, delta],
        tags=task_tags)
    return async_result
Exemple #6
0
    def create_publish_schedule(self, repo_id, distributor_id, publish_options, schedule_data):
        """
        Create a new scheduled publish for the given repository and distributor.
        @param repo_id:
        @param distributor_id:
        @param publish_options:
        @param schedule_data:
        @return:
        """

        # validate the input
        self._validate_distributor(repo_id, distributor_id)
        self._validate_keys(publish_options, _PUBLISH_OPTION_KEYS)
        if 'schedule' not in schedule_data:
            raise pulp_exceptions.MissingValue(['schedule'])

        # build the publish call
        publish_manager = managers_factory.repo_publish_manager()
        args = [repo_id, distributor_id]
        kwargs = {'publish_config_override': publish_options['override_config']}
        weight = pulp_config.config.getint('tasks', 'publish_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id)]
        call_request = CallRequest(publish_manager.publish, args, kwargs, weight=weight, tags=tags, archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        call_request.add_life_cycle_callback(dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK, publish_manager.prep_publish)

        # schedule the publish
        scheduler = dispatch_factory.scheduler()
        schedule_id = scheduler.add(call_request, **schedule_data)
        distributor_manager = managers_factory.repo_distributor_manager()
        distributor_manager.add_publish_schedule(repo_id, distributor_id, schedule_id)
        return schedule_id
Exemple #7
0
    def PUT(self, repo_id, distributor_id):
        """
        Used to update a repo distributor instance. This requires update permissions.
        The expected parameters are 'distributor_config', which is a dictionary containing
        configuration values accepted by the distributor type, and 'delta', which is a dictionary
        containing other configuration values for the distributor (like the auto_publish flag,
        for example). Currently, the only supported key in the delta is 'auto_publish', which
        should have a boolean value.

        :param repo_id:         The repository ID
        :type  repo_id:         str
        :param distributor_id:  The unique distributor ID of the distributor instance to update.
        :type  distributor_id:  str
        """
        params = self.params()
        delta = params.get("delta", None)
        # validate
        manager = manager_factory.repo_distributor_manager()
        manager.get_distributor(repo_id, distributor_id)
        config = params.get("distributor_config")
        if config is None:
            logger.error(
                "Missing configuration when updating distributor [%s] on repository [%s]", distributor_id, repo_id
            )
            raise exceptions.MissingValue(["distributor_config"])
        # update
        tags = [
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
            action_tag("update_distributor"),
        ]
        async_result = repository.distributor_update.apply_async_with_reservation(
            dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id, [repo_id, distributor_id, config, delta], tags=tags
        )
        raise exceptions.OperationPostponed(async_result)
Exemple #8
0
    def create_sync_schedule(self, repo_id, importer_id, sync_options, schedule_data):
        """
        Create a new sync schedule for a given repository using the given importer.
        @param repo_id:
        @param importer_id:
        @param sync_options:
        @param schedule_data:
        @return:
        """

        # validate the input
        self._validate_importer(repo_id, importer_id)
        self._validate_keys(sync_options, _SYNC_OPTION_KEYS)
        if 'schedule' not in schedule_data:
            raise pulp_exceptions.MissingValue(['schedule'])

        # build the sync call request
        sync_manager = managers_factory.repo_sync_manager()
        args = [repo_id]
        kwargs = {'sync_config_override': sync_options['override_config']}
        weight = pulp_config.config.getint('tasks', 'sync_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id)]
        call_request = CallRequest(sync_manager.sync, args, kwargs, weight=weight, tags=tags, archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        call_request.add_life_cycle_callback(dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK, sync_manager.prep_sync)

        # schedule the sync
        scheduler = dispatch_factory.scheduler()
        schedule_id = scheduler.add(call_request, **schedule_data)
        importer_manager = managers_factory.repo_importer_manager()
        importer_manager.add_sync_schedule(repo_id, schedule_id)
        return schedule_id
Exemple #9
0
    def PUT(self, consumer_id, content_type):
        """
        Update the association of a profile with a consumer by content type ID.
        @param consumer_id: A consumer ID.
        @type consumer_id: str
        @param content_type: A content unit type ID.
        @type content_type: str
        @return: The updated model object:
            {consumer_id:<str>, content_type:<str>, profile:<dict>}
        @rtype: dict
        """
        body = self.params()
        profile = body.get('profile')

        manager = managers.consumer_profile_manager()
        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
                resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, content_type),
                action_tag('profile_update')]

        call_request = CallRequest(manager.update,
                                   [consumer_id, content_type],
                                   {'profile': profile},
                                   tags=tags,
                                   weight=0,
                                   kwarg_blacklist=['profile'])
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)

        call_report = CallReport.from_call_request(call_request)
        call_report.serialize_result = False

        consumer = execution.execute_sync(call_request, call_report)
        link = serialization.link.child_link_obj(consumer_id, content_type)
        consumer.update(link)

        return self.ok(consumer)
Exemple #10
0
    def delete(self, request, repo_id, distributor_id):
        """
        Disassociate the requested distributor.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: The id of the repository the to disassociate from
        :type  repo_id: str
        :param repo_id: The id of the distributor to disassociate
        :type  repo_id: str

        :raises pulp_exceptions.OperationPostponed: dispatch a task
        """

        # validate resources
        manager = manager_factory.repo_distributor_manager()
        manager.get_distributor(repo_id, distributor_id)

        task_tags = [
            tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
            tags.action_tag('remove_distributor')
        ]
        async_result = repo_tasks.distributor_delete.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_TYPE, repo_id, [repo_id, distributor_id],
            tags=task_tags)
        raise pulp_exceptions.OperationPostponed(async_result)
Exemple #11
0
    def put(self, request, repo_id, importer_id):
        """
        Associate an importer to a repository.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: The id of the repository
        :type  repo_id: str
        :param importer_id: The id of the importer to associate
        :type  importer_id: str

        :raises pulp_exceptions.MissingValue: if required param importer_config is not in the body
        :raises pulp_exceptions.MissingResource: if importer does not match the repo's importer
        :raises pulp_exceptions.OperationPostponed: dispatch a task
        """

        importer_manager = manager_factory.repo_importer_manager()
        importer = importer_manager.get_importer(repo_id)
        if importer['id'] != importer_id:
            raise pulp_exceptions.MissingResource(importer_id=importer_id)

        importer_config = request.body_as_json.get('importer_config', None)

        if importer_config is None:
            raise pulp_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 = repo_importer_manager.update_importer_config.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_TYPE,
            repo_id, [repo_id], {'importer_config': importer_config}, tags=task_tags)
        raise pulp_exceptions.OperationPostponed(async_result)
Exemple #12
0
    def POST(self, repo_id):

        # Params (validation will occur in the manager)
        params = self.params()
        distributor_type = params.get('distributor_type_id', None)
        distributor_config = params.get('distributor_config', None)
        distributor_id = params.get('distributor_id', None)
        auto_publish = params.get('auto_publish', False)

        # Update the repo
        distributor_manager = manager_factory.repo_distributor_manager()

        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                action_tag('add_distributor')]
        if distributor_id is not None:
            tags.append(resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id))
        call_request = CallRequest(distributor_manager.add_distributor,
                                   [repo_id, distributor_type],
                                   {'repo_plugin_config': distributor_config, 'auto_publish': auto_publish,
                                    'distributor_id': distributor_id},
                                   weight=weight,
                                   tags=tags,
                                   kwarg_blacklist=['repo_plugin_config'])
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        if distributor_id is not None:
            call_request.creates_resource(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id)
        return execution.execute_created(self, call_request, distributor_id)
Exemple #13
0
    def PUT(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)

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

        schedule_manager = manager_factory.schedule_manager()
        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('update_sync_schedule')]
        call_request = CallRequest(schedule_manager.update_sync_schedule,
                                   [repo_id, importer_id, schedule_id, sync_updates, schedule_updates],
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id)
        execution.execute(call_request)

        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)
Exemple #14
0
    def PUT(self, repo_id, importer_id):

        # Params (validation will occur in the manager)
        params = self.params()
        importer_config = params.get('importer_config', None)

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

        importer_manager = manager_factory.repo_importer_manager()
        resources = {dispatch_constants.RESOURCE_REPOSITORY_TYPE: {repo_id: dispatch_constants.RESOURCE_UPDATE_OPERATION},
                     dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE: {importer_id: dispatch_constants.RESOURCE_UPDATE_OPERATION}}
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id),
                action_tag('update_importer')]
        call_request = CallRequest(importer_manager.update_importer_config,
                                   [repo_id],
                                   {'importer_config': importer_config},
                                   resources=resources,
                                   tags=tags,
                                   archive=True,
                                   kwarg_blacklist=['importer_config'])
        result = execution.execute(call_request)
        return self.ok(result)
Exemple #15
0
    def PUT(self, repo_group_id, distributor_id):
        params = self.params()

        distributor_config = params.get('distributor_config', None)

        if distributor_config is None:
            raise pulp_exceptions.MissingValue(['distributor_config'])

        distributor_manager = managers_factory.repo_group_distributor_manager()

        resources = {
            dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE :
                    {repo_group_id : dispatch_constants.RESOURCE_UPDATE_OPERATION},
            dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE :
                    {distributor_id : dispatch_constants.RESOURCE_UPDATE_OPERATION},
            }
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id),
                action_tag('update_distributor')
        ]

        call_request = CallRequest(distributor_manager.update_distributor_config,
                                   args=[repo_group_id, distributor_id, distributor_config],
                                   resources=resources,
                                   tags=tags,
                                   archive=True)

        result = execution.execute(call_request)

        href = serialization.link.current_link_obj()
        result.update(href)

        return self.ok(result)
Exemple #16
0
    def POST(self, repo_group_id):
        params = self.params()
        distributor_id = params.get('id', None)
        overrides = params.get('override_config', None)

        if distributor_id is None:
            raise MissingValue(['id'])

        publish_manager = managers_factory.repo_group_publish_manager()

        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id),
                action_tag('publish')
        ]
        weight = pulp_config.config.getint('tasks', 'publish_weight')

        call_request = CallRequest(publish_manager.publish,
                                   args=[repo_group_id, distributor_id],
                                   kwargs={'publish_config_override' : overrides},
                                   tags=tags,
                                   weight=weight,
                                   archive=True)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id)
        call_request.add_life_cycle_callback(dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK, publish_manager.prep_publish)

        return execution.execute_async(self, call_request)
Exemple #17
0
    def post(self, request, repo_group_id):
        """
        Dispatch a task to publish content from the repo group using the distributor specified by
        the params.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_group_id: repo group to publish
        :type  repo_group_id: str

        :raises pulp_exceptions.MissingValue if 'id' is not passed in the body
        :raises pulp_exceptions.OperationPosponed: dispatch a task
        """
        params = request.body_as_json
        distributor_id = params.get('id', None)
        overrides = params.get('override_config', None)
        if distributor_id is None:
            raise pulp_exceptions.MissingValue(['id'])
        # If a repo group does not exist, get_group raises a MissingResource exception
        manager = managers_factory.repo_group_query_manager()
        manager.get_group(repo_group_id)
        task_tags = [
            tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id),
            tags.action_tag('publish')
        ]
        async_result = repo_group_publish.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_GROUP_TYPE,
            repo_group_id,
            args=[repo_group_id, distributor_id],
            kwargs={'publish_config_override': overrides},
            tags=task_tags
        )
        raise pulp_exceptions.OperationPostponed(async_result)
Exemple #18
0
    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()

        resources = {dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE : {
            repo_group_id : dispatch_constants.RESOURCE_UPDATE_OPERATION
        }}
        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],
                                   resources=resources,
                                   weight=weight,
                                   tags=tags)
        created = execution.execute(call_request)

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

        return self.created(href['_href'], created)
Exemple #19
0
    def DELETE(self, repo_group_id, distributor_id):
        params = self.params()
        force = params.get('force', False)

        distributor_manager = managers_factory.repo_group_distributor_manager()

        resources = {
            dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE :
                    {repo_group_id : dispatch_constants.RESOURCE_UPDATE_OPERATION},
            dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE :
                    {distributor_id : dispatch_constants.RESOURCE_DELETE_OPERATION},
                     }
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id),
                action_tag('remove_distributor')
               ]
        call_request = CallRequest(distributor_manager.remove_distributor,
                                   args=[repo_group_id, distributor_id],
                                   kwargs={'force' : force},
                                   resources=resources,
                                   tags=tags,
                                   archive=True)

        execution.execute(call_request)
        return self.ok(None)
Exemple #20
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)
Exemple #21
0
    def POST(self, dest_repo_id):

        # Params
        params = self.params()
        source_repo_id = params.get('source_repo_id', None)
        overrides = params.get('override_config', None)

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

        criteria = params.get('criteria', None)
        if criteria is not None:
            try:
                criteria = UnitAssociationCriteria.from_client_input(criteria)
            except:
                _LOG.exception('Error parsing association criteria [%s]' % criteria)
                raise exceptions.PulpDataException(), None, sys.exc_info()[2]

        association_manager = manager_factory.repo_unit_association_manager()
        resources = {dispatch_constants.RESOURCE_REPOSITORY_TYPE: {source_repo_id: dispatch_constants.RESOURCE_READ_OPERATION,
                                                                   dest_repo_id: dispatch_constants.RESOURCE_UPDATE_OPERATION}}
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, dest_repo_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, source_repo_id),
                action_tag('associate')]
        call_request = CallRequest(association_manager.associate_from_repo,
                                   [source_repo_id, dest_repo_id],
                                   {'criteria': criteria, 'import_config_override': overrides},
                                   resources=resources,
                                   tags=tags,
                                   archive=True)
        return execution.execute_async(self, call_request)
Exemple #22
0
    def POST(self, repo_id):

        # Params (validation will occur in the manager)
        params = self.params()
        distributor_type = params.get('distributor_type_id', None)
        distributor_config = params.get('distributor_config', None)
        distributor_id = params.get('distributor_id', None)
        auto_publish = params.get('auto_publish', False)

        # Update the repo
        distributor_manager = manager_factory.repo_distributor_manager()

        resources = {dispatch_constants.RESOURCE_REPOSITORY_TYPE: {repo_id: dispatch_constants.RESOURCE_UPDATE_OPERATION}}
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                action_tag('add_distributor')]
        if distributor_id is not None:
            resources.update({dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE: {distributor_id: dispatch_constants.RESOURCE_CREATE_OPERATION}})
            tags.append(resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id))
        call_request = CallRequest(distributor_manager.add_distributor,
                                   [repo_id, distributor_type, distributor_config, auto_publish, distributor_id],
                                   resources=resources,
                                   weight=weight,
                                   tags=tags)
        return execution.execute_created(self, call_request, distributor_id)
Exemple #23
0
    def POST(self, repo_id, distributor_id):
        distributor_manager = manager_factory.repo_distributor_manager()
        distributor_manager.get_distributor(repo_id, distributor_id)

        schedule_options = self.params()
        publish_options = {'override_config': schedule_options.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_UPDATE_OPERATION}}
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
                action_tag('create_publish_schedule')]
        call_request = CallRequest(schedule_manager.create_publish_schedule,
                                   [repo_id, distributor_id, publish_options, schedule_options],
                                   resources=resources,
                                   weight=weight,
                                   tags=tags,
                                   archive=True)
        schedule_id = execution.execute_sync(call_request)

        scheduler = dispatch_factory.scheduler()
        schedule = scheduler.get(schedule_id)
        obj = serialization.dispatch.scheduled_publish_obj(schedule)
        obj.update(serialization.link.child_link_obj(schedule_id))
        return self.created(obj['_href'], obj)
Exemple #24
0
    def delete(self, request, repo_id, importer_id):
        """
        Remove an importer from a repository.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: The id of the repository to remove the importer from
        :type  repo_id: str
        :param importer_id: The id of the importer to remove from the given repository
        :type  importer_id: str

        :raises pulp_exceptions.MissingResource: if importer cannot be found for this repo
        :raises pulp_exceptions.OperationPostponed: to dispatch a task to delete the importer
        """

        importer_manager = manager_factory.repo_importer_manager()
        importer = importer_manager.get_importer(repo_id)
        if importer['id'] != importer_id:
            raise pulp_exceptions.MissingResource(importer_id=importer_id)

        task_tags = [tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
                     tags.resource_tag(tags.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id),
                     tags.action_tag('delete_importer')]
        async_result = repo_importer_manager.remove_importer.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_TYPE, repo_id, [repo_id], tags=task_tags)
        raise pulp_exceptions.OperationPostponed(async_result)
Exemple #25
0
    def POST(self, repo_id, importer_id):
        importer_manager = manager_factory.repo_importer_manager()
        importer = importer_manager.get_importer(repo_id)
        if importer_id != importer['id']:
            raise exceptions.MissingResource(importer=importer_id)

        schedule_options = self.params()
        sync_options = {'override_config': schedule_options.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_IMPORTER_TYPE: {importer_id: dispatch_constants.RESOURCE_UPDATE_OPERATION}}
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id),
                action_tag('create_sync_schedule')]
        call_request = CallRequest(schedule_manager.create_sync_schedule,
                                   [repo_id, importer_id, sync_options, schedule_options],
                                   resources=resources,
                                   weight=weight,
                                   tags=tags,
                                   archive=True)
        schedule_id = execution.execute_sync(call_request)

        scheduler = dispatch_factory.scheduler()
        schedule = scheduler.get(schedule_id)
        obj = serialization.dispatch.scheduled_sync_obj(schedule)
        obj.update(serialization.link.child_link_obj(schedule_id))
        return self.created(obj['_href'], obj)
Exemple #26
0
    def POST(self, repo_group_id):
        params = self.params()
        distributor_id = params.get('id', None)
        overrides = params.get('override_config', None)

        if distributor_id is None:
            raise MissingValue(['id'])

        publish_manager = managers_factory.repo_group_publish_manager()

        resources = {
            dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE :
                    {repo_group_id : dispatch_constants.RESOURCE_UPDATE_OPERATION},
            dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE :
                    {distributor_id : dispatch_constants.RESOURCE_UPDATE_OPERATION},
            }
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id),
                action_tag('publish')
        ]
        weight = pulp_config.config.getint('tasks', 'publish_weight')

        call_request = CallRequest(publish_manager.publish,
                                   args=[repo_group_id, distributor_id],
                                   kwargs={'publish_config_override' : overrides},
                                   resources=resources,
                                   tags=tags,
                                   weight=weight,
                                   archive=True)

        return execution.execute_async(self, call_request)
Exemple #27
0
 def DELETE(self, consumer_id, repo_id, distributor_id):
     """
     Delete a bind association between the specified
     consumer and repo-distributor.  Designed to be idempotent.
     @param consumer_id: A consumer ID.
     @type consumer_id: str
     @param repo_id: A repo ID.
     @type repo_id: str
     @param distributor_id: A distributor ID.
     @type distributor_id: str
     @return: The deleted bind model object:
         {consumer_id:<str>, repo_id:<str>, distributor_id:<str>}
         Or, None if bind does not exist.
     @rtype: dict
     """
     manager = managers.consumer_bind_manager()
     resources = {
         dispatch_constants.RESOURCE_CONSUMER_TYPE: {consumer_id: dispatch_constants.RESOURCE_READ_OPERATION},
         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
         },
     }
     args = [consumer_id, repo_id, distributor_id]
     tags = [
         resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
         resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
         resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
         action_tag("unbind"),
     ]
     call_request = CallRequest(manager.unbind, args=args, resources=resources, tags=tags)
     return self.ok(execution.execute(call_request))
Exemple #28
0
    def PUT(self, consumer_id, schedule_id):
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        schedule_data = self.params()
        install_options = None
        units = schedule_data.pop('units', None)

        if 'options' in schedule_data:
            install_options = {'options': schedule_data.pop('options')}

        schedule_manager = managers.schedule_manager()

        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
                resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id),
                action_tag('update_unit_uninstall_schedule')]

        call_request = CallRequest(schedule_manager.update_unit_uninstall_schedule,
                                   [consumer_id, schedule_id, units, install_options, schedule_data],
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id)

        execution.execute(call_request)

        scheduler = dispatch_factory.scheduler()
        scheduled_call = scheduler.get(schedule_id)

        scheduled_obj = serialization.dispatch.scheduled_unit_management_obj(scheduled_call)
        scheduled_obj.update(serialization.link.current_link_obj())
        return self.ok(scheduled_obj)
Exemple #29
0
    def PUT(self, repo_id, importer_id):

        # Params (validation will occur in the manager)
        params = self.params()
        importer_config = params.get("importer_config", None)

        if importer_config is None:
            _LOG.exception("Missing configuration updating importer for repository [%s]" % repo_id)
            raise exceptions.MissingValue(["importer_config"])

        importer_manager = manager_factory.repo_importer_manager()
        resources = {
            dispatch_constants.RESOURCE_REPOSITORY_TYPE: {repo_id: dispatch_constants.RESOURCE_UPDATE_OPERATION},
            dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE: {
                importer_id: dispatch_constants.RESOURCE_UPDATE_OPERATION
            },
        }
        tags = [
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id),
            action_tag("update_importer"),
        ]
        call_request = CallRequest(
            importer_manager.update_importer_config,
            [repo_id, importer_config],
            resources=resources,
            tags=tags,
            archive=True,
        )
        return execution.execute_ok(self, call_request)
Exemple #30
0
def distributor_update_itinerary(repo_id, distributor_id, config):
    """
    Get the itinerary for updating a repository distributor.
      1. Update the distributor on the sever.
      2. (re)bind any bound consumers.
    @param repo_id: A repository ID.
    @type repo_id: str
    @return: A list of call_requests known as an itinerary.
    @rtype list
    """

    call_requests = []

    # update the distributor

    manager = managers.repo_distributor_manager()
    resources = {
        dispatch_constants.RESOURCE_REPOSITORY_TYPE: {repo_id: dispatch_constants.RESOURCE_UPDATE_OPERATION},
        dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE: {
            distributor_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),
        action_tag("update_distributor"),
    ]

    update_request = CallRequest(
        manager.update_distributor_config,
        [repo_id, distributor_id],
        {"distributor_config": config},
        resources=resources,
        tags=tags,
        archive=True,
        kwarg_blacklist=["distributor_config"],
    )

    call_requests.append(update_request)

    # append unbind itineraries foreach bound consumer

    options = {}
    manager = managers.consumer_bind_manager()
    for bind in manager.find_by_distributor(repo_id, distributor_id):
        bind_requests = bind_itinerary(
            bind["consumer_id"],
            bind["repo_id"],
            bind["distributor_id"],
            bind["notify_agent"],
            bind["binding_config"],
            options,
        )
        if bind_requests:
            bind_requests[0].depends_on(update_request.id)
            call_requests.extend(bind_requests)

    return call_requests
Exemple #31
0
    def update_repo_and_plugins(repo_id, repo_delta, importer_config,
                                distributor_configs):
        """
        Aggregate method that will update one or more of the following:
        * Repository metadata
        * Importer config
        * Zero or more distributors on the repository

        All of the above pieces do not need to be specified. If a piece is
        omitted it's configuration is not touched, nor is it removed from
        the repository. The same holds true for the distributor_configs dict,
        not every distributor must be represented.

        This call will attempt the updates in the order listed above. If an
        exception occurs during any of these steps, the updates stop and the
        exception is immediately raised. Any updates that have already taken
        place are not rolled back.

        This call will call out to RepoImporterManager.update_importer_config.
        Documentation for that method, especially possible exceptions, should be
        consulted for more information.

        Distributor updates will happen asynchronously as there could be a
        very large number of consumers to update and the repo update call
        is usually made synchronously.

        :param repo_id: unique identifier for the repo
        :type  repo_id: str

        :param repo_delta: list of attributes and their new values to change;
               if None, no attempt to update the repo's metadata will be made
        :type  repo_delta: dict, None

        :param importer_config: new configuration to use for the repo's importer;
               if None, no attempt will be made to update the importer
        :type  importer_config: dict, None

        :param distributor_configs: mapping of distributor ID to the new configuration
               to set for it
        :type  distributor_configs: dict, None

        :return: updated repository object, same as returned from update_repo
        :rtype: TaskResult
        """
        # Repo Update
        if repo_delta is None:
            repo_delta = {}
        repo = RepoManager.update_repo(repo_id, repo_delta)

        # Importer Update
        if importer_config is not None:
            importer_manager = manager_factory.repo_importer_manager()
            importer_manager.update_importer_config(repo_id, importer_config)

        additional_tasks = []
        # Distributor Update
        if distributor_configs is not None:
            for dist_id, dist_config in distributor_configs.items():
                task_tags = [
                    tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
                    tags.resource_tag(
                        tags.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, dist_id),
                    tags.action_tag(tags.ACTION_UPDATE_DISTRIBUTOR)
                ]
                async_result = repository.distributor_update.apply_async_with_reservation(
                    tags.RESOURCE_REPOSITORY_TYPE,
                    repo_id, [repo_id, dist_id, dist_config, None],
                    tags=task_tags)
                additional_tasks.append(async_result)

        return TaskResult(repo, None, additional_tasks)
Exemple #32
0
 def DELETE(self, content_type):
     task_tags = [tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')]
     async_task = orphan.delete_orphans_by_type.apply_async((content_type,), tags=tags)
     raise OperationPostponed(async_task)
Exemple #33
0
 def DELETE(self):
     task_tags = [tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')]
     async_task = orphan.delete_all_orphans.apply_async(tags=task_tags)
     raise OperationPostponed(async_task)
Exemple #34
0
    def test_bind(self, *mocks):

        mock_agent = mocks[0]
        mock_context = mocks[1]
        mock_factory = mocks[2]
        mock_bindings = mocks[3]
        mock_task_status = mocks[4]
        mock_uuid = mocks[5]

        consumer = {'id': '1234'}
        mock_consumer_manager = Mock()
        mock_consumer_manager.get_consumer = Mock(return_value=consumer)
        mock_factory.consumer_manager = Mock(
            return_value=mock_consumer_manager)

        binding = {}
        mock_bind_manager = Mock()
        mock_bind_manager.get_bind = Mock(return_value=binding)
        mock_bind_manager.action_pending = Mock()
        mock_factory.consumer_bind_manager = Mock(
            return_value=mock_bind_manager)

        agent_bindings = []
        mock_bindings.return_value = agent_bindings

        task_id = '2345'
        mock_context.return_value = {}
        mock_uuid.return_value = task_id

        # test manager

        repo_id = '100'
        distributor_id = '200'
        options = {}
        agent_manager = AgentManager()
        agent_manager.bind(consumer['id'], repo_id, distributor_id, options)

        # validations

        task_tags = [
            tags.resource_tag(tags.RESOURCE_CONSUMER_TYPE, consumer['id']),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                              distributor_id),
            tags.action_tag(tags.ACTION_AGENT_BIND)
        ]

        mock_consumer_manager.get_consumer.assert_called_with(consumer['id'])
        mock_bind_manager.get_bind.assert_called_with(consumer['id'], repo_id,
                                                      distributor_id)
        mock_bindings.assert_called_with([binding])

        mock_context.assert_called_with(consumer,
                                        task_id=task_id,
                                        action='bind',
                                        consumer_id=consumer['id'],
                                        repo_id=repo_id,
                                        distributor_id=distributor_id)

        mock_task_status.assert_called_with(task_id=task_id,
                                            worker_name='agent',
                                            tags=task_tags)
        mock_agent.bind.assert_called_with(mock_context.return_value,
                                           agent_bindings, options)
        mock_bind_manager.action_pending.assert_called_with(
            consumer['id'], repo_id, distributor_id, Bind.Action.BIND, task_id)
Exemple #35
0
def update_repo_and_plugins(repo, repo_delta, importer_config,
                            distributor_configs):
    """
    Update a reposiory and its related collections.

    All details do not need to be specified; if a piece is omitted it's configuration is not
    touched, nor is it removed from the repository. The same holds true for the distributor_configs
    dict, not every distributor must be represented.

    This call will attempt to update the repository object, then the importer, then the
    distributors. If an exception occurs during any of these steps, the updates stop and the
    exception is immediately raised. Any updates that have already taken place are not rolled back.

    Distributor updates are asynchronous as there could be a very large number of consumers to
    update. Repository and importer updates are done synchronously.

    :param repo: repository object
    :type  repo: pulp.server.db.model.Repository
    :param repo_delta: list of attributes to change and their new values; if None, no attempt to
                       update the repository object will be made
    :type  repo_delta: dict, None
    :param importer_config: new configuration to use for the repo's importer; if None, no attempt
                            will be made to update the importer
    :type  importer_config: dict, None
    :param distributor_configs: mapping of distributor ID to the new configuration to set for it
    :type  distributor_configs: dict, None

    :return: Task result that contains the updated repository object and additional spawned tasks
    :rtype:  pulp.server.async.tasks.TaskResult

    :raises pulp_exceptions.InvalidValue: if repo_delta is not a dictionary
    """
    if repo_delta:
        if isinstance(repo_delta, dict):
            repo.update_from_delta(repo_delta)
            repo.save()
        else:
            raise pulp_exceptions.PulpCodedValidationException(
                error_code=error_codes.PLP1010,
                field='delta',
                field_type='dict',
                value=repo_delta)

    if importer_config is not None:
        importer_manager = manager_factory.repo_importer_manager()
        importer_manager.update_importer_config(repo.repo_id, importer_config)

    additional_tasks = []
    if distributor_configs is not None:
        for dist_id, dist_config in distributor_configs.items():
            task_tags = [
                tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo.repo_id),
                tags.resource_tag(tags.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                                  dist_id),
                tags.action_tag(tags.ACTION_UPDATE_DISTRIBUTOR)
            ]
            async_result = dist_controller.update.apply_async_with_reservation(
                tags.RESOURCE_REPOSITORY_TYPE,
                repo.repo_id, [repo.repo_id, dist_id, dist_config, None],
                tags=task_tags)
            additional_tasks.append(async_result)
    return TaskResult(repo, None, additional_tasks)
Exemple #36
0
def forced_unbind_itinerary(consumer_id, repo_id, distributor_id, options):
    """
    Get the unbind itinerary.
    A forced unbind immediately deletes the binding instead
    of marking it deleted and going through that lifecycle.
    It is intended to be used to clean up orphaned bindings
    caused by failed/unconfirmed unbind actions on the consumer.
    The itinerary is:
      1. Delete the binding on the server.
      2. Request that the consumer (agent) perform the unbind.
    @param consumer_id: A consumer ID.
    @type consumer_id: str
    @param repo_id: A repository ID.
    @type repo_id: str
    @param distributor_id: A distributor ID.
    @type distributor_id: str
    @param options: Unbind options passed to the agent handler.
    @type options: dict
    @return: A list of call_requests
    @rtype list
    """

    call_requests = []
    bind_manager = managers.consumer_bind_manager()
    agent_manager = managers.consumer_agent_manager()

    # unbind

    resources = {
        dispatch_constants.RESOURCE_CONSUMER_TYPE: {
            consumer_id: dispatch_constants.RESOURCE_READ_OPERATION
        },
    }

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_UNBIND)
    ]

    args = [
        consumer_id,
        repo_id,
        distributor_id,
        True,
    ]

    delete_request = CallRequest(bind_manager.delete,
                                 args=args,
                                 resources=resources,
                                 tags=tags)

    call_requests.append(delete_request)

    # notify agent

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_AGENT_UNBIND)
    ]

    args = [
        consumer_id,
        repo_id,
        distributor_id,
        options,
    ]

    agent_request = CallRequest(agent_manager.unbind,
                                args,
                                weight=0,
                                asynchronous=True,
                                archive=True,
                                tags=tags)

    call_requests.append(agent_request)

    agent_request.depends_on(delete_request.id)

    return call_requests
Exemple #37
0
def bind_itinerary(consumer_id, repo_id, distributor_id, notify_agent,
                   binding_config, agent_options):
    """
    Get the bind itinerary:
      1. Create the binding on the server.
      2. Request that the consumer (agent) perform the bind.
    @param consumer_id: A consumer ID.
    @type consumer_id: str
    @param repo_id: A repository ID.
    @type repo_id: str
    @param distributor_id: A distributor ID.
    @type distributor_id: str
    @param agent_options: Bind options passed to the agent handler.
    @type agent_options: dict
    @param notify_agent: indicates if the agent should be sent a message about the new binding
    @type  notify_agent: bool
    @param binding_config: configuration options to use when generating the payload for this binding

    @return: A list of call_requests.
    @rtype list
    """

    call_requests = []
    bind_manager = managers.consumer_bind_manager()
    agent_manager = managers.consumer_agent_manager()

    # bind

    resources = {
        dispatch_constants.RESOURCE_CONSUMER_TYPE: {
            consumer_id: dispatch_constants.RESOURCE_READ_OPERATION
        },
        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
        },
    }

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_BIND)
    ]

    args = [
        consumer_id,
        repo_id,
        distributor_id,
        notify_agent,
        binding_config,
    ]

    bind_request = CallRequest(bind_manager.bind,
                               args,
                               resources=resources,
                               weight=0,
                               tags=tags)

    call_requests.append(bind_request)

    # notify agent

    if notify_agent:
        tags = [
            resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE,
                         consumer_id),
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            resource_tag(
                dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                distributor_id),
            action_tag(ACTION_AGENT_BIND)
        ]

        args = [consumer_id, repo_id, distributor_id, agent_options]

        agent_request = CallRequest(agent_manager.bind,
                                    args,
                                    weight=0,
                                    asynchronous=True,
                                    archive=True,
                                    tags=tags)

        agent_request.add_life_cycle_callback(
            dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK,
            bind_succeeded)

        agent_request.add_life_cycle_callback(
            dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, bind_failed)

        call_requests.append(agent_request)

        agent_request.depends_on(bind_request.id)

    return call_requests
Exemple #38
0
 def DELETE(self, content_type, content_id):
     ids = [{'content_type_id': content_type, 'unit_id': content_id}]
     task_tags = [tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')]
     async_task = orphan.delete_orphans_by_id.apply_async((ids,), tags=task_tags)
     raise OperationPostponed(async_task)
Exemple #39
0
def unbind_itinerary(consumer_id, repo_id, distributor_id, options):
    """
    Get the unbind itinerary.
    The tasks in the itinerary are as follows:
      1. Mark the binding as (deleted) on the server.
      2. Request that the consumer (agent) perform the unbind.
      3. Delete the binding on the server.
    @param consumer_id: A consumer ID.
    @type consumer_id: str
    @param repo_id: A repository ID.
    @type repo_id: str
    @param distributor_id: A distributor ID.
    @type distributor_id: str
    @param options: Unbind options passed to the agent handler.
    @type options: dict
    @return: A list of call_requests.
    @rtype list
    """

    call_requests = []
    bind_manager = managers.consumer_bind_manager()
    agent_manager = managers.consumer_agent_manager()

    # unbind

    resources = {
        dispatch_constants.RESOURCE_CONSUMER_TYPE: {
            consumer_id: dispatch_constants.RESOURCE_READ_OPERATION
        },
    }

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_UNBIND)
    ]

    args = [
        consumer_id,
        repo_id,
        distributor_id,
    ]

    unbind_request = CallRequest(bind_manager.unbind,
                                 args=args,
                                 resources=resources,
                                 tags=tags)

    call_requests.append(unbind_request)

    # notify agent

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_AGENT_UNBIND)
    ]

    args = [
        consumer_id,
        repo_id,
        distributor_id,
        options,
    ]

    agent_request = CallRequest(agent_manager.unbind,
                                args,
                                weight=0,
                                asynchronous=True,
                                archive=True,
                                tags=tags)

    agent_request.add_life_cycle_callback(
        dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, unbind_succeeded)

    agent_request.add_life_cycle_callback(
        dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, unbind_failed)

    call_requests.append(agent_request)

    agent_request.depends_on(unbind_request.id)

    # delete the binding

    resources = {
        dispatch_constants.RESOURCE_CONSUMER_TYPE: {
            consumer_id: dispatch_constants.RESOURCE_READ_OPERATION
        },
    }

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_DELETE_BINDING)
    ]

    args = [consumer_id, repo_id, distributor_id]

    delete_request = CallRequest(bind_manager.delete,
                                 args=args,
                                 resources=resources,
                                 tags=tags)

    call_requests.append(delete_request)

    delete_request.depends_on(agent_request.id)

    return call_requests