本文整理汇总了Python中pulp.server.db.model.consumer.ConsumerGroup类的典型用法代码示例。如果您正苦于以下问题:Python ConsumerGroup类的具体用法?Python ConsumerGroup怎么用?Python ConsumerGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConsumerGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tearDown
def tearDown(self):
super(self.__class__, self).tearDown()
Consumer.get_collection().remove()
ConsumerGroup.get_collection().remove()
Repo.get_collection().remove()
RepoDistributor.get_collection().remove()
Bind.get_collection().remove()
mock_plugins.reset()
示例2: setUp
def setUp(self):
super(self.__class__, self).setUp()
Consumer.get_collection().remove()
ConsumerGroup.get_collection().remove()
Repo.get_collection().remove()
RepoDistributor.get_collection().remove()
Bind.get_collection().remove()
plugin_api._create_manager()
mock_plugins.install()
示例3: create_consumer_group
def create_consumer_group(self, group_id, display_name=None, description=None, consumer_ids=None, notes=None):
"""
Create a new consumer group.
@param group_id: unique id of the consumer group
@param display_name: display name of the consumer group
@type display_name: str or None
@param description: description of the consumer group
@type description: str or None
@param consumer_ids: list of ids for consumers initially belonging to the consumer group
@type consumer_ids: list or None
@param notes: notes for the consumer group
@type notes: dict or None
@return: SON representation of the consumer group
@rtype: L{bson.SON}
"""
if group_id is None or _CONSUMER_GROUP_ID_REGEX.match(group_id) is None:
raise InvalidValue(['group_id'])
collection = ConsumerGroup.get_collection()
consumer_group = ConsumerGroup(group_id, display_name, description, consumer_ids, notes)
try:
collection.insert(consumer_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
示例4: GET
def GET(self, consumer_group_id):
collection = ConsumerGroup.get_collection()
group = collection.find_one({'id': consumer_group_id})
if group is None:
raise pulp_exceptions.MissingResource(consumer_group=consumer_group_id)
group.update(serialization.link.current_link_obj())
return self.ok(group)
示例5: find_all
def find_all(self):
"""
Returns all consumersitory groups in the database or an empty list if
none exist.
@return: list of database representations of all consumersitory groups
@rtype: list
"""
groups = list(ConsumerGroup.get_collection().find())
return groups
示例6: find_by_criteria
def find_by_criteria(criteria):
"""
Return a list of consumersitory 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 consumer group instances
@rtype: list
"""
return ConsumerGroup.get_collection().query(criteria)
示例7: create_consumer_group
def create_consumer_group(group_id, display_name=None, description=None, consumer_ids=None,
notes=None):
"""
Create a new consumer group.
:param group_id: unique id of the consumer group
:type group_id: str
:param display_name: display name of the consumer group
:type display_name: str or None
:param description: description of the consumer group
:type description: str or None
:param consumer_ids: list of ids for consumers initially belonging to the consumer group
:type consumer_ids: list or None
:param notes: notes for the consumer group
:type notes: dict or None
:return: SON representation of the consumer group
:rtype: bson.SON
"""
validation_errors = []
if group_id is None:
validation_errors.append(PulpCodedException(error_codes.PLP1002, field='group_id'))
elif _CONSUMER_GROUP_ID_REGEX.match(group_id) is None:
validation_errors.append(PulpCodedException(error_codes.PLP1003, field='group_id'))
if consumer_ids:
# Validate that all the consumer_ids exist and raise an exception if they don't
consumer_collection = Consumer.get_collection()
matched_consumers = consumer_collection.find({'id': {'$in': consumer_ids}})
if matched_consumers.count() is not len(consumer_ids):
# Create a set of all the matched consumer_ids
matched_consumers_set = set()
for consumer in matched_consumers:
matched_consumers_set.add(consumer.get('id'))
# find the missing items
for consumer_id in (set(consumer_ids)).difference(matched_consumers_set):
validation_errors.append(PulpCodedException(error_codes.PLP1001,
consumer_id=consumer_id))
if validation_errors:
raise pulp_exceptions.PulpCodedValidationException(validation_errors)
collection = ConsumerGroup.get_collection()
consumer_group = ConsumerGroup(group_id, display_name, description, consumer_ids, notes)
try:
collection.insert(consumer_group, safe=True)
except DuplicateKeyError:
raise pulp_exceptions.PulpCodedValidationException(
[PulpCodedException(error_codes.PLP1004, type=ConsumerGroup.collection_name,
object_id=group_id)])
group = collection.find_one({'id': group_id})
return group
示例8: get
def get(self, request):
"""
List the available consumer groups.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:return: Response containing a list of consumer groups
:rtype: django.http.HttpResponse
"""
collection = ConsumerGroup.get_collection()
cursor = collection.find({})
groups = [serialize(group) for group in cursor]
return generate_json_response_with_pulp_encoder(groups)
示例9: 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)
execution.execute(call_request)
collection = ConsumerGroup.get_collection()
group = collection.find_one({'id': consumer_group_id})
return self.ok(group['consumer_ids'])
示例10: get_group
def get_group(self, consumer_group_id):
"""
Returns the consumersitory group with the given ID, raising an exception
if one does not exist.
@param consumer_group_id: identifies the group
@type consumer_group_id: str
@return: database representation of the consumer group
@raise MissingResource: if there is no group with the given ID
"""
group = ConsumerGroup.get_collection().find_one({"id": consumer_group_id})
if group is None:
raise MissingResource(consumer_group=consumer_group_id)
return group
示例11: validate_existing_consumer_group
def validate_existing_consumer_group(group_id):
"""
Validate the existence of a consumer group, given its id.
Returns the consumer group db collection upon successful validation,
raises an exception upon failure
@param group_id: unique id of the consumer group to validate
@type group_id: str
@return: consumer group db collection
@rtype: L{pulp.server.db.connection.PulpCollection}
@raise: L{pulp.server.exceptions.MissingResource}
"""
collection = ConsumerGroup.get_collection()
consumer_group = collection.find_one({'id': group_id})
if consumer_group is not None:
return collection
raise pulp_exceptions.MissingResource(consumer_group=group_id)
示例12: remove_consumer_from_groups
def remove_consumer_from_groups(self, consumer_id, group_ids=None):
"""
Remove a consumer from the list of consumer groups provided.
If no consumer groups are specified, remove the consumer from all consumer groups
its currently in.
(idempotent: useful when deleting consumersitories)
@param consumer_id: unique id of the consumer to remove from consumer groups
@type consumer_id: str
@param group_ids: list of consumer group ids to remove the consumer from
@type group_ids: list of None
"""
spec = {}
if group_ids is not None:
spec = {'id': {'$in': group_ids}}
collection = ConsumerGroup.get_collection()
collection.update(spec, {'$pull': {'consumer_ids': consumer_id}}, multi=True, safe=True)
示例13: tearDown
def tearDown(self):
PulpItineraryTests.tearDown(self)
Consumer.get_collection().remove()
ConsumerGroup.get_collection().remove()
mock_plugins.reset()
示例14: setUp
def setUp(self):
PulpItineraryTests.setUp(self)
Consumer.get_collection().remove()
ConsumerGroup.get_collection().remove()
mock_plugins.install()
mock_agent.install()
示例15: clean
def clean(self):
super(ConsumerGroupAssociationTests, self).clean()
ConsumerGroup.get_collection().remove()