From 4c69ebbb7a1189788806e610d9030f9194d7519b Mon Sep 17 00:00:00 2001
From: armingol <pablo.armingolrobles@telefonica.com>
Date: Wed, 25 Sep 2024 17:47:42 +0200
Subject: [PATCH] code cleanup

---
 my_deploy.sh                                  |   3 +
 src/common/Constants.py                       |   1 -
 src/pcep/.gitlab-ci.yml                       |   2 +-
 src/pcep/Config.py                            |   2 +-
 src/pcep/Dockerfile                           |   2 +-
 src/pcep/__init__.py                          |   2 +-
 src/pcep/requirements.in                      |   2 +-
 src/pcep/service/PcepService.py               |   2 +-
 src/pcep/service/PcepServiceServicerImpl.py   |   2 +-
 src/pcep/service/__init__.py                  |   2 +-
 src/pcep/service/__main__.py                  |   2 +-
 .../service/resources/BGP4Parameters_2.xml    |  16 +-
 src/pcep/service/resources/log4j2.xml         |  16 +-
 .../service/resources/topologia_ifusion.xml   |  16 +-
 src/pcep/service/tools/GrpcServer.py          |   2 +-
 .../tools/Grpc_TestClient/gRPC_PCEPClient.py  |   2 +-
 .../tools/Grpc_TestClient/grpcService.proto   |   2 +-
 .../tools/Grpc_TestClient/grpcService_pb2.py  |   2 +-
 .../Grpc_TestClient/grpcService_pb2_grpc.py   |   2 +-
 .../tools/Grpc_TestClient/test_gRPC_client.py |   2 +-
 src/pcep/service/tools/JavaRunner.py          |   2 +-
 .../service/tools/PCEServerConfiguration.xml  |  16 +-
 src/pcep/service/tools/__init__.py            |   2 +-
 src/pcep/tests/__init__.py                    |   2 +-
 .../qkd/qkd_service_handler.py                | 364 +++++++++---------
 25 files changed, 263 insertions(+), 205 deletions(-)

diff --git a/my_deploy.sh b/my_deploy.sh
index 88be82b63..cd07c078b 100755
--- a/my_deploy.sh
+++ b/my_deploy.sh
@@ -28,6 +28,9 @@ export TFS_COMPONENTS="context device pathcomp service slice nbi webui load_gene
 # Uncomment to activate Monitoring Framework (new)
 #export TFS_COMPONENTS="${TFS_COMPONENTS} kpi_manager kpi_value_writer kpi_value_api"
 
+# Uncomment to activate pcep
+#export TFS_COMPONENTS="${TFS_COMPONENTS} pcep"
+
 # Uncomment to activate BGP-LS Speaker
 #export TFS_COMPONENTS="${TFS_COMPONENTS} bgpls_speaker"
 
diff --git a/src/common/Constants.py b/src/common/Constants.py
index 0bf1b26fe..c7db87a06 100644
--- a/src/common/Constants.py
+++ b/src/common/Constants.py
@@ -62,7 +62,6 @@ class ServiceNameEnum(Enum):
     E2EORCHESTRATOR        = 'e2e-orchestrator'
     OPTICALCONTROLLER      = 'opticalcontroller'
     BGPLS                  = 'bgpls-speaker'
-    PCEP                   = 'pcep'
     KPIMANAGER             = 'kpi-manager'
     KPIVALUEAPI            = 'kpi-value-api'
     KPIVALUEWRITER         = 'kpi-value-writer'
diff --git a/src/pcep/.gitlab-ci.yml b/src/pcep/.gitlab-ci.yml
index dd861a025..a755aa0b5 100644
--- a/src/pcep/.gitlab-ci.yml
+++ b/src/pcep/.gitlab-ci.yml
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/Config.py b/src/pcep/Config.py
index 1549d9811..a5ccb6078 100644
--- a/src/pcep/Config.py
+++ b/src/pcep/Config.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/Dockerfile b/src/pcep/Dockerfile
index 48f2db27d..38b8cfe9e 100644
--- a/src/pcep/Dockerfile
+++ b/src/pcep/Dockerfile
@@ -38,7 +38,7 @@ RUN python3 -m pip install --upgrade pip-tools
 
 # Install OpenJDK-11
 RUN apt-get update && \
