diff --git a/network_sketcher.py b/network_sketcher.py index 0c9d146..08e2b71 100644 --- a/network_sketcher.py +++ b/network_sketcher.py @@ -32,7 +32,7 @@ def __init__(self): self.click_value_2nd = '' self.click_value_3rd = '' self.root = TkinterDnD.Tk() - self.root.title("Network Sketcher ver 2.1.1") + self.root.title("Network Sketcher ver 2.1.2") self.root.geometry("490x200+100+100") # Notebook diff --git a/network_sketcher_dev.py b/network_sketcher_dev.py index 586b22c..14b2ba2 100644 --- a/network_sketcher_dev.py +++ b/network_sketcher_dev.py @@ -636,6 +636,7 @@ def click_action(self,click_value): if click_value == '1-4b': # select convert to master data file from YAML # check file open print(self.full_filepath) + self.yaml_full_filepath = self.full_filepath self.click_value = '1-4b' @@ -694,6 +695,10 @@ def click_action(self,click_value): import network_sketcher network_sketcher.ns_front_run.sub_excel_master_1(self, file_type_array) + '''add L3 config in yaml to Master file''' + ns_option_convert_to_master.ns_l3_config_to_master_yaml.__init__(self) + + if click_value == '2-1': # select browse fTyp = [("", ".xlsx")] iDir = os.path.abspath(os.path.dirname(sys.argv[0])) diff --git a/ns_l2_table_from_master.py b/ns_l2_table_from_master.py index a8cf327..99b95f4 100644 --- a/ns_l2_table_from_master.py +++ b/ns_l2_table_from_master.py @@ -313,7 +313,7 @@ def __init__(self): #l2_master_data_array.append([tmp_row , [current_area_name, current_device_name, tmp_l2_table_array[1][2], tmp_l2_table_array[1][3], tmp_l2_table_array[1][4], tmp_l2_table_array[1][5]]]) l2_master_data_array.append([tmp_row , [current_area_name, current_device_name, '', tmp_l2_table_array[1][3], '', tmp_l2_table_array[1][5]]]) tmp_row += 1 - print('#### l2_master_data_array ####') + print('--- l2_master_data_array ---') #print(l2_master_data_array) l2_master_data_tuple = {} diff --git a/ns_l3_diagram_create.py b/ns_l3_diagram_create.py index 343719e..2686fbb 100644 --- a/ns_l3_diagram_create.py +++ b/ns_l3_diagram_create.py @@ -60,7 +60,7 @@ def __init__(self): #print(self.result_get_l2_broadcast_domains[4]) self.marged_l2_broadcast_group_array = self.result_get_l2_broadcast_domains[4] print('--- self.target_l2_broadcast_group_array ---') - print(self.target_l2_broadcast_group_array) + #print(self.target_l2_broadcast_group_array) self.l3_table_array = ns_def.convert_master_to_array(ws_l3_name, excel_maseter_file, '<>') #print('--- self.l3_table_array ---') @@ -171,7 +171,7 @@ def __init__(self): def l3_area_create(self, target_folder_name, action_type,offset_x ,offset_y): - print('### l3_area_create ### ',target_folder_name,action_type,offset_x ,offset_y) + print('--- l3_area_create --- ',target_folder_name,action_type,offset_x ,offset_y) self.used_l3segment_array = [] ### get l3segment in the target folder target_all_device_array = [] @@ -804,7 +804,7 @@ def l3_area_create(self, target_folder_name, action_type,offset_x ,offset_y): left_offset = start_l3_seg_inche_x - self.left_margin #print('## end_l3_seg_inche_x ', end_l3_seg_inche_x) - print('--- l3segment_line_array --- [start_l3_seg_inche_x,end_l3_seg_inche_x],tmp_l3segment_y_array, return_get_l3_segment_num[1]') + print('--- l3segment_line_array ---') #print(l3segment_line_array) @@ -1092,7 +1092,7 @@ def l3_area_create(self, target_folder_name, action_type,offset_x ,offset_y): ''' write folder line and outline ''' - print('--- self.area_position_array --- # shape_left, shape_top, shape_width, shape_hight, shape_text') + print('--- self.area_position_array ---') #print(self.area_position_array) ### write folder diff --git a/ns_l3_table_from_master.py b/ns_l3_table_from_master.py index 0b26c21..58646bf 100644 --- a/ns_l3_table_from_master.py +++ b/ns_l3_table_from_master.py @@ -28,7 +28,6 @@ def __init__(self): ''' make L3 Table excel file ''' - print('### ns_l3_table_from_master() ###') #parameter ws_name = 'Master_Data' ws_name_l2 = 'Master_Data_L2' @@ -248,7 +247,7 @@ def __init__(self): tmp_L3_table_array[1][1] = now_shape_name excel_L3_table_array.append(([tmp_L3_table_array[0] + tmp_offset_row,tmp_L3_table_array[1]])) - print('#### excel_L3_table_array ####') + print('--- excel_L3_table_array ---') #print(excel_L3_table_array) L3_master_data_tuple = {} L3_master_data_tuple = ns_def.convert_array_to_tuple(excel_L3_table_array) diff --git a/ns_option_convert_to_master.py b/ns_option_convert_to_master.py index 8ec55d5..7b79242 100644 --- a/ns_option_convert_to_master.py +++ b/ns_option_convert_to_master.py @@ -25,6 +25,7 @@ import ns_def import openpyxl import yaml +from ciscoconfparse import CiscoConfParse class ns_option_convert_to_master_svg(): def __init__(self): @@ -327,3 +328,107 @@ def __init__(self): converted_tuple = ns_def.convert_array_to_tuple(new_master_line_array) ns_def.overwrite_excel_meta(converted_tuple, self.excel_file_path, 'Master_Data', '<>', 0,0) + +class ns_l3_config_to_master_yaml(): + def __init__(self): + # parameter + l3_table_ws_name = 'Master_Data_L3' + l3_table_file = self.full_filepath + target_node_definition_ios = ['iosv','csr1000v','iosvl2','asav'] + target_node_definition_asa = ['asav'] + target_node_definition_iosxr = ['iosxrv9000'] + + #get L3 Table Excel file + l3_table_array = [] + l3_table_array = ns_def.convert_excel_to_array(l3_table_ws_name, l3_table_file, 3) + print('--- l3_table_array ---') + #print(l3_table_array) + + '''get L3 ipaddress from yaml''' + ### read the yaml file + with open(str(self.yaml_full_filepath), 'r') as yml: + config = yaml.safe_load(yml) + # print(config) + + config_array = [] + last_int_array = [] + overwrite_l3_table_array = [] + + print('--- [label, node_definition, id, configuration] ---') + for tmp_config in config['nodes']: + config_array.append([tmp_config['label'], tmp_config['node_definition'], tmp_config['id'], tmp_config['configuration']]) + # print(tmp_config['configuration']) + if tmp_config['node_definition'] in target_node_definition_ios or tmp_config['node_definition'] in target_node_definition_asa or tmp_config['node_definition'] in target_node_definition_iosxr: + ''' + CiscoConfParse + ''' + CONFIG = tmp_config['configuration'] + + if tmp_config['node_definition'] in target_node_definition_ios: + parse = CiscoConfParse(CONFIG.splitlines(), syntax='ios', factory=True) + elif tmp_config['node_definition'] in target_node_definition_asa: + parse = CiscoConfParse(CONFIG.splitlines(), syntax='asa', factory=True) + elif tmp_config['node_definition'] in target_node_definition_iosxr: + parse = CiscoConfParse(CONFIG.splitlines(), syntax='iosxr', factory=True) + + + int_array = [[tmp_config['label'], tmp_config['node_definition'], tmp_config['id']]] + dummy_array = [] + + for tmp_parse in parse.find_objects('^interface\s'): + int_char = list(str(tmp_parse.interface_object)) + int_char_2 = str(tmp_parse.interface_object) + + for i, tmp_char in enumerate(str(tmp_parse.interface_object)): + if re.fullmatch('[0-9]+', tmp_char): + # print(str(i),tmp_char) + int_char.insert(i, ' ') + int_char_2 = str("".join(int_char)) + break + + if str(tmp_parse.ipv4_addr) != '': + dummy_array.append([int_char_2, tmp_parse.ipv4_addr + '/' + str(tmp_parse.ipv4_masklength)]) + + int_array.append(dummy_array) + #print(int_array) + last_int_array.append(int_array) + + for tmp_l3_table_array in l3_table_array: + #print(tmp_l3_table_array[1]) + for tmp_last_int_array in last_int_array: + if tmp_l3_table_array[1][1] == tmp_last_int_array[0][0]: + #print(tmp_last_int_array[0][0] , tmp_l3_table_array[1][1]) + if tmp_last_int_array[0][0] == tmp_l3_table_array[1][1]: + flag_l3_exist = False + for tmp_tmp_last_int_array in tmp_last_int_array[1]: + if tmp_tmp_last_int_array[0] == tmp_l3_table_array[1][2]: + #print('--- L3 address match --- ' + str(tmp_last_int_array) , str(tmp_l3_table_array)) + if len(tmp_l3_table_array[1]) == 3: + tmp_l3_table_array[1].append('') + tmp_l3_table_array[1].append(tmp_tmp_last_int_array[1]) + overwrite_l3_table_array.append(tmp_l3_table_array) + flag_l3_exist = True + if flag_l3_exist == False: + overwrite_l3_table_array.append(tmp_l3_table_array) + + print('--- overwrite_l3_table_array ---') + #print(overwrite_l3_table_array) + + + # write to master file + last_overwrite_l3_table_tuple = {} + last_overwrite_l3_table_tuple = ns_def.convert_array_to_tuple(overwrite_l3_table_array) + print('--- last_overwrite_l3_table_tuple ---') + #print(last_overwrite_l3_table_tuple) + + master_excel_meta = last_overwrite_l3_table_tuple + excel_file_path = self.full_filepath + worksheet_name = l3_table_ws_name + section_write_to = '<>' + offset_row = 2 + offset_column = 0 + ns_def.overwrite_excel_meta(master_excel_meta, excel_file_path, worksheet_name, section_write_to, offset_row, offset_column) + + + +