Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting file publications #205

Merged
merged 1 commit into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------------------------------
Expand Down
27 changes: 18 additions & 9 deletions pulp_file/app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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',
Expand All @@ -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',),
),
]
10 changes: 9 additions & 1 deletion pulp_file/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -47,3 +47,11 @@ class FilePublisher(Publisher):

TYPE = 'file'
manifest = models.TextField()


class FilePublication(Publication):
"""
Publication for 'file' content.
"""

TYPE = 'file'
17 changes: 14 additions & 3 deletions pulp_file/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
11 changes: 5 additions & 6 deletions pulp_file/app/tasks/publishing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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(
Expand Down
20 changes: 18 additions & 2 deletions pulp_file/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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