From cb1582cc4ac47b00aaea18a8df3b3810614b466c Mon Sep 17 00:00:00 2001 From: Armingol <pablo.armingolrobles@telefonica.com> Date: Thu, 21 Nov 2024 11:51:37 +0100 Subject: [PATCH] Code cleanup --- proto/context.proto | 1 - proto/ip_link.proto | 2 -- .../drivers/openconfig/templates/__init__.py | 27 ++++--------------- .../algorithms/tools/ComposeConfigRules.py | 23 ++++++++-------- .../service/algorithms/tools/ServiceTypes.py | 1 - .../grpc/context/ContextOuterClass.java | 11 ++++++++ .../service_handlers/ip_link/ConfigRules.py | 4 +-- 7 files changed, 28 insertions(+), 41 deletions(-) diff --git a/proto/context.proto b/proto/context.proto index 45c808210..27d0cdafd 100644 --- a/proto/context.proto +++ b/proto/context.proto @@ -320,7 +320,6 @@ enum ServiceTypeEnum { SERVICETYPE_OPTICAL_CONNECTIVITY = 6; SERVICETYPE_QKD = 7; SERVICETYPE_IPLINK = 8; - } enum ServiceStatusEnum { diff --git a/proto/ip_link.proto b/proto/ip_link.proto index 79a5bed5a..824596605 100644 --- a/proto/ip_link.proto +++ b/proto/ip_link.proto @@ -15,8 +15,6 @@ syntax = "proto3"; package ip_link; - - message IpLinkRuleSet { string ip = 1; string mask = 3; diff --git a/src/device/service/drivers/openconfig/templates/__init__.py b/src/device/service/drivers/openconfig/templates/__init__.py index b5a231062..632716bf4 100644 --- a/src/device/service/drivers/openconfig/templates/__init__.py +++ b/src/device/service/drivers/openconfig/templates/__init__.py @@ -274,27 +274,22 @@ def cli_compose_config(resources, delete: bool, host: str, user: str, passw: str ssh_client.close() def ufi_interface(resources, delete: bool): #Method used for configuring via CLI directly L2VPN in CISCO devices - + key_value_data = {} for path, json_str in resources: key_value_data[path] = json_str - # Iterate through the resources and extract parameter values dynamically - - # initialize the SSH client ssh_client = paramiko.SSHClient() ssh_client.load_system_host_keys() # add to known hosts ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - + try: ssh_client.connect(hostname='10.95.90.75', username='dnroot', password='dnroot', look_for_keys=False) - #print("Connection successful") LOGGER.warning("Connection successful") except: - #print("[!] Cannot connect to the SSH Server") LOGGER.warning("[!] Cannot connect to the SSH Server") exit() interface = 'ge100-0/0/3/1' @@ -318,9 +313,7 @@ def ufi_interface(resources, delete: bool): #Method used for configuring via channel.send('commit\n') time.sleep(1) - # Capturar la salida del comando output = channel.recv(65535).decode('utf-8') - #print(output) LOGGER.warning(output) # Close the SSH shell channel.close() @@ -330,31 +323,24 @@ def ufi_interface(resources, delete: bool): #Method used for configuring via # Close the SSH client ssh_client.close() - - - + def cisco_interface(resources, delete: bool, host: str, user: str, passw: str): #Method used for configuring via CLI directly L2VPN in CISCO devices - + key_value_data = {} for path, json_str in resources: key_value_data[path] = json_str - # Iterate through the resources and extract parameter values dynamically - - # initialize the SSH client ssh_client = paramiko.SSHClient() ssh_client.load_system_host_keys() # add to known hosts ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - + try: ssh_client.connect(hostname='10.90.95.150', username='cisco', password='cisco123', look_for_keys=False) - #print("Connection successful") LOGGER.warning("Connection successful") except: - #print("[!] Cannot connect to the SSH Server") LOGGER.warning("[!] Cannot connect to the SSH Server") exit() interface = 'FourHundredGigE0/0/0/10.1212' @@ -378,10 +364,7 @@ def cisco_interface(resources, delete: bool, host: str, user: str, passw: str): channel.send('commit\n') time.sleep(0.1) - - # Capturar la salida del comando output = channel.recv(65535).decode('utf-8') - #print(output) LOGGER.warning(output) # Close the SSH shell channel.close() diff --git a/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py b/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py index 4256a8fd0..80b214b9c 100644 --- a/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py +++ b/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py @@ -107,12 +107,12 @@ def compose_tapi_config_rules(main_service_config_rules : List, subservice_confi ] for rule_name, defaults in CONFIG_RULES: compose_config_rules(main_service_config_rules, subservice_config_rules, rule_name, defaults) - + def compose_iplink_config_rules(main_service_config_rules : List, subservice_config_rules : List) -> None: CONFIG_RULES: List[Tuple[str, dict]] = [(SETTINGS_RULE_NAME, IPLINK_SETTINGS_FIELD_DEFAULTS)] for rule_name, defaults in CONFIG_RULES: compose_config_rules(main_service_config_rules, subservice_config_rules, rule_name, defaults) - + def compose_device_config_rules( config_rules : List, subservice_config_rules : List, path_hops : List, device_name_mapping : Dict[str, str], endpoint_name_mapping : Dict[Tuple[str, str], str] @@ -158,10 +158,10 @@ def compose_device_config_rules( device_endpoint_keys = set(itertools.product(device_keys, endpoint_keys)) if len(device_endpoint_keys.intersection(endpoints_traversed)) == 0: continue - + LOGGER.debug('[compose_device_config_rules] adding acl config rule') subservice_config_rules.append(config_rule) - + elif config_rule.WhichOneof('config_rule') == 'ip_link': LOGGER.debug('[compose_device_config_rules] is ip_link') endpoint_id = config_rule.ip_link.endpoint_id @@ -174,7 +174,6 @@ def compose_device_config_rules( endpoint_uuid = endpoint_id.endpoint_uuid.uuid LOGGER.debug('[compose_device_config_rules] endpoint_uuid={:s}'.format(str(endpoint_uuid))) - # given endpoint uuids link 'eth-1/0/20.533', remove last part after the '.' endpoint_uuid_or_name = (endpoint_uuid[::-1].split('.', maxsplit=1)[-1])[::-1] LOGGER.debug('[compose_device_config_rules] endpoint_uuid_or_name={:s}'.format(str(endpoint_uuid_or_name))) endpoint_name_or_uuid_1 = endpoint_name_mapping[(device_uuid_or_name, endpoint_uuid_or_name)] @@ -183,7 +182,7 @@ def compose_device_config_rules( device_endpoint_keys = set(itertools.product(device_keys, endpoint_keys)) if len(device_endpoint_keys.intersection(endpoints_traversed)) == 0: continue - + LOGGER.debug('[compose_device_config_rules] adding ip_link config rule') subservice_config_rules.append(config_rule) @@ -365,12 +364,12 @@ def generate_neighbor_endpoint_config_rules( generated_config_rule['custom']['resource_key'] = resource_key_template.format(*resource_key_values) generated_config_rule['custom']['resource_value'] = json.dumps(resource_value) generated_config_rules.append(generated_config_rule) - else: - LOGGER.debug('[generate_neighbor_endpoint_config_rules] IP_LINK: {:s}'.format(str(config_rule))) - resource_value : Dict = config_rule['ip_link'] - generated_config_rule = copy.deepcopy(config_rule) - generated_config_rule['ip_link'] = resource_value - generated_config_rules.append(generated_config_rule) + else: + LOGGER.debug('[generate_neighbor_endpoint_config_rules] IP_LINK: {:s}'.format(str(config_rule))) + resource_value : Dict = config_rule['ip_link'] + generated_config_rule = copy.deepcopy(config_rule) + generated_config_rule['ip_link'] = resource_value + generated_config_rules.append(generated_config_rule) LOGGER.debug('[generate_neighbor_endpoint_config_rules] generated_config_rules={:s}'.format(str(generated_config_rules))) LOGGER.debug('[generate_neighbor_endpoint_config_rules] end') diff --git a/src/pathcomp/frontend/service/algorithms/tools/ServiceTypes.py b/src/pathcomp/frontend/service/algorithms/tools/ServiceTypes.py index bdd22bf29..f1676ccfb 100644 --- a/src/pathcomp/frontend/service/algorithms/tools/ServiceTypes.py +++ b/src/pathcomp/frontend/service/algorithms/tools/ServiceTypes.py @@ -47,7 +47,6 @@ SERVICE_TYPE_LXNM = {ServiceTypeEnum.SERVICETYPE_L3NM, ServiceTypeEnum.SERVICE SERVICE_TYPE_TAPI = {ServiceTypeEnum.SERVICETYPE_TAPI_CONNECTIVITY_SERVICE} SERVICE_TYPE_IPLINK = {ServiceTypeEnum.SERVICETYPE_IPLINK} - def get_service_type(device_type : DeviceTypeEnum, prv_service_type : ServiceTypeEnum) -> ServiceTypeEnum: if device_type in PACKET_DEVICE_TYPES and (prv_service_type in SERVICE_TYPE_LXNM or prv_service_type in SERVICE_TYPE_IPLINK ): return prv_service_type if device_type in L2_DEVICE_TYPES: return ServiceTypeEnum.SERVICETYPE_L2NM diff --git a/src/policy/target/generated-sources/grpc/context/ContextOuterClass.java b/src/policy/target/generated-sources/grpc/context/ContextOuterClass.java index 779add774..9f2320d78 100644 --- a/src/policy/target/generated-sources/grpc/context/ContextOuterClass.java +++ b/src/policy/target/generated-sources/grpc/context/ContextOuterClass.java @@ -515,6 +515,10 @@ public final class ContextOuterClass { * <code>SERVICETYPE_OPTICAL_CONNECTIVITY = 6;</code> */ SERVICETYPE_OPTICAL_CONNECTIVITY(6), + /** + * <code>SERVICETYPE_QKD = 7;</code> + */ + SERVICETYPE_QKD(7), UNRECOGNIZED(-1); /** @@ -552,6 +556,11 @@ public final class ContextOuterClass { */ public static final int SERVICETYPE_OPTICAL_CONNECTIVITY_VALUE = 6; + /** + * <code>SERVICETYPE_QKD = 7;</code> + */ + + public static final int SERVICETYPE_QKD_VALUE = 7; public final int getNumber() { if (this == UNRECOGNIZED) { throw new java.lang.IllegalArgumentException("Can't get the number of an unknown enum value."); @@ -589,6 +598,8 @@ public final class ContextOuterClass { return SERVICETYPE_E2E; case 6: return SERVICETYPE_OPTICAL_CONNECTIVITY; + case 7: + return SERVICETYPE_QKD; default: return null; } diff --git a/src/service/service/service_handlers/ip_link/ConfigRules.py b/src/service/service/service_handlers/ip_link/ConfigRules.py index 96eab0dbf..20f768373 100644 --- a/src/service/service/service_handlers/ip_link/ConfigRules.py +++ b/src/service/service/service_handlers/ip_link/ConfigRules.py @@ -29,7 +29,6 @@ def setup_config_rules( endpoint_name : str, endpoint_ip_link : List [Tuple] ) -> List[Dict]: - json_config_rules = [ ] @@ -37,7 +36,7 @@ def setup_config_rules( json_config_rules.append( {'action': 1, 'ip_link': res_value} ) - + return json_config_rules def teardown_config_rules( @@ -55,6 +54,5 @@ def teardown_config_rules( settings = (json_settings, json_endpoint_settings, json_device_settings) - json_config_rules = [] return json_config_rules -- GitLab