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
Loading
Loading
Loading
Loading
+30 −20
Original line number Diff line number Diff line
@@ -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,17 +39,26 @@ 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 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', {})
@@ -59,9 +68,10 @@ def config_getter(
        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_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': endpoint_type}
        endpoint_data = {'uuid': sip['uuid'], 'type': str_endpoint_type}
        result.append((endpoint_url, endpoint_data))

    return result