Fix display of volumes and snapshots

* displayName -> display_name
 * displayDescription -> display_description
 * serverId -> server_id
 * volumeId -> volume_id
 * fixes bug 967408

Change-Id: I05b66716246be4f010719a51c242dc74811549c0
This commit is contained in:
Vishvananda Ishaya 2012-03-28 18:50:44 +00:00
parent b2ff1ee446
commit e2b3ac8854
10 changed files with 31 additions and 30 deletions

View File

@ -111,14 +111,14 @@ class LaunchView(forms.ModalFormView):
volume_options = [("", _("Select Volume"))] volume_options = [("", _("Select Volume"))]
def _get_volume_select_item(volume): def _get_volume_select_item(volume):
if hasattr(volume, "volumeId"): if hasattr(volume, "volume_id"):
vol_type = "snap" vol_type = "snap"
visible_label = _("Snapshot") visible_label = _("Snapshot")
else: else:
vol_type = "vol" vol_type = "vol"
visible_label = _("Volume") visible_label = _("Volume")
return (("%s:%s" % (volume.id, vol_type)), return (("%s:%s" % (volume.id, vol_type)),
("%s - %s GB (%s)" % (volume.displayName, ("%s - %s GB (%s)" % (volume.display_name,
volume.size, volume.size,
visible_label))) visible_label)))

View File

@ -35,7 +35,7 @@ class DeleteVolumeSnapshot(tables.DeleteAction):
class VolumeSnapshotsTable(volume_tables.VolumesTableBase): class VolumeSnapshotsTable(volume_tables.VolumesTableBase):
volume_id = tables.Column("volumeId", verbose_name=_("Volume ID")) volume_id = tables.Column("volume_id", verbose_name=_("Volume ID"))
class Meta: class Meta:
name = "volume_snapshots" name = "volume_snapshots"

View File

@ -46,16 +46,16 @@ class VolumeSnapshotsViewTests(test.TestCase):
self.mox.StubOutWithMock(api, 'volume_snapshot_create') self.mox.StubOutWithMock(api, 'volume_snapshot_create')
api.volume_snapshot_create(IsA(http.HttpRequest), api.volume_snapshot_create(IsA(http.HttpRequest),
volume.id, volume.id,
snapshot.displayName, snapshot.display_name,
snapshot.displayDescription) \ snapshot.display_description) \
.AndReturn(snapshot) .AndReturn(snapshot)
self.mox.ReplayAll() self.mox.ReplayAll()
formData = {'method': 'CreateSnapshotForm', formData = {'method': 'CreateSnapshotForm',
'tenant_id': self.tenant.id, 'tenant_id': self.tenant.id,
'volume_id': volume.id, 'volume_id': volume.id,
'name': snapshot.displayName, 'name': snapshot.display_name,
'description': snapshot.displayDescription} 'description': snapshot.display_description}
url = reverse('horizon:nova:instances_and_volumes:volumes:' url = reverse('horizon:nova:instances_and_volumes:volumes:'
'create_snapshot', args=[volume.id]) 'create_snapshot', args=[volume.id])
res = self.client.post(url, formData) res = self.client.post(url, formData)

View File

