Skip to content
Permalink
Browse files

Remove AnsiblePublisher

  • Loading branch information...
daviddavis committed Sep 29, 2018
1 parent e2b1d0c commit 1e49f002caaeff67cec68f1f194f47e6deeba6dd
@@ -162,34 +162,18 @@ Add content to repository ``foo``
``$ http POST ':8000'$REPO_HREF'versions/' add_content_units:="[\"$CONTENT_HREF\"]"``


Create an Ansible publisher
---------------------------

``$ http POST http://localhost:8000/pulp/api/v3/publishers/ansible/ name=bar``

.. code:: json
{
"_href": "http://localhost:8000/pulp/api/v3/publishers/ansible/bar/",
...
}
``$ export PUBLISHER_HREF=$(http :8000/pulp/api/v3/publishers/ansible/ | jq -r '.results[] | select(.name == "bar") | ._href')``


Use the ``bar`` Publisher to create a Publication
Create a Publication
-------------------------------------------------

``$ http POST ':8000'$PUBLISHER_HREF'publish/' repository=$REPO_HREF``
``$ http POST :8000/pulp/api/v3/ansible/publications/ repository=$REPO_HREF``

.. code:: json
{
"task": "http://localhost:8000/pulp/api/v3/tasks/fd4cbecd-6c6a-4197-9cbe-4e45b0516309/"
}
``$ export PUBLICATION_HREF=$(http :8000/pulp/api/v3/publications/ | jq -r --arg PUBLISHER_HREF "$PUBLISHER_HREF" '.results[] | select(.publisher==$PUBLISHER_HREF) | ._href')``
``$ export PUBLICATION_HREF=$(http :8000/pulp/api/v3/publications/ | jq -r '.results[0] | ._href')``


Create a Distribution for the Publication
@@ -2,7 +2,7 @@

from django.db import models

from pulpcore.plugin.models import Content, ContentArtifact, Remote, Publisher
from pulpcore.plugin.models import Content, ContentArtifact, Remote


log = getLogger(__name__)
@@ -73,14 +73,6 @@ class Meta:
)


class AnsiblePublisher(Publisher):
"""
A Publisher for Ansible content.
"""

TYPE = 'ansible'


