예제 #1
0
class RepoAssociate(View):
    """
    View to copy units between repositories.
    """

    @auth_required(authorization.UPDATE)
    @json_body_required
    def post(self, request, dest_repo_id):
        """
        Associate units matching the criteria into the given repository

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param dest_repo_id: id of the repository content will be copied to
        :type  dest_repo_id: str

        :raises exceptions.MissingValue: if required param source_repo_id is not passed
        :raises exceptions.InvalidValue: if source_repo_id is not found or if criteria
                                              params cannot be parsed
        :raises exceptions.OperationPostponed: dispatch a publish repo task
        """
        model.Repository.objects.get_repo_or_missing_resource(dest_repo_id)
        criteria_body = request.body_as_json.get('criteria', {})
        overrides = request.body_as_json.get('override_config', None)
        source_repo_id = request.body_as_json.get('source_repo_id', None)
        if source_repo_id is None:
            raise exceptions.MissingValue(['source_repo_id'])

        # Catch MissingResource because this is body data, raise 400 rather than 404
        try:
            model.Repository.objects.get_repo_or_missing_resource(source_repo_id)
        except exceptions.MissingResource:
            raise exceptions.InvalidValue(['source_repo_id'])

        try:
            criteria = UnitAssociationCriteria.from_client_input(criteria_body)
        except exceptions.InvalidValue, e:
            invalid_criteria = exceptions.InvalidValue('criteria')
            invalid_criteria.add_child_exception(e)
            raise invalid_criteria

        task_tags = [tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, dest_repo_id),
                     tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, source_repo_id),
                     tags.action_tag('associate')]
        async_result = associate_from_repo.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_TYPE, dest_repo_id, [source_repo_id, dest_repo_id],
            {'criteria': criteria.to_dict(), 'import_config_override': overrides}, tags=task_tags)
        raise exceptions.OperationPostponed(async_result)
예제 #2
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'])

        # A 404 only applies to things in the URL, so the destination repo
        # check allows the MissingResource to bubble up, but if the source
        # repo doesn't exist, it's considered bad data.
        repo_query_manager = manager_factory.repo_query_manager()
        repo_query_manager.get_repository(dest_repo_id)

        try:
            repo_query_manager.get_repository(source_repo_id)
        except exceptions.MissingResource:
            raise exceptions.InvalidValue(['source_repo_id'])

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

        task_tags = [
            tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, dest_repo_id),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, source_repo_id),
            tags.action_tag('associate')
        ]
        async_result = associate_from_repo.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_TYPE,
            dest_repo_id, [source_repo_id, dest_repo_id], {
                'criteria': criteria,
                'import_config_override': overrides
            },
            tags=task_tags)
        raise exceptions.OperationPostponed(async_result)
예제 #3
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"])

        # A 404 only applies to things in the URL, so the destination repo
        # check allows the MissingResource to bubble up, but if the source
        # repo doesn't exist, it's considered bad data.
        repo_query_manager = manager_factory.repo_query_manager()
        repo_query_manager.get_repository(dest_repo_id)

        try:
            repo_query_manager.get_repository(source_repo_id)
        except exceptions.MissingResource:
            raise exceptions.InvalidValue(["source_repo_id"])

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

        tags = [
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, dest_repo_id),
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, source_repo_id),
            action_tag("associate"),
        ]
        async_result = associate_from_repo.apply_async_with_reservation(
            dispatch_constants.RESOURCE_REPOSITORY_TYPE,
            dest_repo_id,
            [source_repo_id, dest_repo_id],
            {"criteria": criteria, "import_config_override": overrides},
            tags=tags,
        )
        raise exceptions.OperationPostponed(async_result)
예제 #4
0
        if criteria_body:
            try:
                criteria = UnitAssociationCriteria.from_client_input(criteria_body)
            except pulp_exceptions.InvalidValue, e:
                invalid_criteria = pulp_exceptions.InvalidValue('criteria')
                invalid_criteria.add_child_exception(e)
                raise invalid_criteria
        else:
            criteria = None

        task_tags = [tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, dest_repo_id),
                     tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, source_repo_id),
                     tags.action_tag('associate')]
        async_result = associate_from_repo.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_TYPE, dest_repo_id, [source_repo_id, dest_repo_id],
            {'criteria': criteria, 'import_config_override': overrides}, tags=task_tags)
        raise pulp_exceptions.OperationPostponed(async_result)


class RepoUnassociate(View):
    """
    View to unassociate a unit from a repository.
    """

    @auth_required(authorization.UPDATE)
    @json_body_allow_empty
    def post(self, request, repo_id):
        """
        Unassociate units that match the criteria from the given repository.