Skip to content

Commit

Permalink
Added instance names to floating ip table.
Browse files Browse the repository at this point in the history
    * fixes bug 966764

Change-Id: Id88c7c392a81423c8e530bab43c246164ffb3fa7
  • Loading branch information
emmasteimann committed May 5, 2012
1 parent 041b1c4 commit 5645aa0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ def single(self, table, request, obj_id):
return shortcuts.redirect('horizon:nova:access_and_security:index')


def get_instance_info(instance):
info_string = _("%(INSTANCE_NAME)s (%(INSTANCE_ID)s)")
if instance.instance_id and instance.instance_name:
vals = {'INSTANCE_NAME': instance.instance_name,
'INSTANCE_ID': instance.instance_id}
return info_string % vals
return _("Not available")


def get_instance_link(datum):
view = "horizon:nova:instances_and_volumes:instances:detail"
if datum.instance_id:
Expand All @@ -98,7 +107,7 @@ def get_instance_link(datum):

class FloatingIPsTable(tables.DataTable):
ip = tables.Column("ip", verbose_name=_("IP Address"))
instance = tables.Column("instance_id",
instance = tables.Column(get_instance_info,
link=get_instance_link,
verbose_name=_("Instance"),
empty_value="-")
Expand Down
14 changes: 14 additions & 0 deletions horizon/dashboards/nova/access_and_security/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,18 @@ def get_floating_ips_data(self):
LOG.exception("ClientException in floating ip index")
messages.error(self.request,
_('Error fetching floating ips: %s') % e)

instances = []
try:
instances = api.nova.server_list(self.request, all_tenants=True)
except:
exceptions.handle(self.request,
_('Unable to retrieve instance list.'))

instances_dict = {obj.id: obj for obj in instances}

for ip in floating_ips:
ip.instance_name = instances_dict[ip.instance_id].name \
if ip.instance_id in instances_dict else None

return floating_ips

0 comments on commit 5645aa0

Please sign in to comment.