-    apt-get install -y openjdk-11-jre-headless && \
+    apt-get install -y openjdk-17-jre && \
     apt-get clean;
 
 # Get common Python packages
diff --git a/src/pcep/__init__.py b/src/pcep/__init__.py
index 1549d9811..a5ccb6078 100644
--- a/src/pcep/__init__.py
+++ b/src/pcep/__init__.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/requirements.in b/src/pcep/requirements.in
index bffe88732..c65dd1942 100644
--- a/src/pcep/requirements.in
+++ b/src/pcep/requirements.in
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/service/PcepService.py b/src/pcep/service/PcepService.py
index 744532b3b..04b8702d3 100644
--- a/src/pcep/service/PcepService.py
+++ b/src/pcep/service/PcepService.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/service/PcepServiceServicerImpl.py b/src/pcep/service/PcepServiceServicerImpl.py
index 4975a71dc..2390d8aec 100644
--- a/src/pcep/service/PcepServiceServicerImpl.py
+++ b/src/pcep/service/PcepServiceServicerImpl.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/service/__init__.py b/src/pcep/service/__init__.py
index 1549d9811..a5ccb6078 100644
--- a/src/pcep/service/__init__.py
+++ b/src/pcep/service/__init__.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/service/__main__.py b/src/pcep/service/__main__.py
index 519723200..4825a84b2 100644
--- a/src/pcep/service/__main__.py
+++ b/src/pcep/service/__main__.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/service/resources/BGP4Parameters_2.xml b/src/pcep/service/resources/BGP4Parameters_2.xml
index d7a101668..f59ea1f3b 100644
--- a/src/pcep/service/resources/BGP4Parameters_2.xml
+++ b/src/pcep/service/resources/BGP4Parameters_2.xml
@@ -1,4 +1,18 @@
-<?xml version="1.0" encoding="UTF-8"?>
+ <!-- Copyright 2022-2024 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. -->
+ 
+ <?xml version="1.0" encoding="UTF-8"?>
 <config>
 	<!-- TCP port where the BGP is listening for incoming bgp4 connections. Optional Parameter. Default value: 179 (BGP Port)  --> 
 	<BGP4Port>22179</BGP4Port>
diff --git a/src/pcep/service/resources/log4j2.xml b/src/pcep/service/resources/log4j2.xml
index fa4ad59c9..83a073bbc 100644
--- a/src/pcep/service/resources/log4j2.xml
+++ b/src/pcep/service/resources/log4j2.xml
@@ -1,4 +1,18 @@
-<?xml version="1.0" encoding="UTF-8"?>
+ <!-- Copyright 2022-2024 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. -->
+ 
+ <?xml version="1.0" encoding="UTF-8"?>
     <Configuration status="DEBUG">
       <Appenders>
         <Console name="Console" target="SYSTEM_OUT">
diff --git a/src/pcep/service/resources/topologia_ifusion.xml b/src/pcep/service/resources/topologia_ifusion.xml
index 7c1f9ad3d..f53386686 100644
--- a/src/pcep/service/resources/topologia_ifusion.xml
+++ b/src/pcep/service/resources/topologia_ifusion.xml
@@ -1,4 +1,18 @@
-<?xml version="1.0" encoding="UTF-8"?>
+ <!-- Copyright 2022-2024 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. -->
+ 
+ <?xml version="1.0" encoding="UTF-8"?>
 <network>
 	<domain>
 		<layer type="mpls" ></layer>
