Skip to content
Snippets Groups Projects
Commit d8aae80f authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device component - TAPI Driver:

- corrected parsing of endpoints to improve flexibility in retrieved fields
parent 6103d18d
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!43CI pipeline and multiple module fixes
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment