Loading src/webui/service/device/routes.py +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ device_client = DeviceClient() @device.get('/') def home(): if 'context_topology_uuid' not in session: if 'context_uuid' not in session or 'topology_uuid' not in session: flash("Please select a context!", "warning") return redirect(url_for("main.home")) Loading src/webui/service/link/routes.py +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ context_client = ContextClient() @link.get('/') def home(): if 'context_topology_uuid' not in session: if 'context_uuid' not in session or 'topology_uuid' not in session: flash("Please select a context!", "warning") return redirect(url_for("main.home")) Loading src/webui/service/main/routes.py +35 −19 Original line number Diff line number Diff line Loading @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. import json, logging, re import base64, json, logging, re from flask import jsonify, redirect, render_template, Blueprint, flash, session, url_for, request from common.proto.context_pb2 import Empty, ContextIdList, TopologyId, TopologyIdList from common.proto.context_pb2 import ContextList, Empty, TopologyId, TopologyList from common.tools.descriptor.Loader import DescriptorLoader, compose_notifications from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.Context import json_context_id Loading Loading @@ -55,28 +55,44 @@ def home(): context_topology_form: ContextTopologyForm = ContextTopologyForm() context_topology_form.context_topology.choices.append(('', 'Select...')) ctx_response: ContextIdList = context_client.ListContextIds(Empty()) for context_id in ctx_response.context_ids: context_uuid = context_id.context_uuid.uuid topo_response: TopologyIdList = context_client.ListTopologyIds(context_id) for topology_id in topo_response.topology_ids: topology_uuid = topology_id.topology_uuid.uuid context_topology_uuid = 'ctx[{:s}]/topo[{:s}]'.format(context_uuid, topology_uuid) context_topology_name = 'Context({:s}):Topology({:s})'.format(context_uuid, topology_uuid) contexts : ContextList = context_client.ListContexts(Empty()) for context_ in contexts.contexts: context_uuid : str = context_.context_id.context_uuid.uuid context_name : str = context_.name topologies : TopologyList = context_client.ListTopologies(context_.context_id) for topology_ in topologies.topology_ids: topology_uuid : str = topology_.topology_id.topology_uuid.uuid topology_name : str = topology_.name raw_values = context_uuid, context_name, topology_uuid, topology_name b64_values = [base64.b64decode(v.encode('utf-8')).decode('utf-8') for v in raw_values] context_topology_uuid = ','.join(b64_values) context_topology_name = 'Context({:s}):Topology({:s})'.format(context_name, topology_name) context_topology_entry = (context_topology_uuid, context_topology_name) context_topology_form.context_topology.choices.append(context_topology_entry) if context_topology_form.validate_on_submit(): context_topology_uuid = context_topology_form.context_topology.data if len(context_topology_uuid) > 0: match = re.match('ctx\[([^\]]+)\]\/topo\[([^\]]+)\]', context_topology_uuid) if match is not None: session['context_topology_uuid'] = context_topology_uuid = match.group(0) session['context_uuid'] = context_uuid = match.group(1) session['topology_uuid'] = topology_uuid = match.group(2) MSG = f'Context({context_uuid})/Topology({topology_uuid}) successfully selected.' b64_values = context_topology_uuid.split(',') raw_values = [base64.b64decode(v.encode('utf-8')).decode('utf-8') for v in b64_values] context_uuid, context_name, topology_uuid, topology_name = raw_values session['context_topology_uuid'] = context_topology_uuid session['context_uuid'] = context_uuid session['context_name'] = context_name session['topology_uuid'] = topology_uuid session['topology_name'] = topology_name MSG = f'Context({context_name})/Topology({topology_name}) successfully selected.' flash(MSG, 'success') return redirect(url_for("main.home")) return redirect(url_for('main.home')) #match = re.match('ctx\[([^\]]+)\]\/topo\[([^\]]+)\]', context_topology_uuid) #if match is not None: # session['context_topology_uuid'] = context_topology_uuid = match.group(0) # session['context_uuid'] = context_uuid = match.group(1) # session['topology_uuid'] = topology_uuid = match.group(2) # MSG = f'Context({context_uuid})/Topology({topology_uuid}) successfully selected.' # flash(MSG, 'success') # return redirect(url_for('main.home')) if 'context_topology_uuid' in session: context_topology_form.context_topology.data = session['context_topology_uuid'] Loading @@ -100,7 +116,7 @@ def home(): def topology(): context_client.connect() try: if 'context_topology_uuid' not in session: if 'context_uuid' not in session or 'topology_uuid' not in session: return jsonify({'devices': [], 'links': []}) context_uuid = session['context_uuid'] Loading Loading
src/webui/service/device/routes.py +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ device_client = DeviceClient() @device.get('/') def home(): if 'context_topology_uuid' not in session: if 'context_uuid' not in session or 'topology_uuid' not in session: flash("Please select a context!", "warning") return redirect(url_for("main.home")) Loading
src/webui/service/link/routes.py +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ context_client = ContextClient() @link.get('/') def home(): if 'context_topology_uuid' not in session: if 'context_uuid' not in session or 'topology_uuid' not in session: flash("Please select a context!", "warning") return redirect(url_for("main.home")) Loading
src/webui/service/main/routes.py +35 −19 Original line number Diff line number Diff line Loading @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. import json, logging, re import base64, json, logging, re from flask import jsonify, redirect, render_template, Blueprint, flash, session, url_for, request from common.proto.context_pb2 import Empty, ContextIdList, TopologyId, TopologyIdList from common.proto.context_pb2 import ContextList, Empty, TopologyId, TopologyList from common.tools.descriptor.Loader import DescriptorLoader, compose_notifications from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.Context import json_context_id Loading Loading @@ -55,28 +55,44 @@ def home(): context_topology_form: ContextTopologyForm = ContextTopologyForm() context_topology_form.context_topology.choices.append(('', 'Select...')) ctx_response: ContextIdList = context_client.ListContextIds(Empty()) for context_id in ctx_response.context_ids: context_uuid = context_id.context_uuid.uuid topo_response: TopologyIdList = context_client.ListTopologyIds(context_id) for topology_id in topo_response.topology_ids: topology_uuid = topology_id.topology_uuid.uuid context_topology_uuid = 'ctx[{:s}]/topo[{:s}]'.format(context_uuid, topology_uuid) context_topology_name = 'Context({:s}):Topology({:s})'.format(context_uuid, topology_uuid) contexts : ContextList = context_client.ListContexts(Empty()) for context_ in contexts.contexts: context_uuid : str = context_.context_id.context_uuid.uuid context_name : str = context_.name topologies : TopologyList = context_client.ListTopologies(context_.context_id) for topology_ in topologies.topology_ids: topology_uuid : str = topology_.topology_id.topology_uuid.uuid topology_name : str = topology_.name raw_values = context_uuid, context_name, topology_uuid, topology_name b64_values = [base64.b64decode(v.encode('utf-8')).decode('utf-8') for v in raw_values] context_topology_uuid = ','.join(b64_values) context_topology_name = 'Context({:s}):Topology({:s})'.format(context_name, topology_name) context_topology_entry = (context_topology_uuid, context_topology_name) context_topology_form.context_topology.choices.append(context_topology_entry) if context_topology_form.validate_on_submit(): context_topology_uuid = context_topology_form.context_topology.data if len(context_topology_uuid) > 0: match = re.match('ctx\[([^\]]+)\]\/topo\[([^\]]+)\]', context_topology_uuid) if match is not None: session['context_topology_uuid'] = context_topology_uuid = match.group(0) session['context_uuid'] = context_uuid = match.group(1) session['topology_uuid'] = topology_uuid = match.group(2) MSG = f'Context({context_uuid})/Topology({topology_uuid}) successfully selected.' b64_values = context_topology_uuid.split(',') raw_values = [base64.b64decode(v.encode('utf-8')).decode('utf-8') for v in b64_values] context_uuid, context_name, topology_uuid, topology_name = raw_values session['context_topology_uuid'] = context_topology_uuid session['context_uuid'] = context_uuid session['context_name'] = context_name session['topology_uuid'] = topology_uuid session['topology_name'] = topology_name MSG = f'Context({context_name})/Topology({topology_name}) successfully selected.' flash(MSG, 'success') return redirect(url_for("main.home")) return redirect(url_for('main.home')) #match = re.match('ctx\[([^\]]+)\]\/topo\[([^\]]+)\]', context_topology_uuid) #if match is not None: # session['context_topology_uuid'] = context_topology_uuid = match.group(0) # session['context_uuid'] = context_uuid = match.group(1) # session['topology_uuid'] = topology_uuid = match.group(2) # MSG = f'Context({context_uuid})/Topology({topology_uuid}) successfully selected.' # flash(MSG, 'success') # return redirect(url_for('main.home')) if 'context_topology_uuid' in session: context_topology_form.context_topology.data = session['context_topology_uuid'] Loading @@ -100,7 +116,7 @@ def home(): def topology(): context_client.connect() try: if 'context_topology_uuid' not in session: if 'context_uuid' not in session or 'topology_uuid' not in session: return jsonify({'devices': [], 'links': []}) context_uuid = session['context_uuid'] Loading