diff --git a/src/pcep/service/tools/GrpcServer.py b/src/pcep/service/tools/GrpcServer.py
index eefecf6c1..60a77e405 100644
--- a/src/pcep/service/tools/GrpcServer.py
+++ b/src/pcep/service/tools/GrpcServer.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/service/tools/Grpc_TestClient/gRPC_PCEPClient.py b/src/pcep/service/tools/Grpc_TestClient/gRPC_PCEPClient.py
index 99fe94350..2d233ec48 100644
--- a/src/pcep/service/tools/Grpc_TestClient/gRPC_PCEPClient.py
+++ b/src/pcep/service/tools/Grpc_TestClient/gRPC_PCEPClient.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/service/tools/Grpc_TestClient/grpcService.proto b/src/pcep/service/tools/Grpc_TestClient/grpcService.proto
index ff0ac0b02..1da1ab3ef 100644
--- a/src/pcep/service/tools/Grpc_TestClient/grpcService.proto
+++ b/src/pcep/service/tools/Grpc_TestClient/grpcService.proto
@@ -1,4 +1,4 @@
-// Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+// Copyright 2022-2024 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.
diff --git a/src/pcep/service/tools/Grpc_TestClient/grpcService_pb2.py b/src/pcep/service/tools/Grpc_TestClient/grpcService_pb2.py
index 314442ae4..f36920a1f 100644
--- a/src/pcep/service/tools/Grpc_TestClient/grpcService_pb2.py
+++ b/src/pcep/service/tools/Grpc_TestClient/grpcService_pb2.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/service/tools/Grpc_TestClient/grpcService_pb2_grpc.py b/src/pcep/service/tools/Grpc_TestClient/grpcService_pb2_grpc.py
index a2a3ca301..bd8ea3865 100644
--- a/src/pcep/service/tools/Grpc_TestClient/grpcService_pb2_grpc.py
+++ b/src/pcep/service/tools/Grpc_TestClient/grpcService_pb2_grpc.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/service/tools/Grpc_TestClient/test_gRPC_client.py b/src/pcep/service/tools/Grpc_TestClient/test_gRPC_client.py
index b4eadb877..598165b58 100644
--- a/src/pcep/service/tools/Grpc_TestClient/test_gRPC_client.py
+++ b/src/pcep/service/tools/Grpc_TestClient/test_gRPC_client.py
@@ -1,4 +1,4 @@
-#  Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+#  Copyright 2022-2024 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.
diff --git a/src/pcep/service/tools/JavaRunner.py b/src/pcep/service/tools/JavaRunner.py
index 27d090f1f..71a951577 100644
--- a/src/pcep/service/tools/JavaRunner.py
+++ b/src/pcep/service/tools/JavaRunner.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/service/tools/PCEServerConfiguration.xml b/src/pcep/service/tools/PCEServerConfiguration.xml
index a48b4c03b..64b2ac34d 100644
--- a/src/pcep/service/tools/PCEServerConfiguration.xml
+++ b/src/pcep/service/tools/PCEServerConfiguration.xml
@@ -1,4 +1,18 @@
-<?xml version="1.0" encoding="UTF-8"?>
+ <!-- Copyright 2022-2024 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. -->
+ 
+ <?xml version="1.0" encoding="UTF-8"?>
 <config>
 	<PCEServerPort>4189</PCEServerPort>
 	<PCEManagementPort>6666</PCEManagementPort>
diff --git a/src/pcep/service/tools/__init__.py b/src/pcep/service/tools/__init__.py
index 1549d9811..a5ccb6078 100644
--- a/src/pcep/service/tools/__init__.py
+++ b/src/pcep/service/tools/__init__.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/pcep/tests/__init__.py b/src/pcep/tests/__init__.py
index 1549d9811..a5ccb6078 100644
--- a/src/pcep/tests/__init__.py
+++ b/src/pcep/tests/__init__.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
+# Copyright 2022-2024 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.
diff --git a/src/service/service/service_handlers/qkd/qkd_service_handler.py b/src/service/service/service_handlers/qkd/qkd_service_handler.py
index 76c67867e..be567d652 100644
--- a/src/service/service/service_handlers/qkd/qkd_service_handler.py
+++ b/src/service/service/service_handlers/qkd/qkd_service_handler.py
@@ -17,7 +17,7 @@ import json, logging, uuid
 from typing import Any, Dict, List, Optional, Tuple, Union
 from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method
 from common.proto.context_pb2 import ConfigRule, DeviceId, Service
-from common.proto.app_pb2 import App, QKDAppStatusEnum, QKDAppTypesEnum
+# from common.proto.app_pb2 import App, QKDAppStatusEnum, QKDAppTypesEnum
 from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set
 from common.tools.object_factory.Device import json_device_id
 from common.type_checkers.Checkers import chk_type
@@ -63,235 +63,235 @@ class QKDServiceHandler(_ServiceHandler):
         context_uuid = self.__service.service_id.context_id.context_uuid.uuid
 
         results = []
-        try:
+        # try:
 
-            if len(endpoints) > 4:
-                is_virtual = True
-            else:
-                is_virtual = False
+        #     if len(endpoints) > 4:
+        #         is_virtual = True
+        #     else:
+        #         is_virtual = False
             
