Commit 4d9fa4cf authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device component - TAPI Driver:

- Added logic to retrieve configured services
parent 42794440
Loading
Loading
Loading
Loading
+69 −22
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
import json, logging, operator, requests
from requests.auth import HTTPBasicAuth
from typing import Optional
from device.service.driver_api._Driver import RESOURCE_ENDPOINTS
from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_SERVICES

LOGGER = logging.getLogger(__name__)

@@ -52,8 +52,7 @@ def config_getter(
        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:
@@ -68,12 +67,60 @@ 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 = [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}
            sip_uuid = sip['uuid']

            sip_names = sip.get('name', [])
            sip_name = next(iter([
                sip_name['value']
                for sip_name in sip_names
                if sip_name['value-name'] == 'local-name'
            ]), sip_uuid)

            endpoint_url = '/endpoints/endpoint[{:s}]'.format(sip_uuid)
            endpoint_data = {'uuid': sip_uuid, 'name': sip_name, 'type': str_endpoint_type}
            result.append((endpoint_url, endpoint_data))

    elif resource_key == RESOURCE_SERVICES:
        if 'tapi-common:context' in context:
            context = context['tapi-common:context']
        elif 'context' in context:
            context = context['context']

        if 'tapi-connectivity:connectivity-context' in context:
            context = context['tapi-connectivity:connectivity-context']
        elif 'connectivity-context' in context:
            context = context['connectivity-context']

        for conn_svc in context['connectivity-service']:
            service_uuid = conn_svc['uuid']
            constraints = conn_svc.get('connectivity-constraint', {})
            total_req_cap = constraints.get('requested-capacity', {}).get('total-size', {})

            service_url = '/services/service[{:s}]'.format(service_uuid)
            service_data = {
                'uuid': service_uuid,
                'direction': constraints.get('connectivity-direction', 'UNIDIRECTIONAL'),
                'capacity_unit': total_req_cap.get('unit', '<UNDEFINED>'),
                'capacity_value': total_req_cap.get('value', '<UNDEFINED>'),
            }

            for i,endpoint in enumerate(conn_svc.get('end-point', [])):
                layer_protocol_name = endpoint.get('layer-protocol-name')
                if layer_protocol_name is not None:
                    service_data['layer_protocol_name'] = layer_protocol_name

                layer_protocol_qualifier = endpoint.get('layer-protocol-qualifier')
                if layer_protocol_qualifier is not None:
                    service_data['layer_protocol_qualifier'] = layer_protocol_qualifier

                sip = endpoint['service-interface-point']['service-interface-point-uuid']
                service_data['input_sip' if i == 0 else 'output_sip'] = sip

            result.append((service_url, service_data))

    return result

def create_connectivity_service(
+2 −9
Original line number Diff line number Diff line
@@ -12,16 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES
from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_SERVICES

ALL_RESOURCE_KEYS = [
    RESOURCE_ENDPOINTS,
    RESOURCE_INTERFACES,
    RESOURCE_NETWORK_INSTANCES,
    RESOURCE_SERVICES,
]

RESOURCE_KEY_MAPPINGS = {
    RESOURCE_ENDPOINTS        : 'component',
    RESOURCE_INTERFACES       : 'interface',
    RESOURCE_NETWORK_INSTANCES: 'network_instance',
}