-
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.
Adding publishing code and updating README
This commits adds basic publishing which allows the ansible-galaxy to install the role version directly through a URL. Also, updated the README. fixes #3467 https://pulp.plan.io/issues/3467
- Loading branch information
David Davis
committed
Mar 14, 2018
1 parent
b4461a8
commit 12311eb
Showing
4 changed files
with
168 additions
and
36 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from .synchronizing import synchronize | ||
from .publishing import publish |
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,75 @@ | ||
import logging | ||
|
||
from gettext import gettext as _ | ||
|
||
from celery import shared_task | ||
|
||
from pulpcore.plugin.models import ( | ||
RepositoryVersion, | ||
Publication, | ||
PublishedArtifact, | ||
RemoteArtifact) | ||
from pulpcore.plugin.tasking import UserFacingTask, WorkingDirectory | ||
|
||
from pulp_ansible.app.models import AnsibleRole, AnsiblePublisher | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@shared_task(base=UserFacingTask) | ||
def publish(publisher_pk, repository_version_pk): | ||
""" | ||
Use provided publisher to 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) | ||
|
||
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() |
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