Merge "Improve IP address formatting in Instance table"

This commit is contained in:
Zuul 2018-09-26 02:28:29 +00:00 committed by Gerrit Code Review
commit a04fc597ef
2 changed files with 8 additions and 24 deletions

View File

@ -27,6 +27,7 @@ from django.utils.translation import pgettext_lazy
from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
import netaddr
from horizon import exceptions
from horizon import messages
@ -969,16 +970,9 @@ def get_ips(instance):
ip_groups = {}
for ip_group, addresses in instance.addresses.items():
ip_groups[ip_group] = {}
ip_groups[ip_group]["floating"] = []
ip_groups[ip_group]["non_floating"] = []
for address in addresses:
if ('OS-EXT-IPS:type' in address and
address['OS-EXT-IPS:type'] == "floating"):
ip_groups[ip_group]["floating"].append(address)
else:
ip_groups[ip_group]["non_floating"].append(address)
ips = [addr['addr'] for addr in addresses]
ips.sort(key=lambda ip: netaddr.IPAddress(ip).version)
ip_groups[ip_group] = ips
context = {
"ip_groups": ip_groups,

View File

@ -1,19 +1,9 @@
{% load i18n %}
<ul class="list-unstyled">
{% for ip_group, ips in ip_groups.items %}
{% if ip_groups.keys|length > 1 %}
<h4>{{ ip_group }}</h4>
{% endif %}
<ul class="list-unstyled">
{% for address in ips.non_floating %}
<li>{{ address.addr }}</li>
{% endfor %}
</ul>
{% if ips.floating|length > 0 %}
<h5>{% trans 'Floating IPs:' %}</h5>
<ul class="list-unstyled">
{% for address in ips.floating %}
<li>{{ address.addr }}</li>
{% endfor %}
</ul>
<li><b>{{ ip_group }}</b>
{% endif %}
{{ ips|join:", " }}</li>
{% endfor %}
</ul>