Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added support for importing Pulp Exports
fixes #6329 fixes #6137
- Loading branch information
David Davis
committed
Apr 14, 2020
1 parent
bab111c
commit be696b2
Showing
20 changed files
with
614 additions
and
13 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 API for importing Pulp Exports at ``POST /importers/core/pulp/<uuid>/imports/``. |
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,2 @@ | ||
Added PulpImporter API at ``/pulp/api/v3/importers/core/pulp/``. PulpImporters are used for | ||
importing exports from Pulp. |
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,2 @@ | ||
Added models Import and Importer (as well as serializers and viewsets) that can be used for | ||
importing data into Pulp. |
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
85 changes: 85 additions & 0 deletions
85
pulpcore/app/migrations/0028_import_importer_pulpimporter_pulpimporterrepository.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,85 @@ | ||
# Generated by Django 2.2.11 on 2020-04-13 16:39 | ||
|
||
import django.contrib.postgres.fields.jsonb | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0027_export_backend'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Import', | ||
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)), | ||
('params', django.contrib.postgres.fields.jsonb.JSONField(null=True)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Importer', | ||
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.CreateModel( | ||
name='PulpImport', | ||
fields=[ | ||
('import_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='core_pulp_export', serialize=False, to='core.Import')), | ||
], | ||
options={ | ||
'default_related_name': '%(app_label)s_pulp_export', | ||
}, | ||
bases=('core.import',), | ||
), | ||
migrations.CreateModel( | ||
name='PulpImporter', | ||
fields=[ | ||
('importer_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='core_pulp_importer', serialize=False, to='core.Importer')), | ||
], | ||
options={ | ||
'default_related_name': '%(app_label)s_pulp_importer', | ||
}, | ||
bases=('core.importer',), | ||
), | ||
migrations.AddField( | ||
model_name='import', | ||
name='importer', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Importer'), | ||
), | ||
migrations.AddField( | ||
model_name='import', | ||
name='task', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='core.Task'), | ||
), | ||
migrations.CreateModel( | ||
name='PulpImporterRepository', | ||
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)), | ||
('source_repo', models.TextField()), | ||
('repository', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Repository')), | ||
('pulp_importer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='repo_map', to='core.PulpImporter')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
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,84 @@ | ||
from django.contrib.postgres.fields import JSONField | ||
from django.db import models | ||
|
||
from pulpcore.app.models import ( | ||
BaseModel, | ||
MasterModel, | ||
) | ||
from .repository import Repository | ||
|
||
|
||
class Import(BaseModel): | ||
""" | ||
A model that represents imports into Pulp. | ||
Fields: | ||
params (models.JSONField): A set of parameters used to run the import | ||
Relations: | ||
task (models.ForeignKey): The Task that ran the import | ||
importer (models.ForeignKey): The Importer that imported the export | ||
""" | ||
params = JSONField(null=True) | ||
task = models.ForeignKey("Task", on_delete=models.PROTECT) | ||
importer = models.ForeignKey("Importer", on_delete=models.CASCADE) | ||
|
||
|
||
class Importer(MasterModel): | ||
""" | ||
A base model that provides logic to import data into Pulp. | ||
Can be extended by plugins to provide import functionality. | ||
Fields: | ||
name (models.TextField): The importer unique name. | ||
""" | ||
name = models.TextField(db_index=True, unique=True) | ||
|
||
|
||
class PulpImporter(Importer): | ||
""" | ||
A model that can be used to import exports from other Pulp instances. | ||
""" | ||
TYPE = 'pulp' | ||
|
||
@property | ||
def repo_mapping(self): | ||
return {repo.source_repo: repo.repository.name for repo in self.repo_map.all()} | ||
|
||
@repo_mapping.setter | ||
def repo_mapping(self, mapping): | ||
self.repo_map.all().delete() | ||
for source, repo_name in mapping.items(): | ||
repo = Repository.objects.get(name=repo_name) | ||
self.repo_map.create(source_repo=source, | ||
repository=repo) | ||
|
||
class Meta: | ||
default_related_name = '%(app_label)s_pulp_importer' | ||
|
||
|
||
class PulpImporterRepository(BaseModel): | ||
""" | ||
A model that maps repo names in an export to repos in Pulp. | ||
Fields: | ||
source_repo (models.TextField): The name of the repo in the export | ||
Relations: | ||
pulp_importer (models.ForeignKey): The associated Pulp importer | ||
repository (models.ForeignKey): The repository in Pulp | ||
""" | ||
source_repo = models.TextField() | ||
pulp_importer = models.ForeignKey( | ||
PulpImporter, | ||
related_name="repo_map", | ||
on_delete=models.CASCADE) | ||
repository = models.ForeignKey(Repository, on_delete=models.CASCADE) | ||
|
||
|
||
class PulpImport(Import): | ||
"""A model that represents imports into Pulp from another Pulp instance.""" | ||
|
||
class Meta: | ||
default_related_name = '%(app_label)s_pulp_export' |
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.