예제 #1
0
    def post(self, request):
        """
        Dispatch a delete_orphan_by_id task.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest

        :raises: OperationPostponed when an async operation is performed
        """
        all_orphans = request.body_as_json
        task_tags = [
            tags.action_tag('delete_orphans'),
            tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')
        ]
        async_task = content_orphan.delete_orphans_by_id.apply_async(
            [all_orphans], tags=task_tags)
        raise OperationPostponed(async_task)
예제 #2
0
    def refresh(request):
        """
        Refresh all content sources

        :param request: WSGI request object, body contains bits to upload
        :type request: django.core.handlers.wsgi.WSGIRequest
        :raises: OperationPostponed when an async operation is performed
        """
        container = ContentContainer()
        content_sources = [
            tags.resource_tag(RESOURCE_CONTENT_SOURCE, id)
            for id in container.sources.keys()
        ]
        task_tags = [tags.action_tag(ACTION_REFRESH_ALL_CONTENT_SOURCES)
                     ] + content_sources
        task_result = content.refresh_content_sources.apply_async(
            tags=task_tags)
        raise OperationPostponed(task_result)
예제 #3
0
파일: consumers.py 프로젝트: ipanova/pulp
    def POST(self, consumer_id):
        """
        Creates an async task to regenerate content applicability data for given consumer.

        :param consumer_id: The consumer ID.
        :type consumer_id: basestring
        """
        consumer_query_manager = managers.consumer_query_manager()
        if consumer_query_manager.find_by_id(consumer_id) is None:
            raise MissingResource(consumer_id=consumer_id)
        consumer_criteria = Criteria(filters={'consumer_id': consumer_id})

        task_tags = [tags.action_tag('consumer_content_applicability_regeneration')]
        async_result = regenerate_applicability_for_consumers.apply_async_with_reservation(
            tags.RESOURCE_CONSUMER_TYPE,
            consumer_id,
            (consumer_criteria.as_dict(),),
            tags=task_tags)
        raise OperationPostponed(async_result)
예제 #4
0
파일: content.py 프로젝트: credativ/pulp
    def delete(self, request, content_type):
        """
        Dispatch a delete_orphans_by_type task.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param content_type: restrict the list of orphans to be deleted to this content type
        :type  content_type: str

        :raises: OperationPostponed when an async operation is performed
        """
        orphan_manager = factory.content_orphan_manager()
        orphan_manager.validate_type(content_type)
        task_tags = [
            tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')
        ]
        async_task = content_orphan.delete_orphans_by_type.apply_async(
            (content_type, ), tags=task_tags)
        raise OperationPostponed(async_task)
예제 #5
0
파일: repo_groups.py 프로젝트: omps/pulp
    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'])

        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 = 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 OperationPostponed(async_result)
예제 #6
0
파일: consumers.py 프로젝트: ipanova/pulp
    def POST(self):
        """
        Creates an async task to regenerate content applicability data for given consumers.

        body {consumer_criteria:<dict>}
        """
        body = self.params()
        consumer_criteria = body.get('consumer_criteria', None)
        if consumer_criteria is None:
            raise MissingValue('consumer_criteria')
        try:
            consumer_criteria = Criteria.from_client_input(consumer_criteria)
        except:
            raise InvalidValue('consumer_criteria')

        task_tags = [tags.action_tag('content_applicability_regeneration')]
        async_result = regenerate_applicability_for_consumers.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_PROFILE_APPLICABILITY_TYPE, tags.RESOURCE_ANY_ID,
            (consumer_criteria.as_dict(),), tags=task_tags)
        raise OperationPostponed(async_result)
예제 #7
0
파일: content.py 프로젝트: pombreda/pulp
    def delete(self, request, content_type, unit_id):
        """
        Dispatch a delete_orphans_by_id task.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param content_type: content type of the requested orphan
        :type  content_type: str
        :param unit_id: id of the requested orphan
        :type  unit_id: str

        :raises: OperationPostponed when an async operation is performed
        """
        unit_info = [{'content_type_id': content_type, 'unit_id': unit_id}]
        task_tags = [
            tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')
        ]
        async_task = content_orphan.delete_orphans_by_id.apply_async(
            (unit_info, ), tags=task_tags)
        raise OperationPostponed(async_task)
예제 #8
0
파일: consumers.py 프로젝트: zjhuntin/pulp
    def delete(self, request, consumer_id, repo_id, distributor_id):
        """
        Delete a bind association between the specified
        consumer and repo-distributor.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :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

        :raises OperationPostponed: will dispatch a task if 'notify_agent' is set to True
        :raises InvalidValue: if some parameters are invalid

        :return: Response representing the deleted binding(in case 'notify agent' is set to False)
        :rtype: django.http.HttpResponse
        """

        body = request.body_as_json
        forced = body.get('force', False)
        if not isinstance(forced, bool):
            raise InvalidValue(['force'])
        options = body.get('options', {})
        if not isinstance(options, dict):
            raise InvalidValue(['options'])
        if forced:
            call_report = consumer_controller.force_unbind(
                consumer_id, repo_id, distributor_id, options)
        else:
            call_report = consumer_controller.unbind(consumer_id, repo_id,
                                                     distributor_id, options)

        if call_report.spawned_tasks:
            raise OperationPostponed(call_report)
        else:
            return generate_json_response_with_pulp_encoder(
                call_report.serialize())
