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
This commit is contained in:
parent
a8d21c2727
commit
3c322c368b
@ -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):
|
||||
|
@ -1,8 +1,7 @@
|
||||
{% load i18n sizeformat parse_date %}
|
||||
{% load url from future %}
|
||||
|
||||
<div class="info row detail">
|
||||
<hr class="header_rule">
|
||||
<div class="detail">
|
||||
<dl class="dl-horizontal">
|
||||
<dt>{% trans "Name" %}</dt>
|
||||
<dd>{{ firewall.name|default:_("-") }}</dd>
|
||||
|
@ -1,8 +1,7 @@
|
||||
{% load i18n sizeformat parse_date %}
|
||||
{% load url from future %}
|
||||
|
||||
<div class="info row detail">
|
||||
<hr class="header_rule">
|
||||
<div class="detail">
|
||||
<dl class="dl-horizontal">
|
||||
<dt>{% trans "Name" %}</dt>
|
||||
<dd>{{ policy.name|default:_("-") }}</dd>
|
||||
|
@ -1,8 +1,7 @@
|
||||
{% load i18n sizeformat parse_date %}
|
||||
{% load url from future %}
|
||||
|
||||
<div class="info row detail">
|
||||
<hr class="header_rule">
|
||||
<div class="detail">
|
||||
<dl class="dl-horizontal">
|
||||
<dt>{% trans "Name" %}</dt>
|
||||
<dd>{{ rule.name|default:_("-") }}</dd>
|
||||
|
@ -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<policy_id>[^/]+)/$',
|
||||
|
@ -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):
|
||||
|
@ -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. "
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user