diff --git a/src/service/service/service_handler_api/Tools.py b/src/service/service/service_handler_api/Tools.py index ebd16a532c4ef4e74a61fd075afe9298755e26fb..90fa6098368633f7e44db37c01b75508d5e6e87a 100644 --- a/src/service/service/service_handler_api/Tools.py +++ b/src/service/service/service_handler_api/Tools.py @@ -13,9 +13,10 @@ # limitations under the License. import functools -from typing import Any, List, Union +from typing import Any, List, Optional, Tuple, Union from common.method_wrappers.ServiceExceptions import NotFoundException from common.proto.context_pb2 import Device, EndPoint +from common.type_checkers.Checkers import chk_length, chk_type ACTION_MSG_SET_ENDPOINT = 'Set EndPoint(device_uuid={:s}, endpoint_uuid={:s}, topology_uuid={:s})' ACTION_MSG_DELETE_ENDPOINT = 'Delete EndPoint(device_uuid={:s}, endpoint_uuid={:s}, topology_uuid={:s})' @@ -51,3 +52,9 @@ def get_endpoint_matching(device : Device, endpoint_uuid_or_name : str) -> EndPo device_uuid = device.device_id.device_uuid.uuid extra_details = 'Device({:s})'.format(str(device_uuid)) raise NotFoundException('Endpoint', endpoint_uuid_or_name, extra_details=extra_details) + +def get_device_endpoint_uuids(endpoint : Tuple[str, str, Optional[str]]) -> Tuple[str, str]: + chk_type('endpoint', endpoint, (tuple, list)) + chk_length('endpoint', endpoint, min_length=2, max_length=3) + device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now + return device_uuid, endpoint_uuid diff --git a/src/service/service/service_handlers/l2nm_emulated/ConfigRules.py b/src/service/service/service_handlers/l2nm_emulated/ConfigRules.py index f12c9ab984205b9057dd1507114e5bc17d8deaa6..61fa08a26cf0eb776cb94e3998a7cb90cf663e59 100644 --- a/src/service/service/service_handlers/l2nm_emulated/ConfigRules.py +++ b/src/service/service/service_handlers/l2nm_emulated/ConfigRules.py @@ -17,7 +17,7 @@ from common.tools.object_factory.ConfigRule import json_config_rule_delete, json from service.service.service_handler_api.AnyTreeTools import TreeNode def setup_config_rules( - service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, + service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str, service_settings : TreeNode, endpoint_settings : TreeNode ) -> List[Dict]: @@ -38,7 +38,7 @@ def setup_config_rules( remote_router = json_endpoint_settings.get('remote_router', '0.0.0.0') # '5.5.5.5' circuit_id = json_endpoint_settings.get('circuit_id', '000' ) # '111' - if_cirid_name = '{:s}.{:s}'.format(endpoint_uuid, str(circuit_id)) + if_cirid_name = '{:s}.{:s}'.format(endpoint_name, str(circuit_id)) network_instance_name = 'ELAN-AC:{:s}'.format(str(circuit_id)) connection_point_id = 'VC-1' @@ -76,7 +76,7 @@ def setup_config_rules( return json_config_rules def teardown_config_rules( - service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, + service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str, service_settings : TreeNode, endpoint_settings : TreeNode ) -> List[Dict]: @@ -97,7 +97,7 @@ def teardown_config_rules( #remote_router = json_endpoint_settings.get('remote_router', '0.0.0.0') # '5.5.5.5' circuit_id = json_endpoint_settings.get('circuit_id', '000' ) # '111' - if_cirid_name = '{:s}.{:s}'.format(endpoint_uuid, str(circuit_id)) + if_cirid_name = '{:s}.{:s}'.format(endpoint_name, str(circuit_id)) network_instance_name = 'ELAN-AC:{:s}'.format(str(circuit_id)) connection_point_id = 'VC-1' diff --git a/src/service/service/service_handlers/l2nm_emulated/L2NMEmulatedServiceHandler.py b/src/service/service/service_handlers/l2nm_emulated/L2NMEmulatedServiceHandler.py index 66259d1f636c712bc41f282b4a5d947c57e01fc4..0d4a097cf32cbea7333e4c1693930294e2fb1f52 100644 --- a/src/service/service/service_handlers/l2nm_emulated/L2NMEmulatedServiceHandler.py +++ b/src/service/service/service_handlers/l2nm_emulated/L2NMEmulatedServiceHandler.py @@ -17,8 +17,8 @@ from typing import Any, List, Optional, Tuple, Union from common.method_wrappers.Decorator import MetricTypeEnum, MetricsPool, metered_subclass_method, INF from common.proto.context_pb2 import ConfigRule, DeviceId, Service from common.tools.object_factory.Device import json_device_id -from common.type_checkers.Checkers import chk_length, chk_type -from service.service.service_handler_api.Tools import get_endpoint_matching +from common.type_checkers.Checkers import chk_type +from service.service.service_handler_api.Tools import get_device_endpoint_uuids, get_endpoint_matching from service.service.service_handler_api._ServiceHandler import _ServiceHandler from service.service.service_handler_api.SettingsHandler import SettingsHandler from service.service.task_scheduler.TaskExecutor import TaskExecutor @@ -64,16 +64,16 @@ class L2NMEmulatedServiceHandler(_ServiceHandler): results = [] for endpoint in endpoints: try: - chk_type('endpoint', endpoint, (tuple, list)) - chk_length('endpoint', endpoint, min_length=2, max_length=3) - device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now + device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint) device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj) + endpoint_name = endpoint_obj.name json_config_rules = setup_config_rules( - service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings) + service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name, + settings, endpoint_settings) del device_obj.device_config.config_rules[:] for json_config_rule in json_config_rules: @@ -99,16 +99,16 @@ class L2NMEmulatedServiceHandler(_ServiceHandler): results = [] for endpoint in endpoints: try: - chk_type('endpoint', endpoint, (tuple, list)) - chk_length('endpoint', endpoint, min_length=2, max_length=3) - device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now + device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint) device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj) + endpoint_name = endpoint_obj.name json_config_rules = teardown_config_rules( - service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings) + service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name, + settings, endpoint_settings) del device_obj.device_config.config_rules[:] for json_config_rule in json_config_rules: diff --git a/src/service/service/service_handlers/l2nm_openconfig/ConfigRules.py b/src/service/service/service_handlers/l2nm_openconfig/ConfigRules.py index f12c9ab984205b9057dd1507114e5bc17d8deaa6..61fa08a26cf0eb776cb94e3998a7cb90cf663e59 100644 --- a/src/service/service/service_handlers/l2nm_openconfig/ConfigRules.py +++ b/src/service/service/service_handlers/l2nm_openconfig/ConfigRules.py @@ -17,7 +17,7 @@ from common.tools.object_factory.ConfigRule import json_config_rule_delete, json from service.service.service_handler_api.AnyTreeTools import TreeNode def setup_config_rules( - service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, + service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str, service_settings : TreeNode, endpoint_settings : TreeNode ) -> List[Dict]: @@ -38,7 +38,7 @@ def setup_config_rules( remote_router = json_endpoint_settings.get('remote_router', '0.0.0.0') # '5.5.5.5' circuit_id = json_endpoint_settings.get('circuit_id', '000' ) # '111' - if_cirid_name = '{:s}.{:s}'.format(endpoint_uuid, str(circuit_id)) + if_cirid_name = '{:s}.{:s}'.format(endpoint_name, str(circuit_id)) network_instance_name = 'ELAN-AC:{:s}'.format(str(circuit_id)) connection_point_id = 'VC-1' @@ -76,7 +76,7 @@ def setup_config_rules( return json_config_rules def teardown_config_rules( - service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, + service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str, service_settings : TreeNode, endpoint_settings : TreeNode ) -> List[Dict]: @@ -97,7 +97,7 @@ def teardown_config_rules( #remote_router = json_endpoint_settings.get('remote_router', '0.0.0.0') # '5.5.5.5' circuit_id = json_endpoint_settings.get('circuit_id', '000' ) # '111' - if_cirid_name = '{:s}.{:s}'.format(endpoint_uuid, str(circuit_id)) + if_cirid_name = '{:s}.{:s}'.format(endpoint_name, str(circuit_id)) network_instance_name = 'ELAN-AC:{:s}'.format(str(circuit_id)) connection_point_id = 'VC-1' diff --git a/src/service/service/service_handlers/l2nm_openconfig/L2NMOpenConfigServiceHandler.py b/src/service/service/service_handlers/l2nm_openconfig/L2NMOpenConfigServiceHandler.py index 63442a6b46d3301ff15ee0d4416468f01d2f61a5..b8b30ad742223fb1a2aa4dc1e8a762b9e0fec386 100644 --- a/src/service/service/service_handlers/l2nm_openconfig/L2NMOpenConfigServiceHandler.py +++ b/src/service/service/service_handlers/l2nm_openconfig/L2NMOpenConfigServiceHandler.py @@ -17,8 +17,8 @@ from typing import Any, List, Optional, Tuple, Union from common.method_wrappers.Decorator import MetricTypeEnum, MetricsPool, metered_subclass_method, INF from common.proto.context_pb2 import ConfigRule, DeviceId, Service from common.tools.object_factory.Device import json_device_id -from common.type_checkers.Checkers import chk_length, chk_type -from service.service.service_handler_api.Tools import get_endpoint_matching +from common.type_checkers.Checkers import chk_type +from service.service.service_handler_api.Tools import get_device_endpoint_uuids, get_endpoint_matching from service.service.service_handler_api._ServiceHandler import _ServiceHandler from service.service.service_handler_api.SettingsHandler import SettingsHandler from service.service.task_scheduler.TaskExecutor import TaskExecutor @@ -64,16 +64,16 @@ class L2NMOpenConfigServiceHandler(_ServiceHandler): results = [] for endpoint in endpoints: try: - chk_type('endpoint', endpoint, (tuple, list)) - chk_length('endpoint', endpoint, min_length=2, max_length=3) - device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now + device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint) device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj) + endpoint_name = endpoint_obj.name json_config_rules = setup_config_rules( - service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings) + service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name, + settings, endpoint_settings) del device_obj.device_config.config_rules[:] for json_config_rule in json_config_rules: @@ -99,16 +99,16 @@ class L2NMOpenConfigServiceHandler(_ServiceHandler): results = [] for endpoint in endpoints: try: - chk_type('endpoint', endpoint, (tuple, list)) - chk_length('endpoint', endpoint, min_length=2, max_length=3) - device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now + device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint) device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj) + endpoint_name = endpoint_obj.name json_config_rules = teardown_config_rules( - service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings) + service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name, + settings, endpoint_settings) del device_obj.device_config.config_rules[:] for json_config_rule in json_config_rules: diff --git a/src/service/service/service_handlers/l3nm_emulated/ConfigRules.py b/src/service/service/service_handlers/l3nm_emulated/ConfigRules.py index 3a5aff5884c72f1384666a223a3b07da6d4ae4ec..8479670940ef7eda1f5ce51cd42b3dc5e37e1a32 100644 --- a/src/service/service/service_handlers/l3nm_emulated/ConfigRules.py +++ b/src/service/service/service_handlers/l3nm_emulated/ConfigRules.py @@ -17,7 +17,7 @@ from common.tools.object_factory.ConfigRule import json_config_rule_delete, json from service.service.service_handler_api.AnyTreeTools import TreeNode def setup_config_rules( - service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, + service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str, service_settings : TreeNode, endpoint_settings : TreeNode ) -> List[Dict]: @@ -40,7 +40,7 @@ def setup_config_rules( vlan_id = json_endpoint_settings.get('vlan_id', 1 ) # 400 address_ip = json_endpoint_settings.get('address_ip', '0.0.0.0') # '2.2.2.1' address_prefix = json_endpoint_settings.get('address_prefix', 24 ) # 30 - if_subif_name = '{:s}.{:d}'.format(endpoint_uuid, vlan_id) + if_subif_name = '{:s}.{:d}'.format(endpoint_name, vlan_id) json_config_rules = [ json_config_rule_set( @@ -50,18 +50,18 @@ def setup_config_rules( #'router_id': router_id, 'address_families': address_families, }), json_config_rule_set( - '/interface[{:s}]'.format(endpoint_uuid), { - 'name': endpoint_uuid, 'description': network_interface_desc, 'mtu': mtu, + '/interface[{:s}]'.format(endpoint_name), { + 'name': endpoint_name, 'description': network_interface_desc, 'mtu': mtu, }), json_config_rule_set( - '/interface[{:s}]/subinterface[{:d}]'.format(endpoint_uuid, sub_interface_index), { - 'name': endpoint_uuid, 'index': sub_interface_index, + '/interface[{:s}]/subinterface[{:d}]'.format(endpoint_name, sub_interface_index), { + 'name': endpoint_name, 'index': sub_interface_index, 'description': network_subinterface_desc, 'vlan_id': vlan_id, 'address_ip': address_ip, 'address_prefix': address_prefix, }), json_config_rule_set( '/network_instance[{:s}]/interface[{:s}]'.format(network_instance_name, if_subif_name), { - 'name': network_instance_name, 'id': if_subif_name, 'interface': endpoint_uuid, + 'name': network_instance_name, 'id': if_subif_name, 'interface': endpoint_name, 'subinterface': sub_interface_index, }), json_config_rule_set( @@ -138,7 +138,7 @@ def setup_config_rules( return json_config_rules def teardown_config_rules( - service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, + service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str, service_settings : TreeNode, endpoint_settings : TreeNode ) -> List[Dict]: @@ -157,7 +157,7 @@ def teardown_config_rules( #address_ip = json_endpoint_settings.get('address_ip', '0.0.0.0') # '2.2.2.1' #address_prefix = json_endpoint_settings.get('address_prefix', 24 ) # 30 - if_subif_name = '{:s}.{:d}'.format(endpoint_uuid, vlan_id) + if_subif_name = '{:s}.{:d}'.format(endpoint_name, vlan_id) service_short_uuid = service_uuid.split('-')[-1] network_instance_name = '{:s}-NetInst'.format(service_short_uuid) #network_interface_desc = '{:s}-NetIf'.format(service_uuid) @@ -169,12 +169,12 @@ def teardown_config_rules( 'name': network_instance_name, 'id': if_subif_name, }), json_config_rule_delete( - '/interface[{:s}]/subinterface[{:d}]'.format(endpoint_uuid, sub_interface_index), { - 'name': endpoint_uuid, 'index': sub_interface_index, + '/interface[{:s}]/subinterface[{:d}]'.format(endpoint_name, sub_interface_index), { + 'name': endpoint_name, 'index': sub_interface_index, }), json_config_rule_delete( - '/interface[{:s}]'.format(endpoint_uuid), { - 'name': endpoint_uuid, + '/interface[{:s}]'.format(endpoint_name), { + 'name': endpoint_name, }), json_config_rule_delete( '/network_instance[{:s}]/table_connections[DIRECTLY_CONNECTED][BGP][IPV4]'.format( diff --git a/src/service/service/service_handlers/l3nm_emulated/L3NMEmulatedServiceHandler.py b/src/service/service/service_handlers/l3nm_emulated/L3NMEmulatedServiceHandler.py index 8a39ed47463d70bf2c2c42cbb9308ba5e072caf4..412023a69c4f59865f907001e53a30648df96d53 100644 --- a/src/service/service/service_handlers/l3nm_emulated/L3NMEmulatedServiceHandler.py +++ b/src/service/service/service_handlers/l3nm_emulated/L3NMEmulatedServiceHandler.py @@ -17,8 +17,8 @@ from typing import Any, List, Optional, Tuple, Union from common.method_wrappers.Decorator import MetricTypeEnum, MetricsPool, metered_subclass_method, INF from common.proto.context_pb2 import ConfigRule, DeviceId, Service from common.tools.object_factory.Device import json_device_id -from common.type_checkers.Checkers import chk_length, chk_type -from service.service.service_handler_api.Tools import get_endpoint_matching +from common.type_checkers.Checkers import chk_type +from service.service.service_handler_api.Tools import get_device_endpoint_uuids, get_endpoint_matching from service.service.service_handler_api._ServiceHandler import _ServiceHandler from service.service.service_handler_api.SettingsHandler import SettingsHandler from service.service.task_scheduler.TaskExecutor import TaskExecutor @@ -55,32 +55,25 @@ class L3NMEmulatedServiceHandler(_ServiceHandler): def SetEndpoint( self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None ) -> List[Union[bool, Exception]]: - LOGGER.info('[SetEndpoint] endpoints={:s}'.format(str(endpoints))) - LOGGER.info('[SetEndpoint] connection_uuid={:s}'.format(str(connection_uuid))) - chk_type('endpoints', endpoints, list) if len(endpoints) == 0: return [] service_uuid = self.__service.service_id.service_uuid.uuid settings = self.__settings_handler.get('/settings') - LOGGER.info('[SetEndpoint] settings={:s}'.format(str(settings))) results = [] for endpoint in endpoints: - LOGGER.info('[SetEndpoint] endpoint={:s}'.format(str(endpoint))) try: - chk_type('endpoint', endpoint, (tuple, list)) - chk_length('endpoint', endpoint, min_length=2, max_length=3) - device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now + device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint) device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj) - LOGGER.info('[SetEndpoint] endpoint_settings={:s}'.format(str(endpoint_settings))) + endpoint_name = endpoint_obj.name json_config_rules = setup_config_rules( - service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings) - LOGGER.info('[SetEndpoint] json_config_rules={:s}'.format(str(json_config_rules))) + service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name, + settings, endpoint_settings) del device_obj.device_config.config_rules[:] for json_config_rule in json_config_rules: @@ -91,16 +84,12 @@ class L3NMEmulatedServiceHandler(_ServiceHandler): LOGGER.exception('Unable to SetEndpoint({:s})'.format(str(endpoint))) results.append(e) - LOGGER.info('[SetEndpoint] results={:s}'.format(str(results))) return results @metered_subclass_method(METRICS_POOL) def DeleteEndpoint( self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None ) -> List[Union[bool, Exception]]: - LOGGER.info('[DeleteEndpoint] endpoints={:s}'.format(str(endpoints))) - LOGGER.info('[DeleteEndpoint] connection_uuid={:s}'.format(str(connection_uuid))) - chk_type('endpoints', endpoints, list) if len(endpoints) == 0: return [] @@ -110,16 +99,16 @@ class L3NMEmulatedServiceHandler(_ServiceHandler): results = [] for endpoint in endpoints: try: - chk_type('endpoint', endpoint, (tuple, list)) - chk_length('endpoint', endpoint, min_length=2, max_length=3) - device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now + device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint) device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj) + endpoint_name = endpoint_obj.name json_config_rules = teardown_config_rules( - service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings) + service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name, + settings, endpoint_settings) del device_obj.device_config.config_rules[:] for json_config_rule in json_config_rules: diff --git a/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py b/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py index 3a5aff5884c72f1384666a223a3b07da6d4ae4ec..8479670940ef7eda1f5ce51cd42b3dc5e37e1a32 100644 --- a/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py +++ b/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py @@ -17,7 +17,7 @@ from common.tools.object_factory.ConfigRule import json_config_rule_delete, json from service.service.service_handler_api.AnyTreeTools import TreeNode def setup_config_rules( - service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, + service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str, service_settings : TreeNode, endpoint_settings : TreeNode ) -> List[Dict]: @@ -40,7 +40,7 @@ def setup_config_rules( vlan_id = json_endpoint_settings.get('vlan_id', 1 ) # 400 address_ip = json_endpoint_settings.get('address_ip', '0.0.0.0') # '2.2.2.1' address_prefix = json_endpoint_settings.get('address_prefix', 24 ) # 30 - if_subif_name = '{:s}.{:d}'.format(endpoint_uuid, vlan_id) + if_subif_name = '{:s}.{:d}'.format(endpoint_name, vlan_id) json_config_rules = [ json_config_rule_set( @@ -50,18 +50,18 @@ def setup_config_rules( #'router_id': router_id, 'address_families': address_families, }), json_config_rule_set( - '/interface[{:s}]'.format(endpoint_uuid), { - 'name': endpoint_uuid, 'description': network_interface_desc, 'mtu': mtu, + '/interface[{:s}]'.format(endpoint_name), { + 'name': endpoint_name, 'description': network_interface_desc, 'mtu': mtu, }), json_config_rule_set( - '/interface[{:s}]/subinterface[{:d}]'.format(endpoint_uuid, sub_interface_index), { - 'name': endpoint_uuid, 'index': sub_interface_index, + '/interface[{:s}]/subinterface[{:d}]'.format(endpoint_name, sub_interface_index), { + 'name': endpoint_name, 'index': sub_interface_index, 'description': network_subinterface_desc, 'vlan_id': vlan_id, 'address_ip': address_ip, 'address_prefix': address_prefix, }), json_config_rule_set( '/network_instance[{:s}]/interface[{:s}]'.format(network_instance_name, if_subif_name), { - 'name': network_instance_name, 'id': if_subif_name, 'interface': endpoint_uuid, + 'name': network_instance_name, 'id': if_subif_name, 'interface': endpoint_name, 'subinterface': sub_interface_index, }), json_config_rule_set( @@ -138,7 +138,7 @@ def setup_config_rules( return json_config_rules def teardown_config_rules( - service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, + service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str, service_settings : TreeNode, endpoint_settings : TreeNode ) -> List[Dict]: @@ -157,7 +157,7 @@ def teardown_config_rules( #address_ip = json_endpoint_settings.get('address_ip', '0.0.0.0') # '2.2.2.1' #address_prefix = json_endpoint_settings.get('address_prefix', 24 ) # 30 - if_subif_name = '{:s}.{:d}'.format(endpoint_uuid, vlan_id) + if_subif_name = '{:s}.{:d}'.format(endpoint_name, vlan_id) service_short_uuid = service_uuid.split('-')[-1] network_instance_name = '{:s}-NetInst'.format(service_short_uuid) #network_interface_desc = '{:s}-NetIf'.format(service_uuid) @@ -169,12 +169,12 @@ def teardown_config_rules( 'name': network_instance_name, 'id': if_subif_name, }), json_config_rule_delete( - '/interface[{:s}]/subinterface[{:d}]'.format(endpoint_uuid, sub_interface_index), { - 'name': endpoint_uuid, 'index': sub_interface_index, + '/interface[{:s}]/subinterface[{:d}]'.format(endpoint_name, sub_interface_index), { + 'name': endpoint_name, 'index': sub_interface_index, }), json_config_rule_delete( - '/interface[{:s}]'.format(endpoint_uuid), { - 'name': endpoint_uuid, + '/interface[{:s}]'.format(endpoint_name), { + 'name': endpoint_name, }), json_config_rule_delete( '/network_instance[{:s}]/table_connections[DIRECTLY_CONNECTED][BGP][IPV4]'.format( diff --git a/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py b/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py index 3dc98f71b3f64557782b700220d1d3ab84314b4b..7c75ff1c769f418e394092ee60b186665ae6670f 100644 --- a/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py +++ b/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py @@ -17,8 +17,8 @@ from typing import Any, List, Optional, Tuple, Union from common.method_wrappers.Decorator import MetricTypeEnum, MetricsPool, metered_subclass_method, INF from common.proto.context_pb2 import ConfigRule, DeviceId, Service from common.tools.object_factory.Device import json_device_id -from common.type_checkers.Checkers import chk_length, chk_type -from service.service.service_handler_api.Tools import get_endpoint_matching +from common.type_checkers.Checkers import chk_type +from service.service.service_handler_api.Tools import get_device_endpoint_uuids, get_endpoint_matching from service.service.service_handler_api._ServiceHandler import _ServiceHandler from service.service.service_handler_api.SettingsHandler import SettingsHandler from service.service.task_scheduler.TaskExecutor import TaskExecutor @@ -64,16 +64,16 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): results = [] for endpoint in endpoints: try: - chk_type('endpoint', endpoint, (tuple, list)) - chk_length('endpoint', endpoint, min_length=2, max_length=3) - device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now + device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint) device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj) + endpoint_name = endpoint_obj.name json_config_rules = setup_config_rules( - service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings) + service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name, + settings, endpoint_settings) del device_obj.device_config.config_rules[:] for json_config_rule in json_config_rules: @@ -99,16 +99,16 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): results = [] for endpoint in endpoints: try: - chk_type('endpoint', endpoint, (tuple, list)) - chk_length('endpoint', endpoint, min_length=2, max_length=3) - device_uuid, endpoint_uuid = endpoint[0:2] # ignore topology_uuid by now + device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint) device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj) + endpoint_name = endpoint_obj.name json_config_rules = teardown_config_rules( - service_uuid, connection_uuid, device_uuid, endpoint_uuid, settings, endpoint_settings) + service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name, + settings, endpoint_settings) del device_obj.device_config.config_rules[:] for json_config_rule in json_config_rules: diff --git a/src/service/service/service_handlers/microwave/MicrowaveServiceHandler.py b/src/service/service/service_handlers/microwave/MicrowaveServiceHandler.py index a16f8cdfad5524a45c36502610d615f3b5dbbba4..bfc2122226221c00d1ada545b512f07401360515 100644 --- a/src/service/service/service_handlers/microwave/MicrowaveServiceHandler.py +++ b/src/service/service/service_handlers/microwave/MicrowaveServiceHandler.py @@ -19,6 +19,7 @@ from common.proto.context_pb2 import ConfigRule, DeviceId, Service from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set from common.tools.object_factory.Device import json_device_id from common.type_checkers.Checkers import chk_type +from service.service.service_handler_api.Tools import get_device_endpoint_uuids, get_endpoint_matching from service.service.service_handler_api._ServiceHandler import _ServiceHandler from service.service.service_handler_api.SettingsHandler import SettingsHandler from service.service.task_scheduler.TaskExecutor import TaskExecutor @@ -45,8 +46,7 @@ class MicrowaveServiceHandler(_ServiceHandler): def SetEndpoint( self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None ) -> List[Union[bool, Exception]]: - LOGGER.info('[SetEndpoint] endpoints={:s}'.format(str(endpoints))) - LOGGER.info('[SetEndpoint] connection_uuid={:s}'.format(str(connection_uuid))) + chk_type('endpoints', endpoints, list) if len(endpoints) != 2: return [] @@ -57,12 +57,21 @@ class MicrowaveServiceHandler(_ServiceHandler): results = [] try: - # endpoints are retrieved in the following format --> '/endpoints/endpoint[172.26.60.243:9]' - node_id_src, tp_id_src = check_endpoint(endpoints[0][1], service_uuid) - node_id_dst, tp_id_dst = check_endpoint(endpoints[1][1], service_uuid) - - device_uuid = endpoints[0][0] + device_uuid_src, endpoint_uuid_src = get_device_endpoint_uuids(endpoints[0]) + device_uuid_dst, endpoint_uuid_dst = get_device_endpoint_uuids(endpoints[1]) + + if device_uuid_src != device_uuid_dst: + raise Exception('Diferent Src-Dst devices not supported by now') + device_uuid = device_uuid_src + device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) + endpoint_name_src = get_endpoint_matching(device_obj, endpoint_uuid_src).name + endpoint_name_dst = get_endpoint_matching(device_obj, endpoint_uuid_dst).name + + # endpoints are retrieved in the following format --> '/endpoints/endpoint[172.26.60.243:9]' + node_id_src, tp_id_src = check_endpoint(endpoint_name_src, service_uuid) + node_id_dst, tp_id_dst = check_endpoint(endpoint_name_dst, service_uuid) + json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), { 'uuid' : service_uuid, 'node_id_src': node_id_src, @@ -85,8 +94,6 @@ class MicrowaveServiceHandler(_ServiceHandler): def DeleteEndpoint( self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None ) -> List[Union[bool, Exception]]: - LOGGER.info('[DeleteEndpoint] endpoints={:s}'.format(str(endpoints))) - LOGGER.info('[DeleteEndpoint] connection_uuid={:s}'.format(str(connection_uuid))) chk_type('endpoints', endpoints, list) if len(endpoints) != 2: return [] @@ -95,8 +102,15 @@ class MicrowaveServiceHandler(_ServiceHandler): results = [] try: - device_uuid = endpoints[0][0] + device_uuid_src, _ = get_device_endpoint_uuids(endpoints[0]) + device_uuid_dst, _ = get_device_endpoint_uuids(endpoints[1]) + + if device_uuid_src != device_uuid_dst: + raise Exception('Diferent Src-Dst devices not supported by now') + device_uuid = device_uuid_src + device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) + json_config_rule = json_config_rule_delete('/services/service[{:s}]'.format(service_uuid), { 'uuid': service_uuid }) diff --git a/src/service/service/service_handlers/tapi_tapi/TapiServiceHandler.py b/src/service/service/service_handlers/tapi_tapi/TapiServiceHandler.py index d8a4668bbf102fa5b5f8c9e9f542f34b063bc819..6b1c4a6572e623beb3cf2011c075a8e546f52b1b 100644 --- a/src/service/service/service_handlers/tapi_tapi/TapiServiceHandler.py +++ b/src/service/service/service_handlers/tapi_tapi/TapiServiceHandler.py @@ -19,6 +19,7 @@ from common.proto.context_pb2 import ConfigRule, DeviceId, Service from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set from common.tools.object_factory.Device import json_device_id from common.type_checkers.Checkers import chk_type +from service.service.service_handler_api.Tools import get_device_endpoint_uuids, get_endpoint_matching from service.service.service_handler_api._ServiceHandler import _ServiceHandler from service.service.service_handler_api.SettingsHandler import SettingsHandler from service.service.task_scheduler.TaskExecutor import TaskExecutor @@ -39,8 +40,7 @@ class TapiServiceHandler(_ServiceHandler): def SetEndpoint( self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None ) -> List[Union[bool, Exception]]: - LOGGER.info('[SetEndpoint] endpoints={:s}'.format(str(endpoints))) - LOGGER.info('[SetEndpoint] connection_uuid={:s}'.format(str(connection_uuid))) + chk_type('endpoints', endpoints, list) if len(endpoints) != 2: return [] @@ -55,12 +55,21 @@ class TapiServiceHandler(_ServiceHandler): results = [] try: - device_uuid = endpoints[0][0] + device_uuid_src, endpoint_uuid_src = get_device_endpoint_uuids(endpoints[0]) + device_uuid_dst, endpoint_uuid_dst = get_device_endpoint_uuids(endpoints[1]) + + if device_uuid_src != device_uuid_dst: + raise Exception('Diferent Src-Dst devices not supported by now') + device_uuid = device_uuid_src + device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) - json_config_rule = json_config_rule_set('/service[{:s}]'.format(service_uuid), { + endpoint_name_src = get_endpoint_matching(device_obj, endpoint_uuid_src).name + endpoint_name_dst = get_endpoint_matching(device_obj, endpoint_uuid_dst).name + + json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), { 'uuid' : service_uuid, - 'input_sip' : endpoints[0][1], - 'output_sip' : endpoints[1][1], + 'input_sip' : endpoint_name_src, + 'output_sip' : endpoint_name_dst, 'capacity_unit' : capacity_unit, 'capacity_value' : capacity_value, 'layer_protocol_name' : layer_proto_name, @@ -81,8 +90,6 @@ class TapiServiceHandler(_ServiceHandler): def DeleteEndpoint( self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None ) -> List[Union[bool, Exception]]: - LOGGER.info('[DeleteEndpoint] endpoints={:s}'.format(str(endpoints))) - LOGGER.info('[DeleteEndpoint] connection_uuid={:s}'.format(str(connection_uuid))) chk_type('endpoints', endpoints, list) if len(endpoints) != 2: return [] @@ -91,9 +98,16 @@ class TapiServiceHandler(_ServiceHandler): results = [] try: - device_uuid = endpoints[0][0] + device_uuid_src, _ = get_device_endpoint_uuids(endpoints[0]) + device_uuid_dst, _ = get_device_endpoint_uuids(endpoints[1]) + + if device_uuid_src != device_uuid_dst: + raise Exception('Diferent Src-Dst devices not supported by now') + device_uuid = device_uuid_src + device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) - json_config_rule = json_config_rule_delete('/service[{:s}]'.format(service_uuid), { + + json_config_rule = json_config_rule_delete('/services/service[{:s}]'.format(service_uuid), { 'uuid': service_uuid }) del device_obj.device_config.config_rules[:]