Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Rename docker Tag and Blob models.
Browse files Browse the repository at this point in the history
  • Loading branch information
ipanova committed Aug 9, 2019
1 parent e344271 commit 12c86f5
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 76 deletions.
1 change: 1 addition & 0 deletions CHANGES/5218.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rename docker Tag and Blob models.
2 changes: 1 addition & 1 deletion docs/_static/api.json

Large diffs are not rendered by default.

48 changes: 20 additions & 28 deletions docs/workflows/sync.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,44 +108,36 @@ Response:
.. code:: json
{
"_created": "2019-03-26T15:54:06.448675Z",
"_href": "/pulp/api/v3/repositories/39520001-18e9-4c17-a703-2963a7837060/versions/1/",
"_created": "2019-08-07T20:46:11.311539Z",
"_href": "/pulp/api/v3/repositories/84a3ea29-1444-43c6-92da-14da25f543ec/versions/1/",
"base_version": null,
"content_summary": {
"added": {
"docker.manifest": {
"count": 37,
"href": "/pulp/api/v3/content/docker/manifests/?repository_version_added=/pulp/api/v3/repositories/39520001-18e9-4c17-a703-2963a7837060/versions/1/"
},
"docker.manifest-blob": {
"count": 74,
"href": "/pulp/api/v3/content/docker/blobs/?repository_version_added=/pulp/api/v3/repositories/39520001-18e9-4c17-a703-2963a7837060/versions/1/"
"docker.blob": {
"count": 487,
"href": "/pulp/api/v3/content/docker/blobs/?repository_version_added=/pulp/api/v3/repositories/84a3ea29-1444-43c6-92da-14da25f543ec/versions/1/"
},
"docker.manifest-list": {
"count": 10,
"href": "/pulp/api/v3/content/docker/manifest-lists/?repository_version_added=/pulp/api/v3/repositories/39520001-18e9-4c17-a703-2963a7837060/versions/1/"
"docker.manifest": {
"count": 307,
"href": "/pulp/api/v3/content/docker/manifests/?repository_version_added=/pulp/api/v3/repositories/84a3ea29-1444-43c6-92da-14da25f543ec/versions/1/"
},
"docker.manifest-list-tag": {
"count": 16,
"href": "/pulp/api/v3/content/docker/manifest-list-tags/?repository_version_added=/pulp/api/v3/repositories/39520001-18e9-4c17-a703-2963a7837060/versions/1/"
"docker.tag": {
"count": 135,
"href": "/pulp/api/v3/content/docker/tags/?repository_version_added=/pulp/api/v3/repositories/84a3ea29-1444-43c6-92da-14da25f543ec/versions/1/"
}
},
"present": {
"docker.manifest": {
"count": 37,
"href": "/pulp/api/v3/content/docker/manifests/?repository_version=/pulp/api/v3/repositories/39520001-18e9-4c17-a703-2963a7837060/versions/1/"
},
"docker.manifest-blob": {
"count": 74,
"href": "/pulp/api/v3/content/docker/blobs/?repository_version=/pulp/api/v3/repositories/39520001-18e9-4c17-a703-2963a7837060/versions/1/"
"docker.blob": {
"count": 487,
"href": "/pulp/api/v3/content/docker/blobs/?repository_version=/pulp/api/v3/repositories/84a3ea29-1444-43c6-92da-14da25f543ec/versions/1/"
},
"docker.manifest-list": {
"count": 10,
"href": "/pulp/api/v3/content/docker/manifest-lists/?repository_version=/pulp/api/v3/repositories/39520001-18e9-4c17-a703-2963a7837060/versions/1/"
"docker.manifest": {
"count": 307,
"href": "/pulp/api/v3/content/docker/manifests/?repository_version=/pulp/api/v3/repositories/84a3ea29-1444-43c6-92da-14da25f543ec/versions/1/"
},
"docker.manifest-list-tag": {
"count": 16,
"href": "/pulp/api/v3/content/docker/manifest-list-tags/?repository_version=/pulp/api/v3/repositories/39520001-18e9-4c17-a703-2963a7837060/versions/1/"
"docker.tag": {
"count": 135,
"href": "/pulp/api/v3/content/docker/tags/?repository_version=/pulp/api/v3/repositories/84a3ea29-1444-43c6-92da-14da25f543ec/versions/1/"
}
},
"removed": {}
Expand Down
26 changes: 26 additions & 0 deletions pulp_docker/app/migrations/0002_rename_tag_blob_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 2.2.1 on 2019-08-05 15:09

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0002_increase_artifact_size_field'),
('docker', '0001_initial'),
]

operations = [
migrations.RenameModel(
old_name='ManifestBlob',
new_name='Blob',
),
migrations.RenameModel(
old_name='BlobManifestBlob',
new_name='BlobManifest',
),
migrations.RenameModel(
old_name='ManifestTag',
new_name='Tag',
),
]
20 changes: 10 additions & 10 deletions pulp_docker/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)


class ManifestBlob(Content):
class Blob(Content):
"""
A blob defined within a manifest.
Expand All @@ -39,7 +39,7 @@ class ManifestBlob(Content):
manifest (models.ForeignKey): Many-to-one relationship with Manifest.
"""

TYPE = 'manifest-blob'
TYPE = 'blob'

BLOB_CHOICES = (
(MEDIA_TYPE.CONFIG_BLOB, MEDIA_TYPE.CONFIG_BLOB),
Expand Down Expand Up @@ -68,7 +68,7 @@ class Manifest(Content):
media_type (models.CharField): The manifest media type.
Relations:
blobs (models.ManyToManyField): Many-to-many relationship with ManifestBlob.
blobs (models.ManyToManyField): Many-to-many relationship with Blob.
config_blob (models.ForeignKey): Blob that contains configuration for this Manifest.
listed_manifests (models.ManyToManyField): Many-to-many relationship with Manifest. This
field is used only for a manifest-list type Manifests.
Expand All @@ -87,8 +87,8 @@ class Manifest(Content):
max_length=60,
choices=MANIFEST_CHOICES)

blobs = models.ManyToManyField(ManifestBlob, through='BlobManifestBlob')
config_blob = models.ForeignKey(ManifestBlob, related_name='config_blob',
blobs = models.ManyToManyField(Blob, through='BlobManifest')
config_blob = models.ForeignKey(Blob, related_name='config_blob',
null=True, on_delete=models.CASCADE)

# Order matters for through fields, (source, target)
Expand All @@ -103,15 +103,15 @@ class Meta:
unique_together = ('digest',)


class BlobManifestBlob(models.Model):
class BlobManifest(models.Model):
"""
Many-to-many relationship between ManifestBlobs and ImageManifests.
Many-to-many relationship between Blobs and Manifests.
"""

manifest = models.ForeignKey(
Manifest, related_name='blob_manifests', on_delete=models.CASCADE)
manifest_blob = models.ForeignKey(
ManifestBlob, related_name='manifest_blobs', on_delete=models.CASCADE)
Blob, related_name='manifest_blobs', on_delete=models.CASCADE)

class Meta:
unique_together = ('manifest', 'manifest_blob')
Expand Down Expand Up @@ -150,7 +150,7 @@ class Meta:
unique_together = ('image_manifest', 'manifest_list')


class ManifestTag(Content):
class Tag(Content):
"""
A tagged Manifest.
Expand All @@ -162,7 +162,7 @@ class ManifestTag(Content):
"""

TYPE = 'manifest-tag'
TYPE = 'tag'

name = models.CharField(max_length=255, db_index=True)

Expand Down
8 changes: 4 additions & 4 deletions pulp_docker/app/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pulpcore.plugin.content import Handler, PathNotResolved
from pulpcore.plugin.models import ContentArtifact
from pulp_docker.app.models import DockerDistribution, ManifestTag, MEDIA_TYPE
from pulp_docker.app.models import DockerDistribution, Tag, MEDIA_TYPE


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -106,7 +106,7 @@ async def tags_list(self, request):
repository_version = distribution.get_repository_version()
for c in repository_version.content:
c = c.cast()
if isinstance(c, ManifestTag):
if isinstance(c, Tag):
tags['tags'].add(c.name)
tags['tags'] = list(tags['tags'])
return web.json_response(tags)
Expand Down Expand Up @@ -134,7 +134,7 @@ async def get_tag(self, request):
accepted_media_types = await Registry.get_accepted_media_types(request)

try:
tag = ManifestTag.objects.get(
tag = Tag.objects.get(
pk__in=repository_version.content,
name=tag_name,
)
Expand Down Expand Up @@ -168,7 +168,7 @@ async def dispatch_tag(tag, response_headers):
Finds an artifact associated with a Tag and sends it to the client.
Args:
tag: Either a ManifestTag or ManifestListTag
tag: Tag
response_headers (dict): dictionary that contains the 'Content-Type' header to send
with the response
Expand Down
12 changes: 6 additions & 6 deletions pulp_docker/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from . import models


class ManifestTagSerializer(SingleArtifactContentSerializer):
class TagSerializer(SingleArtifactContentSerializer):
"""
Serializer for ManifestTags.
Serializer for Tags.
"""

name = serializers.CharField(help_text="Tag name")
Expand All @@ -33,7 +33,7 @@ class Meta:
'name',
'tagged_manifest',
)
model = models.ManifestTag
model = models.Tag


class ManifestSerializer(SingleArtifactContentSerializer):
Expand All @@ -54,13 +54,13 @@ class ManifestSerializer(SingleArtifactContentSerializer):
many=True,
help_text="Blobs that are referenced by this Manifest",
view_name='docker-blobs-detail',
queryset=models.ManifestBlob.objects.all()
queryset=models.Blob.objects.all()
)
config_blob = DetailRelatedField(
many=False,
help_text="Blob that contains configuration for this Manifest",
view_name='docker-blobs-detail',
queryset=models.ManifestBlob.objects.all()
queryset=models.Blob.objects.all()
)

class Meta:
Expand Down Expand Up @@ -88,7 +88,7 @@ class Meta:
'digest',
'media_type',
)
model = models.ManifestBlob
model = models.Blob


class RegistryPathField(serializers.CharField):
Expand Down
20 changes: 10 additions & 10 deletions pulp_docker/app/tasks/sync_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from pulpcore.plugin.models import Artifact, ProgressBar, Remote
from pulpcore.plugin.stages import DeclarativeArtifact, DeclarativeContent, Stage

from pulp_docker.app.models import (Manifest, MEDIA_TYPE, ManifestBlob, ManifestTag,
BlobManifestBlob, ManifestListManifest)
from pulp_docker.app.models import (Manifest, MEDIA_TYPE, Blob, Tag,
BlobManifest, ManifestListManifest)


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -175,7 +175,7 @@ def create_tag(self, saved_artifact, url):
tag=tag_name,
)
url = urljoin(self.remote.url, relative_url)
tag = ManifestTag(name=tag_name)
tag = Tag(name=tag_name)
da = DeclarativeArtifact(
artifact=saved_artifact,
url=url,
Expand Down Expand Up @@ -296,7 +296,7 @@ def create_blob(self, man_dc, blob_data):
"""
digest = blob_data.get('digest') or blob_data.get('blobSum')
blob_artifact = Artifact(sha256=digest[len("sha256:"):])
blob = ManifestBlob(
blob = Blob(
digest=digest,
media_type=blob_data.get('mediaType', MEDIA_TYPE.REGULAR_BLOB),
)
Expand Down Expand Up @@ -434,7 +434,7 @@ async def run(self):

def relate_config_blob(self, dc):
"""
Relate a ManifestBlob to a Manifest as a config layer.
Relate a Blob to a Manifest as a config layer.
Args:
dc (pulpcore.plugin.stages.DeclarativeContent): dc for a Blob
Expand All @@ -445,13 +445,13 @@ def relate_config_blob(self, dc):

def relate_blob(self, dc):
"""
Relate a ManifestBlob to a Manifest.
Relate a Blob to a Manifest.
Args:
dc (pulpcore.plugin.stages.DeclarativeContent): dc for a Blob
"""
related_dc = dc.extra_data.get('blob_relation')
thru = BlobManifestBlob(manifest=related_dc.content, manifest_blob=dc.content)
thru = BlobManifest(manifest=related_dc.content, manifest_blob=dc.content)
try:
thru.save()
except IntegrityError:
Expand All @@ -462,15 +462,15 @@ def relate_manifest_tag(self, dc):
Relate an ImageManifest to a Tag.
Args:
dc (pulpcore.plugin.stages.DeclarativeContent): dc for a ManifestTag
dc (pulpcore.plugin.stages.DeclarativeContent): dc for a Tag
"""
related_dc = dc.extra_data.get('man_relation')
dc.content.tagged_manifest = related_dc.content
try:
dc.content.save()
except IntegrityError:
existing_tag = ManifestTag.objects.get(name=dc.content.name,
tagged_manifest=related_dc.content)
existing_tag = Tag.objects.get(name=dc.content.name,
tagged_manifest=related_dc.content)
dc.content = existing_tag

def relate_manifest_to_list(self, dc):
Expand Down
4 changes: 2 additions & 2 deletions pulp_docker/app/tasks/synchronize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)

from .sync_stages import InterrelateContent, DockerFirstStage
from pulp_docker.app.models import DockerRemote, ManifestTag
from pulp_docker.app.models import DockerRemote, Tag


log = logging.getLogger(__name__)
Expand All @@ -39,7 +39,7 @@ def synchronize(remote_pk, repository_pk):
repository = Repository.objects.get(pk=repository_pk)
if not remote.url:
raise ValueError(_('A remote must have a url specified to synchronize.'))
remove_duplicate_tags = [{'model': ManifestTag, 'field_names': ['name']}]
remove_duplicate_tags = [{'model': Tag, 'field_names': ['name']}]
log.info(_('Synchronizing: repository={r} remote={p}').format(
r=repository.name, p=remote.name))
first_stage = DockerFirstStage(remote)
Expand Down

0 comments on commit 12c86f5

Please sign in to comment.