From d8aae80fab3d569831785613fc89dc24f20167be Mon Sep 17 00:00:00 2001
From: gifrerenom <lluis.gifre@cttc.es>
Date: Fri, 27 Jan 2023 14:49:13 +0000
Subject: [PATCH] Device component - TAPI Driver:
- corrected parsing of endpoints to improve flexibility in retrieved fields
---
.../service/drivers/transport_api/Tools.py | 50 +++++++++++--------
1 file changed, 30 insertions(+), 20 deletions(-)
diff --git a/src/device/service/drivers/transport_api/Tools.py b/src/device/service/drivers/transport_api/Tools.py
index 6b1be361b..e54e6497a 100644
--- a/src/device/service/drivers/transport_api/Tools.py
+++ b/src/device/service/drivers/transport_api/Tools.py
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import json, logging, requests
+import json, logging, operator, requests
from requests.auth import HTTPBasicAuth
from typing import Optional
from device.service.driver_api._Driver import RESOURCE_ENDPOINTS
@@ -39,30 +39,40 @@ def config_getter(
response = requests.get(url, timeout=timeout, verify=False, auth=auth)
except requests.exceptions.Timeout:
LOGGER.exception('Timeout connecting {:s}'.format(url))
+ return result
except Exception as e: # pylint: disable=broad-except
LOGGER.exception('Exception retrieving {:s}'.format(resource_key))
result.append((resource_key, e))
- else:
+ return result
+
+ try:
context = json.loads(response.content)
+ except Exception as e: # pylint: disable=broad-except
+ LOGGER.warning('Unable to decode reply: {:s}'.format(str(response.content)))
+ result.append((resource_key, e))
+ return result
+
+ if resource_key != RESOURCE_ENDPOINTS: return result
+
+ if 'tapi-common:context' in context:
+ context = context['tapi-common:context']
+ elif 'context' in context:
+ context = context['context']
- if resource_key == RESOURCE_ENDPOINTS:
- 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']:
- layer_protocol_name = sip.get('layer-protocol-name', '?')
- supportable_spectrum = sip.get('tapi-photonic-media:media-channel-service-interface-point-spec', {})
- supportable_spectrum = supportable_spectrum.get('mc-pool', {})
- supportable_spectrum = supportable_spectrum.get('supportable-spectrum', [])
- supportable_spectrum = supportable_spectrum[0] if len(supportable_spectrum) == 1 else {}
- grid_type = supportable_spectrum.get('frequency-constraint', {}).get('grid-type')
- granularity = supportable_spectrum.get('frequency-constraint', {}).get('adjustment-granularity')
- direction = sip.get('direction', '?')
- endpoint_type = ':'.join([layer_protocol_name, grid_type, granularity, direction])
- endpoint_url = '/endpoints/endpoint[{:s}]'.format(sip['uuid'])
- endpoint_data = {'uuid': sip['uuid'], 'type': endpoint_type}
- result.append((endpoint_url, endpoint_data))
+ for sip in context['service-interface-point']:
+ layer_protocol_name = sip.get('layer-protocol-name', '?')
+ supportable_spectrum = sip.get('tapi-photonic-media:media-channel-service-interface-point-spec', {})
+ supportable_spectrum = supportable_spectrum.get('mc-pool', {})
+ supportable_spectrum = supportable_spectrum.get('supportable-spectrum', [])
+ supportable_spectrum = supportable_spectrum[0] if len(supportable_spectrum) == 1 else {}
+ grid_type = supportable_spectrum.get('frequency-constraint', {}).get('grid-type')
+ granularity = supportable_spectrum.get('frequency-constraint', {}).get('adjustment-granularity')
+ direction = sip.get('direction', '?')
+ endpoint_type = [layer_protocol_name, grid_type, granularity, direction]
+ str_endpoint_type = ':'.join(filter(lambda i: operator.is_not(i, None), endpoint_type))
+ endpoint_url = '/endpoints/endpoint[{:s}]'.format(sip['uuid'])
+ endpoint_data = {'uuid': sip['uuid'], 'type': str_endpoint_type}
+ result.append((endpoint_url, endpoint_data))
return result
--
GitLab