Commit 5c0a7622 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

feat: implement IPoWDM service update logic and integrate context-aware...

feat: implement IPoWDM service update logic and integrate context-aware topology retrieval in IETF drivers adn optical_tfs
parent fcd571ae
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@

import json, logging, threading
from typing import Any, Iterator, List, Optional, Tuple, Union
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME
from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method
from common.tools.object_factory.Device import json_device_id
from common.tools.object_factory.EndPoint import json_endpoint_id
@@ -56,7 +57,12 @@ class IetfL2VpnDriver(_Driver):
        wim_account = {'user': username, 'password': password}
        # Mapping updated dynamically with each request
        config = {'mapping_not_needed': False, 'service_endpoint_mapping': []}
        self.tac = TfsApiClient(self.address, int(self.port), scheme=scheme, username=username, password=password)
        self.__context_uuid = self.settings.get('context_uuid', DEFAULT_CONTEXT_NAME)
        self.__topology_uuid = self.settings.get('topology_uuid', DEFAULT_TOPOLOGY_NAME)
        self.tac = TfsApiClient(
            self.address, int(self.port), scheme=scheme, username=username,
            password=password, context_uuid=self.__context_uuid, topology_uuid=self.__topology_uuid
        )
        self.wim = WimconnectorIETFL2VPN(wim, wim_account, config=config)
        self.conn_info = {} # internal database emulating OSM storage provided to WIM Connectors

+12 −6
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@

import json, logging, requests
from typing import Dict, List, Optional
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME
from common.tools.rest_api.client.RestApiClient import RestApiClient
from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum

@@ -21,6 +22,7 @@ from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum
GET_CONTEXT_IDS_URL = '/tfs-api/context_ids'
GET_DEVICES_URL     = '/tfs-api/devices'
GET_LINKS_URL       = '/tfs-api/links'
TOPOLOGY_URL        = '/tfs-api/context/{context_uuid:s}/topology_details/{topology_uuid:s}'

