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.
Adding PulpExporter model and endpoints
Also adding a new Export model and refactoring existing Exporters. fixes #6328 https://pulp.plan.io/issues/6328 Required PR: pulp/pulp_file#366
- Loading branch information
David Davis
committed
Mar 16, 2020
1 parent
a642907
commit 64f64a0
Showing
13 changed files
with
247 additions
and
58 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,79 @@ | ||
# Generated by Django 2.2.6 on 2020-03-13 16:18 | ||
|
||
import django.contrib.postgres.fields.jsonb | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contenttypes', '0002_remove_content_type_name'), | ||
('file', '0006_delete_filefilesystemexporter'), | ||
('core', '0022_rename_last_version'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Export', | ||
fields=[ | ||
('pulp_id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('pulp_created', models.DateTimeField(auto_now_add=True)), | ||
('pulp_last_updated', models.DateTimeField(auto_now=True, null=True)), | ||
('state', models.TextField(choices=[('waiting', 'Waiting'), ('skipped', 'Skipped'), ('running', 'Running'), ('completed', 'Completed'), ('failed', 'Failed'), ('canceled', 'Canceled')])), | ||
('started_at', models.DateTimeField(null=True)), | ||
('finished_at', models.DateTimeField(null=True)), | ||
('error', django.contrib.postgres.fields.jsonb.JSONField(null=True)), | ||
('user_params', django.contrib.postgres.fields.jsonb.JSONField()), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='ExportedResource', | ||
fields=[ | ||
('pulp_id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('pulp_created', models.DateTimeField(auto_now_add=True)), | ||
('pulp_last_updated', models.DateTimeField(auto_now=True, null=True)), | ||
('object_id', models.UUIDField()), | ||
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), | ||
('export', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exported_resources', to='core.Export')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Exporter', | ||
fields=[ | ||
('pulp_id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('pulp_created', models.DateTimeField(auto_now_add=True)), | ||
('pulp_last_updated', models.DateTimeField(auto_now=True, null=True)), | ||
('pulp_type', models.TextField(default=None)), | ||
('name', models.TextField(db_index=True, unique=True)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.DeleteModel( | ||
name='FileSystemExporter', | ||
), | ||
migrations.CreateModel( | ||
name='PulpExporter', | ||
fields=[ | ||
('exporter_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='core_pulp_exporter', serialize=False, to='core.Exporter')), | ||
], | ||
options={ | ||
'default_related_name': '%(app_label)s_pulp_exporter', | ||
}, | ||
bases=('core.exporter',), | ||
), | ||
migrations.AddField( | ||
model_name='export', | ||
name='exporter', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Exporter'), | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from pulpcore.app.tasks import base, repository, upload # noqa | ||
|
||
from .export import file_system_export # noqa | ||
|
||
from .orphan import orphan_cleanup # noqa |
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,40 @@ | ||
import logging | ||
|
||
from gettext import gettext as _ | ||
|
||
from pulpcore.app.models import Exporter, Publication, RepositoryVersion | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def file_system_export(exporter_pk, publication_pk=None, repository_version_pk=None): | ||
""" | ||
Export to the file system. | ||
Args: | ||
exporter_pk (str): FileSystemExporter pk | ||
publication_pk (str): Publication pk | ||
publication_pk (str): RepositoryVersion pk | ||
""" | ||
exporter = Exporter.objects.get(pk=exporter_pk).cast() | ||
|
||
if publication_pk: | ||
publication = Publication.objects.get(pk=publication_pk).cast() | ||
|
||
log.info( | ||
_( | ||
"Exporting: file_system_exporter={exporter}, publication={publication}, path=path" | ||
).format(exporter=exporter.name, publication=publication.pk, path=exporter.path) | ||
) | ||
exporter.export_publication(publication) | ||
elif repository_version_pk: | ||
repository_version = RepositoryVersion.objects.get(pk=repository_version_pk) | ||
|
||
log.info( | ||
_( | ||
"Exporting: file_system_exporter={exporter}, publication={publication}, path=path" | ||
).format(exporter=exporter.name, publication=publication.pk, path=exporter.path) | ||
) | ||
exporter.export_repository_version(repository_version) |
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.