From 45f01d3eddfd564f71eda249432d4eed8ab4a53d Mon Sep 17 00:00:00 2001
From: gifrerenom <lluis.gifre@cttc.es>
Date: Fri, 14 Oct 2022 11:07:27 +0000
Subject: [PATCH] Device component:

- refined TrandportAPIDriver endpoint retrieval
- refined Driver selection
---
 src/device/service/drivers/__init__.py        | 60 +++++++++----------
 .../service/drivers/transport_api/Tools.py    | 12 +++-
 2 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/src/device/service/drivers/__init__.py b/src/device/service/drivers/__init__.py
index 5fe786667..535b553a8 100644
--- a/src/device/service/drivers/__init__.py
+++ b/src/device/service/drivers/__init__.py
@@ -25,8 +25,8 @@ DRIVERS = []
 from .emulated.EmulatedDriver import EmulatedDriver # pylint: disable=wrong-import-position
 DRIVERS.append(
     (EmulatedDriver, [
+        # TODO: multi-filter is not working
         {
-            # Driver==EMULATED, all device types => use Emulated
             FilterFieldEnum.DEVICE_TYPE: [
                 DeviceTypeEnum.EMULATED_DATACENTER,
                 DeviceTypeEnum.EMULATED_MICROVAWE_RADIO_SYSTEM,
@@ -37,40 +37,40 @@ DRIVERS.append(
                 DeviceTypeEnum.EMULATED_PACKET_ROUTER,
                 DeviceTypeEnum.EMULATED_PACKET_SWITCH,
 
-                DeviceTypeEnum.DATACENTER,
-                DeviceTypeEnum.MICROVAWE_RADIO_SYSTEM,
-                DeviceTypeEnum.OPEN_LINE_SYSTEM,
-                DeviceTypeEnum.OPTICAL_ROADM,
-                DeviceTypeEnum.OPTICAL_TRANSPONDER,
-                DeviceTypeEnum.P4_SWITCH,
-                DeviceTypeEnum.PACKET_ROUTER,
-                DeviceTypeEnum.PACKET_SWITCH,
+                #DeviceTypeEnum.DATACENTER,
+                #DeviceTypeEnum.MICROVAWE_RADIO_SYSTEM,
+                #DeviceTypeEnum.OPEN_LINE_SYSTEM,
+                #DeviceTypeEnum.OPTICAL_ROADM,
+                #DeviceTypeEnum.OPTICAL_TRANSPONDER,
+                #DeviceTypeEnum.P4_SWITCH,
+                #DeviceTypeEnum.PACKET_ROUTER,
+                #DeviceTypeEnum.PACKET_SWITCH,
             ],
             FilterFieldEnum.DRIVER: [
                 ORM_DeviceDriverEnum.UNDEFINED,
             ],
         },
-        {
-            # Emulated devices, all drivers => use Emulated
-            FilterFieldEnum.DEVICE_TYPE: [
-                DeviceTypeEnum.EMULATED_DATACENTER,
-                DeviceTypeEnum.EMULATED_MICROVAWE_RADIO_SYSTEM,
-                DeviceTypeEnum.EMULATED_OPEN_LINE_SYSTEM,
-                DeviceTypeEnum.EMULATED_OPTICAL_ROADM,
-                DeviceTypeEnum.EMULATED_OPTICAL_TRANSPONDER,
-                DeviceTypeEnum.EMULATED_P4_SWITCH,
-                DeviceTypeEnum.EMULATED_PACKET_ROUTER,
-                DeviceTypeEnum.EMULATED_PACKET_SWITCH,
-            ],
-            FilterFieldEnum.DRIVER: [
-                ORM_DeviceDriverEnum.UNDEFINED,
-                ORM_DeviceDriverEnum.OPENCONFIG,
-                ORM_DeviceDriverEnum.TRANSPORT_API,
-                ORM_DeviceDriverEnum.P4,
-                ORM_DeviceDriverEnum.IETF_NETWORK_TOPOLOGY,
-                ORM_DeviceDriverEnum.ONF_TR_352,
-            ],
-        }
+        #{
+        #    # Emulated devices, all drivers => use Emulated
+        #    FilterFieldEnum.DEVICE_TYPE: [
+        #        DeviceTypeEnum.EMULATED_DATACENTER,
+        #        DeviceTypeEnum.EMULATED_MICROVAWE_RADIO_SYSTEM,
+        #        DeviceTypeEnum.EMULATED_OPEN_LINE_SYSTEM,
+        #        DeviceTypeEnum.EMULATED_OPTICAL_ROADM,
+        #        DeviceTypeEnum.EMULATED_OPTICAL_TRANSPONDER,
+        #        DeviceTypeEnum.EMULATED_P4_SWITCH,
+        #        DeviceTypeEnum.EMULATED_PACKET_ROUTER,
+        #        DeviceTypeEnum.EMULATED_PACKET_SWITCH,
+        #    ],
+        #    FilterFieldEnum.DRIVER: [
+        #        ORM_DeviceDriverEnum.UNDEFINED,
+        #        ORM_DeviceDriverEnum.OPENCONFIG,
+        #        ORM_DeviceDriverEnum.TRANSPORT_API,
+        #        ORM_DeviceDriverEnum.P4,
+        #        ORM_DeviceDriverEnum.IETF_NETWORK_TOPOLOGY,
+        #        ORM_DeviceDriverEnum.ONF_TR_352,
+        #    ],
+        #}
     ]))
 
 if LOAD_ALL_DEVICE_DRIVERS:
diff --git a/src/device/service/drivers/transport_api/Tools.py b/src/device/service/drivers/transport_api/Tools.py
index 8f18c56b3..6faee37ce 100644
--- a/src/device/service/drivers/transport_api/Tools.py
+++ b/src/device/service/drivers/transport_api/Tools.py
@@ -36,9 +36,15 @@ def config_getter(root_url, resource_key, timeout):
         context = json.loads(response.content)
 
         if resource_key == RESOURCE_ENDPOINTS:
-            for sip in context['tapi-common:context']['service-interface-point']:
-                result.append(
-                    ('/endpoints/endpoint[{:s}]'.format(sip['uuid']), {'uuid': sip['uuid'], 'type': '10Gbps'}))
+            if 'tapi-common:context' in context:
+                context = context['tapi-common:context']
+            elif 'context' in context:
+                context = context['context']
+            for sip in context['service-interface-point']:
+                endpoint_type = sip.get('layer-protocol-name', '10Gbps')
+                endpoint_url = '/endpoints/endpoint[{:s}]'.format(sip['uuid'])
+                endpoint_data = {'uuid': sip['uuid'], 'type': endpoint_type}
+                result.append((endpoint_url, endpoint_data))
 
     return result
 
-- 
GitLab