Esempio n. 1
0
    def POST(self):
        """
        Determine content applicability.
        body {
        consumer_criteria:<dict> or None, 
        repo_criteria:<dict> or None, 
        unit_criteria: <dict of type_id : unit_criteria> or None,
        override_config: <dict> or None
        }

        :return: 

        When report_style is 'by_consumer' -
        A dict of applicability reports keyed by consumer ID.
            Each consumer report is:
                { <unit_type_id1> : [<ApplicabilityReport>],
                  <unit_type_id1> : [<ApplicabilityReport>]},
                }

        When report_style is 'by_units' -
        A dict of <unit_type_id1>: [<ApplicabilityReport>]
        where applicability_report.summary contains a list of applicable consumer ids.

        :rtype: dict
        """
        body = self.params()

        consumer_criteria = body.get('consumer_criteria', None)
        repo_criteria = body.get('repo_criteria', None)
        units = body.get('unit_criteria', None)
        override_config = body.get('override_config', None)

        if consumer_criteria:
            consumer_criteria = Criteria.from_client_input(consumer_criteria)

        if repo_criteria:
            repo_criteria = Criteria.from_client_input(repo_criteria)

        unit_criteria = {}
        if units:
            for type_id, criteria in units.items():
                # process if criteria is not empty
                if criteria:
                    unit_criteria[type_id] = Criteria.from_client_input(criteria)
                else:
                    unit_criteria[type_id] = criteria

        manager = managers.consumer_applicability_manager()
        report = manager.find_applicable_units(consumer_criteria, repo_criteria, unit_criteria, override_config)

        for unit_type_id, applicability_reports in report.items():
            if isinstance(applicability_reports, list):
                report[unit_type_id] = [serialization.consumer.applicability_report(r) for r in applicability_reports]
            else:
                for consumer_id, report_list in applicability_reports.items():
                    report[unit_type_id][consumer_id] = [serialization.consumer.applicability_report(r) for r in report_list]

        return self.ok(report)
Esempio n. 2
0
    def _get_query_results_from_get(self, ignore_fields=None):
        """
        Looks for query parameters that define a Criteria, and returns the
        results of a search based on that Criteria.

        @param ignore_fields:   Field names to ignore. All other fields will be
                                used in an attempt to generate a Criteria
                                instance, which will fail if unexpected field
                                names are present.
        @type  ignore_fields:   list

        @return:    list of documents from the DB that match the given criteria
                    for the collection associated with this controller
        @rtype:     list
        """
        input = web.input(field=[])
        if ignore_fields:
            for field in ignore_fields:
                input.pop(field, None)

        # rename this to 'fields' within the dict, and omit it if empty so we
        # default to getting all fields
        fields = input.pop('field')
        if fields:
            if 'id' not in fields and u'id' not in fields:
                fields.append('id')
            input['fields'] = fields

        criteria = Criteria.from_client_input(input)
        return list(self.query_method(criteria))
Esempio n. 3
0
    def post(self, request):
        """
        Creates an async task to regenerate content applicability data for given consumers.

        body {consumer_criteria:<dict>}

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

        :raises MissingValue: if some parameters are missing
        :raises InvalidValue: if some parameters are invalid
        :raises OperationPostponed: when an async operation is performed.
        """

        body = request.body_as_json
        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)
Esempio n. 4
0
 def POST(self, consumer_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.consumer_group_manager()
     manager.unassociate(consumer_group_id, criteria)
     query_manager = managers_factory.consumer_group_query_manager()
     group = query_manager.get_group(consumer_group_id)
     return self.ok(group['consumer_ids'])
Esempio n. 5
0
    def post(self, request):
        """
        Creates an async task to regenerate content applicability data for given consumers.

        body {consumer_criteria:<dict>}

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

        :raises MissingValue: if some parameters are missing
        :raises InvalidValue: if some parameters are invalid
        :raises OperationPostponed: when an async operation is performed.
        """

        body = request.body_as_json
        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)
