本文整理汇总了Python中pulp.server.db.model.criteria.UnitAssociationCriteria.from_client_input方法的典型用法代码示例。如果您正苦于以下问题:Python UnitAssociationCriteria.from_client_input方法的具体用法?Python UnitAssociationCriteria.from_client_input怎么用?Python UnitAssociationCriteria.from_client_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.server.db.model.criteria.UnitAssociationCriteria
的用法示例。
在下文中一共展示了UnitAssociationCriteria.from_client_input方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: POST
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def POST(self, repo_id):
# Params
params = self.params()
query = params.get('criteria', None)
repo_query_manager = manager_factory.repo_query_manager()
repo = repo_query_manager.find_by_id(repo_id)
if repo is None:
raise exceptions.MissingResource(repo_id=repo_id)
if query is None:
raise exceptions.MissingValue(['criteria'])
try:
criteria = UnitAssociationCriteria.from_client_input(query)
except:
_LOG.exception('Error parsing association criteria [%s]' % query)
raise exceptions.PulpDataException(), None, sys.exc_info()[2]
# Data lookup
manager = manager_factory.repo_unit_association_query_manager()
if criteria.type_ids is not None and len(criteria.type_ids) == 1:
type_id = criteria.type_ids[0]
units = manager.get_units_by_type(repo_id, type_id, criteria=criteria)
else:
units = manager.get_units_across_types(repo_id, criteria=criteria)
return self.ok(units)
示例2: post
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
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
示例3: POST
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def POST(self, repo_id):
params = self.params()
criteria = params.get("criteria", None)
if criteria is not None:
try:
criteria = UnitAssociationCriteria.from_client_input(criteria)
except:
logger.error("Error parsing unassociation criteria [%s]" % criteria)
raise exceptions.PulpDataException(), None, sys.exc_info()[2]
tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), action_tag("unassociate")]
async_result = unassociate_by_criteria.apply_async_with_reservation(
dispatch_constants.RESOURCE_REPOSITORY_TYPE,
repo_id,
[
repo_id,
criteria,
RepoContentUnit.OWNER_TYPE_USER,
manager_factory.principal_manager().get_principal()["login"],
],
tags=tags,
)
raise exceptions.OperationPostponed(async_result)
示例4: _generate_response
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def _generate_response(cls, query, options, *args, **kwargs):
"""
Perform the database query using the given search data, and return the resuls as a JSON
serialized HttpReponse object.
This overrides the base class so we can validate repo existance and to choose the search
method depending on how many unit types we are dealing with.
:param query: The criteria that should be used to search for objects
:type query: dict
:param options: additional options for including extra data
:type options: dict
:return: The serialized search results in an HttpReponse
:rtype: django.http.HttpResponse
"""
repo_id = kwargs.get('repo_id')
model.Repository.objects.get_repo_or_missing_resource(repo_id)
criteria = UnitAssociationCriteria.from_client_input(query)
manager = manager_factory.repo_unit_association_query_manager()
if criteria.type_ids is not None and len(criteria.type_ids) == 1:
type_id = criteria.type_ids[0]
units = manager.get_units_by_type(repo_id, type_id, criteria=criteria)
else:
units = manager.get_units(repo_id, criteria=criteria)
for unit in units:
content.remap_fields_with_serializer(unit['metadata'])
return generate_json_response_with_pulp_encoder(units)
示例5: test_unassociate_via_criteria
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def test_unassociate_via_criteria(self):
self.manager.associate_unit_by_id(self.repo_id, self.unit_type_id, self.unit_id, OWNER_TYPE_USER, 'admin')
self.manager.associate_unit_by_id(self.repo_id, self.unit_type_id, self.unit_id_2, OWNER_TYPE_USER, 'admin')
criteria_doc = {'filters': {'association': {'unit_id': {'$in': [self.unit_id, 'unit-X']}}}}
criteria = UnitAssociationCriteria.from_client_input(criteria_doc)
self.manager.unassociate_by_criteria(self.repo_id, criteria, OWNER_TYPE_USER, 'admin')
self.assertFalse(self.manager.association_exists(self.repo_id, self.unit_id, self.unit_type_id))
self.assertTrue(self.manager.association_exists(self.repo_id, self.unit_id_2, self.unit_type_id))
示例6: test_unassociate_via_criteria_no_matches
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def test_unassociate_via_criteria_no_matches(self):
self.manager.associate_unit_by_id('repo-1', 'type-1', 'unit-1', OWNER_TYPE_USER, 'admin')
self.manager.associate_unit_by_id('repo-1', 'type-1', 'unit-2', OWNER_TYPE_USER, 'admin')
criteria_doc = {'type_ids': ['type-2']}
criteria = UnitAssociationCriteria.from_client_input(criteria_doc)
self.manager.unassociate_by_criteria('repo-1', criteria, OWNER_TYPE_USER, 'admin')
self.assertTrue(self.manager.association_exists('repo-1', 'unit-1', 'type-1'))
self.assertTrue(self.manager.association_exists('repo-1', 'unit-2', 'type-1'))
示例7: test_unassociate_via_criteria_no_matches
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def test_unassociate_via_criteria_no_matches(self):
self.manager.associate_unit_by_id(self.repo_id, "type-1", "unit-1", OWNER_TYPE_USER, "admin")
self.manager.associate_unit_by_id(self.repo_id, "type-1", "unit-2", OWNER_TYPE_USER, "admin")
criteria_doc = {"type_ids": ["type-2"]}
criteria = UnitAssociationCriteria.from_client_input(criteria_doc)
self.manager.unassociate_by_criteria(self.repo_id, criteria, OWNER_TYPE_USER, "admin")
self.assertTrue(self.manager.association_exists(self.repo_id, "unit-1", "type-1"))
self.assertTrue(self.manager.association_exists(self.repo_id, "unit-2", "type-1"))
示例8: test_unassociate_via_criteria_no_matches
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def test_unassociate_via_criteria_no_matches(self, mock_ctrl):
self.manager.associate_unit_by_id(self.repo_id, 'type-1', 'unit-1')
self.manager.associate_unit_by_id(self.repo_id, 'type-1', 'unit-2')
criteria_doc = {'type_ids': ['type-2']}
criteria = UnitAssociationCriteria.from_client_input(criteria_doc)
result = self.manager.unassociate_by_criteria(self.repo_id, criteria)
self.assertEquals(result, {})
self.assertTrue(self.manager.association_exists(self.repo_id, 'unit-1', 'type-1'))
self.assertTrue(self.manager.association_exists(self.repo_id, 'unit-2', 'type-1'))
示例9: test_unassociate_via_criteria
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def test_unassociate_via_criteria(self, mock_repo_qs, mock_ctrl):
self.manager.associate_unit_by_id(self.repo_id, self.unit_type_id, self.unit_id)
self.manager.associate_unit_by_id(self.repo_id, self.unit_type_id, self.unit_id_2)
criteria_doc = {'filters': {'association': {'unit_id': {'$in': [self.unit_id, 'unit-X']}}}}
criteria = UnitAssociationCriteria.from_client_input(criteria_doc)
self.manager.unassociate_by_criteria(self.repo_id, criteria)
self.assertFalse(self.manager.association_exists(self.repo_id, self.unit_id,
self.unit_type_id))
self.assertTrue(self.manager.association_exists(self.repo_id, self.unit_id_2,
self.unit_type_id))
mock_repo_qs.get_repo_or_missing_resource.assert_called_once_with(self.repo_id)
示例10: test_unassociate_via_criteria
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def test_unassociate_via_criteria(self):
self.manager.associate_unit_by_id('repo-1', 'type-1', 'unit-1', OWNER_TYPE_USER, 'admin')
self.manager.associate_unit_by_id('repo-1', 'type-1', 'unit-2', OWNER_TYPE_USER, 'admin')
self.manager.associate_unit_by_id('repo-1', 'type-1', 'unit-3', OWNER_TYPE_USER, 'admin')
self.manager.associate_unit_by_id('repo-1', 'type-2', 'unit-1', OWNER_TYPE_IMPORTER, 'yum')
self.manager.associate_unit_by_id('repo-1', 'type-2', 'unit-2', OWNER_TYPE_IMPORTER, 'yum')
criteria_doc = {'filters': {'association': {'unit_id': {'$in': ['unit-1', 'unit-3']}}}}
criteria = UnitAssociationCriteria.from_client_input(criteria_doc)
self.manager.unassociate_by_criteria('repo-1', criteria, OWNER_TYPE_USER, 'admin')
self.assertFalse(self.manager.association_exists('repo-1', 'unit-1', 'type-1'))
self.assertTrue(self.manager.association_exists('repo-1', 'unit-2', 'type-1'))
self.assertFalse(self.manager.association_exists('repo-1', 'unit-3', 'type-1'))
self.assertTrue(self.manager.association_exists('repo-1', 'unit-1', 'type-2'))
self.assertTrue(self.manager.association_exists('repo-1', 'unit-2', 'type-2'))
示例11: POST
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def POST(self, repo_id):
params = self.params()
criteria = params.get('criteria', None)
if criteria is not None:
try:
criteria = UnitAssociationCriteria.from_client_input(criteria)
except:
_logger.error('Error parsing unassociation criteria [%s]' % criteria)
raise exceptions.PulpDataException(), None, sys.exc_info()[2]
task_tags = [tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
tags.action_tag('unassociate')]
async_result = unassociate_by_criteria.apply_async_with_reservation(
tags.RESOURCE_REPOSITORY_TYPE, repo_id,
[repo_id, criteria, RepoContentUnit.OWNER_TYPE_USER,
manager_factory.principal_manager().get_principal()['login']], tags=task_tags)
raise exceptions.OperationPostponed(async_result)
示例12: test_parse_criteria
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def test_parse_criteria(self):
# Setup
query = {
'type_ids': ['rpm'],
'filters': {
'unit': {'$and': [
{'$regex': '^p.*'},
{'$not': 'ython$'},
]},
'association': {'created': {'$gt': 'now'}},
},
'limit': 100,
'skip': 200,
'fields': {
'unit': ['name', 'version'],
'association': ['created'],
},
'remove_duplicates': True,
}
# Test
criteria = UnitAssociationCriteria.from_client_input(query)
# Verify
self.assertEqual(criteria.type_ids, ['rpm'])
self.assertEqual(criteria.association_filters, {'created': {'$gt': 'now'}})
self.assertEqual(criteria.limit, 100)
self.assertEqual(criteria.skip, 200)
self.assertEqual(criteria.unit_fields, ['name', 'version'])
self.assertEqual(criteria.association_fields, ['created', 'unit_id', 'unit_type_id'])
self.assertEqual(criteria.remove_duplicates, True)
# Check the special $not handling in the unit filter
self.assertTrue('$and' in criteria.unit_filters)
and_list = criteria.unit_filters['$and']
self.assertTrue('$regex' in and_list[0])
self.assertEqual(and_list[0]['$regex'], '^p.*')
self.assertTrue('$not' in and_list[1])
self.assertEqual(and_list[1]['$not'], re.compile('ython$'))
示例13: POST
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
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:
_LOG.error('Error parsing association criteria [%s]' % criteria)
raise exceptions.PulpDataException(), None, sys.exc_info()[2]
association_manager = manager_factory.repo_unit_association_manager()
resources = {dispatch_constants.RESOURCE_REPOSITORY_TYPE: {source_repo_id: dispatch_constants.RESOURCE_READ_OPERATION,
dest_repo_id: dispatch_constants.RESOURCE_UPDATE_OPERATION}}
tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, dest_repo_id),
resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, source_repo_id),
action_tag('associate')]
call_request = CallRequest(association_manager.associate_from_repo,
[source_repo_id, dest_repo_id],
{'criteria': criteria, 'import_config_override': overrides},
resources=resources,
tags=tags,
archive=True)
return execution.execute_async(self, call_request)
示例14: POST
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def POST(self, repo_id):
# Params
params = self.params()
query = params.get('criteria', {})
options = params.get('options', {})
timeout = params.get('timeout', 60)
try:
criteria = UnitAssociationCriteria.from_client_input(query)
except:
logger.error('Error parsing association criteria [%s]' % query)
raise exceptions.PulpDataException(), None, sys.exc_info()[2]
try:
timeout = int(timeout)
except ValueError:
raise exceptions.InvalidValue(['timeout']), None, sys.exc_info()[2]
dependency_manager = manager_factory.dependency_manager()
result = dependency_manager.resolve_dependencies_by_criteria(repo_id, criteria, options)
return self.ok(result)
示例15: test_get_units_by_type_not_query
# 需要导入模块: from pulp.server.db.model.criteria import UnitAssociationCriteria [as 别名]
# 或者: from pulp.server.db.model.criteria.UnitAssociationCriteria import from_client_input [as 别名]
def test_get_units_by_type_not_query(self):
"""
Mongo really doesn't like $not queries when regular expressions are
involved. This test is to make sure that across mongo and pymongo
versions a not expression against a regular expression continues to
work.
There is an important step in the parsing of the criteria from the
REST call into the Criteria object. This call will use that method
to more closely test the end to end experience.
"""
# Setup
# I got bit by the fact that incoming REST requests are in unicode;
# the criteria parsing didn't account for this. This example specifically
# replicates that by having the not and its value in unicode.
query_string = {
'filters' : {
'unit' : {
'key_1' : {
u'$not' : u'.*aa.*'
}
}
}
}
#criteria = unit_association_criteria(query_string)
criteria = UnitAssociationCriteria.from_client_input(query_string)
# Test
units = self.manager.get_units_by_type('repo-1', 'alpha', criteria)
# Verify
self.assertEqual(len(self.units['alpha']) - 1, len(units))
for u in units:
self.assertTrue(u['metadata']['key_1'] != 'aardvark')