Skip to content

Commit

Permalink
Allow users to upload role versions
Browse files Browse the repository at this point in the history
  • Loading branch information
David Davis committed Apr 18, 2018
1 parent 2286911 commit 7955e94
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
67 changes: 61 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,63 @@ Look at the new Repository Version created
}
Upload ``pulp-0.0.1.tar`` to Pulp
-----------------------------

Create an Artifact by uploading the role version tar to Pulp.

``$ http --form POST http://localhost:8000/api/v3/artifacts/ file@pulp-0.0.1.tar``

.. code:: json
{
"_href": "http://localhost:8000/api/v3/artifacts/7d39e3f6-535a-4b6e-81e9-c83aa56aa19e/",
...
}
Create a Role content unit
--------------------------

Create an Ansible role in Pulp.

``$ http http://localhost:8000/api/v3/content/ansible/roles/ namespace=pulp name=pulp``

.. code:: json
{
"_href": "http://localhost:8000/api/v3/content/ansible/roles/3965b515-53a0-4667-a540-a76714a903d4/",
"_versions_href": "http://localhost:8000/api/v3/content/ansible/roles/3965b515-53a0-4667-a540-a76714a903d4/versions/",
"name": "pulp",
"namespace": "pulp"
}
Create a ``role version`` from the Role and Artifact
-----------------------------------------------------

Create a content unit and point it to your Artifact and Role

``$ http POST http://localhost:8000/api/v3/content/ansible/roles/3965b515-53a0-4667-a540-a76714a903d4/versions/ version=0.0.1 artifact="http://localhost:8000/api/v3/artifacts/7d39e3f6-535a-4b6e-81e9-c83aa56aa19e/"``

.. code:: json
{
"_href": "http://localhost:8000/api/v3/content/ansible/roles/3965b515-53a0-4667-a540-a76714a903d4/versions/183d532c-37e8-4c0a-a00e-5a80b2de4162/",
"artifact": "http://localhost:8000/api/v3/artifacts/7d39e3f6-535a-4b6e-81e9-c83aa56aa19e/",
"version": "0.0.1",
"type": "ansible-role-version"
}
``$ export CONTENT_HREF=$(http :8000/api/v3/content/ansible/roles/3965b515-53a0-4667-a540-a76714a903d4/versions/ | jq -r '.results[] | select(.version == "0.0.1") | ._href')``


Add content to repository ``foo``
---------------------------------

``$ http POST $REPO_HREF'versions/' add_content_units:="[\"$CONTENT_HREF\"]"``


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

Expand All @@ -117,12 +174,10 @@ Use the ``bar`` Publisher to create a Publication

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

Expand Down
2 changes: 1 addition & 1 deletion pulp_ansible/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def artifact(self, artifact):
if self.pk:
ca = ContentArtifact(artifact=artifact,
content=self,
relative_path=self.relative_path)
relative_path="{}.tar".format(self.version))
ca.save()

class Meta:
Expand Down
16 changes: 14 additions & 2 deletions pulp_ansible/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rest_framework import serializers, status
from rest_framework.response import Response

from pulpcore.plugin.models import Repository, RepositoryVersion
from pulpcore.plugin.models import Artifact, Repository, RepositoryVersion
from pulpcore.plugin.viewsets import (
ContentViewSet,
RemoteViewSet,
Expand Down Expand Up @@ -67,8 +67,20 @@ class AnsibleRoleVersionViewSet(ContentViewSet):
def endpoint_pieces(cls):
return (cls.endpoint_name,)

@transaction.atomic
def create(self, request, role_pk):
raise NotImplementedError
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
validated_data = serializer.validated_data

role_version = AnsibleRoleVersion(**validated_data)
role_version.role = AnsibleRole.objects.get(pk=role_pk)
role_version.save()
role_version.artifact = self.get_resource(request.data['artifact'], Artifact)

headers = self.get_success_headers(request.data)
return Response(self.get_serializer(role_version).data, status=status.HTTP_201_CREATED,
headers=headers)


class AnsibleRemoteViewSet(RemoteViewSet):
Expand Down

0 comments on commit 7955e94

Please sign in to comment.