Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding model/serializer and refresh endpoint. closes: #9358 https://pulp.plan.io/issues/9358
- Loading branch information
1 parent
e21ddd3
commit 3cc4402
Showing
12 changed files
with
369 additions
and
20 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 support for Alternate Content Sources. |
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,54 @@ | ||
Alternate Content Sources | ||
========================= | ||
|
||
Alternate Content Sources (ACS) can help speed up populating of new repositories. | ||
If you have content stored locally or geographically near you which matches | ||
the remote content, Alternate Content Sources will allow you to substitute | ||
this content, allowing for faster data transfer. | ||
|
||
`Alternate Content Sources <https://docs.pulpproject.org/pulpcore/workflows/alternate-content-sources.html>`_ | ||
base is provided by pulpcore plugin. | ||
|
||
To use an Alternate Content Source you need a ``RPMRemote`` with path of your ACS. | ||
|
||
.. warning:: | ||
|
||
Remotes with mirrorlist URLs cannot be used as an Alternative Content Source. | ||
|
||
.. code-block:: bash | ||
http POST $BASE_ADDR/pulp/api/v3/remotes/rpm/rpm/ name="myRemoteAcs" policy="on_demand" url="http://fixtures.pulpproject.org/rpm-unsigned/" | ||
Create Alternate Content Source | ||
------------------------------- | ||
|
||
Create an Alternate Content Source. | ||
|
||
.. code-block:: bash | ||
http POST $BASE_ADDR/pulp/api/v3/acs/rpm/rpm/ name="myAcs" remote=$REMOTE_HREF | ||
Alternate Content Source Paths | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
If you have more places with ACS within one base path you can specify them | ||
by paths and all of them will be considered as a ACS. | ||
|
||
.. code-block:: bash | ||
http POST $BASE_ADDR/pulp/api/v3/remotes/rpm/rpm/ name="myRemoteACS" policy="on_demand" url="http://fixtures.pulpproject.org/" | ||
http POST $BASE_ADDR/pulp/api/v3/acs/file/file/ name="myAcs" remote=$REMOTE_HREF paths:='["rpm-unsigned/", "rpm-distribution-tree/"]' | ||
Refresh Alternate Content Source | ||
-------------------------------- | ||
|
||
To make your ACS available for future syncs you need to call ``refresh`` endpoint | ||
on your ACS. This create a catalogue of available content which will be used instead | ||
new content if found. | ||
|
||
.. code-block:: bash | ||
http POST $BASE_ADDR/pulp/api/v3/acs/rpm/rpm/<ACS-UUID>/refresh/ | ||
Alternate Content Source has a global scope so if any content is found in ACS it | ||
will be used in all future syncs. |
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 |
---|---|---|
|
@@ -31,3 +31,4 @@ library with: | |
manage | ||
copy | ||
metadata_signing | ||
alternate-content-source |
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,36 @@ | ||
# Generated by Django 3.2.7 on 2021-09-17 10:47 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("core", "0076_remove_reserved_resource"), | ||
("rpm", "0037_update_json_field"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="RpmAlternateContentSource", | ||
fields=[ | ||
( | ||
"alternatecontentsource_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
related_name="rpm_rpmalternatecontentsource", | ||
serialize=False, | ||
to="core.alternatecontentsource", | ||
), | ||
), | ||
], | ||
options={ | ||
"default_related_name": "%(app_label)s_%(model_name)s", | ||
}, | ||
bases=("core.alternatecontentsource",), | ||
), | ||
] |
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,19 @@ | ||
from logging import getLogger | ||
|
||
from pulpcore.plugin.models import AlternateContentSource | ||
from pulp_rpm.app.models import RpmRemote | ||
|
||
|
||
log = getLogger(__name__) | ||
|
||
|
||
class RpmAlternateContentSource(AlternateContentSource): | ||
""" | ||
Alternate Content Source for 'RPM" content. | ||
""" | ||
|
||
TYPE = "rpm" | ||
REMOTE_TYPES = [RpmRemote] | ||
|
||
class Meta: | ||
default_related_name = "%(app_label)s_%(model_name)s" |
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,24 @@ | ||
from gettext import gettext as _ | ||
from rest_framework import serializers | ||
|
||
from pulpcore.plugin.serializers import AlternateContentSourceSerializer | ||
from pulp_rpm.app.models import RpmAlternateContentSource | ||
|
||
|
||
class RpmAlternateContentSourceSerializer(AlternateContentSourceSerializer): | ||
""" | ||
Serializer for RPM alternate content source. | ||
""" | ||
|
||
def validate_paths(self, paths): | ||
"""Validate that paths do not start with /.""" | ||
for path in paths: | ||
if path.startswith("/"): | ||
raise serializers.ValidationError(_("Path cannot start with a slash.")) | ||
if not path.endswith("/"): | ||
raise serializers.ValidationError(_("Path must end with a slash.")) | ||
return paths | ||
|
||
class Meta: | ||
fields = AlternateContentSourceSerializer.Meta.fields | ||
model = RpmAlternateContentSource |
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.