Esempio n. 6
0
    def post(self, request):
        """
        Dispatch a task to regenerate content applicability data for repositories that match
        the criteria passed in the body.

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

        :raises exceptions.MissingValue: if repo_critera is not a body parameter
        :raises exceptions.InvalidValue: if repo_critera (dict) has unsupported keys,
                                              the manager will raise an InvalidValue for the
                                              specific keys. Here, we create a parent exception
                                              for repo_criteria and include the specific keys as
                                              child exceptions.
        :raises exceptions.OperationPostponed: dispatch a task
        """
        class GroupCallReport(dict):
            def serialize(self):
                return self

        repo_criteria_body = request.body_as_json.get('repo_criteria', None)
        parallel = request.body_as_json.get('parallel', False)

        if repo_criteria_body is None:
            raise exceptions.MissingValue('repo_criteria')
        try:
            repo_criteria = Criteria.from_client_input(repo_criteria_body)
        except exceptions.InvalidValue, e:
            invalid_criteria = exceptions.InvalidValue('repo_criteria')
            invalid_criteria.add_child_exception(e)
            raise invalid_criteria
Esempio n. 7
0
    def post(self, request):
        """
        Dispatch a task to regenerate content applicability data for repositories that match
        the criteria passed in the body.

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

        :raises exceptions.MissingValue: if repo_critera is not a body parameter
        :raises exceptions.InvalidValue: if repo_critera (dict) has unsupported keys,
                                              the manager will raise an InvalidValue for the
                                              specific keys. Here, we create a parent exception
                                              for repo_criteria and include the specific keys as
                                              child exceptions.
        :raises exceptions.OperationPostponed: dispatch a task
        """
        class GroupCallReport(dict):
            def serialize(self):
                return self

        repo_criteria_body = request.body_as_json.get('repo_criteria', None)
        if repo_criteria_body is None:
            raise exceptions.MissingValue('repo_criteria')
        try:
            repo_criteria = Criteria.from_client_input(repo_criteria_body)
        except exceptions.InvalidValue, e:
            invalid_criteria = exceptions.InvalidValue('repo_criteria')
            invalid_criteria.add_child_exception(e)
            raise invalid_criteria
Esempio n. 8
0
 def test_no_exception_for_profiler_notfound(self):
     # Setup
     self.populate()
     # Test
     user_specified_unit_criteria = {
         'rpm': {
             "filters": {
                 "name": {
                     "$in": ['zsh']
                 }
             }
         },
         'xxx': {
             "filters": {
                 "name": {
                     "$in": ['abc']
                 }
             }
         }
     }
     unit_criteria = {}
     for type_id, criteria in user_specified_unit_criteria.items():
         unit_criteria[type_id] = Criteria.from_client_input(criteria)
     manager = factory.consumer_applicability_manager()
     result = manager.find_applicable_units(self.CONSUMER_CRITERIA,
                                            self.REPO_CRITERIA,
                                            unit_criteria)
     self.assertTrue(result == {})
Esempio n. 9
0
 def test_profiler_no_exception(self):
     # Setup
     self.populate()
     profiler, cfg = plugins.get_profiler_by_type('rpm')
     profiler.find_applicable_units = Mock(side_effect=KeyError)
     # Test
     user_specified_unit_criteria = {
         'rpm': {
             "filters": {
                 "name": {
                     "$in": ['zsh', 'ksh']
                 }
             }
         },
         'mock-type': {
             "filters": {
                 "name": {
                     "$in": ['abc', 'def']
                 }
             }
         }
     }
     unit_criteria = {}
     for type_id, criteria in user_specified_unit_criteria.items():
         unit_criteria[type_id] = Criteria.from_client_input(criteria)
     manager = factory.consumer_applicability_manager()
     result = manager.find_applicable_units(self.CONSUMER_CRITERIA,
                                            self.REPO_CRITERIA,
                                            unit_criteria)
     self.assertTrue(result == {})