@ -75,7 +75,7 @@ class AttachForm(forms.SelfHandlingForm):
data['volume_id'], data['volume_id'],
data['instance'], data['instance'],
data['device']) data['device'])
vol_name = api.volume_get(request, data['volume_id']).displayName vol_name = api.volume_get(request, data['volume_id']).display_name
message = (_('Attaching volume %(vol)s to instance ' message = (_('Attaching volume %(vol)s to instance '
'%(inst)s at %(dev)s') % '%(inst)s at %(dev)s') %

View File

@ -90,10 +90,10 @@ def get_attachment(volume):
# Filter out "empty" attachments which the client returns... # Filter out "empty" attachments which the client returns...
for attachment in [att for att in volume.attachments if att]: for attachment in [att for att in volume.attachments if att]:
url = reverse("%s:instances:detail" % URL_PREFIX, url = reverse("%s:instances:detail" % URL_PREFIX,
args=(attachment["serverId"],)) args=(attachment["server_id"],))
# TODO(jake): Make "instance" the instance name # TODO(jake): Make "instance" the instance name
vals = {"url": url, vals = {"url": url,
"instance": attachment["serverId"], "instance": attachment["server_id"],
"dev": attachment["device"]} "dev": attachment["device"]}
attachments.append(link % vals) attachments.append(link % vals)
return safestring.mark_safe(", ".join(attachments)) return safestring.mark_safe(", ".join(attachments))
@ -106,9 +106,9 @@ class VolumesTableBase(tables.DataTable):
("creating", None), ("creating", None),
("error", False), ("error", False),
) )
name = tables.Column("displayName", verbose_name=_("Name"), name = tables.Column("display_name", verbose_name=_("Name"),
link="%s:volumes:detail" % URL_PREFIX) link="%s:volumes:detail" % URL_PREFIX)
description = tables.Column("displayDescription", description = tables.Column("display_description",
verbose_name=_("Description")) verbose_name=_("Description"))
size = tables.Column(get_size, verbose_name=_("Size")) size = tables.Column(get_size, verbose_name=_("Size"))
status = tables.Column("status", status = tables.Column("status",
@ -118,11 +118,11 @@ class VolumesTableBase(tables.DataTable):
status_choices=STATUS_CHOICES) status_choices=STATUS_CHOICES)
def get_object_display(self, obj): def get_object_display(self, obj):
return obj.displayName return obj.display_name
class VolumesTable(VolumesTableBase): class VolumesTable(VolumesTableBase):
name = tables.Column("displayName", name = tables.Column("display_name",
verbose_name=_("Name"), verbose_name=_("Name"),
link="%s:volumes:detail" % URL_PREFIX) link="%s:volumes:detail" % URL_PREFIX)
attachments = tables.Column(get_attachment, attachments = tables.Column(get_attachment,
@ -146,7 +146,7 @@ class DetachVolume(tables.BatchAction):
classes = ('btn-danger', 'btn-detach') classes = ('btn-danger', 'btn-detach')
def action(self, request, obj_id): def action(self, request, obj_id):
instance_id = self.table.get_object_by_id(obj_id)['serverId'] instance_id = self.table.get_object_by_id(obj_id)['server_id']
api.volume_detach(request, instance_id, obj_id) api.volume_detach(request, instance_id, obj_id)
def get_success_url(self, request): def get_success_url(self, request):
@ -154,7 +154,7 @@ class DetachVolume(tables.BatchAction):
class AttachmentsTable(tables.DataTable): class AttachmentsTable(tables.DataTable):
instance = tables.Column("serverId", verbose_name=_("Instance")) instance = tables.Column("server_id", verbose_name=_("Instance"))
device = tables.Column("device") device = tables.Column("device")
def get_object_id(self, obj): def get_object_id(self, obj):
@ -162,7 +162,7 @@ class AttachmentsTable(tables.DataTable):
def get_object_display(self, obj): def get_object_display(self, obj):
vals = {"dev": obj['device'], vals = {"dev": obj['device'],
"instance": obj['serverId']} "instance": obj['server_id']}
return "Attachment %(dev)s on %(instance)s" % vals return "Attachment %(dev)s on %(instance)s" % vals
def get_object_by_id(self, obj_id): def get_object_by_id(self, obj_id):

View File

@ -33,7 +33,8 @@ class OverviewTab(tabs.Tab):
try: try:
volume = api.nova.volume_get(request, volume_id) volume = api.nova.volume_get(request, volume_id)
for att in volume.attachments: for att in volume.attachments:
att['instance'] = api.nova.server_get(request, att['serverId']) att['instance'] = api.nova.server_get(request,
att['server_id'])
except: except:
redirect = reverse('horizon:nova:instances_and_volumes:index') redirect = reverse('horizon:nova:instances_and_volumes:index')
exceptions.handle(self.request, exceptions.handle(self.request,

View File

@ -49,7 +49,7 @@ class VolumeViewTests(test.TestCase):
def test_detail_view(self): def test_detail_view(self):
volume = self.volumes.first() volume = self.volumes.first()
server = self.servers.first() server = self.servers.first()
volume.attachments = [{"serverId": server.id}] volume.attachments = [{"server_id": server.id}]
self.mox.StubOutWithMock(api.nova, 'volume_get') self.mox.StubOutWithMock(api.nova, 'volume_get')
self.mox.StubOutWithMock(api.nova, 'server_get') self.mox.StubOutWithMock(api.nova, 'server_get')
api.nova.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume) api.nova.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)

View File

@ -80,8 +80,8 @@
{% for volume in instance.volumes %} {% for volume in instance.volumes %}
<li> <li>
<strong>{% trans "Volume" %}:</strong> <strong>{% trans "Volume" %}:</strong>
<a href="{% url horizon:nova:instances_and_volumes:volumes:detail volume.volumeId %}"> <a href="{% url horizon:nova:instances_and_volumes:volumes:detail volume.volume_id %}">
{{ volume.volumeId }}&nbsp;({{ volume.device }}) {{ volume.volume_id }}&nbsp;({{ volume.device }})
</a> </a>
</li> </li>
{% endfor %} {% endfor %}

View File

@ -1,15 +1,15 @@
{% load i18n sizeformat parse_date %} {% load i18n sizeformat parse_date %}
<h3>{% trans "Volume Overview" %}: {{volume.displayName }}</h3> <h3>{% trans "Volume Overview" %}: {{volume.display_name }}</h3>
<div class="info row-fluid"> <div class="info row-fluid">
<h4>{% trans "Info" %}</h4> <h4>{% trans "Info" %}</h4>
<hr class="header_rule"> <hr class="header_rule">
<ul> <ul>
<li><strong>{% trans "Name" %}:</strong>&nbsp;{{ volume.displayName }}</li> <li><strong>{% trans "Name" %}:</strong>&nbsp;{{ volume.display_name }}</li>
<li><strong>{% trans "ID" %}:</strong>&nbsp;{{ volume.id }}</li> <li><strong>{% trans "ID" %}:</strong>&nbsp;{{ volume.id }}</li>
{% if volume.displayDescription %} {% if volume.display_description %}
<li><strong>{% trans "Description" %}:</strong>&nbsp;{{ volume.displayDescription }}</li> <li><strong>{% trans "Description" %}:</strong>&nbsp;{{ volume.display_description }}</li>
{% endif %} {% endif %}
</ul> </ul>
</div> </div>
@ -38,7 +38,7 @@
{% for attachment in volume.attachments %} {% for attachment in volume.attachments %}
<li> <li>
<strong>{% trans "Attached To" %}:</strong> <strong>{% trans "Attached To" %}:</strong>
{% url horizon:nova:instances_and_volumes:volumes:detail attachment.serverId as instance_url%} {% url horizon:nova:instances_and_volumes:volumes:detail attachment.server_id as instance_url%}
<a href="{{ instance_url }}">{% trans "Instance" %}&nbsp;{{ attachment.instance.id }} ({{ attachment.instance.name }})</a> <a href="{{ instance_url }}">{% trans "Instance" %}&nbsp;{{ attachment.instance.id }} ({{ attachment.instance.name }})</a>
<span>{% trans "on" %}&nbsp;{{ attachment.device }}</span> <span>{% trans "on" %}&nbsp;{{ attachment.device }}</span>
</li> </li>

View File

@ -147,7 +147,7 @@ def data(TEST):
name='test_volume', name='test_volume',
status='available', status='available',
size=40, size=40,
displayName='', display_name='',
attachments={})) attachments={}))
TEST.volumes.add(volume) TEST.volumes.add(volume)
@ -275,11 +275,11 @@ def data(TEST):
volume_snapshot = vol_snaps.Snapshot(vol_snaps.SnapshotManager(None), volume_snapshot = vol_snaps.Snapshot(vol_snaps.SnapshotManager(None),
{'id': 2, {'id': 2,
'displayName': 'test snapshot', 'display_name': 'test snapshot',
'displayDescription': 'vol snap!', 'display_description': 'vol snap!',
'size': 40, 'size': 40,
'status': 'available', 'status': 'available',
'volumeId': 1}) 'volume_id': 1})
TEST.volume_snapshots.add(volume_snapshot) TEST.volume_snapshots.add(volume_snapshot)
cert_data = {'private_key': 'private', cert_data = {'private_key': 'private',