diff --git a/src/webui/service/service/routes.py b/src/webui/service/service/routes.py index b5873de7e3e8607e3e186f5238a30d6fa22091b7..a6e55adedc93508d4f4c3e2844daec5913cf371c 100644 --- a/src/webui/service/service/routes.py +++ b/src/webui/service/service/routes.py @@ -55,14 +55,14 @@ type = ["ACL_UNDEFINED", "ACL_IPV4","ACL_IPV6","ACL_L2","ACL_MPLS","ACL_MIXE f_action = ["UNDEFINED", "DROP","ACCEPT","REJECT"] l_action = ["UNDEFINED", "LOG_NONE","LOG_SYSLOG"] -@service.get('/') #Route for the homepage of the created "service" blueprint -@contextmanager -def connected_client(c): - try: - c.connect() - yield c - finally: - c.close() +#@service.get('/') #Route for the homepage of the created "service" blueprint +#@contextmanager +#def connected_client(c): +# try: +# c.connect() +# yield c +# finally: +# c.close() # Context client must be in connected state when calling this function def get_device_drivers_in_use(topology_uuid: str, context_uuid: str) -> Set[str]: @@ -123,139 +123,139 @@ def get_hub_module_name(dev: Device) -> Optional[str]: pass return None -@service.route('add-xr', methods=['GET', 'POST']) -def add_xr(): - ### FIXME: copypaste - if 'context_uuid' not in session or '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() - grpc_topology = get_topology(context_client, topology_uuid, context_uuid=context_uuid, rw_copy=False) - if grpc_topology is None: - flash('Context({:s})/Topology({:s}) not found'.format(str(context_uuid), str(topology_uuid)), 'danger') - return redirect(url_for("main.home")) - else: - topo_device_uuids = {device_id.device_uuid.uuid for device_id in grpc_topology.device_ids} - grpc_devices= context_client.ListDevices(Empty()) - devices = [ - device for device in grpc_devices.devices - if device.device_id.device_uuid.uuid in topo_device_uuids and DeviceDriverEnum.DEVICEDRIVER_XR in device.device_drivers - ] - devices.sort(key=lambda dev: dev.name) - - hub_interfaces_by_device = defaultdict(list) - leaf_interfaces_by_device = defaultdict(list) - constellation_name_to_uuid = {} - dev_ep_to_uuid = {} - ep_uuid_to_name = {} - for d in devices: - constellation_name_to_uuid[d.name] = d.device_id.device_uuid.uuid - hm_name = get_hub_module_name(d) - if hm_name is not None: - hm_if_prefix= hm_name + "|" - for ep in d.device_endpoints: - dev_ep_to_uuid[(d.name, ep.name)] = ep.endpoint_id.endpoint_uuid.uuid - if ep.name.startswith(hm_if_prefix): - hub_interfaces_by_device[d.name].append(ep.name) - else: - leaf_interfaces_by_device[d.name].append(ep.name) - ep_uuid_to_name[ep.endpoint_id.endpoint_uuid.uuid] = (d.name, ep.name) - hub_interfaces_by_device[d.name].sort() - leaf_interfaces_by_device[d.name].sort() - - # Find out what endpoints are already used so that they can be disabled - # in the create screen - context_obj = get_context(context_client, context_uuid, rw_copy=False) - if context_obj is None: - flash('Context({:s}) not found'.format(str(context_uuid)), 'danger') - return redirect(request.url) - - services = context_client.ListServices(context_obj.context_id) - ep_used_by={} - for service in services.services: - if service.service_type == ServiceTypeEnum.SERVICETYPE_TAPI_CONNECTIVITY_SERVICE: - for ep in service.service_endpoint_ids: - ep_uuid = ep.endpoint_uuid.uuid - if ep_uuid in ep_uuid_to_name: - dev_name, ep_name = ep_uuid_to_name[ep_uuid] - ep_used_by[f"{ep_name}@{dev_name}"] = service.name - - context_client.close() - - if request.method != 'POST': - return render_template('service/add-xr.html', devices=devices, hub_if=hub_interfaces_by_device, leaf_if=leaf_interfaces_by_device, ep_used_by=ep_used_by) - else: - service_name = request.form["service_name"] - if service_name == "": - flash(f"Service name must be specified", 'danger') - - constellation = request.form["constellation"] - constellation_uuid = constellation_name_to_uuid.get(constellation, None) - if constellation_uuid is None: - flash(f"Invalid constellation \"{constellation}\"", 'danger') - - hub_if = request.form["hubif"] - hub_if_uuid = dev_ep_to_uuid.get((constellation, hub_if), None) - if hub_if_uuid is None: - flash(f"Invalid hub interface \"{hub_if}\"", 'danger') - - leaf_if = request.form["leafif"] - leaf_if_uuid = dev_ep_to_uuid.get((constellation, leaf_if), None) - if leaf_if_uuid is None: - flash(f"Invalid leaf interface \"{leaf_if}\"", 'danger') - - if service_name == "" or constellation_uuid is None or hub_if_uuid is None or leaf_if_uuid is None: - return redirect(request.url) - - - json_context_uuid=json_context_id(context_uuid) - sr = { - "name": service_name, - "service_id": { - "context_id": {"context_uuid": {"uuid": context_uuid}}, - "service_uuid": {"uuid": service_name} - }, - 'service_type' : ServiceTypeEnum.SERVICETYPE_TAPI_CONNECTIVITY_SERVICE, - "service_endpoint_ids": [ - {'device_id': {'device_uuid': {'uuid': constellation_uuid}}, 'endpoint_uuid': {'uuid': hub_if_uuid}, 'topology_id': json_topology_id("admin", context_id=json_context_uuid)}, - {'device_id': {'device_uuid': {'uuid': constellation_uuid}}, 'endpoint_uuid': {'uuid': leaf_if_uuid}, 'topology_id': json_topology_id("admin", context_id=json_context_uuid)} - ], - 'service_status' : {'service_status': ServiceStatusEnum.SERVICESTATUS_PLANNED}, - 'service_constraints' : [], - } - - json_tapi_settings = { - 'capacity_value' : 50.0, - 'capacity_unit' : 'GHz', - 'layer_proto_name': 'PHOTONIC_MEDIA', - 'layer_proto_qual': 'tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_NMC', - 'direction' : 'UNIDIRECTIONAL', - } - config_rule = json_config_rule_set('/settings', json_tapi_settings) - - with connected_client(service_client) as sc: - endpoints, sr['service_endpoint_ids'] = sr['service_endpoint_ids'], [] - try: - create_response = sc.CreateService(Service(**sr)) - except Exception as e: - flash(f'Failure to update service name {service_name} with endpoints and configuration, exception {str(e)}', 'danger') - return redirect(request.url) - - sr['service_endpoint_ids'] = endpoints - sr['service_config'] = {'config_rules': [config_rule]} - - try: - update_response = sc.UpdateService(Service(**sr)) - flash(f'Created service {update_response.service_uuid.uuid}', 'success') - except Exception as e: - flash(f'Failure to update service {create_response.service_uuid.uuid} with endpoints and configuration, exception {str(e)}', 'danger') - return redirect(request.url) - - return redirect(url_for('service.home')) +#@service.route('add-xr', methods=['GET', 'POST']) +#def add_xr(): +# ### FIXME: copypaste +# if 'context_uuid' not in session or '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() +# grpc_topology = get_topology(context_client, topology_uuid, context_uuid=context_uuid, rw_copy=False) +# if grpc_topology is None: +# flash('Context({:s})/Topology({:s}) not found'.format(str(context_uuid), str(topology_uuid)), 'danger') +# return redirect(url_for("main.home")) +# else: +# topo_device_uuids = {device_id.device_uuid.uuid for device_id in grpc_topology.device_ids} +# grpc_devices= context_client.ListDevices(Empty()) +# devices = [ +# device for device in grpc_devices.devices +# if device.device_id.device_uuid.uuid in topo_device_uuids and DeviceDriverEnum.DEVICEDRIVER_XR in device.device_drivers +# ] +# devices.sort(key=lambda dev: dev.name) +# +# hub_interfaces_by_device = defaultdict(list) +# leaf_interfaces_by_device = defaultdict(list) +# constellation_name_to_uuid = {} +# dev_ep_to_uuid = {} +# ep_uuid_to_name = {} +# for d in devices: +# constellation_name_to_uuid[d.name] = d.device_id.device_uuid.uuid +# hm_name = get_hub_module_name(d) +# if hm_name is not None: +# hm_if_prefix= hm_name + "|" +# for ep in d.device_endpoints: +# dev_ep_to_uuid[(d.name, ep.name)] = ep.endpoint_id.endpoint_uuid.uuid +# if ep.name.startswith(hm_if_prefix): +# hub_interfaces_by_device[d.name].append(ep.name) +# else: +# leaf_interfaces_by_device[d.name].append(ep.name) +# ep_uuid_to_name[ep.endpoint_id.endpoint_uuid.uuid] = (d.name, ep.name) +# hub_interfaces_by_device[d.name].sort() +# leaf_interfaces_by_device[d.name].sort() +# +# # Find out what endpoints are already used so that they can be disabled +# # in the create screen +# context_obj = get_context(context_client, context_uuid, rw_copy=False) +# if context_obj is None: +# flash('Context({:s}) not found'.format(str(context_uuid)), 'danger') +# return redirect(request.url) +# +# services = context_client.ListServices(context_obj.context_id) +# ep_used_by={} +# for service in services.services: +# if service.service_type == ServiceTypeEnum.SERVICETYPE_TAPI_CONNECTIVITY_SERVICE: +# for ep in service.service_endpoint_ids: +# ep_uuid = ep.endpoint_uuid.uuid +# if ep_uuid in ep_uuid_to_name: +# dev_name, ep_name = ep_uuid_to_name[ep_uuid] +# ep_used_by[f"{ep_name}@{dev_name}"] = service.name +# +# context_client.close() +# +# if request.method != 'POST': +# return render_template('service/add-xr.html', devices=devices, hub_if=hub_interfaces_by_device, leaf_if=leaf_interfaces_by_device, ep_used_by=ep_used_by) +# else: +# service_name = request.form["service_name"] +# if service_name == "": +# flash(f"Service name must be specified", 'danger') +# +# constellation = request.form["constellation"] +# constellation_uuid = constellation_name_to_uuid.get(constellation, None) +# if constellation_uuid is None: +# flash(f"Invalid constellation \"{constellation}\"", 'danger') +# +# hub_if = request.form["hubif"] +# hub_if_uuid = dev_ep_to_uuid.get((constellation, hub_if), None) +# if hub_if_uuid is None: +# flash(f"Invalid hub interface \"{hub_if}\"", 'danger') +# +# leaf_if = request.form["leafif"] +# leaf_if_uuid = dev_ep_to_uuid.get((constellation, leaf_if), None) +# if leaf_if_uuid is None: +# flash(f"Invalid leaf interface \"{leaf_if}\"", 'danger') +# +# if service_name == "" or constellation_uuid is None or hub_if_uuid is None or leaf_if_uuid is None: +# return redirect(request.url) +# +# +# json_context_uuid=json_context_id(context_uuid) +# sr = { +# "name": service_name, +# "service_id": { +# "context_id": {"context_uuid": {"uuid": context_uuid}}, +# "service_uuid": {"uuid": service_name} +# }, +# 'service_type' : ServiceTypeEnum.SERVICETYPE_TAPI_CONNECTIVITY_SERVICE, +# "service_endpoint_ids": [ +# {'device_id': {'device_uuid': {'uuid': constellation_uuid}}, 'endpoint_uuid': {'uuid': hub_if_uuid}, 'topology_id': json_topology_id("admin", context_id=json_context_uuid)}, +# {'device_id': {'device_uuid': {'uuid': constellation_uuid}}, 'endpoint_uuid': {'uuid': leaf_if_uuid}, 'topology_id': json_topology_id("admin", context_id=json_context_uuid)} +# ], +# 'service_status' : {'service_status': ServiceStatusEnum.SERVICESTATUS_PLANNED}, +# 'service_constraints' : [], +# } +# +# json_tapi_settings = { +# 'capacity_value' : 50.0, +# 'capacity_unit' : 'GHz', +# 'layer_proto_name': 'PHOTONIC_MEDIA', +# 'layer_proto_qual': 'tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_NMC', +# 'direction' : 'UNIDIRECTIONAL', +# } +# config_rule = json_config_rule_set('/settings', json_tapi_settings) +# +# with connected_client(service_client) as sc: +# endpoints, sr['service_endpoint_ids'] = sr['service_endpoint_ids'], [] +# try: +# create_response = sc.CreateService(Service(**sr)) +# except Exception as e: +# flash(f'Failure to update service name {service_name} with endpoints and configuration, exception {str(e)}', 'danger') +# return redirect(request.url) +# +# sr['service_endpoint_ids'] = endpoints +# sr['service_config'] = {'config_rules': [config_rule]} +# +# try: +# update_response = sc.UpdateService(Service(**sr)) +# flash(f'Created service {update_response.service_uuid.uuid}', 'success') +# except Exception as e: +# flash(f'Failure to update service {create_response.service_uuid.uuid} with endpoints and configuration, exception {str(e)}', 'danger') +# return redirect(request.url) +# +# return redirect(url_for('service.home')) @service.get('<path:service_uuid>/detail') def detail(service_uuid: str): diff --git a/src/webui/service/templates/service/home.html b/src/webui/service/templates/service/home.html index 4e4c1f82f33113402bdc3948b1073a579e2922a3..c22d476e7a36c04f3a1c828bda540c20fdbf407c 100644 --- a/src/webui/service/templates/service/home.html +++ b/src/webui/service/templates/service/home.html @@ -25,7 +25,7 @@ <i class="bi bi-plus"></i> Add New Service </a> - </div> --> + </div> <!-- Only display XR service addition button if there are XR constellations. Otherwise it might confuse user, as other service types do not have GUI to add service yet. -->