Esempio n. 10
0
    def POST(self):
        """
        Creates an async task to regenerate content applicability data for given updated
        repositories.

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

        manager = manager_factory.applicability_regeneration_manager()
        regeneration_tag = action_tag('applicability_regeneration')
        call_request = CallRequest(manager.regenerate_applicability_for_repos,
                                   [repo_criteria],
                                   tags = [regeneration_tag])
        # allow only one applicability regeneration task at a time
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_PROFILE_APPLICABILITY_TYPE,
                                      dispatch_constants.RESOURCE_ANY_ID)
        return execution.execute_async(self, call_request)
Esempio n. 11
0
 def POST(self, repo_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.repo_group_manager()
     manager.unassociate(repo_group_id, criteria)
     collection = RepoGroup.get_collection()
     group = collection.find_one({'id': repo_group_id})
     return self.ok(group['repo_ids'])
Esempio n. 12
0
 def POST(self, consumer_group_id):
     criteria = Criteria.from_client_input(self.params().get(
         'criteria', {}))
     manager = managers_factory.consumer_group_manager()
     manager.unassociate(consumer_group_id, criteria)
     query_manager = managers_factory.consumer_group_query_manager()
     group = query_manager.get_group(consumer_group_id)
     return self.ok(group['consumer_ids'])
Esempio n. 13
0
 def POST(self, consumer_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.consumer_group_manager()
     tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id),
             action_tag('consumer_group_unassociate')]
     call_request = CallRequest(manager.unassociate,
                                [consumer_group_id, criteria],
                                tags=tags)
     call_request.updates_resource(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id)
     matched = execution.execute(call_request)
     return self.ok(matched)
Esempio n. 14
0
 def GET(self):
     valid_filters = ['tag']
     filters = self.filters(valid_filters)
     criteria_filters = {}
     tags = filters.get('tag', [])
     if tags:
         criteria_filters['tags'] = {'$all':  filters.get('tag', [])}
     criteria = Criteria.from_client_input({'filters': criteria_filters})
     serialized_task_statuses = []
     for task in TaskStatusManager.find_by_criteria(criteria):
         task.update(serialization.dispatch.spawned_tasks(task))
         serialized_task_statuses.append(task)
     return self.ok(serialized_task_statuses)
Esempio n. 15
0
 def POST(self, repo_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.repo_group_manager()
     tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
             action_tag('repo_group_unassociate')]
     call_request = CallRequest(manager.unassociate,
                                [repo_group_id, criteria],
                                tags=tags)
     call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
     execution.execute(call_request)
     collection = RepoGroup.get_collection()
     group = collection.find_one({'id': repo_group_id})
     return self.ok(group['repo_ids'])
Esempio n. 16
0
 def test_no_exception_for_profiler_notfound(self):
     # Setup
     self.populate()
     # Test
     user_specified_unit_criteria = {'rpm': {"filters": {"name": {"$in":['zsh']}}},
                      'xxx': {"filters": {"name": {"$in":['abc']}}}
                     }
     unit_criteria = {}
     for type_id, criteria in user_specified_unit_criteria.items():
         unit_criteria[type_id] = Criteria.from_client_input(criteria)
     manager = factory.consumer_applicability_manager()
     result = manager.find_applicable_units(self.CONSUMER_CRITERIA, self.REPO_CRITERIA, unit_criteria)
     self.assertTrue(result == {})
Esempio n. 17
0
 def POST(self, consumer_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.consumer_group_manager()
     tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id),
             action_tag('consumer_group_unassociate')]
     call_request = CallRequest(manager.unassociate,
                                [consumer_group_id, criteria],
                                tags=tags)
     call_request.updates_resource(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id)
     execution.execute(call_request)
     query_manager = managers_factory.consumer_group_query_manager()
     group = query_manager.get_group(consumer_group_id)
     return self.ok(group['consumer_ids'])
Esempio n. 18
0
 def POST(self, repo_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.repo_group_manager()
     tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
             action_tag('repo_group_unassociate')]
     call_request = CallRequest(manager.unassociate,
                                [repo_group_id, criteria],
                                tags=tags)
     call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
     execution.execute(call_request)
     collection = RepoGroup.get_collection()
     group = collection.find_one({'id': repo_group_id})
     return self.ok(group['repo_ids'])
Esempio n. 19
0
 def POST(self, consumer_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.consumer_group_manager()
     tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id),
             action_tag('consumer_group_associate')]
     call_request = CallRequest(manager.associate,
                                [consumer_group_id, criteria],
                                tags=tags)
     call_request.updates_resource(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id)
     execution.execute(call_request)
     collection = ConsumerGroup.get_collection()
     group = collection.find_one({'id': consumer_group_id})
     return self.ok(group['consumer_ids'])
Esempio n. 20
0
 def GET(self):
     valid_filters = ['tag']
     filters = self.filters(valid_filters)
     criteria_filters = {}
     tags = filters.get('tag', [])
     if tags:
         criteria_filters['tags'] = {'$all':  filters.get('tag', [])}
     criteria = Criteria.from_client_input({'filters': criteria_filters})
     serialized_task_statuses = []
     for task in TaskStatusManager.find_by_criteria(criteria):
         task.update(serialization.dispatch.spawned_tasks(task))
         task.update(serialization.dispatch.task_result_href(task))
         serialized_task_statuses.append(task)
     return self.ok(serialized_task_statuses)
Esempio n. 21
0
    def POST(self):
        """
        Determine content applicability.
        body {
        consumer_criteria:<dict> or None, 
        repo_criteria:<dict> or None, 
        units: {<type_id1> : [{<unit1>}, {<unit2}, ..]
                <type_id2> : [{<unit1>}, {<unit2}, ..]} or None
        }

        :return: A dict of applicability reports keyed by consumer ID.
            Each consumer report is:
                { <unit_type_id1> : [<ApplicabilityReport>],
                  <unit_type_id1> : [<ApplicabilityReport>]},
                }
                
        :rtype: dict
        """
        body = self.params()

        consumer_criteria = body.get('consumer_criteria', None)
        repo_criteria = body.get('repo_criteria', None)
        units = body.get('units', None)

        if consumer_criteria:
            consumer_criteria = Criteria.from_client_input(consumer_criteria)

        if repo_criteria:
            repo_criteria = Criteria.from_client_input(repo_criteria)

        manager = managers.consumer_applicability_manager()
        report = manager.units_applicable(consumer_criteria, repo_criteria, units)

        for consumer_report in report.values():
            for unit_type_id, report_list in consumer_report.items():
                consumer_report[unit_type_id] = [serialization.consumer.applicability_report(r) for r in report_list]
        return self.ok(report)
Esempio n. 22
0
 def test_profiler_no_exception(self):
     # Setup
     self.populate()
     profiler, cfg = plugins.get_profiler_by_type('rpm')
     profiler.find_applicable_units = Mock(side_effect=KeyError)
     # Test
     user_specified_unit_criteria = {'rpm': {"filters": {"name": {"$in":['zsh','ksh']}}},
                                     'mock-type': {"filters": {"name": {"$in":['abc','def']}}}
                                     }
     unit_criteria = {}
     for type_id, criteria in user_specified_unit_criteria.items():
         unit_criteria[type_id] = Criteria.from_client_input(criteria)
     manager = factory.consumer_applicability_manager()
     result = manager.find_applicable_units(self.CONSUMER_CRITERIA, self.REPO_CRITERIA, unit_criteria)
     self.assertTrue(result == {})
Esempio n. 23
0
    def _get_consumer_criteria(self):
        """
        Process the POST data, finding the criteria given by the user, and resolve it to Criteria
        object.

        :return: A Criteria object
        :rtype:  pulp.server.db.model.criteria.Criteria
        """
        body = self.params()

        try:
            consumer_criteria = body.get('criteria')
        except AttributeError:
            raise InvalidValue('The input to this method must be a JSON object with a '
                               "'criteria' key.")
        consumer_criteria = Criteria.from_client_input(consumer_criteria)
        return consumer_criteria
Esempio n. 24
0
    def _get_query_results_from_post(self):
        """
        Looks for a Criteria passed as a POST parameter on ket 'criteria', and
        returns the results of a search based on that Criteria.

        @return:    list of documents from the DB that match the given criteria
                    for the collection associated with this controller
        @rtype:     list
        """
        try:
            criteria_param = self.params()['criteria']
        except KeyError:
            raise exceptions.MissingValue(['criteria'])
        criteria = Criteria.from_client_input(criteria_param)
        if criteria.fields and 'id' not in criteria.fields and u'id' not in criteria.fields:
            criteria.fields.append('id')
        return list(self.query_method(criteria))
Esempio n. 25
0
    def post(self, request, consumer_group_id):
        """
        Associate a consumer to the group.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_group_id: id for the requested group
        :type consumer_group_id: str
        :return: Response containing consumers bound to the group
        :rtype: django.http.HttpResponse
        """
        params = request.body_as_json
        criteria = Criteria.from_client_input(params.get('criteria', {}))
        manager = factory.consumer_group_manager()
        manager.associate(consumer_group_id, criteria)
        query_manager = factory.consumer_group_query_manager()
        group = query_manager.get_group(consumer_group_id)
        return generate_json_response_with_pulp_encoder(group['consumer_ids'])
Esempio n. 26
0
    def post(self, request, consumer_group_id):
        """
        Unassociate a consumer from the group.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_group_id: id for the requested group
        :type consumer_group_id: str
        :return: Response containing consumers bound to the group
        :rtype: django.http.HttpResponse
        """
        params = request.body_as_json
        criteria = Criteria.from_client_input(params.get('criteria', {}))
        manager = factory.consumer_group_manager()
        manager.unassociate(consumer_group_id, criteria)
        query_manager = factory.consumer_group_query_manager()
        group = query_manager.get_group(consumer_group_id)
        return generate_json_response_with_pulp_encoder(group['consumer_ids'])
Esempio n. 27
0
    def post(self, request, repo_group_id):
        """
        Unassociate repos that match criteria specified in the body to the specified repo group.
        Call is idempotent.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_group_id: matching repos are unassociated with this repo group
        :type  repo_group_id: str

        :return: Response containing a serialized list of unassociated repository names
        :rtype: django.http.HttpResponse
        """
        criteria = Criteria.from_client_input(request.body_as_json.get('criteria', {}))
        manager = managers_factory.repo_group_manager()
        manager.unassociate(repo_group_id, criteria)
        collection = RepoGroupModel.get_collection()
        group = collection.find_one({'id': repo_group_id})
        return generate_json_response(group['repo_ids'])
Esempio n. 28
0
    def _get_query_results_from_post(self, is_user_search=False):
        """
        Looks for a Criteria passed as a POST parameter on ket 'criteria', and
        returns the results of a search based on that Criteria.

        @return:    list of documents from the DB that match the given criteria
                    for the collection associated with this controller
        @rtype:     list
        """
        try:
            criteria_param = self.params()['criteria']
        except KeyError:
            raise exceptions.MissingValue(['criteria'])
        criteria = Criteria.from_client_input(criteria_param)
        if criteria.fields:
            if not is_user_search and 'id' not in criteria.fields and u'id' not in criteria.fields:
                criteria.fields.append('id')
            if is_user_search and 'login' not in criteria.fields and u'login' not in criteria.fields:
                criteria.fields.append('login')
        return list(self.query_method(criteria))
Esempio n. 29
0
    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)
Esempio n. 30
0
    def post(self, request, repo_group_id):
        """
        Unassociate repos that match criteria specified in the body to the specified repo group.
        Call is idempotent.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_group_id: matching repos are unassociated with this repo group
        :type  repo_group_id: str

        :return: Response containing a serialized list of unassociated repository names
        :rtype: django.http.HttpResponse
        """
        criteria = Criteria.from_client_input(
            request.body_as_json.get('criteria', {}))
        manager = managers_factory.repo_group_manager()
        manager.unassociate(repo_group_id, criteria)
        collection = RepoGroupModel.get_collection()
        group = collection.find_one({'id': repo_group_id})
        return generate_json_response(group['repo_ids'])
Esempio n. 31
0
    def POST(self):
        """
        Creates an async task to regenerate content applicability data for given updated
        repositories.

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

        regeneration_tag = tags.action_tag('content_applicability_regeneration')
        async_result = regenerate_applicability_for_repos.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_PROFILE_APPLICABILITY_TYPE, tags.RESOURCE_ANY_ID,
            (repo_criteria.as_dict(),), tags=[regeneration_tag])
        raise exceptions.OperationPostponed(async_result)
