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 7, 2019
1 parent e344271 commit cb6d9b7
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 48 deletions.
2 changes: 2 additions & 0 deletions CHANGES/5218.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Rename docker Tag and Blob models.

2 changes: 1 addition & 1 deletion docs/_static/api.json

Large diffs are not rendered by default.

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
28 changes: 14 additions & 14 deletions pulp_docker/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from . import models, serializers, tasks


class ManifestTagFilter(ContentFilter):
class TagFilter(ContentFilter):
"""
FilterSet for Tags.
"""
Expand All @@ -39,7 +39,7 @@ class ManifestTagFilter(ContentFilter):
digest = CharFilter(field_name='tagged_manifest__digest')

class Meta:
model = models.ManifestTag
model = models.Tag
fields = {
'name': ['exact', 'in'],
}
Expand All @@ -59,20 +59,20 @@ class Meta:
}


class ManifestTagViewSet(ContentViewSet):
class TagViewSet(ContentViewSet):
"""
ViewSet for ManifestTag.
ViewSet for Tag.
"""

endpoint_name = 'manifest-tags'
queryset = models.ManifestTag.objects.all()
serializer_class = serializers.ManifestTagSerializer
filterset_class = ManifestTagFilter
endpoint_name = 'tags'
queryset = models.Tag.objects.all()
serializer_class = serializers.TagSerializer
filterset_class = TagFilter

@transaction.atomic
def create(self, request):
"""
Create a new ManifestTag from a request.
Create a new Tag from a request.
"""
raise NotImplementedError()

Expand Down Expand Up @@ -100,29 +100,29 @@ class BlobFilter(ContentFilter):
FilterSet for Blobs.
"""

media_type = MultipleChoiceFilter(choices=models.ManifestBlob.BLOB_CHOICES)
media_type = MultipleChoiceFilter(choices=models.Blob.BLOB_CHOICES)

class Meta:
model = models.ManifestBlob
model = models.Blob
fields = {
'digest': ['exact', 'in'],
}


class BlobViewSet(ContentViewSet):
"""
ViewSet for ManifestBlobs.
ViewSet for Blobs.
"""

endpoint_name = 'blobs'
queryset = models.ManifestBlob.objects.all()
queryset = models.Blob.objects.all()
serializer_class = serializers.BlobSerializer
filterset_class = BlobFilter

@transaction.atomic
def create(self, request):
"""
Create a new ManifestBlob from a request.
Create a new Blob from a request.
"""
raise NotImplementedError()

Expand Down
2 changes: 1 addition & 1 deletion pulp_docker/tests/functional/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# FIXME: replace 'unit' with your own content type names, and duplicate as necessary for each type
DOCKER_CONTENT_PATH = urljoin(CONTENT_PATH, 'docker/units/')

DOCKER_CONTENT_NAME = 'docker.manifest-blob'
DOCKER_CONTENT_NAME = 'docker.blob'

DOCKER_DISTRIBUTION_PATH = urljoin(BASE_DISTRIBUTION_PATH, 'docker/docker/')

Expand Down

0 comments on commit cb6d9b7

Please sign in to comment.