Loading src/webui/service/__init__.py +5 −4 Changes for src/webui/service/__init__.py: 5 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -19,10 +19,10 @@ from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient def get_working_context() -> str: if 'context_uuid' in session: return session['context_uuid'] else: return 'Not selected' return session['context_uuid'] if 'context_uuid' in session else '---' def get_working_topology() -> str: return session['topology_uuid'] if 'topology_uuid' in session else '---' def liveness(): pass Loading Loading @@ -85,6 +85,7 @@ def create_app(use_config=None, web_app_root=None): app.jinja_env.filters['from_json'] = from_json app.jinja_env.globals.update(get_working_context=get_working_context) app.jinja_env.globals.update(get_working_topology=get_working_topology) if web_app_root is not None: app.wsgi_app = SetSubAppMiddleware(app.wsgi_app, web_app_root) Loading src/webui/service/device/routes.py +20 −6 Changes for src/webui/service/device/routes.py: 20 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ from flask import current_app, render_template, Blueprint, flash, session, redir from common.proto.context_pb2 import ( ConfigActionEnum, ConfigRule, Device, DeviceDriverEnum, DeviceId, DeviceList, DeviceOperationalStatusEnum, Empty) Empty, TopologyId) from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Topology import json_topology_id from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from webui.service.device.forms import AddDeviceForm Loading @@ -27,15 +29,27 @@ device_client = DeviceClient() @device.get('/') def home(): context_uuid = session.get('context_uuid', '-') if context_uuid == "-": if 'context_topology_uuid' not in session: flash("Please select a context!", "warning") return redirect(url_for("main.home")) context_uuid = session['context_uuid'] topology_uuid = session['topology_uuid'] context_client.connect() response: DeviceList = context_client.ListDevices(Empty()) json_topo_id = json_topology_id(topology_uuid, context_id=json_context_id(context_uuid)) grpc_topology = context_client.GetTopology(TopologyId(**json_topo_id)) topo_device_uuids = {device_id.device_uuid.uuid for device_id in grpc_topology.device_ids} grpc_devices: DeviceList = context_client.ListDevices(Empty()) context_client.close() return render_template('device/home.html', devices=response.devices, dde=DeviceDriverEnum, devices = [ device for device in grpc_devices.devices if device.device_id.device_uuid.uuid in topo_device_uuids ] return render_template( 'device/home.html', devices=devices, dde=DeviceDriverEnum, dose=DeviceOperationalStatusEnum) @device.route('add', methods=['GET', 'POST']) Loading src/webui/service/link/routes.py +20 −8 Changes for src/webui/service/link/routes.py: 20 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -14,7 +14,9 @@ from flask import current_app, render_template, Blueprint, flash, session, redirect, url_for from common.proto.context_pb2 import Empty, Link, LinkEvent, LinkId, LinkIdList, LinkList, DeviceId from common.proto.context_pb2 import Empty, Link, LinkEvent, LinkId, LinkIdList, LinkList, DeviceId, TopologyId from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Topology import json_topology_id from context.client.ContextClient import ContextClient Loading @@ -23,18 +25,28 @@ context_client = ContextClient() @link.get('/') def home(): context_uuid = session.get('context_uuid', '-') if context_uuid == "-": if 'context_topology_uuid' not in session: flash("Please select a context!", "warning") return redirect(url_for("main.home")) request = Empty() context_uuid = session['context_uuid'] topology_uuid = session['topology_uuid'] context_client.connect() response = context_client.ListLinks(request) json_topo_id = json_topology_id(topology_uuid, context_id=json_context_id(context_uuid)) grpc_topology = context_client.GetTopology(TopologyId(**json_topo_id)) topo_link_uuids = {link_id.link_uuid.uuid for link_id in grpc_topology.link_ids} grpc_links: LinkList = context_client.ListLinks(Empty()) context_client.close() links = [ link for link in grpc_links.links if link.link_id.link_uuid.uuid in topo_link_uuids ] return render_template( "link/home.html", links=response.links, ) 'link/home.html', links=links) @link.route('detail/<path:link_uuid>', methods=('GET', 'POST')) def detail(link_uuid: str): Loading src/webui/service/main/forms.py +5 −4 Changes for src/webui/service/main/forms.py: 5 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -19,19 +19,20 @@ from wtforms import SelectField, FileField, SubmitField from wtforms.validators import DataRequired, Length class ContextForm(FlaskForm): context = SelectField( 'Context', class ContextTopologyForm(FlaskForm): context_topology = SelectField( 'Ctx/Topo', choices=[], validators=[ DataRequired(), Length(min=1) ]) submit = SubmitField('Submit') class DescriptorForm(FlaskForm): descriptors = FileField('Descriptors', descriptors = FileField( 'Descriptors', validators=[ FileAllowed(['json'], 'JSON Descriptors only!') ]) Loading src/webui/service/main/routes.py +49 −16 Changes for src/webui/service/main/routes.py: 49 added lines, 16 removed lines. Original line number Diff line number Diff line Loading @@ -12,10 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. import json, logging import json, logging, re from flask import jsonify, redirect, render_template, Blueprint, flash, session, url_for, request from common.proto.context_pb2 import Connection, Context, Device, Empty, Link, Service, Slice, Topology, ContextIdList from common.proto.context_pb2 import Connection, Context, Device, Empty, Link, Service, Slice, Topology, ContextIdList, TopologyId, TopologyIdList from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Topology import json_topology_id from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from service.client.ServiceClient import ServiceClient Loading @@ -23,7 +25,7 @@ from slice.client.SliceClient import SliceClient from webui.service.main.DescriptorTools import ( format_custom_config_rules, get_descriptors_add_contexts, get_descriptors_add_services, get_descriptors_add_slices, get_descriptors_add_topologies, split_devices_by_rules) from webui.service.main.forms import ContextForm, DescriptorForm from webui.service.main.forms import ContextTopologyForm, DescriptorForm main = Blueprint('main', __name__) Loading Loading @@ -154,20 +156,34 @@ def process_descriptors(descriptors): def home(): context_client.connect() device_client.connect() response: ContextIdList = context_client.ListContextIds(Empty()) context_form: ContextForm = ContextForm() context_form.context.choices.append(('', 'Select...')) context_topology_form: ContextTopologyForm = ContextTopologyForm() context_topology_form.context_topology.choices.append(('', 'Select...')) for context in response.context_ids: context_form.context.choices.append((context.context_uuid.uuid, context.context_uuid)) 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) context_topology_entry = (context_topology_uuid, context_topology_name) context_topology_form.context_topology.choices.append(context_topology_entry) if context_form.validate_on_submit(): session['context_uuid'] = context_form.context.data flash(f'The context was successfully set to `{context_form.context.data}`.', 'success') 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.' flash(MSG, 'success') return redirect(url_for("main.home")) if 'context_uuid' in session: context_form.context.data = session['context_uuid'] if 'context_topology_uuid' in session: context_topology_form.context_topology.data = session['context_topology_uuid'] descriptor_form: DescriptorForm = DescriptorForm() try: Loading @@ -181,22 +197,39 @@ def home(): context_client.close() device_client.close() return render_template('main/home.html', context_form=context_form, descriptor_form=descriptor_form) return render_template( 'main/home.html', context_topology_form=context_topology_form, descriptor_form=descriptor_form) @main.route('/topology', methods=['GET']) def topology(): context_client.connect() try: if 'context_topology_uuid' not in session: return jsonify({'devices': [], 'links': []}) context_uuid = session['context_uuid'] topology_uuid = session['topology_uuid'] json_topo_id = json_topology_id(topology_uuid, context_id=json_context_id(context_uuid)) grpc_topology = context_client.GetTopology(TopologyId(**json_topo_id)) topo_device_uuids = {device_id.device_uuid.uuid for device_id in grpc_topology.device_ids} topo_link_uuids = {link_id .link_uuid .uuid for link_id in grpc_topology.link_ids } response = context_client.ListDevices(Empty()) devices = [{ devices = [] for device in response.devices: if device.device_id.device_uuid.uuid not in topo_device_uuids: continue devices.append({ 'id': device.device_id.device_uuid.uuid, 'name': device.device_id.device_uuid.uuid, 'type': device.device_type, } for device in response.devices] }) response = context_client.ListLinks(Empty()) links = [] for link in response.links: if link.link_id.link_uuid.uuid not in topo_link_uuids: continue if len(link.link_endpoint_ids) != 2: str_link = grpc_message_to_json_string(link) logger.warning('Unexpected link with len(endpoints) != 2: {:s}'.format(str_link)) Loading Loading
src/webui/service/__init__.py +5 −4 Changes for src/webui/service/__init__.py: 5 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -19,10 +19,10 @@ from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient def get_working_context() -> str: if 'context_uuid' in session: return session['context_uuid'] else: return 'Not selected' return session['context_uuid'] if 'context_uuid' in session else '---' def get_working_topology() -> str: return session['topology_uuid'] if 'topology_uuid' in session else '---' def liveness(): pass Loading Loading @@ -85,6 +85,7 @@ def create_app(use_config=None, web_app_root=None): app.jinja_env.filters['from_json'] = from_json app.jinja_env.globals.update(get_working_context=get_working_context) app.jinja_env.globals.update(get_working_topology=get_working_topology) if web_app_root is not None: app.wsgi_app = SetSubAppMiddleware(app.wsgi_app, web_app_root) Loading
src/webui/service/device/routes.py +20 −6 Changes for src/webui/service/device/routes.py: 20 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ from flask import current_app, render_template, Blueprint, flash, session, redir from common.proto.context_pb2 import ( ConfigActionEnum, ConfigRule, Device, DeviceDriverEnum, DeviceId, DeviceList, DeviceOperationalStatusEnum, Empty) Empty, TopologyId) from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Topology import json_topology_id from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from webui.service.device.forms import AddDeviceForm Loading @@ -27,15 +29,27 @@ device_client = DeviceClient() @device.get('/') def home(): context_uuid = session.get('context_uuid', '-') if context_uuid == "-": if 'context_topology_uuid' not in session: flash("Please select a context!", "warning") return redirect(url_for("main.home")) context_uuid = session['context_uuid'] topology_uuid = session['topology_uuid'] context_client.connect() response: DeviceList = context_client.ListDevices(Empty()) json_topo_id = json_topology_id(topology_uuid, context_id=json_context_id(context_uuid)) grpc_topology = context_client.GetTopology(TopologyId(**json_topo_id)) topo_device_uuids = {device_id.device_uuid.uuid for device_id in grpc_topology.device_ids} grpc_devices: DeviceList = context_client.ListDevices(Empty()) context_client.close() return render_template('device/home.html', devices=response.devices, dde=DeviceDriverEnum, devices = [ device for device in grpc_devices.devices if device.device_id.device_uuid.uuid in topo_device_uuids ] return render_template( 'device/home.html', devices=devices, dde=DeviceDriverEnum, dose=DeviceOperationalStatusEnum) @device.route('add', methods=['GET', 'POST']) Loading
src/webui/service/link/routes.py +20 −8 Changes for src/webui/service/link/routes.py: 20 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -14,7 +14,9 @@ from flask import current_app, render_template, Blueprint, flash, session, redirect, url_for from common.proto.context_pb2 import Empty, Link, LinkEvent, LinkId, LinkIdList, LinkList, DeviceId from common.proto.context_pb2 import Empty, Link, LinkEvent, LinkId, LinkIdList, LinkList, DeviceId, TopologyId from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Topology import json_topology_id from context.client.ContextClient import ContextClient Loading @@ -23,18 +25,28 @@ context_client = ContextClient() @link.get('/') def home(): context_uuid = session.get('context_uuid', '-') if context_uuid == "-": if 'context_topology_uuid' not in session: flash("Please select a context!", "warning") return redirect(url_for("main.home")) request = Empty() context_uuid = session['context_uuid'] topology_uuid = session['topology_uuid'] context_client.connect() response = context_client.ListLinks(request) json_topo_id = json_topology_id(topology_uuid, context_id=json_context_id(context_uuid)) grpc_topology = context_client.GetTopology(TopologyId(**json_topo_id)) topo_link_uuids = {link_id.link_uuid.uuid for link_id in grpc_topology.link_ids} grpc_links: LinkList = context_client.ListLinks(Empty()) context_client.close() links = [ link for link in grpc_links.links if link.link_id.link_uuid.uuid in topo_link_uuids ] return render_template( "link/home.html", links=response.links, ) 'link/home.html', links=links) @link.route('detail/<path:link_uuid>', methods=('GET', 'POST')) def detail(link_uuid: str): Loading
src/webui/service/main/forms.py +5 −4 Changes for src/webui/service/main/forms.py: 5 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -19,19 +19,20 @@ from wtforms import SelectField, FileField, SubmitField from wtforms.validators import DataRequired, Length class ContextForm(FlaskForm): context = SelectField( 'Context', class ContextTopologyForm(FlaskForm): context_topology = SelectField( 'Ctx/Topo', choices=[], validators=[ DataRequired(), Length(min=1) ]) submit = SubmitField('Submit') class DescriptorForm(FlaskForm): descriptors = FileField('Descriptors', descriptors = FileField( 'Descriptors', validators=[ FileAllowed(['json'], 'JSON Descriptors only!') ]) Loading
src/webui/service/main/routes.py +49 −16 Changes for src/webui/service/main/routes.py: 49 added lines, 16 removed lines. Original line number Diff line number Diff line Loading @@ -12,10 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. import json, logging import json, logging, re from flask import jsonify, redirect, render_template, Blueprint, flash, session, url_for, request from common.proto.context_pb2 import Connection, Context, Device, Empty, Link, Service, Slice, Topology, ContextIdList from common.proto.context_pb2 import Connection, Context, Device, Empty, Link, Service, Slice, Topology, ContextIdList, TopologyId, TopologyIdList from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Topology import json_topology_id from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from service.client.ServiceClient import ServiceClient Loading @@ -23,7 +25,7 @@ from slice.client.SliceClient import SliceClient from webui.service.main.DescriptorTools import ( format_custom_config_rules, get_descriptors_add_contexts, get_descriptors_add_services, get_descriptors_add_slices, get_descriptors_add_topologies, split_devices_by_rules) from webui.service.main.forms import ContextForm, DescriptorForm from webui.service.main.forms import ContextTopologyForm, DescriptorForm main = Blueprint('main', __name__) Loading Loading @@ -154,20 +156,34 @@ def process_descriptors(descriptors): def home(): context_client.connect() device_client.connect() response: ContextIdList = context_client.ListContextIds(Empty()) context_form: ContextForm = ContextForm() context_form.context.choices.append(('', 'Select...')) context_topology_form: ContextTopologyForm = ContextTopologyForm() context_topology_form.context_topology.choices.append(('', 'Select...')) for context in response.context_ids: context_form.context.choices.append((context.context_uuid.uuid, context.context_uuid)) 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) context_topology_entry = (context_topology_uuid, context_topology_name) context_topology_form.context_topology.choices.append(context_topology_entry) if context_form.validate_on_submit(): session['context_uuid'] = context_form.context.data flash(f'The context was successfully set to `{context_form.context.data}`.', 'success') 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.' flash(MSG, 'success') return redirect(url_for("main.home")) if 'context_uuid' in session: context_form.context.data = session['context_uuid'] if 'context_topology_uuid' in session: context_topology_form.context_topology.data = session['context_topology_uuid'] descriptor_form: DescriptorForm = DescriptorForm() try: Loading @@ -181,22 +197,39 @@ def home(): context_client.close() device_client.close() return render_template('main/home.html', context_form=context_form, descriptor_form=descriptor_form) return render_template( 'main/home.html', context_topology_form=context_topology_form, descriptor_form=descriptor_form) @main.route('/topology', methods=['GET']) def topology(): context_client.connect() try: if 'context_topology_uuid' not in session: return jsonify({'devices': [], 'links': []}) context_uuid = session['context_uuid'] topology_uuid = session['topology_uuid'] json_topo_id = json_topology_id(topology_uuid, context_id=json_context_id(context_uuid)) grpc_topology = context_client.GetTopology(TopologyId(**json_topo_id)) topo_device_uuids = {device_id.device_uuid.uuid for device_id in grpc_topology.device_ids} topo_link_uuids = {link_id .link_uuid .uuid for link_id in grpc_topology.link_ids } response = context_client.ListDevices(Empty()) devices = [{ devices = [] for device in response.devices: if device.device_id.device_uuid.uuid not in topo_device_uuids: continue devices.append({ 'id': device.device_id.device_uuid.uuid, 'name': device.device_id.device_uuid.uuid, 'type': device.device_type, } for device in response.devices] }) response = context_client.ListLinks(Empty()) links = [] for link in response.links: if link.link_id.link_uuid.uuid not in topo_link_uuids: continue if len(link.link_endpoint_ids) != 2: str_link = grpc_message_to_json_string(link) logger.warning('Unexpected link with len(endpoints) != 2: {:s}'.format(str_link)) Loading