Esempio n. 1
0
            except PulpException, e:
                # Log a message so that we can debug but don't throw
                logger.debug(e.message)
                bind_errors.append(e)
            except Exception, e:
                logger.exception(e.message)
                # Don't do anything else since we still want to process all the other consumers
                bind_errors.append(e)

        bind_error = None
        if len(bind_errors) > 0:
            bind_error = PulpCodedException(error_codes.PLP0004,
                                            repo_id=repo_id,
                                            distributor_id=distributor_id,
                                            group_id=group_id)
            bind_error.child_exceptions = bind_errors

        return TaskResult(error=bind_error, spawned_tasks=additional_tasks)

    @staticmethod
    def unbind(group_id, repo_id, distributor_id, options):
        """
        Unbind the members of the specified consumer group.
        :param group_id: A consumer group ID.
        :type group_id: str
        :param repo_id: A repository ID.
        :type repo_id: str
        :param distributor_id: A distributor ID.
        :type distributor_id: str
        :param options: Bind options passed to the agent handler.
        :type options: dict
Esempio n. 2
0
    def update_repo_and_plugins(repo_id, repo_delta, importer_config,
                                distributor_configs):
        """
        Aggregate method that will update one or more of the following:
        * Repository metadata
        * Importer config
        * Zero or more distributors on the repository

        All of the above pieces do not need to be specified. If a piece is
        omitted it's configuration is not touched, nor is it removed from
        the repository. The same holds true for the distributor_configs dict,
        not every distributor must be represented.

        This call will attempt the updates in the order listed above. If an
        exception occurs during any of these steps, the updates stop and the
        exception is immediately raised. Any updates that have already taken
        place are not rolled back.

        This call will call out to RepoImporterManager.update_importer_config.
        Documentation for that method, especially possible exceptions, should be
        consulted for more information.

        Distributor updates will happen asynchronously as there could be a
        very large number of consumers to update and the repo update call
        is usually made synchronously.

        :param repo_id: unique identifier for the repo
        :type  repo_id: str

        :param repo_delta: list of attributes and their new values to change;
               if None, no attempt to update the repo's metadata will be made
        :type  repo_delta: dict, None

        :param importer_config: new configuration to use for the repo's importer;
               if None, no attempt will be made to update the importer
        :type  importer_config: dict, None

        :param distributor_configs: mapping of distributor ID to the new configuration
               to set for it
        :type  distributor_configs: dict, None

        :return: updated repository object, same as returned from update_repo
        :rtype: TaskResult
        """

        # Repo Update
        if repo_delta is None:
            repo_delta = {}
        repo = RepoManager.update_repo(repo_id, repo_delta)

        # Importer Update
        if importer_config is not None:
            importer_manager = manager_factory.repo_importer_manager()
            importer_manager.update_importer_config(repo_id, importer_config)

        errors = []
        additional_tasks = []
        # Distributor Update
        if distributor_configs is not None:
            for dist_id, dist_config in distributor_configs.items():
                update_result = repository.distributor_update(repo_id, dist_id, dist_config, None)
                additional_tasks.extend(update_result.spawned_tasks)
                errors.append(update_result.error)

        error = None
        if len(errors) > 0:
            error = PulpCodedException(error_code=error_codes.PLP0006,
                                       repo_id=repo_id)
            error.child_exceptions = errors
        return TaskResult(repo, error, additional_tasks)
Esempio n. 3
0
    manager = managers.consumer_bind_manager()

    additional_tasks = []
    errors = []
    for bind in manager.find_by_repo(repo_id):
        try:
            report = consumer.unbind(bind["consumer_id"], bind["repo_id"], bind["distributor_id"], options)
            if report:
                additional_tasks.extend(report.spawned_tasks)
        except Exception, e:
            errors.append(e)

    error = None
    if len(errors) > 0:
        error = PulpCodedException(PLP0007, repo_id=repo_id)
        error.child_exceptions = errors

    return TaskResult(error=error, spawned_tasks=additional_tasks)


@celery.task(base=Task)
def distributor_delete(repo_id, distributor_id):
    """
    Get the itinerary for deleting a repository distributor.
      1. Delete the distributor on the sever.
      2. Unbind any bound consumers.
    :param repo_id: A repository ID.
    :type repo_id: str
    :param distributor_id: A distributor id
    :type distributor_id: str
    :return: Any errors that may have occurred and the list of tasks spawned for each consumer
Esempio n. 4
0
    manager = managers.consumer_bind_manager()
    for bind in manager.find_by_distributor(repo_id, distributor_id):
        try:
            report = consumer.unbind(bind['consumer_id'], bind['repo_id'],
                                     bind['distributor_id'], options)
            if report:
                additional_tasks.extend(report.spawned_tasks)
        except Exception, e:
            unbind_errors.append(e)

    bind_error = None
    if len(unbind_errors) > 0:
        bind_error = PulpCodedException(PLP0003,
                                        repo_id=repo_id,
                                        distributor_id=distributor_id)
        bind_error.child_exceptions = unbind_errors
    return TaskResult(error=bind_error, spawned_tasks=additional_tasks)


@celery.task(base=Task, name='pulp.server.tasks.repository.distributor_update')
def update(repo_id, distributor_id, config, delta):
    """
    Get the itinerary for updating a repository distributor.
      1. Update the distributor on the server.
      2. (re)bind any bound consumers.

    :param repo_id:         A repository ID.
    :type  repo_id:         str
    :param distributor_id:  A unique distributor id
    :type  distributor_id:  str
    :param config:          A configuration dictionary for a distributor instance. The contents of