Esempio n. 32
0
    def _get_consumer_criteria(self, request):
        """
        Process the POST data, finding the criteria given by the user, and resolve it to Criteria
        object.

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

        :raises InvalidValue: if some parameters were invalid

        :return: A Criteria object
        :rtype:  pulp.server.db.model.criteria.Criteria
        """

        body = request.body_as_json

        consumer_criteria = body.get('criteria')
        if consumer_criteria is None:
            raise InvalidValue("The input to this method must be a JSON object with a "
                               "'criteria' key.")
        consumer_criteria = Criteria.from_client_input(consumer_criteria)
        return consumer_criteria
Esempio n. 33
0
    def _get_query_results_from_get(self,
                                    ignore_fields=None,
                                    is_user_search=False):
        """
        Looks for query parameters that define a Criteria, and returns the
        results of a search based on that Criteria.

        @param ignore_fields:   Field names to ignore. All other fields will be
                                used in an attempt to generate a Criteria
                                instance, which will fail if unexpected field
                                names are present.
        @type  ignore_fields:   list

        @type is_user_search:   True if executing a user search. This is basically to add
                                login by default to the fields instead of id

        @type is_user_search

        @return:    list of documents from the DB that match the given criteria
                    for the collection associated with this controller
        @rtype:     list
        """
        input = self._ensure_input_encoding(web.input(field=[]))
        if ignore_fields:
            for field in ignore_fields:
                input.pop(field, None)

        # rename this to 'fields' within the dict, and omit it if empty so we
        # default to getting all fields
        fields = input.pop('field')
        if fields:
            if not is_user_search and 'id' not in fields and u'id' not in fields:
                fields.append('id')
            if is_user_search and 'login' not in fields and u'login' not in fields:
                fields.append('login')
            input['fields'] = fields

        criteria = Criteria.from_client_input(input)
        return list(self.query_method(criteria))
