Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ver2.1.1 #13

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion network_sketcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions network_sketcher_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion ns_l2_table_from_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
8 changes: 4 additions & 4 deletions ns_l3_diagram_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<<L3_TABLE>>')
#print('--- self.l3_table_array ---')
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions ns_l3_table_from_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
105 changes: 105 additions & 0 deletions ns_option_convert_to_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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', '<<POSITION_LINE>>', 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 = '<<L3_TABLE>>'
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)