-            devices    = []
-            qkdn_ids   = []
-            interfaces = []
-            links      = []
+        #     devices    = []
+        #     qkdn_ids   = []
+        #     interfaces = []
+        #     links      = []
 
-            # Optare: First a big iteration through all devices is done in order to obtain all information needed for the whole operation
-            # Optare: This is a way to minimize time of operation. Otherwise it would require many O(N) operations. This way we can reduce it to one
+        #     # Optare: First a big iteration through all devices is done in order to obtain all information needed for the whole operation
+        #     # Optare: This is a way to minimize time of operation. Otherwise it would require many O(N) operations. This way we can reduce it to one
 
-            # Populate devices and QKDN ids
-            for idx, endpoint in enumerate(endpoints[::2]):
-                device_uuid, endpoint_left_uuid = get_device_endpoint_uuids(endpoint)
-                _, endpoint_right_uuid = get_device_endpoint_uuids(endpoints[2 * idx + 1])
+        #     # Populate devices and QKDN ids
+        #     for idx, endpoint in enumerate(endpoints[::2]):
+        #         device_uuid, endpoint_left_uuid = get_device_endpoint_uuids(endpoint)
+        #         _, endpoint_right_uuid = get_device_endpoint_uuids(endpoints[2 * idx + 1])
 
-                device = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid)))
-                devices.append(device)
-                interfaces.append([0,0])
-                links.append([])
+        #         device = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid)))
+        #         devices.append(device)
+        #         interfaces.append([0,0])
+        #         links.append([])
 
 
 
 
 
-                endpoint_left =  get_endpoint_name_by_uuid(device, endpoint_left_uuid) if idx > 0 else None
-                endpoint_right = get_endpoint_name_by_uuid(device, endpoint_right_uuid) if 2 * idx + 2 < len(endpoints) else None
+        #         endpoint_left =  get_endpoint_name_by_uuid(device, endpoint_left_uuid) if idx > 0 else None
+        #         endpoint_right = get_endpoint_name_by_uuid(device, endpoint_right_uuid) if 2 * idx + 2 < len(endpoints) else None
 
 
-                for config_rule in device.device_config.config_rules:
-                    resource_key = config_rule.custom.resource_key
+        #         for config_rule in device.device_config.config_rules:
+        #             resource_key = config_rule.custom.resource_key
 
-                    if resource_key == '__node__':
-                        value = json.loads(config_rule.custom.resource_value)
-                        qkdn_ids.append(value['qkdn_id'])
+        #             if resource_key == '__node__':
+        #                 value = json.loads(config_rule.custom.resource_value)
+        #                 qkdn_ids.append(value['qkdn_id'])
                     
-                    elif resource_key.startswith('/interface'):
-                        value = json.loads(config_rule.custom.resource_value)
-                        try:
-                            endpoint_str = value['qkdi_att_point']['uuid']
-                            LOGGER.info("A: " + str(endpoint_str) + "....." + str(endpoint_left) + "....." + str(endpoint_right))
-
-                            if endpoint_str == endpoint_left:
-                                interfaces[idx][0] = value['qkdi_id']
-                            elif endpoint_str == endpoint_right:
-                                interfaces[idx][1] = value['qkdi_id']
-                        except KeyError:
-                            pass
+        #             elif resource_key.startswith('/interface'):
+        #                 value = json.loads(config_rule.custom.resource_value)
+        #                 try:
+        #                     endpoint_str = value['qkdi_att_point']['uuid']
+        #                     LOGGER.info("A: " + str(endpoint_str) + "....." + str(endpoint_left) + "....." + str(endpoint_right))
+
+        #                     if endpoint_str == endpoint_left:
+        #                         interfaces[idx][0] = value['qkdi_id']
+        #                     elif endpoint_str == endpoint_right:
+        #                         interfaces[idx][1] = value['qkdi_id']
+        #                 except KeyError:
+        #                     pass
                     
