diff --git a/trove_dashboard/content/databases/tables.py b/trove_dashboard/content/databases/tables.py index bda1176..4a898d1 100644 --- a/trove_dashboard/content/databases/tables.py +++ b/trove_dashboard/content/databases/tables.py @@ -15,6 +15,7 @@ from urllib import parse as urlparse from django.conf import settings +from django import template from django.template import defaultfilters as d_filters from django import urls from django.urls import reverse @@ -573,11 +574,28 @@ def get_datastore_version(instance): return _("Not available") +# NOTE(e0ne): the logic is based on +# openstack_dashboard.dashboards.project.instances.tables.get_ips +# Trove has a different instance addresses structure so we can't re-use +# nova-related code as is. +def get_ips(instance): + template_name = 'project/instances/_instance_ips.html' + ip_groups = {} + + for address in getattr(instance, 'addresses', []): + ip_groups[address["type"]] = [address["address"]] + + context = { + "ip_groups": ip_groups, + } + return template.loader.render_to_string(template_name, context) + + def get_host(instance): if hasattr(instance, "hostname"): return instance.hostname elif hasattr(instance, "ip") and instance.ip: - return instance.ip[0] + return get_ips(instance) return _("Not Assigned") diff --git a/trove_dashboard/test/test_data/trove_data.py b/trove_dashboard/test/test_data/trove_data.py index e39679e..7fd90e2 100644 --- a/trove_dashboard/test/test_data/trove_data.py +++ b/trove_dashboard/test/test_data/trove_data.py @@ -148,6 +148,8 @@ DATABASE_DATA_ONE = { "ip": [ "10.0.0.3", ], + "addresses": [{"type": "private", + "address": "10.0.0.3"}], "volume": { "used": 0.13, "size": 1, @@ -171,6 +173,7 @@ DATABASE_DATA_TWO = { "links": [], "created": "2013-08-12T22:00:03", "hostname": "trove.instance-2.com", + "addresses": [], "volume": { "used": 0.13, "size": 1, @@ -195,6 +198,8 @@ DATABASE_DATA_THREE = { "ip": [ "10.0.0.3", ], + "addresses": [{"type": "private", + "address": "10.0.0.3"}], "volume": { "used": 0.13, "size": 1,