class AnsibleRemote(Remote):
"""
A Remote for Ansible content.
@@ -1,10 +1,10 @@
from rest_framework import serializers

from pulpcore.plugin.serializers import ContentSerializer, IdentityField, NestedIdentityField, \
RelatedField, RemoteSerializer, PublisherSerializer
RelatedField, RemoteSerializer
from pulpcore.plugin.models import Artifact

from .models import AnsibleRemote, AnsiblePublisher, AnsibleRole, AnsibleRoleVersion
from .models import AnsibleRemote, AnsibleRole, AnsibleRoleVersion


class AnsibleRoleSerializer(ContentSerializer):
@@ -61,13 +61,3 @@ class AnsibleRemoteSerializer(RemoteSerializer):
class Meta:
fields = RemoteSerializer.Meta.fields
model = AnsibleRemote


class AnsiblePublisherSerializer(PublisherSerializer):
"""
A serializer for Ansible Publishers.
"""

class Meta:
fields = PublisherSerializer.Meta.fields
model = AnsiblePublisher
@@ -2,72 +2,25 @@

from gettext import gettext as _

from pulpcore.plugin.models import (
RepositoryVersion,
Publication,
PublishedArtifact,
RemoteArtifact)
from pulpcore.plugin.tasking import WorkingDirectory

from pulp_ansible.app.models import AnsiblePublisher
from pulpcore.plugin.models import RepositoryVersion, Publication


log = logging.getLogger(__name__)


def publish(publisher_pk, repository_version_pk):
def publish(repository_version_pk):
"""
Use provided publisher to create a Publication based on a RepositoryVersion.
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.
"""
publisher = AnsiblePublisher.objects.get(pk=publisher_pk)
repository_version = RepositoryVersion.objects.get(pk=repository_version_pk)

log.info(
_('Publishing: repository=%(repository)s, version=%(version)d, publisher=%(publisher)s'),
{
'repository': repository_version.repository.name,
'version': repository_version.number,
'publisher': publisher.name,
})

with WorkingDirectory():
with Publication.create(repository_version, publisher) as publication:
populate(publication)
with Publication.create(repository_version, pass_through=True) as publication:
pass

log.info(
_('Publication: %(publication)s created'),
{
'publication': publication.pk
})


def populate(publication):
"""
Populate a publication.
Create published artifacts and yield a Manifest Entry for each.
Args:
publication (pulpcore.plugin.models.Publication): A Publication to populate.
Yields:
Entry: Each manifest entry.
"""
def find_artifact():
_artifact = content_artifact.artifact
if not _artifact:
_artifact = RemoteArtifact.objects.filter(content_artifact=content_artifact).first()
return _artifact

for content in publication.repository_version.content:
content_artifact = content.contentartifact_set.get()
published_artifact = PublishedArtifact(
relative_path=content_artifact.relative_path,
publication=publication,
content_artifact=content_artifact)
published_artifact.save()
@@ -1,28 +1,28 @@
from django.db import transaction
from drf_yasg.utils import swagger_auto_schema
from rest_framework.decorators import detail_route
from rest_framework import status
from rest_framework import mixins, status
from rest_framework.response import Response

from pulpcore.plugin.models import Artifact, RepositoryVersion
from pulpcore.plugin.models import Artifact, RepositoryVersion, Publication
from pulpcore.plugin.serializers import (
AsyncOperationResponseSerializer,
RepositoryPublishURLSerializer,
RepositorySyncURLSerializer,
)
from pulpcore.plugin.tasking import enqueue_with_reservation
from pulpcore.plugin.viewsets import (
BaseFilterSet,
ContentViewSet,
RemoteViewSet,
NamedModelViewSet,
OperationPostponedResponse,
PublisherViewSet,
BaseFilterSet
RemoteViewSet
)

from . import tasks
from .models import AnsibleRemote, AnsiblePublisher, AnsibleRole, AnsibleRoleVersion
from .serializers import (AnsibleRemoteSerializer, AnsiblePublisherSerializer,
AnsibleRoleSerializer, AnsibleRoleVersionSerializer)
from .models import AnsibleRemote, AnsibleRole, AnsibleRoleVersion
from .serializers import (AnsibleRemoteSerializer, AnsibleRoleSerializer,
AnsibleRoleVersionSerializer)


class AnsibleRoleFilter(BaseFilterSet):
@@ -153,25 +153,22 @@ def sync(self, request, pk):
return OperationPostponedResponse(result, request)


class AnsiblePublisherViewSet(PublisherViewSet):
class AnsiblePublicationsViewSet(NamedModelViewSet,
mixins.CreateModelMixin):
"""
ViewSet for Ansible Publishers.
ViewSet for Ansible Publications.
"""

endpoint_name = 'ansible'
queryset = AnsiblePublisher.objects.all()
serializer_class = AnsiblePublisherSerializer
endpoint_name = 'ansible/publications'
queryset = Publication.objects.all()

@swagger_auto_schema(
operation_description="Trigger an asynchronous task to publish Ansible content.",
responses={202: AsyncOperationResponseSerializer}
)
@detail_route(methods=('post',), serializer_class=RepositoryPublishURLSerializer)
def publish(self, request, pk):
@swagger_auto_schema(operation_description="Trigger an asynchronous task to create "
"a new Ansible content publication.",
responses={202: AsyncOperationResponseSerializer})
def create(self, request):
"""
Dispatches a publish task.
Queues a task that publishes a new Ansible Publication.
"""
publisher = self.get_object()
serializer = RepositoryPublishURLSerializer(
data=request.data,
context={'request': request}
@@ -183,10 +180,10 @@ def publish(self, request, pk):
if not repository_version:
repository = serializer.validated_data.get('repository')
repository_version = RepositoryVersion.latest(repository)

result = enqueue_with_reservation(
tasks.publish, [repository_version.repository, publisher],
tasks.publish, [repository_version.repository],
kwargs={
'publisher_pk': str(publisher.pk),
'repository_version_pk': str(repository_version.pk)
}
)

This file was deleted.

0 comments on commit 1e49f00

Please sign in to comment.
You can’t perform that action at this time.