-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://pulp.plan.io/issues/4634 closes #4634
- Loading branch information
Brian Bouterse
committed
May 2, 2019
1 parent
51bf29c
commit 85a86a4
Showing
4 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from gettext import gettext as _ | ||
import json | ||
import logging | ||
import tarfile | ||
|
||
from django.db import transaction | ||
|
||
from pulpcore.plugin.models import Artifact, ContentArtifact, CreatedResource | ||
from pulp_ansible.app.models import Collection | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def import_collection(artifact_pk): | ||
""" | ||
Create a collection from an uploaded artifact | ||
Args: | ||
artifact_pk (str): The pk or the Artifact to create the Collection from. | ||
""" | ||
artifact = Artifact.objects.get(pk=artifact_pk) | ||
with tarfile.open(str(artifact.file.path), "r") as tar: | ||
log.info(_('Reading MANIFEST.json from {path}').format(path=artifact.file.path)) | ||
file_obj = tar.extractfile('MANIFEST.json') | ||
manifest_data = json.load(file_obj) | ||
collection_info = manifest_data['collection_info'] | ||
|
||
collection = Collection( | ||
namespace=collection_info['namespace'], | ||
name=collection_info['name'], | ||
version=collection_info['version'] | ||
) | ||
with transaction.atomic(): | ||
collection.save() | ||
ContentArtifact.objects.create( | ||
artifact=artifact, | ||
content=collection, | ||
relative_path=collection.relative_path, | ||
) | ||
CreatedResource.objects.create(content_object=collection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
from django.conf.urls import url | ||
|
||
from pulp_ansible.app.galaxy.views import ( | ||
GalaxyCollectionView, | ||
GalaxyVersionView, | ||
RoleList, | ||
RoleVersionList | ||
) | ||
|
||
|
||
urlpatterns = [ | ||
url(r'pulp_ansible/galaxy/(?P<path>.+)/api/$', GalaxyVersionView.as_view()), | ||
url(r'pulp_ansible/galaxy/(?P<path>.+)/api/v1/roles/$', RoleList.as_view()), | ||
url(r'pulp_ansible/galaxy/(?P<path>.+)/api/v1/roles/(?P<role_pk>.+)/versions/$', | ||
RoleVersionList.as_view()) | ||
RoleVersionList.as_view()), | ||
url(r'pulp_ansible/galaxy/(?P<path>.+)/api/v2/collections/$', GalaxyCollectionView.as_view()), | ||
] |