From 887d7fb8476dc37d813bfc19b1312b58aab9e3c7 Mon Sep 17 00:00:00 2001 From: Trygve Vea Date: Sat, 21 Oct 2017 00:07:51 +0000 Subject: [PATCH] Add network availability zone information for network agents This patch adds the availability zone column for network agents on the system information page, if either the router_availability_zone or the network_availability_zone extension is enabled. Change-Id: Id7509fab440383bff45cb8ce5bdc3f8eb62045f4 Closes-Bug: #1716638 --- .../dashboards/admin/info/tables.py | 22 +++++++++++++++++++ .../dashboards/admin/info/tests.py | 3 +++ 2 files changed, 25 insertions(+) diff --git a/openstack_dashboard/dashboards/admin/info/tables.py b/openstack_dashboard/dashboards/admin/info/tables.py index 76afed740c..44f0758ebc 100644 --- a/openstack_dashboard/dashboards/admin/info/tables.py +++ b/openstack_dashboard/dashboards/admin/info/tables.py @@ -19,6 +19,7 @@ from django.utils.translation import ugettext_lazy as _ from horizon import tables from horizon.utils import filters as utils_filters +from openstack_dashboard import api SERVICE_ENABLED = "enabled" @@ -161,6 +162,13 @@ class NetworkAgentsFilterAction(tables.FilterAction): return filter(comp, agents) +def get_network_agent_zone(agent): + if agent.availability_zone: + return agent.availability_zone + + return _('-') + + def get_network_agent_status(agent): if agent.admin_state_up: return _('Enabled') @@ -196,6 +204,7 @@ class NetworkAgentsTable(tables.DataTable): agent_type = tables.Column('agent_type', verbose_name=_('Type')) binary = tables.Column("binary", verbose_name=_('Name')) host = tables.Column('host', verbose_name=_('Host')) + zone = tables.Column(get_network_agent_zone, verbose_name=_('Zone')) status = tables.Column(get_network_agent_status, verbose_name=_('Status')) state = tables.Column(get_network_agent_state, verbose_name=_('State')) heartbeat_timestamp = tables.Column('heartbeat_timestamp', @@ -205,6 +214,19 @@ class NetworkAgentsTable(tables.DataTable): filters=(utils_filters.parse_isotime, filters.timesince)) + def __init__(self, request, data=None, needs_form_wrapper=None, **kwargs): + super(NetworkAgentsTable, self).__init__( + request, + data=data, + needs_form_wrapper=needs_form_wrapper, + **kwargs) + + availability_zone_supported = api.neutron.is_extension_supported( + request, + "availability_zone") + if not availability_zone_supported: + del self.columns["zone"] + def get_object_id(self, obj): return "%s-%s" % (obj.binary, obj.host) diff --git a/openstack_dashboard/dashboards/admin/info/tests.py b/openstack_dashboard/dashboards/admin/info/tests.py index ce4e3df5f9..c7405d3ead 100644 --- a/openstack_dashboard/dashboards/admin/info/tests.py +++ b/openstack_dashboard/dashboards/admin/info/tests.py @@ -41,6 +41,9 @@ class SystemInfoViewTests(test.BaseAdminViewTests): 'agent').AndReturn(True) agents = self.agents.list() api.neutron.agent_list(IsA(http.HttpRequest)).AndReturn(agents) + api.neutron.is_extension_supported(IsA(http.HttpRequest), + "availability_zone")\ + .AndReturn(False) cinder_services = self.cinder_services.list() api.cinder.service_list(IsA(http.HttpRequest)).\