-                    elif resource_key.startswith('/link'):
-                        value = json.loads(config_rule.custom.resource_value)
-                        links[idx].append(( value['uuid'],
-                            (value['src_qkdn_id'], value['src_interface_id']), 
-                            (value['dst_qkdn_id'], value['dst_interface_id'])
-                        ))
+        #             elif resource_key.startswith('/link'):
+        #                 value = json.loads(config_rule.custom.resource_value)
+        #                 links[idx].append(( value['uuid'],
+        #                     (value['src_qkdn_id'], value['src_interface_id']), 
+        #                     (value['dst_qkdn_id'], value['dst_interface_id'])
+        #                 ))
 
 
-            LOGGER.info("IFs: " + str(interfaces))
-            LOGGER.info("Links: " + str(links))
-            LOGGER.info("context_: " + context_uuid)
+        #     LOGGER.info("IFs: " + str(interfaces))
+        #     LOGGER.info("Links: " + str(links))
+        #     LOGGER.info("context_: " + context_uuid)
 
 
-            # Optare: From here now is where the work is really done. It iterates over every device in use for the service (ordered)
+        #     # Optare: From here now is where the work is really done. It iterates over every device in use for the service (ordered)
 
-            src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0])
-            src_device = devices[0]
-            src_endpoint = get_endpoint_matching(src_device, src_endpoint_uuid)
+        #     src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0])
+        #     src_device = devices[0]
+        #     src_endpoint = get_endpoint_matching(src_device, src_endpoint_uuid)
 
-            dst_device_uuid, dst_endpoint_uuid = get_device_endpoint_uuids(endpoints[-1])
-            dst_device = devices[-1]
-            dst_endpoint = get_endpoint_matching(dst_device, dst_endpoint_uuid)
+        #     dst_device_uuid, dst_endpoint_uuid = get_device_endpoint_uuids(endpoints[-1])
+        #     dst_device = devices[-1]
+        #     dst_endpoint = get_endpoint_matching(dst_device, dst_endpoint_uuid)
 
-            src_qkdn_id = qkdn_ids[0]
-            dst_qkdn_id = qkdn_ids[-1]
+        #     src_qkdn_id = qkdn_ids[0]
+        #     dst_qkdn_id = qkdn_ids[-1]
 
-            src_interface_id = interfaces[0][1]
-            dst_interface_id = interfaces[-1][0]
+        #     src_interface_id = interfaces[0][1]
+        #     dst_interface_id = interfaces[-1][0]
 
-            service_qkdl_id_src_dst = str(uuid.uuid4())
-            service_qkdl_id_dst_src = str(uuid.uuid4())
+        #     service_qkdl_id_src_dst = str(uuid.uuid4())
+        #     service_qkdl_id_dst_src = str(uuid.uuid4())
 
             
-            for idx, device in enumerate(devices):
+        #     for idx, device in enumerate(devices):
 
-                # Even though we always create them together. There is a chance the admin deletes one of the rules manually
-                phys_qkdl_id_right = None if idx == (len(devices) - 1) else '' # None == impossible
-                phys_qkdl_id_left = None if idx == 0 else '' # None == impossible
+        #         # Even though we always create them together. There is a chance the admin deletes one of the rules manually
+        #         phys_qkdl_id_right = None if idx == (len(devices) - 1) else '' # None == impossible
+        #         phys_qkdl_id_left = None if idx == 0 else '' # None == impossible
 
-                for link_uuid, link_src, link_dst in links[idx]:
-                    qkdn_link_src, qkdn_interface_src = link_src
-                    qkdn_link_dst, qkdn_interface_dst = link_dst
+        #         for link_uuid, link_src, link_dst in links[idx]:
+        #             qkdn_link_src, qkdn_interface_src = link_src
+        #             qkdn_link_dst, qkdn_interface_dst = link_dst
 