예제 #9
0
파일: consumers.py 프로젝트: zjhuntin/pulp
    def post(self, request, consumer_id):
        """
        Create a bind association between the specified
        consumer 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_id: consumer to bind.
        :type  consumer_id: str

        :raises OperationPostponed: will dispatch a task if 'notify_agent' is set to True
        :raises InvalidValue: if binding_config is invalid

        :return: Response representing the binding(in case 'notify agent' is set to False)
        :rtype: django.http.HttpResponse
        """

        # get other options and validate them
        body = request.body_as_json
        repo_id = body.get('repo_id')
        distributor_id = body.get('distributor_id')
        binding_config = body.get('binding_config', {})
        options = body.get('options', {})
        notify_agent = body.get('notify_agent', True)

        if not isinstance(binding_config, dict):
            raise InvalidValue(['binding_config'])

        call_report = consumer_controller.bind(consumer_id, repo_id,
                                               distributor_id, notify_agent,
                                               binding_config, options)

        if call_report.spawned_tasks:
            raise OperationPostponed(call_report)
        else:
            return generate_json_response_with_pulp_encoder(
                call_report.serialize())
예제 #10
0
파일: consumers.py 프로젝트: zjhuntin/pulp
    def uninstall(self, request, consumer_id, units, options):
        """
        Uninstall content (units) on a consumer.

        Expected body: {units:[], options:<dict>}
        where unit is: {type_id:<str>, unit_key={}} and the
        options is a dict of uninstall options.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: A consumer ID.
        :type consumer_id: str
        :param units: units to install
        :type units: list
        :param options: install options
        :type options: dict

        :raises OperationPostponed: when an async operation is performed.
        """

        agent_manager = factory.consumer_agent_manager()
        task = agent_manager.uninstall_content(consumer_id, units, options)
        raise OperationPostponed(TaskResult.from_task_status_dict(task))
예제 #11
0
def execute_created(controller, call_request, location):
    """
    Execute a call request via the coordinator.
    @param controller: web services rest controller
    @type  controller: pulp.server.webservices.controller.base.JSONController
    @param call_request: call request to execute
    @type  call_request: pulp.server.dispatch.call.CallRequest
    @param location: the location of the created resource
    @type  location: str
    @return: http server response
    @deprecated: create should always return an _href field which requires post
                 return processing
    """
    coordinator = dispatch_factory.coordinator()
    call_report = coordinator.execute_call(call_request)
    if call_report.response is dispatch_constants.CALL_REJECTED_RESPONSE:
        raise ConflictingOperation(call_report.reasons)
    # covers postponed and accepted
    if call_report.state in dispatch_constants.CALL_INCOMPLETE_STATES:
        raise OperationPostponed(call_report)
    if call_report.state is dispatch_constants.CALL_ERROR_STATE:
        raise call_report.exception, None, call_report.traceback
    return controller.created(location, call_report.result)
예제 #12
0
파일: consumers.py 프로젝트: ipanova/pulp
    def uninstall(self, consumer_id):
        """
        Uninstall content (units) on a consumer.
        Expected body: {units:[], options:<dict>}
        where unit is: {type_id:<str>, unit_key={}} and the
        options is a dict of uninstall options.
        @param consumer_id: A consumer ID.
        @type consumer_id: str
        """
        body = self.params()
        missing_params = []
        units = body.get('units')
        if units is None:
            missing_params.append('units')
        options = body.get('options')
        if options is None:
            missing_params.append('options')

        if len(missing_params) > 0:
            raise MissingValue(missing_params)

        agent_manager = managers.consumer_agent_manager()
        task = agent_manager.uninstall_content(consumer_id, units, options)
        raise OperationPostponed(TaskResult.from_task_status_dict(task))
예제 #13
0
    def delete(self, request, content_type):
        """
        Dispatch a delete_orphans_by_type task.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param content_type: restrict the list of orphans to be deleted to this content type
        :type  content_type: str

        :raises: OperationPostponed when an async operation is performed
        :raises: MissingResource when the content type does not exist
        """
        try:
            # this tests if the type exists
            units.get_unit_key_fields_for_type(content_type)
        except ValueError:
            raise MissingResource(content_type_id=content_type)

        task_tags = [
            tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')
        ]
        async_task = content_orphan.delete_orphans_by_type.apply_async(
            (content_type, ), tags=task_tags)
        raise OperationPostponed(async_task)
예제 #14
0
파일: contents.py 프로젝트: aweiteka/pulp
 def POST(self):
     orphans = self.params()
     task_tags = [tags.action_tag('delete_orphans'),
             tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')]
     async_task = orphan.delete_orphans_by_id.apply_async([orphans], tags=task_tags)
     raise OperationPostponed(async_task)
예제 #15
0
파일: contents.py 프로젝트: aweiteka/pulp
 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)
예제 #16
0
파일: contents.py 프로젝트: aweiteka/pulp
 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)
예제 #17
0
파일: contents.py 프로젝트: aweiteka/pulp
 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)