Loading src/service/service/service_handlers/microwave/MicrowaveServiceHandler.py +24 −22 Original line number Diff line number Diff line Loading @@ -24,6 +24,12 @@ from service.service.task_scheduler.TaskExecutor import TaskExecutor LOGGER = logging.getLogger(__name__) def check_endpoint(endpoint : str, service_uuid : str) -> Tuple[str, str]: endpoint_split = endpoint.split(':') if len(endpoint_split) != 2: raise Exception('Endpoint({:s}) is malformed for Service({:s})'.format(str(endpoint), str(service_uuid))) return endpoint_split class MicrowaveServiceHandler(_ServiceHandler): def __init__( # pylint: disable=super-init-not-called self, service : Service, task_executor : TaskExecutor, **settings Loading Loading @@ -51,29 +57,24 @@ class MicrowaveServiceHandler(_ServiceHandler): ) -> 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 [] service_uuid = self.__service.service_id.service_uuid.uuid results = [] try: chk_type('endpoints', endpoints, list) if len(endpoints) != 2: raise Exception('len(endpoints) != 2') settings : TreeNode = get_subnode(self.__resolver, self.__config, '/settings', None) if settings is None: raise Exception('Unable to retrieve settings for Service({:s})'.format(str(service_uuid))) if settings is None: raise Exception('Unable to retrieve settings for Service({:s})'.format(str(service_uuid))) json_settings : Dict = settings.value vlan_id = json_settings.get('vlan_id', 121) # endpoints are retrieved in the following format --> '/endpoints/endpoint[172.26.60.243:9]' try: endpoint_src_split = endpoints[0][1].split(':') endpoint_dst_split = endpoints[1][1].split(':') if len(endpoint_src_split) != 2 and len(endpoint_dst_split) != 2: return [] node_id_src = endpoint_src_split[0] tp_id_src = endpoint_src_split[1] node_id_dst = endpoint_dst_split[0] tp_id_dst = endpoint_dst_split[1] except ValueError: return [] 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) results = [] try: device_uuid = endpoints[0][0] device = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) json_config_rule = json_config_rule_set('/service[{:s}]'.format(service_uuid), { Loading @@ -89,7 +90,7 @@ class MicrowaveServiceHandler(_ServiceHandler): self.__task_executor.configure_device(device) results.append(True) except Exception as e: # pylint: disable=broad-except LOGGER.exception('Unable to configure Service({:s})'.format(str(service_uuid))) LOGGER.exception('Unable to SetEndpoint for Service({:s})'.format(str(service_uuid))) results.append(e) return results Loading @@ -100,12 +101,13 @@ class MicrowaveServiceHandler(_ServiceHandler): 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 [] service_uuid = self.__service.service_id.service_uuid.uuid results = [] try: chk_type('endpoints', endpoints, list) if len(endpoints) != 2: raise Exception('len(endpoints) != 2') device_uuid = endpoints[0][0] device = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) json_config_rule = json_config_rule_delete('/service[{:s}]'.format(service_uuid), {'uuid': service_uuid}) Loading Loading
src/service/service/service_handlers/microwave/MicrowaveServiceHandler.py +24 −22 Original line number Diff line number Diff line Loading @@ -24,6 +24,12 @@ from service.service.task_scheduler.TaskExecutor import TaskExecutor LOGGER = logging.getLogger(__name__) def check_endpoint(endpoint : str, service_uuid : str) -> Tuple[str, str]: endpoint_split = endpoint.split(':') if len(endpoint_split) != 2: raise Exception('Endpoint({:s}) is malformed for Service({:s})'.format(str(endpoint), str(service_uuid))) return endpoint_split class MicrowaveServiceHandler(_ServiceHandler): def __init__( # pylint: disable=super-init-not-called self, service : Service, task_executor : TaskExecutor, **settings Loading Loading @@ -51,29 +57,24 @@ class MicrowaveServiceHandler(_ServiceHandler): ) -> 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 [] service_uuid = self.__service.service_id.service_uuid.uuid results = [] try: chk_type('endpoints', endpoints, list) if len(endpoints) != 2: raise Exception('len(endpoints) != 2') settings : TreeNode = get_subnode(self.__resolver, self.__config, '/settings', None) if settings is None: raise Exception('Unable to retrieve settings for Service({:s})'.format(str(service_uuid))) if settings is None: raise Exception('Unable to retrieve settings for Service({:s})'.format(str(service_uuid))) json_settings : Dict = settings.value vlan_id = json_settings.get('vlan_id', 121) # endpoints are retrieved in the following format --> '/endpoints/endpoint[172.26.60.243:9]' try: endpoint_src_split = endpoints[0][1].split(':') endpoint_dst_split = endpoints[1][1].split(':') if len(endpoint_src_split) != 2 and len(endpoint_dst_split) != 2: return [] node_id_src = endpoint_src_split[0] tp_id_src = endpoint_src_split[1] node_id_dst = endpoint_dst_split[0] tp_id_dst = endpoint_dst_split[1] except ValueError: return [] 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) results = [] try: device_uuid = endpoints[0][0] device = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) json_config_rule = json_config_rule_set('/service[{:s}]'.format(service_uuid), { Loading @@ -89,7 +90,7 @@ class MicrowaveServiceHandler(_ServiceHandler): self.__task_executor.configure_device(device) results.append(True) except Exception as e: # pylint: disable=broad-except LOGGER.exception('Unable to configure Service({:s})'.format(str(service_uuid))) LOGGER.exception('Unable to SetEndpoint for Service({:s})'.format(str(service_uuid))) results.append(e) return results Loading @@ -100,12 +101,13 @@ class MicrowaveServiceHandler(_ServiceHandler): 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 [] service_uuid = self.__service.service_id.service_uuid.uuid results = [] try: chk_type('endpoints', endpoints, list) if len(endpoints) != 2: raise Exception('len(endpoints) != 2') device_uuid = endpoints[0][0] device = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) json_config_rule = json_config_rule_delete('/service[{:s}]'.format(service_uuid), {'uuid': service_uuid}) Loading