Add fip to lbaas vip info
This change adds floating ip address where the vip is displayed. The floating IP is a critical peice of information and it is a real hassle to find this information. Change-Id: Id9cfeffd3eebe7651bc53baa5e52972ce2c50547 Closes-bug: #1452411
This commit is contained in:
parent
be6fdd8a38
commit
0b7901c4ca
@ -141,7 +141,7 @@ def pool_create(request, **kwargs):
|
||||
return Pool(pool)
|
||||
|
||||
|
||||
def _get_vip(request, pool, vip_dict, expand_name_only=False):
|
||||
def _get_vip(request, pool, vip_dict):
|
||||
if pool['vip_id'] is not None:
|
||||
try:
|
||||
if vip_dict:
|
||||
@ -152,8 +152,6 @@ def _get_vip(request, pool, vip_dict, expand_name_only=False):
|
||||
messages.warning(request, _("Unable to get VIP for pool "
|
||||
"%(pool)s.") % {"pool": pool["id"]})
|
||||
vip = Vip({'id': pool['vip_id'], 'name': ''})
|
||||
if expand_name_only:
|
||||
vip = vip.name_or_id
|
||||
return vip
|
||||
else:
|
||||
return None
|
||||
@ -175,8 +173,7 @@ def _pool_list(request, expand_subnet=False, expand_vip=False, **kwargs):
|
||||
vips = vip_list(request)
|
||||
vip_dict = SortedDict((v.id, v) for v in vips)
|
||||
for p in pools:
|
||||
p['vip_name'] = _get_vip(request, p, vip_dict,
|
||||
expand_name_only=True)
|
||||
p['vip'] = _get_vip(request, p, vip_dict)
|
||||
return [Pool(p) for p in pools]
|
||||
|
||||
|
||||
@ -202,8 +199,7 @@ def _pool_get(request, pool_id, expand_resource=False):
|
||||
except Exception:
|
||||
messages.warning(request, _("Unable to get subnet for pool "
|
||||
"%(pool)s.") % {"pool": pool_id})
|
||||
pool['vip'] = _get_vip(request, pool, vip_dict=None,
|
||||
expand_name_only=False)
|
||||
pool['vip'] = _get_vip(request, pool, vip_dict=None)
|
||||
try:
|
||||
pool['members'] = _member_list(request, expand_pool=False,
|
||||
pool_id=pool_id)
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django import template
|
||||
from django.template import defaultfilters as filters
|
||||
from django.utils import http
|
||||
from django.utils.translation import pgettext_lazy
|
||||
@ -220,14 +221,6 @@ class UpdateMonitorLink(policy.PolicyTargetMixin, tables.LinkAction):
|
||||
return base_url
|
||||
|
||||
|
||||
def get_vip_link(pool):
|
||||
if pool.vip_id:
|
||||
return reverse("horizon:project:loadbalancers:vipdetails",
|
||||
args=(http.urlquote(pool.vip_id),))
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
class AddPMAssociationLink(policy.PolicyTargetMixin,
|
||||
tables.LinkAction):
|
||||
name = "addassociation"
|
||||
@ -273,9 +266,9 @@ class UpdatePoolsRow(tables.Row):
|
||||
pool = api.lbaas.pool_get(request, pool_id)
|
||||
try:
|
||||
vip = api.lbaas.vip_get(request, pool.vip_id)
|
||||
pool.vip_name = vip.name
|
||||
pool.vip = vip
|
||||
except Exception:
|
||||
pool.vip_name = pool.vip_id
|
||||
pass
|
||||
try:
|
||||
subnet = api.neutron.subnet_get(request, pool.subnet_id)
|
||||
pool.subnet_name = subnet.cidr
|
||||
@ -311,6 +304,15 @@ STATUS_DISPLAY_CHOICES = (
|
||||
)
|
||||
|
||||
|
||||
def get_vip_name(pool):
|
||||
if hasattr(pool, "vip") and pool.vip:
|
||||
template_name = 'project/loadbalancers/_pool_table_vip_cell.html'
|
||||
context = {"vip": pool.vip, }
|
||||
return template.loader.render_to_string(template_name, context)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
class PoolsTable(tables.DataTable):
|
||||
METHOD_DISPLAY_CHOICES = (
|
||||
("round_robin", pgettext_lazy("load balancing method",
|
||||
@ -337,8 +339,7 @@ class PoolsTable(tables.DataTable):
|
||||
status=True,
|
||||
status_choices=STATUS_CHOICES,
|
||||
display_choices=STATUS_DISPLAY_CHOICES)
|
||||
vip_name = tables.Column('vip_name', verbose_name=_("VIP"),
|
||||
link=get_vip_link)
|
||||
vip_name = tables.Column(get_vip_name, verbose_name=_("VIP"))
|
||||
|
||||
class Meta(object):
|
||||
name = "poolstable"
|
||||
|
@ -30,12 +30,22 @@ class PoolsTab(tabs.TableTab):
|
||||
template_name = "horizon/common/_detail_table.html"
|
||||
|
||||
def get_poolstable_data(self):
|
||||
try:
|
||||
tenant_id = self.request.user.tenant_id
|
||||
pools = api.lbaas.pool_list(self.tab_group.request,
|
||||
tenant_id=tenant_id)
|
||||
except Exception:
|
||||
pools = []
|
||||
try:
|
||||
request = self.tab_group.request
|
||||
tenant_id = self.request.user.tenant_id
|
||||
pools = api.lbaas.pool_list(request,
|
||||
tenant_id=tenant_id)
|
||||
fips = None
|
||||
for pool in pools:
|
||||
if hasattr(pool, "vip") and pool.vip:
|
||||
if not fips:
|
||||
fips = api.network.tenant_floating_ip_list(request)
|
||||
vip_fip = [fip for fip in fips
|
||||
if fip.port_id == pool.vip.port_id]
|
||||
if vip_fip:
|
||||
pool.vip.fip = vip_fip[0]
|
||||
except Exception:
|
||||
exceptions.handle(self.tab_group.request,
|
||||
_('Unable to retrieve pools list.'))
|
||||
return pools
|
||||
@ -100,10 +110,15 @@ class VipDetailsTab(tabs.Tab):
|
||||
|
||||
def get_context_data(self, request):
|
||||
vid = self.tab_group.kwargs['vip_id']
|
||||
vip = []
|
||||
try:
|
||||
vip = api.lbaas.vip_get(request, vid)
|
||||
fips = api.network.tenant_floating_ip_list(self.tab_group.request)
|
||||
vip_fip = [fip for fip in fips
|
||||
if fip.port_id == vip.port.id]
|
||||
if vip_fip:
|
||||
vip.fip = vip_fip[0]
|
||||
except Exception:
|
||||
vip = []
|
||||
exceptions.handle(self.tab_group.request,
|
||||
_('Unable to retrieve VIP details.'))
|
||||
return {'vip': vip}
|
||||
|
@ -0,0 +1,9 @@
|
||||
{% load i18n %}
|
||||
{% url 'horizon:project:loadbalancers:vipdetails' vip.id as vip_url %}
|
||||
<a href="{{ vip_url }}">{{ vip.name }}</a>
|
||||
<br/>
|
||||
{% trans "Address:" %} {{ vip.address }}
|
||||
{% if vip.fip %}
|
||||
<br/>
|
||||
{% trans "Floating IP:" %} {{ vip.fip.floating_ip_address }}
|
||||
{% endif %}
|
@ -22,6 +22,11 @@
|
||||
<dt>{% trans "Address" %}</dt>
|
||||
<dd>{{ vip.address }}</dd>
|
||||
|
||||
{% if vip.fip %}
|
||||
<dt>{% trans "Floating IP" %}</dt>
|
||||
<dd>{{ vip.fip.floating_ip_address }}</dd>
|
||||
{% endif %}
|
||||
|
||||
<dt>{% trans "Protocol Port" %}</dt>
|
||||
<dd>{{ vip.protocol_port }}</dd>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user