forked from pulp/pulpcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migrate endpoint to move artifacts to another storage backend
fixes: pulp#3358
- Loading branch information
Showing
15 changed files
with
477 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added new `/migrate/` endpoint to Domains that allows for migrating artifacts from one storage backend to another. |
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
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,35 @@ | ||
from gettext import gettext as _ | ||
|
||
from django.core.management import BaseCommand, CommandError | ||
from django.conf import settings | ||
|
||
from pulpcore.app.models import Worker | ||
from pulpcore.plugin.tasking import dispatch | ||
from pulpcore.app.tasks import migrate_backend | ||
from pulpcore.app.serializers.domain import DomainBackendMigratorSerializer, StorageSettingsSerializer | ||
from pulpcore.app.util import get_default_domain | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Django management command to migrate artifacts to new storage backend.""" | ||
|
||
help = 'Migrate artifacts from old storage backend to new backend specified in settings.' | ||
|
||
def add_arguments(self, parser): | ||
pass | ||
|
||
def handle(self, *args, **options): | ||
if Worker.objects.online().count() == 0: | ||
raise CommandError(_("No worker instances online to run migrate task.")) | ||
data = { | ||
"storage_class": settings.DEFAULT_FILE_STORAGE, | ||
"storage_settings": StorageSettingsSerializer.get_default_domain_settings(settings) | ||
} | ||
serializer = DomainBackendMigratorSerializer(data=data) | ||
serializer.is_valid(raise_exception=True) | ||
|
||
dispatch( | ||
migrate_backend, | ||
args=(serializer.validated_data,), | ||
exclusive_resources=[get_default_domain()], | ||
) |
34 changes: 34 additions & 0 deletions
34
pulpcore/app/migrations/0118_store_default_domain_settings.py
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,34 @@ | ||
# Generated by Django 4.2.10 on 2024-04-24 11:38 | ||
|
||
from django.db import migrations | ||
from pulpcore.app.serializers.domain import StorageSettingsSerializer | ||
from django.conf import settings | ||
|
||
|
||
def default_domain_settings(apps, schema_editor): | ||
Domain = apps.get_model("core", "Domain") | ||
default_domain = Domain.objects.get(name="default") | ||
config_settings = StorageSettingsSerializer.get_default_domain_settings(settings) | ||
default_domain.storage_class = settings.DEFAULT_FILE_STORAGE | ||
default_domain.storage_settings = config_settings | ||
default_domain.hide_guarded_distributions = settings.HIDE_GUARDED_DISTRIBUTIONS | ||
default_domain.redirect_to_object_storage = settings.REDIRECT_TO_OBJECT_STORAGE | ||
default_domain.save(skip_hooks=True) | ||
|
||
|
||
def reverse_default_domain_settings(apps, schema_editor): | ||
Domain = apps.get_model("core", "Domain") | ||
default_domain = Domain.objects.get(name="default") | ||
default_domain.storage_settings = {} | ||
default_domain.save(skip_hooks=True) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0117_task_unblocked_at'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(default_domain_settings, reverse_code=reverse_default_domain_settings), | ||
] |
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
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
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
Oops, something went wrong.