Merge "Improve IP address formatting in Instance table"
This commit is contained in:
commit
a04fc597ef
|
@ -27,6 +27,7 @@ from django.utils.translation import pgettext_lazy
|
||||||
from django.utils.translation import string_concat
|
from django.utils.translation import string_concat
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils.translation import ungettext_lazy
|
from django.utils.translation import ungettext_lazy
|
||||||
|
import netaddr
|
||||||
|
|
||||||
from horizon import exceptions
|
from horizon import exceptions
|
||||||
from horizon import messages
|
from horizon import messages
|
||||||
|
@ -969,16 +970,9 @@ def get_ips(instance):
|
||||||
ip_groups = {}
|
ip_groups = {}
|
||||||
|
|
||||||
for ip_group, addresses in instance.addresses.items():
|
for ip_group, addresses in instance.addresses.items():
|
||||||
ip_groups[ip_group] = {}
|
ips = [addr['addr'] for addr in addresses]
|
||||||
ip_groups[ip_group]["floating"] = []
|
ips.sort(key=lambda ip: netaddr.IPAddress(ip).version)
|
||||||
ip_groups[ip_group]["non_floating"] = []
|
ip_groups[ip_group] = ips
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"ip_groups": ip_groups,
|
"ip_groups": ip_groups,
|
||||||
|
|
|
@ -1,19 +1,9 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
<ul class="list-unstyled">
|
||||||
{% for ip_group, ips in ip_groups.items %}
|
{% for ip_group, ips in ip_groups.items %}
|
||||||
{% if ip_groups.keys|length > 1 %}
|
{% if ip_groups.keys|length > 1 %}
|
||||||
<h4>{{ ip_group }}</h4>
|
<li><b>{{ ip_group }}</b>
|
||||||
{% 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>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{{ ips|join:", " }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
Loading…
Reference in New Issue