GBP UI - added policy targets UI
Change-Id: Ib2074e794db2f1a6e7ab02225ad9173d1c77cf06
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
# Copyright 2010-2011 OpenStack Foundation
|
||||
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
@@ -45,6 +42,22 @@ def update_pruleset_attributes(request, prset):
|
||||
return prset
|
||||
|
||||
|
||||
def update_service_policy_attributes(policy):
|
||||
np = policy.network_service_params
|
||||
params = ""
|
||||
if len(np) > 0:
|
||||
tags = []
|
||||
for item in np:
|
||||
dl = ["<dl class='dl-horizontal'>"]
|
||||
dl.extend(["<dt>%s<dt><dd>%s</dd>" %
|
||||
(k, v) for k, v in item.items()])
|
||||
dl.append("</dl>")
|
||||
tags.append("".join(dl))
|
||||
params = mark_safe("".join(tags))
|
||||
setattr(policy, 'network_service_params', params)
|
||||
return policy
|
||||
|
||||
|
||||
def update_policy_target_attributes(request, pt):
|
||||
url = "horizon:project:application_policy:policy_rule_set_details"
|
||||
provided = pt.provided_policy_rule_sets
|
||||
@@ -70,7 +83,7 @@ def update_policy_target_attributes(request, pt):
|
||||
l2url = "horizon:project:network_policy:l2policy_details"
|
||||
if pt.l2_policy_id is not None:
|
||||
policy = client.l2policy_get(request, pt.l2_policy_id)
|
||||
u = reverse(l2url, {'l2policy_id': policy.id})
|
||||
u = reverse(l2url, kwargs={'l2policy_id': policy.id})
|
||||
atag = mark_safe(
|
||||
"<a href='" + u + "'>" + policy.name + "</a>")
|
||||
setattr(pt, 'l2_policy_id', atag)
|
||||
@@ -80,24 +93,52 @@ def update_policy_target_attributes(request, pt):
|
||||
def update_policyrule_attributes(request, prule):
|
||||
url = "horizon:project:application_policy:policyclassifierdetails"
|
||||
classifier_id = prule.policy_classifier_id
|
||||
classifier = client. policyclassifier_get(request, classifier_id)
|
||||
classifier = client.policyclassifier_get(request, classifier_id)
|
||||
u = reverse(url, kwargs={'policyclassifier_id': classifier.id})
|
||||
tag = mark_safe("<a href='" + u + "'>" + classifier.name + "</a>")
|
||||
setattr(prule, 'policy_classifier_id', tag)
|
||||
actions = prule.policy_actions
|
||||
action_url = "horizon:project:application_policy:policyactiondetails"
|
||||
ul = ["<ul>"]
|
||||
for a in actions:
|
||||
action = client.policyaction_get(request, a)
|
||||
u = reverse(action_url, kwargs={'policyaction_id': a})
|
||||
if action.action_type == 'redirect':
|
||||
spec = client.get_servicechain_spec(request, action.action_value)
|
||||
spec_details = "%s:%s" % (spec.name, str(spec.id))
|
||||
li = "<li><a href='%s'>%s</a></li>" % (u, spec_details)
|
||||
else:
|
||||
li = "<li><a href='%s'>%s</a></li>" % (u, action.name)
|
||||
ul.append(li)
|
||||
ul.append("</ul>")
|
||||
ultag = "".join(ul)
|
||||
setattr(prule, 'policy_actions', mark_safe(ultag))
|
||||
return prule
|
||||
|
||||
|
||||
def update_policyaction_attributes(request, paction):
|
||||
if paction.action_type == 'redirect':
|
||||
spec = client.get_servicechain_spec(request,
|
||||
paction.action_value)
|
||||
url = "horizon:project:network_services:sc_spec_details"
|
||||
url = reverse(url, kwargs={'scspec_id': spec.id})
|
||||
tag_content = (url, spec.name + ":" + spec.id)
|
||||
tag = "<a href='%s'>%s</a>" % tag_content
|
||||
setattr(paction, 'action_value', mark_safe(tag))
|
||||
return paction
|
||||
|
||||
|
||||
def update_sc_spec_attributes(request, scspec):
|
||||
nodes = scspec.nodes
|
||||
nodes = [client.get_servicechain_node(request, item) for item in nodes]
|
||||
value = ["<table class='table table-condensed'> \
|
||||
<tr><td><span class='glyphicon glyphicon-remove-circle'>< /span></td>"]
|
||||
t = "<table class='table table-condensed'><tr><td>"
|
||||
val = [t + "<span class='glyphicon glyphicon-remove-circle'></span></td>"]
|
||||
for n in nodes:
|
||||
value.append(
|
||||
val.append(
|
||||
"<td><span class='glyphicon glyphicon-arrow-right'></span></td>")
|
||||
value.append("<td>" + n.name + "(" + n.service_type + ")</td>")
|
||||
value.append("</tr></table>")
|
||||
setattr(scspec, 'nodes', mark_safe("".join(value)))
|
||||
val.append("<td>" + n.name + "(" + n.service_type + ")</td>")
|
||||
val.append("</tr></table>")
|
||||
setattr(scspec, 'nodes', mark_safe("".join(val)))
|
||||
return scspec
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user