From 8b1a41e013b2092d37e507caeab7a843917af7fb Mon Sep 17 00:00:00 2001 From: gifrerenom Date: Wed, 26 Apr 2023 12:22:41 +0000 Subject: [PATCH 1/2] WebUI cpomponent: - Added basic policy tab --- src/webui/service/__init__.py | 3 + src/webui/service/policy/__init__.py | 14 ++++ src/webui/service/policy/routes.py | 50 ++++++++++++ src/webui/service/templates/base.html | 7 ++ src/webui/service/templates/policy/home.html | 84 ++++++++++++++++++++ 5 files changed, 158 insertions(+) create mode 100644 src/webui/service/policy/__init__.py create mode 100644 src/webui/service/policy/routes.py create mode 100644 src/webui/service/templates/policy/home.html diff --git a/src/webui/service/__init__.py b/src/webui/service/__init__.py index fca107141..e7f50ed42 100644 --- a/src/webui/service/__init__.py +++ b/src/webui/service/__init__.py @@ -95,6 +95,9 @@ def create_app(use_config=None, web_app_root=None): from webui.service.link.routes import link # pylint: disable=import-outside-toplevel app.register_blueprint(link) + from webui.service.policy.routes import policy # pylint: disable=import-outside-toplevel + app.register_blueprint(policy) + app.jinja_env.globals.update({ # pylint: disable=no-member 'enumerate' : enumerate, 'json_to_list' : json_to_list, diff --git a/src/webui/service/policy/__init__.py b/src/webui/service/policy/__init__.py new file mode 100644 index 000000000..1549d9811 --- /dev/null +++ b/src/webui/service/policy/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/src/webui/service/policy/routes.py b/src/webui/service/policy/routes.py new file mode 100644 index 000000000..6d14f86b4 --- /dev/null +++ b/src/webui/service/policy/routes.py @@ -0,0 +1,50 @@ +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import grpc +from flask import render_template, Blueprint +from common.proto.context_pb2 import Empty +from common.proto.policy_pb2 import PolicyRuleStateEnum +from context.client.ContextClient import ContextClient + +policy = Blueprint('policy', __name__, url_prefix='/policy') + +context_client = ContextClient() + +@policy.get('/') +def home(): + context_client.connect() + policy_rules = context_client.ListPolicyRules(Empty()) + policy_rules = policy_rules.policyRules + context_client.close() + return render_template('policy/home.html', policy_rules=policy_rules, prse=PolicyRuleStateEnum) + +#@policy.get('/detail') +#def detail(policy_uuid: str): +# try: +# context_client.connect() +# +# slice_obj = get_slice_by_uuid(context_client, slice_uuid, rw_copy=False) +# if slice_obj is None: +# flash('Context({:s})/Slice({:s}) not found'.format(str(context_uuid), str(slice_uuid)), 'danger') +# slice_obj = Slice() +# +# context_client.close() +# +# return render_template( +# 'slice/detail.html', slice=slice_obj, prse=PolicyRuleStateEnum) +# except Exception as e: +# flash('The system encountered an error and cannot show the details of this slice.', 'warning') +# current_app.logger.exception(e) +# return redirect(url_for('slice.home')) diff --git a/src/webui/service/templates/base.html b/src/webui/service/templates/base.html index 1dfa36871..61c283b0d 100644 --- a/src/webui/service/templates/base.html +++ b/src/webui/service/templates/base.html @@ -83,6 +83,13 @@ Slice {% endif %} + diff --git a/src/webui/service/templates/policy/home.html b/src/webui/service/templates/policy/home.html new file mode 100644 index 000000000..64a8f8288 --- /dev/null +++ b/src/webui/service/templates/policy/home.html @@ -0,0 +1,84 @@ + + +{% extends 'base.html' %} + +{% block content %} +

Policy

+ +
+
+ {{ policies | length }} policies found in context {{ session['context_uuid'] }} +
+
+ + + + + + + + + + + + + + + + + + + + {% if policies %} + {% for policy in policies %} + {% if policy.WhichOneof('policy_rule') == 'device' %} + + + + + + + + + + + + + {% elif policy.WhichOneof('policy_rule') == 'service' %} + + + + + + + + + + + + + {% else %} + + {% endif %} + {% endfor %} + {% else %} + + {% endif %} + +
UUIDKindPriorityConditionOperatorActionServiceDevicesStateMessageExtra
{{ policy.device.policyRuleBasic.policyRuleId.uuid }}{{ policy.WhichOneof('policy_rule') }}{{ policy.device.policyRuleBasic.priority }}{{ policy.device.policyRuleBasic.conditionList }}{{ policy.device.policyRuleBasic.booleanOperator }}{{ policy.device.policyRuleBasic.actionList }}-{{ policy.device.deviceList }}{{ prse.Name(policy.device.policyRuleBasic.policyRuleState.policyRuleState).replace('POLICY_', '') }}{{ policy.device.policyRuleBasic.policyRuleState.policyRuleStateMessage }}
{{ policy.service.policyRuleBasic.policyRuleId.uuid }}{{ policy.WhichOneof('policy_rule') }}{{ policy.service.policyRuleBasic.priority }}{{ policy.service.policyRuleBasic.conditionList }}{{ policy.service.policyRuleBasic.booleanOperator }}{{ policy.service.policyRuleBasic.actionList }}{{ policy.service.serviceId }}{{ policy.service.deviceList }}{{ prse.Name(policy.service.policyRuleBasic.policyRuleState.policyRuleState).replace('POLICY_', '') }}{{ policy.service.policyRuleBasic.policyRuleState.policyRuleStateMessage }}
Unsupported policy type {{ policy.WhichOneof('policy_rule') }}
No policies found
+ +{% endblock %} -- GitLab From c722b8689564da7f48e7b3294f244ce4b1ff6a6d Mon Sep 17 00:00:00 2001 From: gifrerenom Date: Wed, 26 Apr 2023 17:25:41 +0000 Subject: [PATCH 2/2] WebUI component: - Minor correction in policy template --- src/webui/service/templates/policy/home.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webui/service/templates/policy/home.html b/src/webui/service/templates/policy/home.html index 64a8f8288..081a7f0b5 100644 --- a/src/webui/service/templates/policy/home.html +++ b/src/webui/service/templates/policy/home.html @@ -72,11 +72,11 @@ {{ policy.service.policyRuleBasic.policyRuleState.policyRuleStateMessage }} {% else %} - Unsupported policy type {{ policy.WhichOneof('policy_rule') }} + Unsupported policy type {{ policy.WhichOneof('policy_rule') }} {% endif %} {% endfor %} {% else %} - No policies found + No policies found {% endif %} -- GitLab