-
Notifications
You must be signed in to change notification settings - Fork 53
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
Mutable Prototype #389
Closed
Closed
Mutable Prototype #389
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b4bb079
Deprecation status through sync machinery
fao89 f8d88c9
Introducing MutableCollectionMetadata model
fao89 9a360d1
Sync collection deprecation status
fao89 11994e0
Introducing metadata endpoint
fao89 ee56972
Sync from metadata endpoint
fao89 b4a1df2
Include MutableCollectionMetadata on modify endpoint
fao89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from pulpcore.plugin.models import Content, RepositoryVersion | ||
|
||
from pulp_ansible.app.models import AnsibleRepository, MutableCollectionMetadata | ||
|
||
|
||
def add_and_remove(repository_pk, add_content_units, remove_content_units, base_version_pk=None): | ||
""" | ||
Create a new repository version by adding and then removing content units. | ||
|
||
Args: | ||
repository_pk (int): The primary key for a Repository for which a new Repository Version | ||
should be created. | ||
add_content_units (list): List of PKs for :class:`~pulpcore.app.Content` that | ||
should be added to the previous Repository Version for this Repository. | ||
remove_content_units (list): List of PKs for:class:`~pulpcore.app.Content` that | ||
should be removed from the previous Repository Version for this Repository. | ||
base_version_pk (int): the primary key for a RepositoryVersion whose content will be used | ||
as the initial set of content for our new RepositoryVersion | ||
""" | ||
repository = AnsibleRepository.objects.get(pk=repository_pk) | ||
|
||
if base_version_pk: | ||
base_version = RepositoryVersion.objects.get(pk=base_version_pk) | ||
else: | ||
base_version = None | ||
|
||
if "*" in remove_content_units: | ||
latest = repository.latest_version() | ||
if latest: | ||
remove_content_units = latest.content.values_list("pk", flat=True) | ||
else: | ||
remove_content_units = [] | ||
|
||
to_add = [] | ||
with repository.new_version(base_version=base_version) as new_version: | ||
new_version.remove_content(Content.objects.filter(pk__in=remove_content_units)) | ||
new_version.add_content(Content.objects.filter(pk__in=add_content_units)) | ||
|
||
for collection_id, deprecated in MutableCollectionMetadata.objects.filter( | ||
repository_version__repository=repository, collection__versions__in=add_content_units | ||
).values_list("collection_id", "deprecated"): | ||
to_add.append( | ||
MutableCollectionMetadata( | ||
repository_version=new_version, | ||
collection_id=collection_id, | ||
deprecated=deprecated, | ||
) | ||
) | ||
|
||
if to_add: | ||
MutableCollectionMetadata.objects.bulk_create(to_add, ignore_conflicts=True) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used in synclist - "custom" sync between repositories