Skip to content

Commit

Permalink
Cloud images - support duplicated names
Browse files Browse the repository at this point in the history
  • Loading branch information
tomez committed Jun 25, 2019
1 parent bd2d884 commit faf0b80
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ralph/virtual/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ class CloudProviderAdmin(RalphAdmin):
@register(CloudImage)
class CloudImageAdmin(RalphAdmin):
list_display = ['name', 'image_id']
list_filter = ['name', 'image_id']
list_filter = ['name']

fieldsets = (
('Cloud Image', {
Expand Down
5 changes: 3 additions & 2 deletions src/ralph/virtual/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ralph.data_center.models import DCHost
from ralph.security.api import SecurityScanSerializer
from ralph.security.models import SecurityScan
from ralph.virtual.admin import CloudFlavorAdmin, VirtualServerAdmin
from ralph.virtual.admin import VirtualServerAdmin
from ralph.virtual.models import (
CloudFlavor,
CloudHost,
Expand Down Expand Up @@ -178,7 +178,7 @@ class CloudFlavorViewSet(RalphAPIViewSet):
serializer_class = CloudFlavorSerializer
save_serializer_class = SaveCloudFlavorSerializer
prefetch_related = ['tags', 'virtualcomponent_set__model']
list_filter = CloudFlavorAdmin.list_filter + ['flavor_id']
filter_fields = ['flavor_id']


class CloudProviderViewSet(RalphAPIViewSet):
Expand All @@ -189,6 +189,7 @@ class CloudProviderViewSet(RalphAPIViewSet):
class CloudImageViewSet(RalphAPIViewSet):
queryset = CloudImage.objects.all()
serializer_class = CloudImageSerializer
filter_fields = ['image_id']


class CloudHostViewSet(BaseObjectViewSetMixin, RalphAPIViewSet):
Expand Down
23 changes: 23 additions & 0 deletions src/ralph/virtual/migrations/0013_auto_20190625_1239.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('virtual', '0012_cloudimage'),
]

operations = [
migrations.AlterModelOptions(
name='cloudimage',
options={},
),
migrations.AlterField(
model_name='cloudimage',
name='name',
field=models.CharField(max_length=200),
),
]
7 changes: 2 additions & 5 deletions src/ralph/virtual/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,13 @@ def __str__(self):
return 'Cloud Project: {}'.format(self.name)


class CloudImage(AdminAbsoluteUrlMixin, NamedMixin):
class Meta:
verbose_name = _('Cloud image')
verbose_name_plural = _('Cloud images')

class CloudImage(AdminAbsoluteUrlMixin, models.Model):
image_id = models.CharField(
verbose_name=_('image ID'),
unique=True,
max_length=100
)
name = models.CharField(max_length=200, unique=False)

def __str__(self):
return 'Cloud Image: {}'.format(self.name)
Expand Down

0 comments on commit faf0b80

Please sign in to comment.