From 3c322c368bbbe0f11303a0aae6f3f63fe257d3e5 Mon Sep 17 00:00:00 2001 From: Rob Cresswell Date: Tue, 13 Oct 2015 13:13:15 +0100 Subject: [PATCH] Add firewall detail actions and breadcrumb nav This patch adds the standard table row actions to firewalls, along with basic breadcrumb navigation. Also makes minor changes to workflow step titles and adds missing translation to the Ports breadcrumb. Change-Id: I3941d8ae8b75ecd1e85b4f140f24aa0f8eddb5cc Closes-Bug: 1457437 Partial-Bug: 1413823 --- .../dashboards/project/firewalls/tabs.py | 47 +------ .../firewalls/_firewall_details.html | 3 +- .../templates/firewalls/_policy_details.html | 3 +- .../templates/firewalls/_rule_details.html | 3 +- .../dashboards/project/firewalls/urls.py | 5 + .../dashboards/project/firewalls/views.py | 124 ++++++++++++++++-- .../dashboards/project/firewalls/workflows.py | 6 +- .../project/networks/ports/views.py | 4 +- 8 files changed, 133 insertions(+), 62 deletions(-) diff --git a/openstack_dashboard/dashboards/project/firewalls/tabs.py b/openstack_dashboard/dashboards/project/firewalls/tabs.py index e1424ffe03..7ee50b37fe 100644 --- a/openstack_dashboard/dashboards/project/firewalls/tabs.py +++ b/openstack_dashboard/dashboards/project/firewalls/tabs.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -from django.core.urlresolvers import reverse_lazy from django.utils.translation import ugettext_lazy as _ from horizon import exceptions @@ -94,64 +93,30 @@ class FirewallsTab(tabs.TableTab): class RuleDetailsTab(tabs.Tab): - name = _("Firewall Rule Details") + name = _("Rule") slug = "ruledetails" template_name = "project/firewalls/_rule_details.html" - failure_url = reverse_lazy('horizon:project:firewalls:index') def get_context_data(self, request): - rid = self.tab_group.kwargs['rule_id'] - try: - rule = api.fwaas.rule_get(request, rid) - except Exception: - exceptions.handle(request, - _('Unable to retrieve rule details.'), - redirect=self.failure_url) - return {'rule': rule} + return {"rule": self.tab_group.kwargs['rule']} class PolicyDetailsTab(tabs.Tab): - name = _("Firewall Policy Details") + name = _("Policy") slug = "policydetails" template_name = "project/firewalls/_policy_details.html" - failure_url = reverse_lazy('horizon:project:firewalls:index') def get_context_data(self, request): - pid = self.tab_group.kwargs['policy_id'] - try: - policy = api.fwaas.policy_get(request, pid) - except Exception: - exceptions.handle(request, - _('Unable to retrieve policy details.'), - redirect=self.failure_url) - return {'policy': policy} + return {"policy": self.tab_group.kwargs['policy']} class FirewallDetailsTab(tabs.Tab): - name = _("Firewall Details") + name = _("Firewall") slug = "firewalldetails" template_name = "project/firewalls/_firewall_details.html" - failure_url = reverse_lazy('horizon:project:firewalls:index') def get_context_data(self, request): - fid = self.tab_group.kwargs['firewall_id'] - try: - firewall = api.fwaas.firewall_get(request, fid) - body = {'firewall': firewall} - if api.neutron.is_extension_supported(request, - 'fwaasrouterinsertion'): - tenant_id = self.request.user.tenant_id - tenant_routers = api.neutron.router_list(request, - tenant_id=tenant_id) - router_ids = firewall.get_dict()['router_ids'] - routers = [r for r in tenant_routers - if r['id'] in router_ids] - body['routers'] = routers - except Exception: - exceptions.handle(request, - _('Unable to retrieve firewall details.'), - redirect=self.failure_url) - return body + return {"firewall": self.tab_group.kwargs['firewall']} class FirewallTabs(tabs.TabGroup): diff --git a/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_firewall_details.html b/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_firewall_details.html index 37fb59bfb1..ccbeec737a 100644 --- a/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_firewall_details.html +++ b/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_firewall_details.html @@ -1,8 +1,7 @@ {% load i18n sizeformat parse_date %} {% load url from future %} -
-
+
{% trans "Name" %}
{{ firewall.name|default:_("-") }}
diff --git a/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_policy_details.html b/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_policy_details.html index d6a6750e06..19ef4efcff 100644 --- a/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_policy_details.html +++ b/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_policy_details.html @@ -1,8 +1,7 @@ {% load i18n sizeformat parse_date %} {% load url from future %} -
-
+
{% trans "Name" %}
{{ policy.name|default:_("-") }}
diff --git a/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_rule_details.html b/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_rule_details.html index 1ac1ba0412..d95d799da3 100644 --- a/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_rule_details.html +++ b/openstack_dashboard/dashboards/project/firewalls/templates/firewalls/_rule_details.html @@ -1,8 +1,7 @@ {% load i18n sizeformat parse_date %} {% load url from future %} -
-
+
{% trans "Name" %}
{{ rule.name|default:_("-") }}
diff --git a/openstack_dashboard/dashboards/project/firewalls/urls.py b/openstack_dashboard/dashboards/project/firewalls/urls.py index 4ae691160f..dc04b2f274 100644 --- a/openstack_dashboard/dashboards/project/firewalls/urls.py +++ b/openstack_dashboard/dashboards/project/firewalls/urls.py @@ -20,6 +20,11 @@ from openstack_dashboard.dashboards.project.firewalls import views urlpatterns = patterns( 'openstack_dashboard.dashboards.project.firewalls.views', url(r'^$', views.IndexView.as_view(), name='index'), + url(r'^\?tab=fwtabs__firewalls$', + views.IndexView.as_view(), name='firewalls'), + url(r'^\?tab=fwtabs__rules$', views.IndexView.as_view(), name='rules'), + url(r'^\?tab=fwtabs__policies$', + views.IndexView.as_view(), name='policies'), url(r'^addrule$', views.AddRuleView.as_view(), name='addrule'), url(r'^addpolicy$', views.AddPolicyView.as_view(), name='addpolicy'), url(r'^addfirewall/(?P[^/]+)/$', diff --git a/openstack_dashboard/dashboards/project/firewalls/views.py b/openstack_dashboard/dashboards/project/firewalls/views.py index 34e76f3e98..a06925f17f 100644 --- a/openstack_dashboard/dashboards/project/firewalls/views.py +++ b/openstack_dashboard/dashboards/project/firewalls/views.py @@ -79,23 +79,127 @@ class AddFirewallView(workflows.WorkflowView): return workflow -class FireWallDetailTabs(tabs.TabView): - template_name = 'project/firewalls/details_tabs.html' - - -class RuleDetailsView(FireWallDetailTabs): +class RuleDetailsView(tabs.TabView): tab_group_class = (RuleDetailsTabs) - page_title = _("Firewall Rule Details") + template_name = 'horizon/common/_detail.html' + page_title = "{{ rule.name|default:rule.id }}" + failure_url = reverse_lazy('horizon:project:firewalls:index') + + def get_context_data(self, **kwargs): + context = super(RuleDetailsView, self).get_context_data(**kwargs) + rule = self.get_data() + table = fw_tabs.RulesTable(self.request) + breadcrumb = [ + (_("Firewalls"), + reverse_lazy('horizon:project:firewalls:firewalls')), + (_("Rules"), reverse_lazy('horizon:project:firewalls:rules'))] + context["custom_breadcrumb"] = breadcrumb + context["rule"] = rule + context["url"] = self.failure_url + context["actions"] = table.render_row_actions(rule) + return context + + @memoized.memoized_method + def get_data(self): + try: + rule_id = self.kwargs['rule_id'] + rule = api.fwaas.rule_get(self.request, rule_id) + except Exception: + exceptions.handle(self.request, + _('Unable to retrieve rule details.'), + redirect=self.failure_url) + return rule + + def get_tabs(self, request, *args, **kwargs): + rule = self.get_data() + return self.tab_group_class(request, rule=rule, **kwargs) -class PolicyDetailsView(FireWallDetailTabs): +class PolicyDetailsView(tabs.TabView): tab_group_class = (PolicyDetailsTabs) - page_title = _("Firewall Policy Details") + template_name = 'horizon/common/_detail.html' + page_title = "{{ policy.name|default:policy.id }}" + failure_url = reverse_lazy('horizon:project:firewalls:index') + + def get_context_data(self, **kwargs): + context = super(PolicyDetailsView, self).get_context_data(**kwargs) + policy = self.get_data() + table = fw_tabs.PoliciesTable(self.request) + breadcrumb = [ + (_("Firewalls"), + reverse_lazy('horizon:project:firewalls:firewalls')), + (_("Policies"), + reverse_lazy('horizon:project:firewalls:policies'))] + context["custom_breadcrumb"] = breadcrumb + context["policy"] = policy + context["url"] = self.failure_url + context["actions"] = table.render_row_actions(policy) + return context + + @memoized.memoized_method + def get_data(self): + try: + policy_id = self.kwargs['policy_id'] + policy = api.fwaas.policy_get(self.request, policy_id) + except Exception: + exceptions.handle(self.request, + _('Unable to retrieve policy details.'), + redirect=self.failure_url) + return policy + + def get_tabs(self, request, *args, **kwargs): + policy = self.get_data() + return self.tab_group_class(request, policy=policy, **kwargs) -class FirewallDetailsView(FireWallDetailTabs): +class FirewallDetailsView(tabs.TabView): tab_group_class = (FirewallDetailsTabs) - page_title = _("Firewall Details") + template_name = 'horizon/common/_detail.html' + page_title = "{{ firewall.name|default:firewall.id }}" + failure_url = reverse_lazy('horizon:project:firewalls:index') + + def get_context_data(self, **kwargs): + context = super(FirewallDetailsView, self).get_context_data(**kwargs) + firewall = self.get_data() + routers = self.get_routers_data(firewall) + table = fw_tabs.FirewallsTable(self.request) + context["firewall"] = firewall + context["routers"] = routers + context["url"] = self.failure_url + context["actions"] = table.render_row_actions(firewall) + return context + + @memoized.memoized_method + def get_data(self): + try: + firewall_id = self.kwargs['firewall_id'] + firewall = api.fwaas.firewall_get(self.request, firewall_id) + except Exception: + exceptions.handle(self.request, + _('Unable to retrieve firewall details.'), + redirect=self.failure_url) + return firewall + + @memoized.memoized_method + def get_routers_data(self, firewall): + routers = [] + try: + if api.neutron.is_extension_supported(self.request, + 'fwaasrouterinsertion'): + tenant_id = self.request.user.tenant_id + tenant_routers = api.neutron.router_list(self.request, + tenant_id=tenant_id) + router_ids = firewall.get_dict()['router_ids'] + routers = [r for r in tenant_routers + if r['id'] in router_ids] + except Exception: + exceptions.handle(self.request, + _('Unable to retrieve list of routers.'), ) + return routers + + def get_tabs(self, request, *args, **kwargs): + firewall = self.get_data() + return self.tab_group_class(request, firewall=firewall, **kwargs) class UpdateRuleView(forms.ModalFormView): diff --git a/openstack_dashboard/dashboards/project/firewalls/workflows.py b/openstack_dashboard/dashboards/project/firewalls/workflows.py index 0055cc8613..5fe8177ca7 100644 --- a/openstack_dashboard/dashboards/project/firewalls/workflows.py +++ b/openstack_dashboard/dashboards/project/firewalls/workflows.py @@ -70,7 +70,7 @@ class AddRuleAction(workflows.Action): super(AddRuleAction, self).__init__(request, *args, **kwargs) class Meta(object): - name = _("AddRule") + name = _("Rule") permissions = ('openstack.services.network',) help_text = _("Create a firewall rule.\n\n" "Protocol and action must be specified. " @@ -230,7 +230,7 @@ class AddPolicyAction(workflows.Action): super(AddPolicyAction, self).__init__(request, *args, **kwargs) class Meta(object): - name = _("AddPolicy") + name = _("Policy") permissions = ('openstack.services.network',) help_text = _("Create a firewall policy with an ordered list " "of firewall rules.\n\n" @@ -301,7 +301,7 @@ class AddFirewallAction(workflows.Action): self.fields['firewall_policy_id'].choices = firewall_policy_id_choices class Meta(object): - name = _("AddFirewall") + name = _("Firewall") permissions = ('openstack.services.network',) help_text = _("Create a firewall based on a policy.\n\n" "A policy must be selected. " diff --git a/openstack_dashboard/dashboards/project/networks/ports/views.py b/openstack_dashboard/dashboards/project/networks/ports/views.py index 8766f9e76e..257b0ee614 100644 --- a/openstack_dashboard/dashboards/project/networks/ports/views.py +++ b/openstack_dashboard/dashboards/project/networks/ports/views.py @@ -81,10 +81,10 @@ class DetailView(tabs.TabView): network_id=port.network_id) # TODO(robcresswell) Add URL for "Ports" crumb after bug/1416838 breadcrumb = [ - ("Networks", self.get_redirect_url()), + (_("Networks"), self.get_redirect_url()), (network_nav, reverse('horizon:project:networks:detail', args=(port.network_id,))), - ("Ports",), ] + (_("Ports"),), ] context["custom_breadcrumb"] = breadcrumb context["port"] = port context["url"] = self.get_redirect_url()