本文整理汇总了Python中pulp.server.db.model.criteria.Criteria类的典型用法代码示例。如果您正苦于以下问题:Python Criteria类的具体用法?Python Criteria怎么用?Python Criteria使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Criteria类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self, request, consumer_id):
"""
Creates an async task to regenerate content applicability data for given consumer.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param consumer_id: The consumer ID.
:type consumer_id: str
:raises MissingResource: if some parameters are missing
:raises OperationPostponed: when an async operation is performed.
"""
consumer_query_manager = factory.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)
示例2: POST
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)
示例3: regenerate_applicability_for_repos
def regenerate_applicability_for_repos(repo_criteria):
"""
Regenerate and save applicability data affected by given updated repositories.
:param repo_criteria: The repo selection criteria
:type repo_criteria: dict
"""
repo_criteria = Criteria.from_dict(repo_criteria)
repo_query_manager = managers.repo_query_manager()
# Process repo criteria
repo_criteria.fields = ['id']
repo_ids = [r['id'] for r in repo_query_manager.find_by_criteria(repo_criteria)]
for repo_id in repo_ids:
# Find all existing applicabilities for given repo_id
existing_applicabilities = RepoProfileApplicability.get_collection().find(
{'repo_id': repo_id})
for existing_applicability in existing_applicabilities:
# Convert cursor to RepoProfileApplicability object
existing_applicability = RepoProfileApplicability(**dict(existing_applicability))
profile_hash = existing_applicability['profile_hash']
unit_profile = UnitProfile.get_collection().find_one({'profile_hash': profile_hash},
fields=['id', 'content_type'])
if unit_profile is None:
# Unit profiles change whenever packages are installed or removed on consumers,
# and it is possible that existing_applicability references a UnitProfile
# that no longer exists. This is harmless, as Pulp has a monthly cleanup task
# that will identify these dangling references and remove them.
continue
# Regenerate applicability data for given unit_profile and repo id
ApplicabilityRegenerationManager.regenerate_applicability(
profile_hash, unit_profile['content_type'], unit_profile['id'], repo_id,
existing_applicability)
示例4: regenerate_applicability_for_repos
def regenerate_applicability_for_repos(repo_criteria):
"""
Regenerate and save applicability data affected by given updated repositories.
:param repo_criteria: The repo selection criteria
:type repo_criteria: dict
"""
repo_criteria = Criteria.from_dict(repo_criteria)
repo_query_manager = managers.repo_query_manager()
# Process repo criteria
repo_criteria.fields = ["id"]
repo_ids = [r["id"] for r in repo_query_manager.find_by_criteria(repo_criteria)]
for repo_id in repo_ids:
# Find all existing applicabilities for given repo_id
existing_applicabilities = RepoProfileApplicability.get_collection().find({"repo_id": repo_id})
for existing_applicability in existing_applicabilities:
# Convert cursor to RepoProfileApplicability object
existing_applicability = RepoProfileApplicability(**dict(existing_applicability))
profile_hash = existing_applicability["profile_hash"]
unit_profile = UnitProfile.get_collection().find_one(
{"profile_hash": profile_hash}, fields=["id", "content_type"]
)
# Regenerate applicability data for given unit_profile and repo id
ApplicabilityRegenerationManager.regenerate_applicability(
profile_hash, unit_profile["content_type"], unit_profile["id"], repo_id, existing_applicability
)
示例5: POST
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'])
示例6: post
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
示例7: POST
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'])
示例8: _get_query_results_from_get
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))
示例9: POST
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)
示例10: translate_criteria
def translate_criteria(self, model, crit):
"""
To preserve backwards compatability of our search API, we must translate the fields from
the external representation to the internal representation. This is done most often with
'id' since this is not an allowable key in the database in Mongoengine.
This method relies on a map defined in the subclass's Meta: `remapped_fields` which should
be a dictionary containing the fields that have been renamed in the format:
{'internal repr': 'external repr'}
:param model: the class that defines this document's fields
:type model: sublcass of mongoengine.Document
:param crit: criteria object to be translated from external to internal representation
:type crit: pulp.server.db.model.criteria.Criteria
:return: translated Criteria object
:rtype: pulp.server.db.model.criteria.Criteria
"""
# Circular import avoidance, since criteria imports models which imports serializers
from pulp.server.db.model.criteria import Criteria
crit_dict = crit.as_dict()
if crit.filters:
crit_dict['filters'] = self._translate_filters(model, crit.filters)
if crit.sort:
sort = [(self._translate(model, field), direc) for field, direc in crit.sort]
crit_dict['sort'] = sort
if crit.fields:
crit_dict['fields'] = [self._translate(model, field) for field in crit.fields]
return Criteria.from_dict(crit_dict)
示例11: POST
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)
示例12: POST
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)
示例13: POST
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'])
示例14: POST
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'])
示例15: GET
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)