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) except DuplicateKeyError: raise pulp_exceptions.DuplicateResource(group_id), None, sys.exc_info()[2] group = collection.find_one({'id': group_id}) return 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 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
def create_repo(repo_id, display_name=None, description=None, notes=None, importer_type_id=None, importer_repo_plugin_config=None, distributor_list=[]): """ Create a repository and add importers and distributors if they are specified. If there are any issues adding any of the importers or distributors, the repo will be deleted and the exceptions will be reraised. Multiple distributors can be created in this call. Each distributor is specified as a dict with the following keys: distributor_type - ID of the type of distributor being added distributor_config - values sent to the distributor when used by this repository auto_publish - boolean indicating if the distributor should automatically publish with every sync; defaults to False distributor_id - used to refer to the distributor later; if omitted, one will be generated :param repo_id: unique identifier for the repo :type repo_id: str :param display_name: user-friendly name for the repo :type display_name: str :param description: user-friendly text describing the repo's contents :type description: str :param notes: key-value pairs to programmatically tag the repo :type notes: dict :param importer_type_id: if specified, an importer with this type ID will be added to the repo :type importer_type_id: str :param importer_repo_plugin_config: configuration values for the importer, may be None :type importer_repo_plugin_config: dict :param distributor_list: iterable of distributor dicts to add; more details above :type distributor_list: list or tuple :raises DuplicateResource: if there is already a repo with the requested ID :raises InvalidValue: if any of the fields are invalid :return: created repository object :rtype: pulp.server.db.model.Repository """ # Prevalidation. if not isinstance(distributor_list, (list, tuple)): raise pulp_exceptions.InvalidValue(['distributor_list']) # Note: the repo must be saved before the importer and distributor managers can be called # because the first thing that they do is validate that the repo exists. repo = model.Repository(repo_id=repo_id, display_name=display_name, description=description, notes=notes) try: repo.save() except NotUniqueError: raise pulp_exceptions.DuplicateResource(repo_id) except ValidationError, e: raise pulp_exceptions.InvalidValue(e.to_dict().keys())
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 create_repo_group(self, 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: L{bson.SON} """ 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
def create_user(login, password=None, name=None, roles=None): """ Creates a new Pulp user and adds it to specified to roles. :param login: login name / unique identifier for the user :type login: str :param password: password for login credentials :type password: str :param name: user's full name :type name: str :param roles: list of roles user will belong to :type roles: list :raise DuplicateResource: if there is already a user with the requested login :raise InvalidValue: if any of the fields are unacceptable """ user = model.User(login=login, name=name, roles=roles) user.set_password(password) try: user.save() except NotUniqueError: raise pulp_exceptions.DuplicateResource(login) except ValidationError, e: raise pulp_exceptions.InvalidValue(e.to_dict().keys())