本文整理汇总了Python中pulp.server.db.model.repo_group.RepoGroup.get_collection方法的典型用法代码示例。如果您正苦于以下问题:Python RepoGroup.get_collection方法的具体用法?Python RepoGroup.get_collection怎么用?Python RepoGroup.get_collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.server.db.model.repo_group.RepoGroup
的用法示例。
在下文中一共展示了RepoGroup.get_collection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GET
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def GET(self, repo_group_id):
collection = RepoGroup.get_collection()
group = collection.find_one({'id': repo_group_id})
if group is None:
raise pulp_exceptions.MissingResource(repo_group=repo_group_id)
group.update(serialization.link.current_link_obj())
return self.ok(group)
示例2: find_with_distributor_type
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def find_with_distributor_type(self, distributor_type_id):
"""
Returns a list of repository groups, including a list of distributor
instances, for all groups that have a configured distributor of the
given type. The distributor list will be stored in the group under
the key "distributors"
@return: list of group objects from the database with an extra key
added holding the distributor instances
"""
group_coll = RepoGroup.get_collection()
group_distributor_coll = RepoGroupDistributor.get_collection()
groups_by_id = {}
spec = {'distributor_type_id' : distributor_type_id}
group_distributors = list(group_distributor_coll.find(spec))
for gd in group_distributors:
group = groups_by_id.get(gd['repo_group_id'], None)
if group is None:
group = group_coll.find_one({'id' : gd['repo_group_id']})
groups_by_id[gd['repo_group_id']] = group
dists = group.setdefault('distributors', [])
dists.append(gd)
return groups_by_id.values()
示例3: POST
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
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'])
示例4: create_repo_group
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def create_repo_group(group_id, display_name=None, description=None, repo_ids=None, notes=None):
"""
Create a new repo group.
:param group_id: unique id of the repo group
:param display_name: display name of the repo group
:type display_name: str or None
:param description: description of the repo group
:type description: str or None
:param repo_ids: list of ids for repos initially belonging to the repo group
:type repo_ids: list or None
:param notes: notes for the repo group
:type notes: dict or None
:return: SON representation of the repo group
:rtype: bson.SON
"""
if repo_ids:
# Check if ids in repo_ids belong to existing repositories
repo_query_manager = manager_factory.repo_query_manager()
for repo_id in repo_ids:
repo_query_manager.get_repository(repo_id)
# Create repo group
collection = RepoGroup.get_collection()
repo_group = RepoGroup(group_id, display_name, description, repo_ids, notes)
try:
collection.insert(repo_group, safe=True)
except DuplicateKeyError:
raise pulp_exceptions.DuplicateResource(group_id), None, sys.exc_info()[2]
group = collection.find_one({'id': group_id})
return group
示例5: create_repo_group
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def create_repo_group(group_id, display_name=None, description=None, repo_ids=None, notes=None):
"""
Create a new repo group.
:param group_id: unique id of the repo group
:param display_name: display name of the repo group
:type display_name: str or None
:param description: description of the repo group
:type description: str or None
:param repo_ids: list of ids for repos initially belonging to the repo group
:type repo_ids: list or None
:param notes: notes for the repo group
:type notes: dict or None
:return: SON representation of the repo group
:rtype: bson.SON
"""
# Check if ids in repo_ids belong to existing repositories
existing_repos = model.Repository.objects(repo_id__in=repo_ids)
if repo_ids and existing_repos.count() != len(repo_ids):
existing_repo_ids = set([repo.repo_id for repo in existing_repos])
non_existing_repo_ids = list(set(repo_ids) - existing_repo_ids)
raise pulp_exceptions.MissingResource(repositories=non_existing_repo_ids)
# Create repo group
collection = RepoGroup.get_collection()
repo_group = RepoGroup(group_id, display_name, description, repo_ids, notes)
try:
collection.insert(repo_group, safe=True)
except DuplicateKeyError:
raise pulp_exceptions.DuplicateResource(group_id), None, sys.exc_info()[2]
group = collection.find_one({"id": group_id})
return group
示例6: find_all
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def find_all(self):
"""
Returns all repository groups in the database or an empty list if
none exist.
@return: list of database representations of all repository groups
@rtype: list
"""
groups = list(RepoGroup.get_collection().find())
return groups
示例7: find_by_criteria
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def find_by_criteria(criteria):
"""
Return a list of repository groups that match the provided criteria.
@param criteria: A Criteria object representing a search you want
to perform
@type criteria: pulp.server.db.model.criteria.Criteria
@return: list of repo group instances
@rtype: list
"""
return RepoGroup.get_collection().query(criteria)
示例8: POST
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
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'])
示例9: test_update
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def test_update(self):
# Setup
group_id = 'update-me'
self.manager.create_repo_group(group_id, display_name='Original')
# Test
changed = {'display_name' : 'Updated'}
status, body = self.put('/v2/repo_groups/%s/' % group_id, changed)
# Verify
self.assertEqual(200, status)
found = RepoGroup.get_collection().find_one({'id' : group_id})
self.assertEqual(changed['display_name'], found['display_name'])
示例10: test_post_with_repos
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def test_post_with_repos(self):
# Setup
manager_factory.repo_manager().create_repo("add-me")
data = {"id": "with-repos", "repo_ids": ["add-me"]}
# Test
status, body = self.post("/v2/repo_groups/", data)
# Verify
self.assertEqual(201, status)
found = RepoGroup.get_collection().find_one({"id": data["id"]})
self.assertEqual(found["repo_ids"], data["repo_ids"])
示例11: test_post
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def test_post(self):
# Setup
data = {"id": "post-group", "display_name": "Post Group", "description": "Post Description"}
# Test
status, body = self.post("/v2/repo_groups/", data)
# Verify
self.assertEqual(201, status)
found = RepoGroup.get_collection().find_one({"id": data["id"]})
self.assertTrue(found is not None)
for k, v in data.items():
self.assertEqual(found[k], v)
示例12: test_delete
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def test_delete(self):
# Setup
group_id = "doomed"
self.manager.create_repo_group(group_id)
# Test
status, body = self.delete("/v2/repo_groups/%s/" % group_id)
# Verify
self.assertEqual(200, status)
found = RepoGroup.get_collection().find_one({"id": group_id})
self.assertTrue(found is None)
self.assertEqual(body, None)
示例13: test_update
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def test_update(self):
# Setup
group_id = "update-me"
self.manager.create_repo_group(group_id, display_name="Original")
# Test
changed = {"display_name": "Updated"}
status, body = self.put("/v2/repo_groups/%s/" % group_id, changed)
# Verify
self.assertEqual(200, status)
found = RepoGroup.get_collection().find_one({"id": group_id})
self.assertEqual(changed["display_name"], found["display_name"])
示例14: test_update_notes
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def test_update_notes(self):
group_id = "update-me"
self.manager.create_repo_group(group_id, display_name="Original", notes={"a": "A", "b": "B"})
# Test
changed = {"notes": {"b": ""}}
status, body = self.put("/v2/repo_groups/%s/" % group_id, changed)
# Verify
self.assertEqual(200, status)
found = RepoGroup.get_collection().find_one({"id": group_id})
self.assertTrue("a" in found["notes"])
self.assertTrue("b" not in found["notes"])
示例15: test_update_notes
# 需要导入模块: from pulp.server.db.model.repo_group import RepoGroup [as 别名]
# 或者: from pulp.server.db.model.repo_group.RepoGroup import get_collection [as 别名]
def test_update_notes(self):
group_id = 'update-me'
self.manager.create_repo_group(group_id, display_name='Original',
notes={'a':'A', 'b':'B'})
# Test
changed = {'notes' : {'b':''}}
status, body = self.put('/v2/repo_groups/%s/' % group_id, changed)
# Verify
self.assertEqual(200, status)
found = RepoGroup.get_collection().find_one({'id' : group_id})
self.assertTrue('a' in found['notes'])
self.assertTrue('b' not in found['notes'])