diff --git a/.context.log.swp b/.context.log.swp index 1d5d6b23da8cf9d7348152649f7e75767b1dbe64..6a5328d3f841c922f1450e5517e2e576a481c914 100644 Binary files a/.context.log.swp and b/.context.log.swp differ diff --git a/src/context/service/database/models/OpticalLinkModel.py b/src/context/service/database/models/OpticalLinkModel.py index 3015f445bb108e3e67979b9bcd4aa27c6dfe0d9c..3a300d46b9ed085284e5b01e01ada622a7619855 100644 --- a/src/context/service/database/models/OpticalLinkModel.py +++ b/src/context/service/database/models/OpticalLinkModel.py @@ -36,12 +36,13 @@ class SlotType(TypeDecorator): slot={} for k,v in value.items(): slot[k]=v - logging.info(f"dict from slotType {slot}") + value = json.dumps(slot) return value def process_result_value(self, value, dialect): + logging.info(f"dict from slotType {value}") if value is not None: value = json.loads(value) return value diff --git a/src/opticalcontroller/OpticalController.py b/src/opticalcontroller/OpticalController.py index 262cf115ef5945b6edcb069b04e5df789e4c2c49..3b857374445ca8095541ed2f79b40d02d129ef20 100644 --- a/src/opticalcontroller/OpticalController.py +++ b/src/opticalcontroller/OpticalController.py @@ -208,16 +208,39 @@ class GetFlows(Resource): except: return "Error", 404 -@optical.route('/GetTopology/<path:topology_id>',methods=(['GET'])) +@optical.route('/GetTopology/<path:context_id>/<path:topology_id>',methods=['GET']) @optical.response(200, 'Success') @optical.response(404, 'Error, not found') class GetTopology(Resource): @staticmethod - def get(topology_id:TopologyId): + def get(context_id:str,topology_id:str): + topog_id = TopologyId() + topog_id.topology_uuid.uuid=topology_id + topog_id.context_id.context_uuid.uuid=context_id + try: - nodes , links = readTopologyDataFromContext(topology_id) - print(f"nodes {nodes} and links {links}") + links_dict={"optical_links":[]} + node_dict = {} + i=0 + nodes , topo = readTopologyDataFromContext(topog_id) + + for node in nodes : + links_dict["optical_links"].append(node) + for device in topo : + dic = {} + dic= { + "id":device.device_id.device_uuid.uuid, + "ip":f"10.30.2.{207+i}", + "port":"50001", + "type":"OC-ROADM" if device.device_type =="optical-roadm" else "OC-ROADM", + "driver": "OpticalOC" + } + node_dict[device.name]=dic + i+=1 + print(f"refresh_opticacontroller optical_links_dict {links_dict}") + print(f"refresh_opticacontroller node_dict {node_dict}") + rsa = RSA(node_dict, links_dict) return "Done" except Exception as e: print(f"err {e}") @@ -232,7 +255,7 @@ if __name__ == '__main__': nodes_dict, links_dict = readTopologyData(nodes_json, topology_json) - rsa = RSA(nodes_dict, links_dict) + #rsa = RSA(nodes_dict, links_dict) #print(rsa.init_link_slots2(testing)) app.run(host='0.0.0.0', port=10060) diff --git a/src/service/service/ServiceServiceServicerImpl.py b/src/service/service/ServiceServiceServicerImpl.py index 880c0525c82e82a7182af55c58f294aaad4fb782..f2edc2e2092b815bd4d53aa1781ec1b5b47a8e42 100644 --- a/src/service/service/ServiceServiceServicerImpl.py +++ b/src/service/service/ServiceServiceServicerImpl.py @@ -254,8 +254,8 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): DEFAULT_TOPOLOGY_NAME, context_id_x) topology_details = context_client.GetTopologyDetails( TopologyId(**topology_id_x)) - - #refresh_opticalcontroller(TopologyId(**topology_id_x)) + + refresh_opticalcontroller(topology_id_x) # devices = get_devices_in_topology(context_client, TopologyId(**topology_id_x), ContextId(**context_id_x)) devices = topology_details.devices context_uuid_x = topology_details.topology_id.context_id.context_uuid.uuid diff --git a/src/service/service/task_scheduler/TaskExecutor.py b/src/service/service/task_scheduler/TaskExecutor.py index 5c5747970c6accf3c76da6d4ffb60de48edbcdac..d39119689b5938730bd35049f7399abc8495b926 100644 --- a/src/service/service/task_scheduler/TaskExecutor.py +++ b/src/service/service/task_scheduler/TaskExecutor.py @@ -32,7 +32,7 @@ from service.service.service_handler_api.Exceptions import ( ) from service.service.service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory, get_service_handler_class from service.service.tools.ObjectKeys import get_connection_key, get_device_key, get_service_key - +from service.service.tools.object_uuid import opticalconfig_get_uuid if TYPE_CHECKING: from service.service.service_handler_api._ServiceHandler import _ServiceHandler @@ -120,24 +120,27 @@ class TaskExecutor: def configure_optical_device(self, device : Device, settings : str, flows : list, is_opticalband : bool): device_key = get_device_key(device.device_id) optical_config_id = OpticalConfigId() - optical_config_id.opticalconfig_uuid = device.device_id.device_uuid.uuid + optical_config_id.opticalconfig_uuid = opticalconfig_get_uuid(device.device_id) + optical_config = OpticalConfig() + setting = settings.value if settings else "" new_config = {} try: result = self._context_client.SelectOpticalConfig(optical_config_id) + LOGGER.info(f"configure_optical_device {result}") new_config = json.loads(result.config) if result is not None : new_config["new_config"] = setting new_config["is_opticalband"] = is_opticalband new_config["flow"] = flows - result.config = str(new_config) + result.config = json.dumps(new_config) optical_config.CopyFrom(result) self._device_client.ConfigureOpticalDevice(optical_config) self._store_grpc_object(CacheableObjectType.DEVICE, device_key, device) except Exception as e: - LOGGER.info("error in config my config %s",e) + LOGGER.info("error in configure_optical_device %s",e) def get_device_controller(self, device : Device) -> Optional[Device]: #json_controller = None diff --git a/src/service/service/tools/OpticalTools.py b/src/service/service/tools/OpticalTools.py index 31bcb7bcf0de599930f4511901615f8a18a6a2e8..02d1c5c41d2478d9d08d329af4325819b4ff5c97 100644 --- a/src/service/service/tools/OpticalTools.py +++ b/src/service/service/tools/OpticalTools.py @@ -77,11 +77,15 @@ def get_device_name_from_uuid(devices: List[Device], device_uuid: str): return device_name return "" -def refresh_opticalcontroller (topology_id:TopologyId): - headers = {"Content-Type": "application/json"} - urlx = "http://{}:{}/GetTopology/{}".format(OPTICAL_IP, OPTICAL_PORT,topology_id) - res = requests.get(urlx, headers=headers) - logging.info(f"Refresh opticalcontroller {res}") +def refresh_opticalcontroller (topology_id:dict): + logging.info(f"t_id {topology_id}") + topo_id_str= topology_id["topology_uuid"]["uuid"] + cxt_id_str=topology_id["context_id"]["context_uuid"]["uuid"] + headers = {"Content-Type": "application/json"} + urlx = f"http://{OPTICAL_IP}:{OPTICAL_PORT}/OpticalTFS/GetTopology/{cxt_id_str}/{topo_id_str}" + + res = requests.get(urlx, headers=headers) + logging.info(f"Refresh opticalcontroller {res}") def add_lightpath(src, dst, bitrate, bidir, ob_band) -> str: if not testing: diff --git a/src/service/service/tools/object_uuid.py b/src/service/service/tools/object_uuid.py new file mode 100644 index 0000000000000000000000000000000000000000..a5d905d109d3dfc0e48b82cf2b1f78def6e07570 --- /dev/null +++ b/src/service/service/tools/object_uuid.py @@ -0,0 +1,34 @@ + +from common.method_wrappers.ServiceExceptions import InvalidArgumentsException +from typing import Optional, Union +from uuid import UUID, uuid4, uuid5 +from common.proto.context_pb2 import DeviceId + + +NAMESPACE_TFS = UUID('200e3a1f-2223-534f-a100-758e29c37f40') + +def get_uuid_from_string(str_uuid_or_name : Union[str, UUID], prefix_for_name : Optional[str] = None) -> str: + # if UUID given, assume it is already a valid UUID + if isinstance(str_uuid_or_name, UUID): return str_uuid_or_name + if not isinstance(str_uuid_or_name, str): + MSG = 'Parameter({:s}) cannot be used to produce a UUID' + raise Exception(MSG.format(str(repr(str_uuid_or_name)))) + try: + # try to parse as UUID + return str(UUID(str_uuid_or_name)) + except: # pylint: disable=bare-except + # produce a UUID within TFS namespace from parameter + if prefix_for_name is not None: + str_uuid_or_name = '{:s}/{:s}'.format(prefix_for_name, str_uuid_or_name) + return str(uuid5(NAMESPACE_TFS, str_uuid_or_name)) + + +def opticalconfig_get_uuid ( device_id: DeviceId) -> str : + device_uuid = device_id.device_uuid.uuid + if (len(device_uuid)>0): + return get_uuid_from_string(f"{device_uuid}_opticalconfig") + + raise InvalidArgumentsException([ + ('DeviceId ', device_id), + + ], extra_details=['device_id is required to produce a OpticalConfig UUID']) \ No newline at end of file diff --git a/src/webui/service/templates/opticalconfig/details.html b/src/webui/service/templates/opticalconfig/details.html index 85aafb3a4af86e7705e69e9679625f0228277922..4d39ef62b820970ad2f258280598c3e2ce0f4b5a 100644 --- a/src/webui/service/templates/opticalconfig/details.html +++ b/src/webui/service/templates/opticalconfig/details.html @@ -33,21 +33,21 @@ </div> <div class="col-sm-12"> <div class="col-sm-12"> - <div class="row"> + <div class="row mb-3 "> - <div class="col-sm-3"> - <button type="button" class="btn btn-success" onclick="window.location.href='{{ url_for('opticalconfig.home') }}'"> - <i class="bi bi-box-arrow-in-left"></i> - Back to device list - </button> + <div class="col-sm-3"> + <button type="button" class="btn btn-success" onclick="window.location.href='{{ url_for('opticalconfig.home') }}'"> + <i class="bi bi-box-arrow-in-left"></i> + Back to device list + </button> + </div> + <div class="col-sm-3"> + <!-- <button type="button" class="btn btn-danger"><i class="bi bi-x-square"></i>Delete device</button> --> + <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal"> + <i class="bi bi-x-square"></i> + Delete Optical Config + </button> </div> - <div class="col-sm-3"> - <!-- <button type="button" class="btn btn-danger"><i class="bi bi-x-square"></i>Delete device</button> --> - <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal"> - <i class="bi bi-x-square"></i> - Delete Optical Config - </button> - </div> </div> </div> <div class="col-sm-12">