-                    if phys_qkdl_id_right == '' and \
-                        qkdn_link_src == qkdn_ids[idx] and qkdn_interface_src == interfaces[idx][1] and \
-                        qkdn_link_dst[idx+1] and qkdn_interface_dst == interfaces[idx+1][0]:
-                        phys_qkdl_id_right = link_uuid
+        #             if phys_qkdl_id_right == '' and \
+        #                 qkdn_link_src == qkdn_ids[idx] and qkdn_interface_src == interfaces[idx][1] and \
+        #                 qkdn_link_dst[idx+1] and qkdn_interface_dst == interfaces[idx+1][0]:
+        #                 phys_qkdl_id_right = link_uuid
 
 
-                    if phys_qkdl_id_left == '' and \
-                        qkdn_link_src == qkdn_ids[idx] and qkdn_interface_src == interfaces[idx][0] and \
-                        qkdn_link_dst[idx-1] and qkdn_interface_dst == interfaces[idx-1][1]:
-                        phys_qkdl_id_left = link_uuid
+        #             if phys_qkdl_id_left == '' and \
+        #                 qkdn_link_src == qkdn_ids[idx] and qkdn_interface_src == interfaces[idx][0] and \
+        #                 qkdn_link_dst[idx-1] and qkdn_interface_dst == interfaces[idx-1][1]:
+        #                 phys_qkdl_id_left = link_uuid
 
 
-                # Optare: Before adding information to config_rules you have to delete the list first otherwise old content will be called again
-                del device.device_config.config_rules[:]
+        #         # Optare: Before adding information to config_rules you have to delete the list first otherwise old content will be called again
+        #         del device.device_config.config_rules[:]
 
 
-                if phys_qkdl_id_right:
-                    if not is_virtual:
-                        service_qkdl_id_src_dst = phys_qkdl_id_right
+        #         if phys_qkdl_id_right:
+        #             if not is_virtual:
+        #                 service_qkdl_id_src_dst = phys_qkdl_id_right
 
-                elif phys_qkdl_id_right == '':
-                    qkdl_id_src_dst = str(uuid.uuid4()) if is_virtual else service_qkdl_id_src_dst
+        #         elif phys_qkdl_id_right == '':
+        #             qkdl_id_src_dst = str(uuid.uuid4()) if is_virtual else service_qkdl_id_src_dst
 
-                    json_config_rule = json_config_rule_set('/link/link[{:s}]'.format(qkdl_id_src_dst), {
-                        'uuid'               : qkdl_id_src_dst,
-                        'type'               : 'DIRECT',
-                        'src_qkdn_id'        : qkdn_ids[idx],
-                        'src_interface_id'   : interfaces[idx][1],
-                        'dst_qkdn_id'        : qkdn_ids[idx+1],
-                        'dst_interface_id'   : interfaces[idx+1][0],
-                    })
+        #             json_config_rule = json_config_rule_set('/link/link[{:s}]'.format(qkdl_id_src_dst), {
+        #                 'uuid'               : qkdl_id_src_dst,
+        #                 'type'               : 'DIRECT',
+        #                 'src_qkdn_id'        : qkdn_ids[idx],
+        #                 'src_interface_id'   : interfaces[idx][1],
+        #                 'dst_qkdn_id'        : qkdn_ids[idx+1],
+        #                 'dst_interface_id'   : interfaces[idx+1][0],
+        #             })
 
-                    device.device_config.config_rules.append(ConfigRule(**json_config_rule))
+        #             device.device_config.config_rules.append(ConfigRule(**json_config_rule))
 
 
-                if phys_qkdl_id_left:
-                    if not is_virtual:
-                        service_qkdl_id_dst_src = phys_qkdl_id_left
+        #         if phys_qkdl_id_left:
+        #             if not is_virtual:
+        #                 service_qkdl_id_dst_src = phys_qkdl_id_left
 
-                elif phys_qkdl_id_left == '':
-                    qkdl_id_dst_src = str(uuid.uuid4()) if is_virtual else service_qkdl_id_dst_src
+        #         elif phys_qkdl_id_left == '':
+        #             qkdl_id_dst_src = str(uuid.uuid4()) if is_virtual else service_qkdl_id_dst_src
 
-                    json_config_rule = json_config_rule_set('/link/link[{:s}]'.format(qkdl_id_dst_src), {
-                        'uuid'               : qkdl_id_dst_src,
-                        'type'               : 'DIRECT',
-                        'src_qkdn_id'        : qkdn_ids[idx],
-                        'src_interface_id'   : interfaces[idx][0],
-                        'dst_qkdn_id'        : qkdn_ids[idx-1],
-                        'dst_interface_id'   : interfaces[idx-1][1],
-                    })
+        #             json_config_rule = json_config_rule_set('/link/link[{:s}]'.format(qkdl_id_dst_src), {
+        #                 'uuid'               : qkdl_id_dst_src,
+        #                 'type'               : 'DIRECT',
+        #                 'src_qkdn_id'        : qkdn_ids[idx],
+        #                 'src_interface_id'   : interfaces[idx][0],
+        #                 'dst_qkdn_id'        : qkdn_ids[idx-1],
+        #                 'dst_interface_id'   : interfaces[idx-1][1],
+        #             })
 
