Loading src/device/service/drivers/ietf_l2vpn/IetfL2VpnDriver.py +42 −15 Original line number Diff line number Diff line Loading @@ -17,16 +17,30 @@ 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 device.service.driver_api._Driver import _Driver, RESOURCE_ENDPOINTS, RESOURCE_SERVICES from .Tools import find_key from .Tools import connection_point, find_key, wim_mapping from .WimconnectorIETFL2VPN import WimconnectorIETFL2VPN LOGGER = logging.getLogger(__name__) def process_endpoint(method : str, endpoint : Any) -> Any: LOGGER.warning('[{:s}][process_endpoint] endpoint={:s}'.format(str(method), str(endpoint))) return endpoint def process_connectivity_service(method : str, service : Any) -> Any: LOGGER.warning('[{:s}][process_connectivity_service] service={:s}'.format(str(method), str(service))) return service def service_exists(param : Any) -> bool: LOGGER.warning('[service_exists] param={:s}'.format(str(param))) return False ALL_RESOURCE_KEYS = [ RESOURCE_ENDPOINTS, RESOURCE_SERVICES, ] SERVICE_TYPE = 'ELINE' METRICS_POOL = MetricsPool('Device', 'Driver', labels={'driver': 'ietf_l2vpn'}) class IetfL2VpnDriver(_Driver): Loading @@ -39,7 +53,8 @@ class IetfL2VpnDriver(_Driver): scheme = settings.get('scheme', 'http') wim = {'wim_url': '{:s}://{:s}:{:d}'.format(scheme, address, int(port))} wim_account = {'user': username, 'password': password} config = {'mapping_not_needed': False, 'service_endpoint_mapping': mapping} # Mapping updated dynamically with each request config = {'mapping_not_needed': False, 'service_endpoint_mapping': []} self.wim = WimconnectorIETFL2VPN(wim, wim_account, config=config) self.conn_info = {} # internal database emulating OSM storage provided to WIM Connectors Loading @@ -48,7 +63,7 @@ class IetfL2VpnDriver(_Driver): try: self.wim.check_credentials() except Exception: # pylint: disable=broad-except LOGGER.exception('Exception connecting {:s}'.format(str(self.__tapi_root))) LOGGER.exception('Exception checking credentials') return False else: self.__started.set() Loading Loading @@ -78,15 +93,15 @@ class IetfL2VpnDriver(_Driver): if resource_key == RESOURCE_ENDPOINTS: # return endpoints through debug-api and list-devices method endpoints = self.debug_api.get_endpoints() for endpoint in endpoints: results.append(process_endpoint(endpoint)) for endpoint in endpoints: results.append(process_endpoint('GetConfig', endpoint)) elif resource_key == RESOURCE_SERVICES: # return all services through services = self.wim.get_all_active_connectivity_services() for service in services: results.append(process_service(service)) for service in services: results.append(process_connectivity_service('GetConfig', service)) else: # assume single-service retrieval service = self.wim.get_connectivity_service() results.append(process_service(service)) results.append(process_connectivity_service('GetConfig', service)) return results @metered_subclass_method(METRICS_POOL) Loading @@ -98,24 +113,34 @@ class IetfL2VpnDriver(_Driver): for resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) uuid = find_key(resource, 'uuid') #input_sip = find_key(resource, 'input_sip') #output_sip = find_key(resource, 'output_sip') service_uuid = find_key(resource, 'uuid') a_endpoint = find_key(resource, 'a_endpoint') z_endpoint = find_key(resource, 'z_endpoint') #capacity_value = find_key(resource, 'capacity_value') #capacity_unit = find_key(resource, 'capacity_unit') #layer_protocol_name = find_key(resource, 'layer_protocol_name') #layer_protocol_qualifier = find_key(resource, 'layer_protocol_qualifier') #direction = find_key(resource, 'direction') encapsulation_type = find_key(resource, 'encapsulation_type') vlan_id = find_key(resource, 'vlan_id') conn_info = {} result = self.wim.get_connectivity_service_status( service_uuid, conn_info=conn_info) connection_points = [] for endpoint_id in [a_endpoint, z_endpoint]: site_id = str(endpoint_id) self.wim.mappings[endpoint_id] = wim_mapping(site_id, endpoint_id) connection_points.append(connection_point(endpoint_id, encapsulation_type, vlan_id)) if service_exists(result): result = self.wim.create_connectivity_service( service_type, connection_points) SERVICE_TYPE, connection_points) else: result = self.wim.edit_connectivity_service( self.wim.edit_connectivity_service( service_uuid, conn_info=conn_info, connection_points=connection_points) results.extend(process_result(result)) results.extend(process_connectivity_service('SetConfig', None)) return results @metered_subclass_method(METRICS_POOL) Loading @@ -126,16 +151,18 @@ class IetfL2VpnDriver(_Driver): self.wim.check_credentials() for resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) uuid = find_key(resource, 'uuid') service_uuid = find_key(resource, 'uuid') conn_info = {} result = self.wim.get_connectivity_service_status( service_uuid, conn_info=conn_info) if service_exists(result): result = self.wim.delete_connectivity_service( self.wim.delete_connectivity_service( service_uuid, conn_info=conn_info) else: result = False results.append(process_result(result)) results.extend(process_connectivity_service('DeleteConfig', None)) return results @metered_subclass_method(METRICS_POOL) Loading Loading
src/device/service/drivers/ietf_l2vpn/IetfL2VpnDriver.py +42 −15 Original line number Diff line number Diff line Loading @@ -17,16 +17,30 @@ 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 device.service.driver_api._Driver import _Driver, RESOURCE_ENDPOINTS, RESOURCE_SERVICES from .Tools import find_key from .Tools import connection_point, find_key, wim_mapping from .WimconnectorIETFL2VPN import WimconnectorIETFL2VPN LOGGER = logging.getLogger(__name__) def process_endpoint(method : str, endpoint : Any) -> Any: LOGGER.warning('[{:s}][process_endpoint] endpoint={:s}'.format(str(method), str(endpoint))) return endpoint def process_connectivity_service(method : str, service : Any) -> Any: LOGGER.warning('[{:s}][process_connectivity_service] service={:s}'.format(str(method), str(service))) return service def service_exists(param : Any) -> bool: LOGGER.warning('[service_exists] param={:s}'.format(str(param))) return False ALL_RESOURCE_KEYS = [ RESOURCE_ENDPOINTS, RESOURCE_SERVICES, ] SERVICE_TYPE = 'ELINE' METRICS_POOL = MetricsPool('Device', 'Driver', labels={'driver': 'ietf_l2vpn'}) class IetfL2VpnDriver(_Driver): Loading @@ -39,7 +53,8 @@ class IetfL2VpnDriver(_Driver): scheme = settings.get('scheme', 'http') wim = {'wim_url': '{:s}://{:s}:{:d}'.format(scheme, address, int(port))} wim_account = {'user': username, 'password': password} config = {'mapping_not_needed': False, 'service_endpoint_mapping': mapping} # Mapping updated dynamically with each request config = {'mapping_not_needed': False, 'service_endpoint_mapping': []} self.wim = WimconnectorIETFL2VPN(wim, wim_account, config=config) self.conn_info = {} # internal database emulating OSM storage provided to WIM Connectors Loading @@ -48,7 +63,7 @@ class IetfL2VpnDriver(_Driver): try: self.wim.check_credentials() except Exception: # pylint: disable=broad-except LOGGER.exception('Exception connecting {:s}'.format(str(self.__tapi_root))) LOGGER.exception('Exception checking credentials') return False else: self.__started.set() Loading Loading @@ -78,15 +93,15 @@ class IetfL2VpnDriver(_Driver): if resource_key == RESOURCE_ENDPOINTS: # return endpoints through debug-api and list-devices method endpoints = self.debug_api.get_endpoints() for endpoint in endpoints: results.append(process_endpoint(endpoint)) for endpoint in endpoints: results.append(process_endpoint('GetConfig', endpoint)) elif resource_key == RESOURCE_SERVICES: # return all services through services = self.wim.get_all_active_connectivity_services() for service in services: results.append(process_service(service)) for service in services: results.append(process_connectivity_service('GetConfig', service)) else: # assume single-service retrieval service = self.wim.get_connectivity_service() results.append(process_service(service)) results.append(process_connectivity_service('GetConfig', service)) return results @metered_subclass_method(METRICS_POOL) Loading @@ -98,24 +113,34 @@ class IetfL2VpnDriver(_Driver): for resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) uuid = find_key(resource, 'uuid') #input_sip = find_key(resource, 'input_sip') #output_sip = find_key(resource, 'output_sip') service_uuid = find_key(resource, 'uuid') a_endpoint = find_key(resource, 'a_endpoint') z_endpoint = find_key(resource, 'z_endpoint') #capacity_value = find_key(resource, 'capacity_value') #capacity_unit = find_key(resource, 'capacity_unit') #layer_protocol_name = find_key(resource, 'layer_protocol_name') #layer_protocol_qualifier = find_key(resource, 'layer_protocol_qualifier') #direction = find_key(resource, 'direction') encapsulation_type = find_key(resource, 'encapsulation_type') vlan_id = find_key(resource, 'vlan_id') conn_info = {} result = self.wim.get_connectivity_service_status( service_uuid, conn_info=conn_info) connection_points = [] for endpoint_id in [a_endpoint, z_endpoint]: site_id = str(endpoint_id) self.wim.mappings[endpoint_id] = wim_mapping(site_id, endpoint_id) connection_points.append(connection_point(endpoint_id, encapsulation_type, vlan_id)) if service_exists(result): result = self.wim.create_connectivity_service( service_type, connection_points) SERVICE_TYPE, connection_points) else: result = self.wim.edit_connectivity_service( self.wim.edit_connectivity_service( service_uuid, conn_info=conn_info, connection_points=connection_points) results.extend(process_result(result)) results.extend(process_connectivity_service('SetConfig', None)) return results @metered_subclass_method(METRICS_POOL) Loading @@ -126,16 +151,18 @@ class IetfL2VpnDriver(_Driver): self.wim.check_credentials() for resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) uuid = find_key(resource, 'uuid') service_uuid = find_key(resource, 'uuid') conn_info = {} result = self.wim.get_connectivity_service_status( service_uuid, conn_info=conn_info) if service_exists(result): result = self.wim.delete_connectivity_service( self.wim.delete_connectivity_service( service_uuid, conn_info=conn_info) else: result = False results.append(process_result(result)) results.extend(process_connectivity_service('DeleteConfig', None)) return results @metered_subclass_method(METRICS_POOL) Loading