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
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()
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()
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) except DuplicateKeyError: raise pulp_exceptions.DuplicateResource(group_id), None, sys.exc_info()[2] group = collection.find_one({'id': group_id}) return group
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)
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
def GET(self): collection = ConsumerGroup.get_collection() cursor = collection.find({}) groups = [] for group in cursor: group.update(serialization.link.child_link_obj(group['id'])) groups.append(group) return self.ok(groups)
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
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)
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
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'])
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)
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)
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)
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
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)
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
def get(self, request, consumer_group_id): """ Return a serialized object representing the requested group. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param consumer_group_id: id for the requested group :type consumer_group_id: str :return: Response containing data for the requested group :rtype: django.http.HttpResponse :raises: MissingResource if group ID does not exist """ 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) return generate_json_response_with_pulp_encoder(serialize(group))
def POST(self, consumer_group_id): """ Create a bind association between the specified consumer by id included in the URL path and a repo-distributor specified in the POST body: {repo_id:<str>, distributor_id:<str>}. Designed to be itempotent so only MissingResource is expected to be raised by manager. @param consumer_group_id: The consumer to bind. @type consumer_group_id: str @return: The created bind model object: {consumer_group_id:<str>, repo_id:<str>, distributor_id:<str>} @rtype: dict """ body = self.params() repo_id = body.get('repo_id') distributor_id = body.get('distributor_id') collection = ConsumerGroup.get_collection() consumer_group = collection.find_one({'id': consumer_group_id}) resources = { dispatch_constants.RESOURCE_CONSUMER_TYPE: {consumer_group_id:dispatch_constants.RESOURCE_READ_OPERATION}, dispatch_constants.RESOURCE_REPOSITORY_TYPE: {repo_id:dispatch_constants.RESOURCE_READ_OPERATION}, dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE: {distributor_id:dispatch_constants.RESOURCE_READ_OPERATION}, } args = [ consumer_group_id, repo_id, distributor_id, ] manager = managers_factory.consumer_group_manager() call_request = CallRequest( manager.bind, args, resources=resources, weight=0) link = serialization.link.child_link_obj( consumer_group_id, repo_id, distributor_id) result = execution.execute_sync_created(self, call_request, link) return result
def POST(self, consumer_group_id): """ Create a bind association between the specified consumer by id included in the URL path and a repo-distributor specified in the POST body: {repo_id:<str>, distributor_id:<str>}. Designed to be itempotent so only MissingResource is expected to be raised by manager. @param consumer_group_id: The consumer to bind. @type consumer_group_id: str @return: The created bind model object: {consumer_group_id:<str>, repo_id:<str>, distributor_id:<str>} @rtype: dict """ body = self.params() repo_id = body.get('repo_id') distributor_id = body.get('distributor_id') collection = ConsumerGroup.get_collection() consumer_group = collection.find_one({'id': consumer_group_id}) resources = { dispatch_constants.RESOURCE_CONSUMER_TYPE: { consumer_group_id: dispatch_constants.RESOURCE_READ_OPERATION }, dispatch_constants.RESOURCE_REPOSITORY_TYPE: { repo_id: dispatch_constants.RESOURCE_READ_OPERATION }, dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE: { distributor_id: dispatch_constants.RESOURCE_READ_OPERATION }, } args = [ consumer_group_id, repo_id, distributor_id, ] manager = managers_factory.consumer_group_manager() call_request = CallRequest(manager.bind, args, resources=resources, weight=0) link = serialization.link.child_link_obj(consumer_group_id, repo_id, distributor_id) result = execution.execute_sync_created(self, call_request, link) return result
def get(self, request, consumer_group_id): """ Return a serialized object representing the requested group. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param consumer_group_id: id for the requested group :type consumer_group_id: str :return: Response containing data for the requested group :rtype: django.http.HttpResponse :raises: MissingResource if group ID does not exist """ 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) return generate_json_response_with_pulp_encoder(serialize(group))
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 = [] for group in cursor: link = {"_href": reverse('consumer_group_resource', kwargs={'consumer_group_id': group['id']})} group.update(link) groups.append(group) return generate_json_response_with_pulp_encoder(groups)
def clean(self): super(ConsumerGroupAssociationTests, self).clean() ConsumerGroup.get_collection().remove()
def setUp(self): PulpItineraryTests.setUp(self) Consumer.get_collection().remove() ConsumerGroup.get_collection().remove() mock_plugins.install() mock_agent.install()
def tearDown(self): PulpItineraryTests.tearDown(self) Consumer.get_collection().remove() ConsumerGroup.get_collection().remove() mock_plugins.reset()
def setUp(self): super(self.__class__, self).setUp() Consumer.get_collection().remove() ConsumerGroup.get_collection().remove()
def tearDown(self): super(self.__class__, self).tearDown() Consumer.get_collection().remove() ConsumerGroup.get_collection().remove()
def tearDown(self): super(ConsumerGroupTests, self).tearDown() self.manager = None Consumer.get_collection().remove(safe=True) ConsumerGroup.get_collection().remove(safe=True)
def setUp(self): super(ConsumerGroupTests, self).setUp() self.collection = ConsumerGroup.get_collection() self.manager = cud.ConsumerGroupManager()
def test_constructor(self): try: ConsumerGroup('contructor_group') except: self.fail(traceback.format_exc())