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
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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
-----------------------------------------
@@ -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',),
),
]
@@ -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'
@@ -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
@@ -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(
@@ -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
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.