-                    device.device_config.config_rules.append(ConfigRule(**json_config_rule))
+        #             device.device_config.config_rules.append(ConfigRule(**json_config_rule))
                 
 
 
-                if is_virtual:
-                    if idx < len(qkdn_ids) - 1:
-                        json_config_rule = json_config_rule_set('/link/link[{:s}]'.format(service_qkdl_id_src_dst), {
-                            'uuid'               : service_qkdl_id_src_dst,
-                            'type'               : 'VIRTUAL',
-                            'src_qkdn_id'        : src_qkdn_id,
-                            'src_interface_id'   : src_interface_id,
-                            'dst_qkdn_id'        : dst_qkdn_id,
-                            'dst_interface_id'   : dst_interface_id,
-                            'virt_prev_hop'      : qkdn_ids[idx-1] if idx > 0 else None,
-                            'virt_next_hops'     : qkdn_ids[idx+1:],
-                            'virt_bandwidth'     : 0,
-                        })
-
-                        device.device_config.config_rules.append(ConfigRule(**json_config_rule))
-
-                    if idx > 0:
-                        json_config_rule = json_config_rule_set('/link/link[{:s}]'.format(service_qkdl_id_dst_src), {
-                            'uuid'               : service_qkdl_id_dst_src,
-                            'type'               : 'VIRTUAL',
-                            'src_qkdn_id'        : dst_qkdn_id,
-                            'src_interface_id'   : dst_interface_id,
-                            'dst_qkdn_id'        : src_qkdn_id,
-                            'dst_interface_id'   : src_interface_id,
-                            'virt_prev_hop'      : qkdn_ids[idx+1] if idx < len(qkdn_ids) - 1 else None,
-                            'virt_next_hops'     : qkdn_ids[idx-1::-1],
-                            'virt_bandwidth'     : 0,
-                        })
-
-                        device.device_config.config_rules.append(ConfigRule(**json_config_rule))
-
-
-
-                json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), {
-                    'uuid'               : service_uuid,
-                    'qkdl_id_src_dst'    : service_qkdl_id_src_dst,
-                    'qkdl_id_dst_src'    : service_qkdl_id_dst_src,
-                })
-
-                device.device_config.config_rules.append(ConfigRule(**json_config_rule))
-                self.__task_executor.configure_device(device)
-
-
-            if is_virtual:
-
-                # Register App
-                internal_app_src_dst = {
-                    'app_id': {'context_id': {'context_uuid': {'uuid': context_uuid}}, 'app_uuid': {'uuid': str(uuid.uuid4())}},
-                    'app_status': QKDAppStatusEnum.QKDAPPSTATUS_ON,
-                    'app_type': QKDAppTypesEnum.QKDAPPTYPES_INTERNAL,
-                    'server_app_id': '',
-                    'client_app_id': [],
-                    'backing_qkdl_id': [{'qkdl_uuid': {'uuid': service_qkdl_id_src_dst}}],
-                    'local_device_id': src_device.device_id,
-                    'remote_device_id': dst_device.device_id,
-                }
-
-                self.__task_executor.register_app(App(**internal_app_src_dst))
+        #         if is_virtual:
+        #             if idx < len(qkdn_ids) - 1:
+        #                 json_config_rule = json_config_rule_set('/link/link[{:s}]'.format(service_qkdl_id_src_dst), {
+        #                     'uuid'               : service_qkdl_id_src_dst,
+        #                     'type'               : 'VIRTUAL',
+        #                     'src_qkdn_id'        : src_qkdn_id,
+        #                     'src_interface_id'   : src_interface_id,
+        #                     'dst_qkdn_id'        : dst_qkdn_id,
+        #                     'dst_interface_id'   : dst_interface_id,
+        #                     'virt_prev_hop'      : qkdn_ids[idx-1] if idx > 0 else None,
+        #                     'virt_next_hops'     : qkdn_ids[idx+1:],
+        #                     'virt_bandwidth'     : 0,
+        #                 })
+
+        #                 device.device_config.config_rules.append(ConfigRule(**json_config_rule))
+
+        #             if idx > 0:
+        #                 json_config_rule = json_config_rule_set('/link/link[{:s}]'.format(service_qkdl_id_dst_src), {
+        #                     'uuid'               : service_qkdl_id_dst_src,
+        #                     'type'               : 'VIRTUAL',
+        #                     'src_qkdn_id'        : dst_qkdn_id,
+        #                     'src_interface_id'   : dst_interface_id,
+        #                     'dst_qkdn_id'        : src_qkdn_id,
+        #                     'dst_interface_id'   : src_interface_id,
+        #                     'virt_prev_hop'      : qkdn_ids[idx+1] if idx < len(qkdn_ids) - 1 else None,
+        #                     'virt_next_hops'     : qkdn_ids[idx-1::-1],
+        #                     'virt_bandwidth'     : 0,
+        #                 })
+
+        #                 device.device_config.config_rules.append(ConfigRule(**json_config_rule))
+
+
+
+        #         json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), {
+        #             'uuid'               : service_uuid,
+        #             'qkdl_id_src_dst'    : service_qkdl_id_src_dst,
+        #             'qkdl_id_dst_src'    : service_qkdl_id_dst_src,
+        #         })
+
+        #         device.device_config.config_rules.append(ConfigRule(**json_config_rule))
+        #         self.__task_executor.configure_device(device)
+
+
+        #     if is_virtual:
+
+        #         # Register App
+        #         internal_app_src_dst = {
+        #             'app_id': {'context_id': {'context_uuid': {'uuid': context_uuid}}, 'app_uuid': {'uuid': str(uuid.uuid4())}},
+        #             'app_status': QKDAppStatusEnum.QKDAPPSTATUS_ON,
+        #             'app_type': QKDAppTypesEnum.QKDAPPTYPES_INTERNAL,
+        #             'server_app_id': '',
+        #             'client_app_id': [],
+        #             'backing_qkdl_id': [{'qkdl_uuid': {'uuid': service_qkdl_id_src_dst}}],
+        #             'local_device_id': src_device.device_id,
+        #             'remote_device_id': dst_device.device_id,
+        #         }
+
+        #         self.__task_executor.register_app(App(**internal_app_src_dst))
                 
 
-                # Register App
-                internal_app_dst_src = {
-                    'app_id': {'context_id': {'context_uuid': {'uuid': context_uuid}}, 'app_uuid': {'uuid': str(uuid.uuid4())}},
-                    'app_status': QKDAppStatusEnum.QKDAPPSTATUS_ON,
-                    'app_type': QKDAppTypesEnum.QKDAPPTYPES_INTERNAL,
-                    'server_app_id': '',
-                    'client_app_id': [],
-                    'backing_qkdl_id': [{'qkdl_uuid': {'uuid': service_qkdl_id_dst_src}}],
-                    'local_device_id': dst_device.device_id,
-                    'remote_device_id': src_device.device_id,
-                }
-
-                self.__task_executor.register_app(App(**internal_app_dst_src))
-
-            results.append(True)
-        except Exception as e: # pylint: disable=broad-except
-            LOGGER.exception('Unable to SetEndpoint for Service({:s})'.format(str(service_uuid)))
-            results.append(e)
+        #         # Register App
+        #         internal_app_dst_src = {
+        #             'app_id': {'context_id': {'context_uuid': {'uuid': context_uuid}}, 'app_uuid': {'uuid': str(uuid.uuid4())}},
+        #             'app_status': QKDAppStatusEnum.QKDAPPSTATUS_ON,
+        #             'app_type': QKDAppTypesEnum.QKDAPPTYPES_INTERNAL,
+        #             'server_app_id': '',
+        #             'client_app_id': [],
+        #             'backing_qkdl_id': [{'qkdl_uuid': {'uuid': service_qkdl_id_dst_src}}],
+        #             'local_device_id': dst_device.device_id,
+        #             'remote_device_id': src_device.device_id,
+        #         }
+
+        #         self.__task_executor.register_app(App(**internal_app_dst_src))
+
+        #     results.append(True)
+        # except Exception as e: # pylint: disable=broad-except
+        #     LOGGER.exception('Unable to SetEndpoint for Service({:s})'.format(str(service_uuid)))
+        #     results.append(e)
 
         return results
 
-- 
GitLab