diff --git a/src/device/service/Tools.py b/src/device/service/Tools.py index 1dccea3ab9774fe6682fa346c8c3d20107b46fbf..3694ce1293e20b2b814752ffaa093014e0cb47aa 100644 --- a/src/device/service/Tools.py +++ b/src/device/service/Tools.py @@ -202,7 +202,7 @@ def populate_endpoints( _sub_link.name = resource_value['name'] new_sub_links[_sub_link_uuid] = _sub_link - for device_uuid,endpoint_uuid in resource_value['name']: + for device_uuid,endpoint_uuid in resource_value['endpoints']: _sub_link_endpoint_id = _sub_link.link_endpoint_ids.add() # pylint: disable=no-member _sub_link_endpoint_id.topology_id.context_id.context_uuid.uuid = DEFAULT_CONTEXT_NAME _sub_link_endpoint_id.topology_id.topology_uuid.uuid = DEFAULT_TOPOLOGY_NAME diff --git a/src/device/service/drivers/ietf_l2vpn/IetfL2VpnDriver.py b/src/device/service/drivers/ietf_l2vpn/IetfL2VpnDriver.py index 8c7feb2490ae6ffc253fb9dfe5ecfd6677c592ba..e08b7625bf8295f73b0bd0d5619bc731d10bf97c 100644 --- a/src/device/service/drivers/ietf_l2vpn/IetfL2VpnDriver.py +++ b/src/device/service/drivers/ietf_l2vpn/IetfL2VpnDriver.py @@ -131,24 +131,12 @@ class IetfL2VpnDriver(_Driver): results.append((resource[0], exc)) continue - src_device_endpoint = resource_value['src'] - src_device = src_device_endpoint['device'] - #src_device_uuid = src_device['uuid'] - src_device_name = src_device['name'] - src_endpoint = src_device_endpoint['endpoint'] - #src_endpoint_uuid = src_endpoint['uuid'] - src_endpoint_name = src_endpoint['name'] - - dst_device_endpoint = resource_value['dst'] - dst_device = dst_device_endpoint['device'] - #dst_device_uuid = dst_device['uuid'] - dst_device_name = dst_device['name'] - dst_endpoint = dst_device_endpoint['endpoint'] - #dst_endpoint_uuid = dst_endpoint['uuid'] - dst_endpoint_name = dst_endpoint['name'] - - encap_type = resource_value['encapsulation_type'] - vlan_id = resource_value['vlan_id'] + src_device_name = resource_value['src_device_name'] + src_endpoint_name = resource_value['src_endpoint_name'] + dst_device_name = resource_value['dst_device_name'] + dst_endpoint_name = resource_value['dst_endpoint_name'] + encap_type = resource_value['encapsulation_type'] + vlan_id = resource_value['vlan_id'] src_endpoint_id = json_endpoint_id(json_device_id(src_device_name), src_endpoint_name) src_service_endpoint_id, src_mapping = wim_mapping('1', src_endpoint_id) @@ -163,10 +151,8 @@ class IetfL2VpnDriver(_Driver): connection_point(dst_service_endpoint_id, encap_type, vlan_id), ] - result = self.wim.create_connectivity_service(SERVICE_TYPE, connection_points) - LOGGER.info('[SetConfig] CREATE result={:s}'.format(str(result))) - - results.extend(process_connectivity_service('SetConfig', None)) + self.wim.create_connectivity_service(service_uuid, SERVICE_TYPE, connection_points) + results.append((resource_key, True)) except Exception as e: # pylint: disable=broad-except LOGGER.exception('Unhandled error processing resource_key({:s})'.format(str(resource_key))) results.append((resource_key, e)) @@ -187,8 +173,7 @@ class IetfL2VpnDriver(_Driver): if service_exists(self.wim, service_uuid): self.wim.delete_connectivity_service(service_uuid) - - results.extend(process_connectivity_service('DeleteConfig', None)) + results.append((resource_key, True)) except Exception as e: # pylint: disable=broad-except LOGGER.exception('Unhandled error processing resource_key({:s})'.format(str(resource_key))) results.append((resource_key, e)) diff --git a/src/device/service/drivers/ietf_l2vpn/WimconnectorIETFL2VPN.py b/src/device/service/drivers/ietf_l2vpn/WimconnectorIETFL2VPN.py index 960256cd0647447dca49851a074a11b4aee97885..34ff184c022f379e7420de237bd08fc1dc6282a6 100644 --- a/src/device/service/drivers/ietf_l2vpn/WimconnectorIETFL2VPN.py +++ b/src/device/service/drivers/ietf_l2vpn/WimconnectorIETFL2VPN.py @@ -119,7 +119,7 @@ class WimconnectorIETFL2VPN(SdnConnectorBase): else: return self.mappings[id] - def create_connectivity_service(self, service_type, connection_points, **kwargs): + def create_connectivity_service(self, service_uuid, service_type, connection_points, **kwargs): """Stablish WAN connectivity between the endpoints Arguments: @@ -154,9 +154,7 @@ class WimconnectorIETFL2VPN(SdnConnectorBase): Other QoS might be passed as keyword arguments. Returns: - tuple: ``(service_id, conn_info)`` containing: - - *service_uuid* (str): UUID of the established connectivity - service + tuple: ``conn_info``: - *conn_info* (dict or None): Information to be stored at the database (or ``None``). This information will be provided to the :meth:`~.edit_connectivity_service` and :obj:`~.delete`. @@ -182,9 +180,8 @@ class WimconnectorIETFL2VPN(SdnConnectorBase): raise SdnConnectorError(msg.format(min_endpoints, service_type)) """First step, create the vpn service""" - uuid_l2vpn = str(uuid.uuid4()) vpn_service = {} - vpn_service["vpn-id"] = uuid_l2vpn + vpn_service["vpn-id"] = service_uuid vpn_service["vpn-svc-type"] = vpn_service_type vpn_service["svc-topo"] = "any-to-any" vpn_service["customer-name"] = "osm" @@ -277,7 +274,7 @@ class WimconnectorIETFL2VPN(SdnConnectorBase): site_network_access["connection"] = connection self.logger.info("Sending connection:{}".format(connection)) vpn_attach = {} - vpn_attach["vpn-id"] = uuid_l2vpn + vpn_attach["vpn-id"] = service_uuid vpn_attach["site-role"] = vpn_service["svc-topo"] + "-role" site_network_access["vpn-attachment"] = vpn_attach self.logger.info("Sending vpn-attachement :{}".format(vpn_attach)) @@ -379,7 +376,7 @@ class WimconnectorIETFL2VPN(SdnConnectorBase): raise SdnConnectorError("Request Timeout", http_code=408) - return uuid_l2vpn, conn_info + return conn_info def delete_connectivity_service(self, service_uuid, conn_info=None): """Disconnect multi-site endpoints previously connected diff --git a/src/device/service/drivers/xr/XrDriver.py b/src/device/service/drivers/xr/XrDriver.py index 605f4ce8d0f9c875a4b1736ff0aaa02fcb468778..83ffd52183a5e8f81b465aaa15c07e1478e67a8d 100644 --- a/src/device/service/drivers/xr/XrDriver.py +++ b/src/device/service/drivers/xr/XrDriver.py @@ -16,9 +16,11 @@ import logging import threading import json -from typing import Any, Iterator, List, Optional, Tuple, Union +from typing import Any, Iterator, List, Optional, Set, Tuple, Union import urllib3 +from common.DeviceTypes import DeviceTypeEnum from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method +from common.proto.context_pb2 import DeviceDriverEnum, DeviceOperationalStatusEnum from common.type_checkers.Checkers import chk_type from device.service.driver_api._Driver import _Driver from .cm.cm_connection import CmConnection, ConsistencyMode @@ -98,7 +100,50 @@ class XrDriver(_Driver): constellation = self.__cm_connection.get_constellation_by_hub_name(self.__hub_module_name) if constellation: self.__constellation = constellation - return [(f"/endpoints/endpoint[{ifname}]", {'uuid': ifname, 'type': 'optical', 'sample_types': {}}) for ifname in constellation.ifnames()] + #return [(f"/endpoints/endpoint[{ifname}]", {'uuid': ifname, 'type': 'optical', 'sample_types': {}}) for ifname in constellation.ifnames()] + + devices : Set[str] = set() + pluggables : Set[str] = set() + devices_and_endpoints = [] + for ifname in constellation.ifnames(): + device_name,pluggable_name = ifname.split('|') + + if device_name not in devices: + device_url = '/devices/device[{:s}]'.format(device_name) + device_data = { + 'uuid': device_name, 'name': device_name, + 'type': DeviceTypeEnum.EMULATED_PACKET_ROUTER.value, + 'status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED, + 'drivers': [DeviceDriverEnum.DEVICEDRIVER_UNDEFINED], + } + devices_and_endpoints.append((device_url, device_data)) + + for copper_if_index in range(4): + copper_ifname = '1/{:d}'.format(copper_if_index + 1) + endpoint_url = '/endpoints/endpoint[{:s}]'.format(copper_ifname) + endpoint_data = { + 'device_uuid': device_name, 'uuid': copper_ifname, 'name': copper_ifname, + 'type': 'copper/internal', 'sample_types': {} + } + devices_and_endpoints.append((endpoint_url, endpoint_data)) + + devices.add(device_name) + + if ifname not in pluggables: + endpoint_url = '/endpoints/endpoint[{:s}]'.format(ifname) + if 'hub' in ifname.lower(): + endpoint_type = 'optical/xr-hub' + elif 'leaf' in ifname.lower(): + endpoint_type = 'optical/xr-leaf' + else: + endpoint_type = 'optical/xr' + endpoint_data = { + 'device_uuid': device_name, 'uuid': pluggable_name, 'name': pluggable_name, + 'type': endpoint_type, 'sample_types': {} + } + devices_and_endpoints.append((endpoint_url, endpoint_data)) + + return devices_and_endpoints else: return []