Skip to content
Snippets Groups Projects
Commit cb1582cc authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Code cleanup

parent 90ab9bc0
No related branches found
No related tags found
2 merge requests!341Draft: Resolve "optical bandwidth expansion",!239Draft: Resolve "(TID) Creation of IP link with supporting coherent pluggable to pluggable connection"
This commit is part of merge request !239. Comments created here will be created in the context of that merge request.
......@@ -320,7 +320,6 @@ enum ServiceTypeEnum {
SERVICETYPE_OPTICAL_CONNECTIVITY = 6;
SERVICETYPE_QKD = 7;
SERVICETYPE_IPLINK = 8;
}
enum ServiceStatusEnum {
......
......@@ -15,8 +15,6 @@
syntax = "proto3";
package ip_link;
message IpLinkRuleSet {
string ip = 1;
string mask = 3;
......
......@@ -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()
......
......@@ -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')
......
......@@ -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
......
......@@ -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;
}
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment