Esempio n. 1
0
File: cud.py Progetto: beav/pulp
    def delete_repo_group(group_id):
        """
        Delete a repo group.
        @param group_id: unique id of the repo group to delete
        @type group_id: str
        """
        collection = validate_existing_repo_group(group_id)

        # Delete all distributors on the group
        distributors = RepoGroupDistributorManager.find_distributors(group_id)
        for distributor in distributors:
            RepoGroupDistributorManager.remove_distributor(group_id, distributor['id'])

        # Delete the working directory for the group
        working_dir = common_utils.repo_group_working_dir(group_id)
        if os.path.exists(working_dir):
            try:
                shutil.rmtree(working_dir)
            except Exception:
                msg = _('Error while deleting working dir [%(d)s] for repo group [%(g)s]')
                msg = msg % {'d': working_dir, 'g': group_id}
                _logger.exception(msg)
                raise

        # Delete from the database
        collection.remove({'id': group_id}, safe=True)
Esempio n. 2
0
File: cud.py Progetto: nbetm/pulp
    def create_and_configure_repo_group(
        group_id, display_name=None, description=None, repo_ids=None, notes=None, distributor_list=None
    ):
        """
        Create a new repository group and add distributors in a single call. This is equivalent to
        calling RepoGroupManager.create_repo_group and then
        RepoGroupDistributorManager.add_distributor for each distributor in the distributor list.

        :param group_id: unique id of the repository group
        :type group_id: str
        :param display_name: user-friendly name of the repository id
        :type display_name: str or None
        :param description: description of the repository group
        :type description: str or None
        :param repo_ids: the list of repository ids in this repository group
        :type repo_ids: list of str or None
        :param notes: A collection of key=value pairs
        :type notes: dict or None
        :param distributor_list: A list of dictionaries used to add distributors. The following keys
                                 are expected: from pulp.common.constants: DISTRIBUTOR_TYPE_ID_KEY,
                                 DISTRIBUTOR_CONFIG_KEY, and DISTRIBUTOR_ID_KEY, which should hold
                                 values str, dict, and str or None
        :type distributor_list: list of dict
        :return: SON representation of the repo group
        :rtype: bson.SON
        """
        if distributor_list is None:
            distributor_list = ()

        # Validate the distributor list before creating a repo group
        if not isinstance(distributor_list, (list, tuple)) or not all(
            isinstance(dist, dict) for dist in distributor_list
        ):
            raise pulp_exceptions.InvalidValue(["distributor_list"])

        # Create the repo group using the vanilla group create method
        repo_group = RepoGroupManager.create_repo_group(group_id, display_name, description, repo_ids, notes)

        for distributor in distributor_list:
            try:
                # Attempt to add the distributor to the group.
                type_id = distributor.get(distributor_constants.DISTRIBUTOR_TYPE_ID_KEY)
                plugin_config = distributor.get(distributor_constants.DISTRIBUTOR_CONFIG_KEY)
                distributor_id = distributor.get(distributor_constants.DISTRIBUTOR_ID_KEY)
                RepoGroupDistributorManager.add_distributor(group_id, type_id, plugin_config, distributor_id)
            except Exception:
                # If an exception occurs, pass it on after cleaning up the repository group
                _logger.exception(
                    "Exception adding distributor to repo group [%s]; the group will" " be deleted" % group_id
                )
                RepoGroupManager.delete_repo_group(group_id)
                raise

        return repo_group
Esempio n. 3
0
    def create_and_configure_repo_group(group_id, display_name=None, description=None,
                                        repo_ids=None, notes=None, distributor_list=None):
        """
        Create a new repository group and add distributors in a single call. This is equivalent to
        calling RepoGroupManager.create_repo_group and then
        RepoGroupDistributorManager.add_distributor for each distributor in the distributor list.

        :param group_id: unique id of the repository group
        :type group_id: str
        :param display_name: user-friendly name of the repository id
        :type display_name: str or None
        :param description: description of the repository group
        :type description: str or None
        :param repo_ids: the list of repository ids in this repository group
        :type repo_ids: list of str or None
        :param notes: A collection of key=value pairs
        :type notes: dict or None
        :param distributor_list: A list of dictionaries used to add distributors. The following keys
                                 are expected: from pulp.common.constants: DISTRIBUTOR_TYPE_ID_KEY,
                                 DISTRIBUTOR_CONFIG_KEY, and DISTRIBUTOR_ID_KEY, which should hold
                                 values str, dict, and str or None
        :type distributor_list: list of dict
        :return: SON representation of the repo group
        :rtype: bson.SON
        """
        if distributor_list is None:
            distributor_list = ()

        # Validate the distributor list before creating a repo group
        if not isinstance(distributor_list, (list, tuple)) or not \
                all(isinstance(dist, dict) for dist in distributor_list):
            raise pulp_exceptions.InvalidValue(['distributor_list'])

        # Create the repo group using the vanilla group create method
        repo_group = RepoGroupManager.create_repo_group(group_id, display_name, description,
                                                        repo_ids, notes)

        for distributor in distributor_list:
            try:
                # Attempt to add the distributor to the group.
                type_id = distributor.get(distributor_constants.DISTRIBUTOR_TYPE_ID_KEY)
                plugin_config = distributor.get(distributor_constants.DISTRIBUTOR_CONFIG_KEY)
                distributor_id = distributor.get(distributor_constants.DISTRIBUTOR_ID_KEY)
                RepoGroupDistributorManager.add_distributor(group_id, type_id, plugin_config,
                                                            distributor_id)
            except Exception:
                # If an exception occurs, pass it on after cleaning up the repository group
                _logger.exception('Exception adding distributor to repo group [%s]; the group will'
                                  ' be deleted' % group_id)
                RepoGroupManager.delete_repo_group(group_id)
                raise

        return repo_group
Esempio n. 4
0
File: cud.py Progetto: nbetm/pulp
    def delete_repo_group(group_id):
        """
        Delete a repo group.
        @param group_id: unique id of the repo group to delete
        @type group_id: str
        """
        collection = validate_existing_repo_group(group_id)

        # Delete all distributors on the group
        distributors = RepoGroupDistributorManager.find_distributors(group_id)
        for distributor in distributors:
            RepoGroupDistributorManager.remove_distributor(group_id, distributor["id"])

        # Delete from the database
        collection.remove({"id": group_id}, safe=True)
Esempio n. 5
0
    def delete_repo_group(group_id):
        """
        Delete a repo group.
        @param group_id: unique id of the repo group to delete
        @type group_id: str
        """
        collection = validate_existing_repo_group(group_id)

        # Delete all distributors on the group
        distributors = RepoGroupDistributorManager.find_distributors(group_id)
        for distributor in distributors:
            RepoGroupDistributorManager.remove_distributor(group_id, distributor['id'])

        # Delete from the database
        collection.remove({'id': group_id})
Esempio n. 6
0
    def delete_repo_group(group_id):
        """
        Delete a repo group.
        @param group_id: unique id of the repo group to delete
        @type group_id: str
        """
        collection = validate_existing_repo_group(group_id)

        # Delete all distributors on the group
        distributors = RepoGroupDistributorManager.find_distributors(group_id)
        for distributor in distributors:
            RepoGroupDistributorManager.remove_distributor(group_id, distributor['id'])

        # Delete the working directory for the group
        working_dir = common_utils.repo_group_working_dir(group_id)
        if os.path.exists(working_dir):
            try:
                shutil.rmtree(working_dir)
            except Exception:
                logger.exception('Error while deleting working dir [%s] for repo group [%s]' % (working_dir, group_id))
                raise

        # Delete from the database
        collection.remove({'id': group_id}, safe=True)