本文整理汇总了Python中pulp.server.db.model.criteria.Criteria类的典型用法代码示例。如果您正苦于以下问题:Python Criteria类的具体用法?Python Criteria怎么用?Python Criteria使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Criteria类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:alanoe,项目名称:pulp,代码行数:25,代码来源:consumers.py
示例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)
开发者ID:kbotc,项目名称:pulp,代码行数:58,代码来源:consumers.py
示例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)
开发者ID:beav,项目名称:pulp,代码行数:35,代码来源:applicability.py
示例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
)
开发者ID:preethit,项目名称:pulp-1,代码行数:28,代码来源:applicability.py
示例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'])
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:7,代码来源:consumer_groups.py
示例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
开发者ID:grizax,项目名称:pulp,代码行数:31,代码来源:repositories.py
示例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'])
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:7,代码来源:repo_groups.py
示例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))
开发者ID:stpierre,项目名称:pulp,代码行数:30,代码来源:search.py
示例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)
开发者ID:hennessy80,项目名称:pulp,代码行数:25,代码来源:repositories.py
示例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)
开发者ID:grizax,项目名称:pulp,代码行数:30,代码来源:__init__.py
示例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)
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:19,代码来源:consumers.py
示例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)
开发者ID:jessegonzalez,项目名称:pulp,代码行数:11,代码来源:consumer_groups.py
示例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'])
开发者ID:stpierre,项目名称:pulp,代码行数:13,代码来源:repo_groups.py
示例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'])
开发者ID:ehelms,项目名称:pulp,代码行数:13,代码来源:consumer_groups.py
示例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)
开发者ID:preethit,项目名称:pulp-1,代码行数:13,代码来源:dispatch.py
示例16: test_no_exception_for_profiler_notfound
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 == {})
开发者ID:bartwo,项目名称:pulp,代码行数:13,代码来源:test_applicability_manager.py
示例17: POST
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)
开发者ID:graco,项目名称:pulp,代码行数:37,代码来源:consumers.py
示例18: test_profiler_no_exception
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 == {})
开发者ID:bartwo,项目名称:pulp,代码行数:15,代码来源:test_applicability_manager.py
示例19: _get_consumer_criteria
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
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:17,代码来源:consumers.py
示例20: _get_query_results_from_post
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))
开发者ID:stpierre,项目名称:pulp,代码行数:17,代码来源:search.py
注:本文中的pulp.server.db.model.criteria.Criteria类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论