コード例 #1
0
    async def migrate_to_pulp3(cls, pulp2distributor, repo_version):
        """
        Migrate distributor to Pulp 3.

        Args:
            pulp2distributor(Pulp2ditributor): Pre-migrated pulp2 distributor to migrate

        Return:
            publication and distribution: FilePublication and FileDistribution in Pulp3
            created(bool): True if Distribution has just been created; False if Distribution
                           is an existing one
        """
        if not repo_version:
            repo_version = pulp2distributor.pulp2_repository.pulp3_repository_version
        publication = repo_version.publication_set.first()
        if not publication:
            # create publication
            with FilePublication.create(repo_version,
                                        pass_through=True) as publication:
                manifest = Manifest('PULP_MANIFEST')
                manifest.write(populate(publication))
                PublishedMetadata.create_from_file(file=File(
                    open(manifest.relative_path, "rb")),
                                                   publication=publication)
        # create distribution
        pulp2_config = pulp2distributor.pulp2_config
        base_config = cls.parse_base_config(pulp2distributor, pulp2_config)
        base_config['base_path'] = pulp2_config.get(
            'relative_url', pulp2distributor.pulp2_repository.pulp2_repo_id)
        base_config['publication'] = publication
        distribution, created = FileDistribution.objects.update_or_create(
            **base_config)

        return publication, distribution, created
コード例 #2
0
def publish(manifest, repository_version_pk):
    """
    Create a Publication based on a RepositoryVersion.

    Args:
        manifest (str): Filename to use for manifest file.
        repository_version_pk (str): Create a publication from this repository version.

    """
    repo_version = RepositoryVersion.objects.get(pk=repository_version_pk)

    log.info(
        _("Publishing: repository={repo}, version={ver}, manifest={manifest}").
        format(repo=repo_version.repository.name,
               ver=repo_version.number,
               manifest=manifest))

    with WorkingDirectory():
        with FilePublication.create(repo_version,
                                    pass_through=True) as publication:
            manifest = Manifest(manifest)
            manifest.write(populate(publication))
            PublishedMetadata.create_from_file(file=File(
                open(manifest.relative_path, "rb")),
                                               publication=publication)

    log.info(
        _("Publication: {publication} created").format(
            publication=publication.pk))
コード例 #3
0
ファイル: synchronizing.py プロジェクト: pavelpicka/pulp_file
def synchronize(remote_pk, repository_pk, mirror):
    """
    Sync content from the remote repository.

    Create a new version of the repository that is synchronized with the remote.

    Args:
        remote_pk (str): The remote PK.
        repository_pk (str): The repository PK.
        mirror (bool): True for mirror mode, False for additive.

    Raises:
        ValueError: If the remote does not specify a URL to sync.

    """
    remote = FileRemote.objects.get(pk=remote_pk)
    repository = FileRepository.objects.get(pk=repository_pk)

    if not remote.url:
        raise ValueError(
            _("A remote must have a url specified to synchronize."))

    first_stage = FileFirstStage(remote)
    dv = DeclarativeVersion(first_stage, repository, mirror=mirror)
    rv = dv.create()
    if rv and mirror:
        # TODO: this is awful, we really should rewrite the DeclarativeVersion API to
        # accomodate this use case
        global metadata_files
        with FilePublication.create(rv, pass_through=True) as publication:
            (mdfile_path, relative_path) = metadata_files.pop()
            PublishedMetadata.create_from_file(
                file=File(open(mdfile_path, "rb")),
                relative_path=relative_path,
                publication=publication,
            )
            publication.manifest = relative_path
            publication.save()

        log.info(
            _("Publication: {publication} created").format(
                publication=publication.pk))

    return rv
コード例 #4
0
def publish(publisher_pk, repository_version_pk):
    """
    Use provided publisher to create a Publication based on a RepositoryVersion.

    Args:
        publisher_pk (str): Use the publish settings provided by this publisher.
        repository_version_pk (str): Create a publication from this repository version.

    """
    if publisher_pk:
        publisher = FilePublisher.objects.get(pk=publisher_pk)
        manifest = publisher.manifest
        publisher_name = publisher.name
    else:
        publisher = None
        manifest = 'PULP_MANIFEST'
        publisher_name = ''

    repo_version = RepositoryVersion.objects.get(pk=repository_version_pk)

    log.info(
        _('Publishing: repository={repo}, version={ver}, publisher={pub}').
        format(
            repo=repo_version.repository.name,
            ver=repo_version.number,
            pub=publisher_name,
        ))

    with WorkingDirectory():
        with FilePublication.create(repo_version, publisher,
                                    pass_through=True) as publication:
            manifest = Manifest(manifest)
            manifest.write(populate(publication))
            metadata = PublishedMetadata(
                relative_path=os.path.basename(manifest.relative_path),
                publication=publication,
                file=File(open(manifest.relative_path, 'rb')))
            metadata.save()

    log.info(
        _('Publication: {publication} created').format(
            publication=publication.pk))