diff --git a/README.rst b/README.rst index c18e8a3c..ce83f21d 100644 --- a/README.rst +++ b/README.rst @@ -197,7 +197,7 @@ Use the ``bar`` Publisher to create a Publication "task": "/pulp/api/v3/tasks/fd4cbecd-6c6a-4197-9cbe-4e45b0516309/" } -``$ export PUBLICATION_HREF=$(http :24817/pulp/api/v3/publications/ | jq -r --arg PUBLISHER_HREF "$PUBLISHER_HREF" '.results[] | select(.publisher==$PUBLISHER_HREF) | ._href')`` +``$ export PUBLICATION_HREF=$(http :24817/pulp/api/v3/publications/file/file/ | jq -r --arg PUBLISHER_HREF "$PUBLISHER_HREF" '.results[] | select(.publisher==$PUBLISHER_HREF) | ._href')`` Create a Distribution for the Publication ----------------------------------------- diff --git a/pulp_file/app/migrations/0001_initial.py b/pulp_file/app/migrations/0001_initial.py index 4c123810..4621efe8 100644 --- a/pulp_file/app/migrations/0001_initial.py +++ b/pulp_file/app/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.7 on 2019-03-19 16:18 +# Generated by Django 2.2 on 2019-04-22 17:56 from django.db import migrations, models import django.db.models.deletion @@ -14,13 +14,14 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='FileContent', + name='FilePublication', fields=[ - ('content_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='core.Content')), - ('relative_path', models.CharField(max_length=255)), - ('digest', models.CharField(max_length=255)), + ('publication_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='core.Publication')), ], - bases=('core.content',), + options={ + 'abstract': False, + }, + bases=('core.publication',), ), migrations.CreateModel( name='FilePublisher', @@ -43,8 +44,16 @@ class Migration(migrations.Migration): }, bases=('core.remote',), ), - migrations.AlterUniqueTogether( - name='filecontent', - unique_together={('relative_path', 'digest')}, + migrations.CreateModel( + name='FileContent', + fields=[ + ('content_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='core.Content')), + ('relative_path', models.CharField(max_length=255)), + ('digest', models.CharField(max_length=64)), + ], + options={ + 'unique_together': {('relative_path', 'digest')}, + }, + bases=('core.content',), ), ] diff --git a/pulp_file/app/models.py b/pulp_file/app/models.py index d6e31552..0888c914 100644 --- a/pulp_file/app/models.py +++ b/pulp_file/app/models.py @@ -2,7 +2,7 @@ from django.db import models -from pulpcore.plugin.models import Content, Remote, Publisher +from pulpcore.plugin.models import Content, Remote, Publication, Publisher log = getLogger(__name__) @@ -47,3 +47,11 @@ class FilePublisher(Publisher): TYPE = 'file' manifest = models.TextField() + + +class FilePublication(Publication): + """ + Publication for 'file' content. + """ + + TYPE = 'file' diff --git a/pulp_file/app/serializers.py b/pulp_file/app/serializers.py index f6f5f21d..44a6e8d9 100644 --- a/pulp_file/app/serializers.py +++ b/pulp_file/app/serializers.py @@ -3,13 +3,14 @@ from rest_framework import serializers from pulpcore.plugin.serializers import ( - SingleArtifactContentSerializer, - RemoteSerializer, + PublicationSerializer, PublisherSerializer, + RemoteSerializer, + SingleArtifactContentSerializer, relative_path_validator, ) -from .models import FileContent, FileRemote, FilePublisher +from .models import FileContent, FileRemote, FilePublication, FilePublisher class FileContentSerializer(SingleArtifactContentSerializer): @@ -71,3 +72,13 @@ class FilePublisherSerializer(PublisherSerializer): class Meta: fields = PublisherSerializer.Meta.fields + ('manifest',) model = FilePublisher + + +class FilePublicationSerializer(PublicationSerializer): + """ + Serializer for File Publications. + """ + + class Meta: + fields = PublicationSerializer.Meta.fields + model = FilePublication diff --git a/pulp_file/app/tasks/publishing.py b/pulp_file/app/tasks/publishing.py index ff1076ba..c096f0a0 100644 --- a/pulp_file/app/tasks/publishing.py +++ b/pulp_file/app/tasks/publishing.py @@ -7,12 +7,11 @@ from pulpcore.plugin.models import ( RepositoryVersion, - Publication, PublishedMetadata, RemoteArtifact) from pulpcore.plugin.tasking import WorkingDirectory -from pulp_file.app.models import FileContent, FilePublisher +from pulp_file.app.models import FileContent, FilePublication, FilePublisher from pulp_file.manifest import Entry, Manifest @@ -29,16 +28,16 @@ def publish(publisher_pk, repository_version_pk): """ publisher = FilePublisher.objects.get(pk=publisher_pk) - repository_version = RepositoryVersion.objects.get(pk=repository_version_pk) + repo_version = RepositoryVersion.objects.get(pk=repository_version_pk) log.info(_('Publishing: repository={repo}, version={ver}, publisher={pub}').format( - repo=repository_version.repository.name, - ver=repository_version.number, + repo=repo_version.repository.name, + ver=repo_version.number, pub=publisher.name, )) with WorkingDirectory(): - with Publication.create(repository_version, publisher, pass_through=True) as publication: + with FilePublication.create(repo_version, publisher, pass_through=True) as publication: manifest = Manifest(publisher.manifest) manifest.write(populate(publication)) metadata = PublishedMetadata( diff --git a/pulp_file/app/viewsets.py b/pulp_file/app/viewsets.py index 3d5c4d75..8e9173fa 100644 --- a/pulp_file/app/viewsets.py +++ b/pulp_file/app/viewsets.py @@ -14,12 +14,18 @@ ContentFilter, RemoteViewSet, OperationPostponedResponse, + PublicationViewSet, PublisherViewSet, ) from . import tasks -from .models import FileContent, FileRemote, FilePublisher -from .serializers import FileContentSerializer, FileRemoteSerializer, FilePublisherSerializer +from .models import FileContent, FileRemote, FilePublication, FilePublisher +from .serializers import ( + FileContentSerializer, + FileRemoteSerializer, + FilePublicationSerializer, + FilePublisherSerializer, +) class FileContentFilter(ContentFilter): @@ -119,3 +125,13 @@ def publish(self, request, pk): } ) return OperationPostponedResponse(result, request) + + +class FilePublicationViewSet(PublicationViewSet): + """ + ViewSet for File Publications. + """ + + endpoint_name = 'file' + queryset = FilePublication.objects.all() + serializer_class = FilePublicationSerializer