MAPPING_STATUS = {
    'DEVICEOPERATIONALSTATUS_UNDEFINED': 0,
@@ -62,12 +64,16 @@ class TfsApiClient(RestApiClient):
    def __init__(
        self, address : str, port : int, scheme : str = 'http',
        username : Optional[str] = None, password : Optional[str] = None,
        timeout : Optional[int] = 30
        timeout : Optional[int] = 30,
        context_uuid : str = DEFAULT_CONTEXT_NAME,
        topology_uuid : str = DEFAULT_TOPOLOGY_NAME
    ) -> None:
        super().__init__(
            address, port, scheme=scheme, username=username, password=password,
            timeout=timeout, verify_certs=False, allow_redirects=True, logger=LOGGER
        )
        self.context_uuid = context_uuid
        self.topology_uuid = topology_uuid


    def check_credentials(self, raise_if_fail : bool = True) -> None:
@@ -101,10 +107,12 @@ class TfsApiClient(RestApiClient):
            MSG = 'Unsupported import_topology mode: {:s}'
            raise Exception(MSG.format(str(import_topology)))

        devices = self.get(GET_DEVICES_URL, expected_status_codes={requests.codes['OK']})
        topology = self.get(TOPOLOGY_URL.format(
            context_uuid=self.context_uuid, topology_uuid=self.topology_uuid
        ))

        result = list()
        for json_device in devices['devices']:
        for json_device in topology.get('devices', []):
            device_uuid : str = json_device['device_id']['device_uuid']['uuid']
            device_type : str = json_device['device_type']
            #if not device_type.startswith('emu-'): device_type = 'emu-' + device_type
@@ -170,9 +178,7 @@ class TfsApiClient(RestApiClient):
            LOGGER.debug('[get_devices_endpoints] devices only; returning')
            return result

        links = self.get(GET_LINKS_URL, expected_status_codes={requests.codes['OK']})

        for json_link in links['links']:
        for json_link in topology.get('links', []):
            link_uuid : str = json_link['link_id']['link_uuid']['uuid']
            link_url = '/links/link[{:s}]'.format(link_uuid)
            link_endpoint_ids = [
+13 −3
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@

import anytree, copy, json, logging, re, threading
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME
from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method
from common.tools.rest_conf.client.RestConfClient import RestConfClient
from common.type_checkers.Checkers import chk_length, chk_string, chk_type
@@ -63,9 +64,14 @@ class IetfL3VpnDriver(_Driver):
            password=password, timeout=timeout
        )

        self.__context_uuid = self.settings.get('context_uuid', DEFAULT_CONTEXT_NAME)
        self.__topology_uuid = self.settings.get('topology_uuid', DEFAULT_TOPOLOGY_NAME)

        restconf_settings = copy.deepcopy(settings)
        restconf_settings.pop('base_url', None)
        restconf_settings.pop('import_topology', None)
        restconf_settings.pop('context_uuid', None)
        restconf_settings.pop('topology_uuid', None)
        restconf_settings['logger'] = logging.getLogger(__name__ + '.RestConfClient')
        self._rest_conf_client = RestConfClient(address, port=port, **restconf_settings)
        self._handler_subscription = SubscriptionHandler(self._rest_conf_client)
@@ -163,7 +169,11 @@ class IetfL3VpnDriver(_Driver):
                    chk_string(str_resource_name, resource_key, allow_empty=False)
                    if resource_key == RESOURCE_ENDPOINTS:
                        # return endpoints through TFS NBI API and list-devices method
                        results.extend(self.tac.get_devices_endpoints(self.__import_topology))
                        results.extend(self.tac.get_devices_endpoints(
                            self.__import_topology,
                            context_uuid=self.__context_uuid,
                            topology_uuid=self.__topology_uuid
                        ))
                    else:
                        resource_key = SPECIAL_RESOURCE_MAPPINGS.get(
                            resource_key, resource_key
@@ -194,9 +204,9 @@ class IetfL3VpnDriver(_Driver):
                for resource in resources:
                    if 'ipowdm' in str(resource):
                        try:
                            create_request(resource)
                            status = create_request(resource)
                            LOGGER.info('Request created successfully')
                            results.append((resource, True))
                            results.append((resource, status))
                        except Exception as e:
                            MSG = 'Invalid resource_value type: expected dict, got {:s}'
                            results.append((resource, e))
+12 −8
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@

import json, logging, requests
from typing import Dict, List, Optional
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME
from common.tools.rest_api.client.RestApiClient import RestApiClient
from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum

@@ -21,6 +22,7 @@ from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum
GET_CONTEXT_IDS_URL = '/tfs-api/context_ids'
GET_DEVICES_URL     = '/tfs-api/devices'
GET_LINKS_URL       = '/tfs-api/links'
TOPOLOGY_URL        = '/tfs-api/context/{context_uuid:s}/topology_details/{topology_uuid:s}'


IETF_L3VPN_ALL_URL  = '/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services'
@@ -96,20 +98,24 @@ class TfsApiClient(RestApiClient):


    def get_devices_endpoints(
        self, import_topology : ImportTopologyEnum = ImportTopologyEnum.DEVICES
        self, import_topology : ImportTopologyEnum = ImportTopologyEnum.DEVICES,
        context_uuid : str = DEFAULT_CONTEXT_NAME,
        topology_uuid : str = DEFAULT_TOPOLOGY_NAME
    ) -> List[Dict]:
        LOGGER.debug('[get_devices_endpoints] begin')
        MSG = '[get_devices_endpoints] import_topology={:s}'
        LOGGER.debug(MSG.format(str(import_topology)))
        MSG = '[get_devices_endpoints] import_topology={:s} context_uuid={:s} topology_uuid={:s}'
        LOGGER.debug(MSG.format(str(import_topology), str(context_uuid), str(topology_uuid)))

        if import_topology == ImportTopologyEnum.DISABLED:
            MSG = 'Unsupported import_topology mode: {:s}'
            raise Exception(MSG.format(str(import_topology)))

        devices = self.get(GET_DEVICES_URL, expected_status_codes={requests.codes['OK']})
        topology = self.get(TOPOLOGY_URL.format(
            context_uuid=context_uuid, topology_uuid=topology_uuid
        ))

        result = list()
        for json_device in devices['devices']:
        for json_device in topology.get('devices', []):
            device_uuid : str = json_device['device_id']['device_uuid']['uuid']
            device_type : str = json_device['device_type']
            #if not device_type.startswith('emu-'): device_type = 'emu-' + device_type
@@ -175,9 +181,7 @@ class TfsApiClient(RestApiClient):
            LOGGER.debug('[get_devices_endpoints] devices only; returning')
            return result

        links = self.get(GET_LINKS_URL, expected_status_codes={requests.codes['OK']})

        for json_link in links['links']:
        for json_link in topology.get('links', []):
            link_uuid : str = json_link['link_id']['link_uuid']['uuid']
            link_url = '/links/link[{:s}]'.format(link_uuid)
            link_endpoint_ids = [
+5 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import json, logging, threading
from typing import Any, Iterator, List, Optional, Tuple, Union
from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method
from common.type_checkers.Checkers import chk_string, chk_type
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME
from device.service.driver_api._Driver import _Driver, RESOURCE_ENDPOINTS, RESOURCE_SERVICES
from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum, get_import_topology
from .TfsApiClient import TfsApiClient
@@ -42,9 +43,12 @@ class OpticalTfsDriver(_Driver):
        password = self.settings.get('password')
        scheme   = self.settings.get('scheme', 'http')
        timeout  = int(self.settings.get('timeout', 60))
        self.__context_uuid = self.settings.get('context_uuid', DEFAULT_CONTEXT_NAME)
        self.__topology_uuid = self.settings.get('topology_uuid', DEFAULT_TOPOLOGY_NAME)
        self.tac = TfsApiClient(
            self.address, self.port, scheme=scheme, username=username,
            password=password, timeout=timeout
            password=password, timeout=timeout,
            context_uuid=self.__context_uuid, topology_uuid=self.__topology_uuid
        )
        #self.toc = TfsOpticalClient(
        #    self.address, int(self.port), scheme=scheme, username=username,
Loading