Esempio n. 34
0
    def _get_consumer_criteria(self, request):
        """
        Process the POST data, finding the criteria given by the user, and resolve it to Criteria
        object.

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

        :raises InvalidValue: if some parameters were invalid

        :return: A Criteria object
        :rtype:  pulp.server.db.model.criteria.Criteria
        """

        body = request.body_as_json

        consumer_criteria = body.get('criteria')
        if consumer_criteria is None:
            raise InvalidValue("The input to this method must be a JSON object with a "
                               "'criteria' key.")
        consumer_criteria = Criteria.from_client_input(consumer_criteria)
        return consumer_criteria
Esempio n. 35
0
    def POST(self):
        """
        Creates an async task to regenerate content applicability data for given updated
        repositories.

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

        regeneration_tag = tags.action_tag(
            'content_applicability_regeneration')
        async_result = regenerate_applicability_for_repos.apply_async_with_reservation(
            tags.RESOURCE_REPOSITORY_PROFILE_APPLICABILITY_TYPE,
            tags.RESOURCE_ANY_ID, (repo_criteria.as_dict(), ),
            tags=[regeneration_tag])
        raise exceptions.OperationPostponed(async_result)
Esempio n. 36
0
    def POST(self):
        """
        Determine content applicability.
        body {
        consumer_criteria:<dict> or None, 
        repo_criteria:<dict> or None, 
        unit_criteria: <dict of type_id : unit_criteria> or None,
        override_config: <dict> or None
        }

        :return: 

        When report_style is 'by_consumer' -
        A dict of applicability reports keyed by consumer ID.
            Each consumer report is:
                { <unit_type_id1> : [<ApplicabilityReport>],
                  <unit_type_id1> : [<ApplicabilityReport>]},
                }

        When report_style is 'by_units' -
        A dict of <unit_type_id1>: [<ApplicabilityReport>]
        where applicability_report.summary contains a list of applicable consumer ids.

        :rtype: dict
        """
        body = self.params()

        consumer_criteria = body.get('consumer_criteria', None)
        repo_criteria = body.get('repo_criteria', None)
        units = body.get('unit_criteria', None)
        override_config = body.get('override_config', None)

        if consumer_criteria:
            consumer_criteria = Criteria.from_client_input(consumer_criteria)

        if repo_criteria:
            repo_criteria = Criteria.from_client_input(repo_criteria)

        # If unit_criteria is not specified, consider all units of all types
        if not units:
            units = {}
            all_unit_type_ids = content_types_db.all_type_ids()
            for unit_type_id in all_unit_type_ids:
                units[unit_type_id] = {}
        # Validate user defined criteria and convert them to Criteria objects
        unit_criteria = {}
        for type_id, criteria in units.items():
            if criteria is None:
                criteria = {}
            unit_criteria[type_id] = Criteria.from_client_input(criteria)

        manager = managers.consumer_applicability_manager()
        report = manager.find_applicable_units(consumer_criteria,
                                               repo_criteria, unit_criteria,
                                               override_config)

        for unit_type_id, applicability_reports in report.items():
            if isinstance(applicability_reports, list):
                report[unit_type_id] = [
                    serialization.consumer.applicability_report(r)
                    for r in applicability_reports
                ]
            else:
                for consumer_id, report_list in applicability_reports.items():
                    report[unit_type_id][consumer_id] = [
                        serialization.consumer.applicability_report(r)
                        for r in report_list
                    ]

        return self.ok(report)
Esempio n. 37
0
    def POST(self):
        """
        Determine content applicability.
        body {
        consumer_criteria:<dict> or None, 
        repo_criteria:<dict> or None, 
        unit_criteria: <dict of type_id : unit_criteria> or None,
        override_config: <dict> or None
        }

        :return: 

        When report_style is 'by_consumer' -
        A dict of applicability reports keyed by consumer ID.
            Each consumer report is:
                { <unit_type_id1> : [<ApplicabilityReport>],
                  <unit_type_id1> : [<ApplicabilityReport>]},
                }

        When report_style is 'by_units' -
        A dict of <unit_type_id1>: [<ApplicabilityReport>]
        where applicability_report.summary contains a list of applicable consumer ids.

        :rtype: dict
        """
        body = self.params()

        consumer_criteria = body.get('consumer_criteria', None)
        repo_criteria = body.get('repo_criteria', None)
        units = body.get('unit_criteria', None)
        override_config = body.get('override_config', None)

        if consumer_criteria:
            consumer_criteria = Criteria.from_client_input(consumer_criteria)

        if repo_criteria:
            repo_criteria = Criteria.from_client_input(repo_criteria)

        # If unit_criteria is not specified, consider all units of all types
        if not units:
            units = {}
            all_unit_type_ids = content_types_db.all_type_ids()
            for unit_type_id in all_unit_type_ids:
                units[unit_type_id] = {}
        # Validate user defined criteria and convert them to Criteria objects
        unit_criteria = {}
        for type_id, criteria in units.items():
            if criteria is None:
                criteria = {}
            unit_criteria[type_id] = Criteria.from_client_input(criteria)

        manager = managers.consumer_applicability_manager()
        report = manager.find_applicable_units(consumer_criteria, repo_criteria, unit_criteria, override_config)

        for unit_type_id, applicability_reports in report.items():
            if isinstance(applicability_reports, list):
                report[unit_type_id] = [serialization.consumer.applicability_report(r) for r in applicability_reports]
            else:
                for consumer_id, report_list in applicability_reports.items():
                    report[unit_type_id][consumer_id] = [serialization.consumer.applicability_report(r) for r in report_list]

        return self.ok(report)