-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathns_sync_between_layers.py
556 lines (436 loc) · 28.1 KB
/
ns_sync_between_layers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
'''
SPDX-License-Identifier: Apache-2.0
Copyright 2023 Cisco Systems, Inc. and its affiliates
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''
from pptx import *
import sys, os, re
import numpy as np
import math,shutil
import openpyxl
import tkinter as tk ,tkinter.ttk as ttk,tkinter.filedialog, tkinter.messagebox
import ns_def ,ns_ddx_figure , network_sketcher,network_sketcher_dev
def l2_device_table_sync_with_l3_master(self):
#print('--- l2_device_table_sync_with_l3_master ---')
### get exist L2 table sheet in master file
ws_l2_name = 'Master_Data_L2'
ws_l3_name = 'Master_Data_L3'
excel_maseter_file = self.full_filepath
original_master_l2_table_array = ns_def.convert_master_to_array(ws_l2_name, excel_maseter_file, '<<L2_TABLE>>')
original_master_l3_table_array = ns_def.convert_master_to_array(ws_l3_name, excel_maseter_file, '<<L3_TABLE>>')
del original_master_l2_table_array[:2]
del original_master_l3_table_array[:2]
#print(original_master_l2_table_array)
#print(original_master_l3_table_array)
for index_l2,tmp_original_master_l2_table_array in enumerate(original_master_l2_table_array):
tmp_original_master_l2_table_array[1].extend(['','','','','','','',''])
del tmp_original_master_l2_table_array[1][8:]
original_master_l2_table_array[index_l2] = tmp_original_master_l2_table_array
for index_l3,tmp_original_master_l3_table_array in enumerate(original_master_l3_table_array):
tmp_original_master_l3_table_array[1].extend(['','','','','','','','','',''])
del tmp_original_master_l3_table_array[1][7:]
original_master_l3_table_array[index_l3] = tmp_original_master_l3_table_array
### remove Master L3 sheet
ppt_meta_file = excel_maseter_file
copy_sheet_name = ws_l3_name
ns_def.remove_excel_sheet(ppt_meta_file, copy_sheet_name)
### re-create Master L3 sheet
#run L3-1-2 in network_sketcher_dev , add l3 master sheet
self.click_value = 'L3-1-2'
network_sketcher_dev.ns_front_run.click_action(self, 'L3-1-2')
# remove exist L3/ file
if os.path.isfile(self.full_filepath.replace('[MASTER]', '[L3_TABLE]')) == True:
os.remove(self.full_filepath.replace('[MASTER]', '[L3_TABLE]'))
### get re-create L3 Master
recreate_master_l3_table_array = ns_def.convert_master_to_array(ws_l3_name, excel_maseter_file, '<<L3_TABLE>>')
del recreate_master_l3_table_array[:2]
for index_l3,tmp_recreate_master_l3_table_array in enumerate(recreate_master_l3_table_array):
tmp_recreate_master_l3_table_array[1].extend(['','','','','','','','','',''])
del tmp_recreate_master_l3_table_array[1][7:]
recreate_master_l3_table_array[index_l3] = tmp_recreate_master_l3_table_array
### update original L3 Master values to recreate L3 Master
for index_l3_2 ,tmp_recreate_master_l3_table_array in enumerate(recreate_master_l3_table_array):
tmp_recreate_master_l3_table_array[1].append(ns_def.get_if_value(tmp_recreate_master_l3_table_array[1][2]))
tmp_recreate_master_l3_table_array[1].extend([str(ns_def.split_portname(tmp_recreate_master_l3_table_array[1][2])[0])])
recreate_master_l3_table_array[index_l3_2] = tmp_recreate_master_l3_table_array
for tmp_original_master_l3_table_array in original_master_l3_table_array:
if tmp_recreate_master_l3_table_array[1][1] == tmp_original_master_l3_table_array[1][1] and tmp_recreate_master_l3_table_array[1][2] == tmp_original_master_l3_table_array[1][2]:
recreate_master_l3_table_array[index_l3_2][1][3] = tmp_original_master_l3_table_array[1][3]
recreate_master_l3_table_array[index_l3_2][1][4] = tmp_original_master_l3_table_array[1][4]
recreate_master_l3_table_array[index_l3_2][1][5] = tmp_original_master_l3_table_array[1][5]
recreate_master_l3_table_array[index_l3_2][1][6] = tmp_original_master_l3_table_array[1][6]
### make array for sort
sort_master_l3_table_array = []
for tmp_recreate_master_l3_table_array in recreate_master_l3_table_array:
sort_master_l3_table_array.append(tmp_recreate_master_l3_table_array[1])
sort_master_l3_table_array = sorted(sort_master_l3_table_array, reverse=False, key=lambda x: (x[0], x[1], x[3], x[8], x[7], x[4])) # sort l3 table
last_master_l3_table_array = []
last_master_l3_table_array.append([1, ['<<L3_TABLE>>']])
last_master_l3_table_array.append([2, ['Area', 'Device Name', 'L3 IF Name','L3 Instance Name', 'IP Address / Subnet mask (Comma Separated)', '[VPN] Target Device Name (Comma Separated)', '[VPN] Target L3 Port Name (Comma Separated)']])
for index_l3_3,tmp_sort_master_l3_table_array in enumerate(sort_master_l3_table_array):
del tmp_sort_master_l3_table_array[-2:]
last_master_l3_table_array.append([index_l3_3 + 3 ,tmp_sort_master_l3_table_array])
#print('--- last_master_l3_table_array ---')
#print(last_master_l3_table_array)
### Re-Write L3 sheet
last_master_l3_table_tuple = ns_def.convert_array_to_tuple(last_master_l3_table_array)
tmp_ws_name = ws_l3_name
ppt_meta_file = excel_maseter_file
clear_section_taple = last_master_l3_table_tuple
ns_def.clear_section_sheet(tmp_ws_name, ppt_meta_file, clear_section_taple)
master_excel_meta = last_master_l3_table_tuple
excel_file_path = excel_maseter_file
worksheet_name = ws_l3_name
section_write_to = '<<L3_TABLE>>'
offset_row = 0
offset_column = 0
ns_def.overwrite_excel_meta(master_excel_meta, excel_file_path, worksheet_name, section_write_to, offset_row, offset_column)
def l2_device_port_name_sync_with_l3_master(self):
#print('--- l2_device_vport_name_sync_with_l3_master ---')
ws_name = 'Master_Data'
ws_l2_name = 'Master_Data_L2'
ws_l3_name = 'Master_Data_L3'
excel_maseter_file = self.full_filepath
device_table_file = self.inFileTxt_12_1.get()
device_l2_table_ws_name = 'L2 Table'
self.update_l2_table_vport_array = []
excel_device_table = openpyxl.load_workbook(device_table_file)
excel_device_table.active = excel_device_table.sheetnames.index(device_l2_table_ws_name)
# GET Folder and wp name List
folder_wp_name_array = ns_def.get_folder_wp_array_from_master(ws_name, excel_maseter_file)
#print('---- folder_wp_name_array ----')
# print(folder_wp_name_array)
flag_get_start = False
for tmp_column in range(1, 100):
for tmp_row in range(1, 100):
if '4f81bd' in str(excel_device_table.active.cell(tmp_row, tmp_column).fill.bgColor.value).lower() and 'dce6f1' in str(excel_device_table.active.cell(tmp_row + 1, tmp_column).fill.bgColor.value).lower():
start_folder_array = tmp_row + 1, tmp_column, excel_device_table.active.cell(tmp_row + 1, tmp_column).value
for tmp_folder_wp_name_array in folder_wp_name_array[0]:
if tmp_folder_wp_name_array == start_folder_array[2]:
flag_get_start = True
break
if flag_get_start == True:
break
#print('start_folder_array')
#print(start_folder_array)
# convert from device table to array and convert to tuple
excel_ws_name = 'L2 Table'
excel_file = device_table_file
start_row = start_folder_array[0]
self.device_l2_table_array = ns_def.convert_excel_to_array(excel_ws_name, excel_file, start_row)
update_device_l2_table_array = []
current_folder_name = '__dummy__'
current_shape_name = '__dummy__'
for tmp_device_l2_table_array in self.device_l2_table_array:
tmp_device_l2_table_array[1].extend(['','','','','','','','',''])
del tmp_device_l2_table_array[1][8:]
tmp_device_l2_table_array[1][2] = ''
tmp_device_l2_table_array[1][4] = ''
if tmp_device_l2_table_array[1][0] != '':
current_folder_name = tmp_device_l2_table_array[1][0]
elif tmp_device_l2_table_array[1][0] == '':
tmp_device_l2_table_array[1][0] = current_folder_name
if tmp_device_l2_table_array[1][1] != '':
current_shape_name = tmp_device_l2_table_array[1][1]
elif tmp_device_l2_table_array[1][1] == '':
tmp_device_l2_table_array[1][1] = current_shape_name
update_device_l2_table_array.append(tmp_device_l2_table_array[1])
if '\n' in tmp_device_l2_table_array[1][5]:
tmp_update_if_name = tmp_device_l2_table_array[1][5]
tmp_update_if_array = tmp_update_if_name.split('\n')
self.update_l2_table_vport_array.append([tmp_device_l2_table_array[1][1],tmp_update_if_array[0],tmp_update_if_array[1]])
#print('--- update_device_l2_table_array. ---')
#print(update_device_l2_table_array)
#print('--- self.update_l2_table_vport_array ---')
#print(self.update_l2_table_vport_array)
### make overwrite tuple
ws_l2_name = 'Master_Data_L2'
ws_l3_name = 'Master_Data_L3'
excel_maseter_file = self.full_filepath
master_l2_table_array = ns_def.convert_master_to_array(ws_l2_name, excel_maseter_file, '<<L2_TABLE>>')
master_l3_table_array = ns_def.convert_master_to_array(ws_l3_name, excel_maseter_file, '<<L3_TABLE>>')
for index_l2,tmp_master_l2_table_array in enumerate(master_l2_table_array):
tmp_master_l2_table_array[1].extend(['','','','','','','',''])
del tmp_master_l2_table_array[1][8:]
master_l2_table_array[index_l2] = tmp_master_l2_table_array
for index_l3,tmp_master_l3_table_array in enumerate(master_l3_table_array):
tmp_master_l3_table_array[1].extend(['','','','','','','','','','',])
del tmp_master_l3_table_array[1][7:]
master_l3_table_array[index_l3] = tmp_master_l3_table_array
#convert to tuple
master_l2_table_tuple = ns_def.convert_array_to_tuple(master_l2_table_array)
master_l3_table_tuple = ns_def.convert_array_to_tuple(master_l3_table_array)
overwrite_master_l2_table_tuple = {}
overwrite_master_l3_table_tuple = {}
for tmp_master_l2_table_tuple in master_l2_table_tuple:
if tmp_master_l2_table_tuple[1] == 2 and tmp_master_l2_table_tuple[0] != 1 and tmp_master_l2_table_tuple[0] != 2:
for tmp_update_l2_table_vport_array in self.update_l2_table_vport_array:
if tmp_update_l2_table_vport_array[0] == master_l2_table_tuple[tmp_master_l2_table_tuple[0],tmp_master_l2_table_tuple[1]] and tmp_update_l2_table_vport_array[1] == master_l2_table_tuple[tmp_master_l2_table_tuple[0],6]:
overwrite_master_l2_table_tuple[tmp_master_l2_table_tuple[0],6] = tmp_update_l2_table_vport_array[2]
break
for tmp_master_l3_table_tuple in master_l3_table_tuple:
if tmp_master_l3_table_tuple[1] == 2 and tmp_master_l3_table_tuple[0] != 1 and tmp_master_l3_table_tuple[0] != 2:
for tmp_update_l3_table_vport_array in self.update_l2_table_vport_array:
if tmp_update_l3_table_vport_array[0] == master_l3_table_tuple[tmp_master_l3_table_tuple[0],tmp_master_l3_table_tuple[1]] and tmp_update_l3_table_vport_array[1] == master_l3_table_tuple[tmp_master_l3_table_tuple[0],3]:
overwrite_master_l3_table_tuple[tmp_master_l3_table_tuple[0],3] = tmp_update_l3_table_vport_array[2]
break
#print('--- overwrite_master_l2_table_tuple ,overwrite_master_l3_table_tuple---')
#print(overwrite_master_l2_table_tuple,overwrite_master_l3_table_tuple)
### write master l2/l3
master_excel_meta = overwrite_master_l2_table_tuple
excel_file_path = excel_maseter_file
worksheet_name = ws_l2_name
section_write_to = '<<L2_TABLE>>'
offset_row = 0
offset_column = 0
ns_def.overwrite_excel_meta(master_excel_meta, excel_file_path, worksheet_name, section_write_to,offset_row, offset_column)
master_excel_meta = overwrite_master_l3_table_tuple
excel_file_path = excel_maseter_file
worksheet_name = ws_l3_name
section_write_to = '<<L3_TABLE>>'
offset_row = 0
offset_column = 0
ns_def.overwrite_excel_meta(master_excel_meta, excel_file_path, worksheet_name, section_write_to,offset_row, offset_column)
def l1_device_port_name_sync_with_l2l3_master(self):
#print('--- l1_device_port_name_sync_with_l2l3_master ---')
#print(self.update_port_num_array)
ws_l2_name = 'Master_Data_L2'
ws_l3_name = 'Master_Data_L3'
excel_maseter_file = self.full_filepath
master_l2_table_array = ns_def.convert_master_to_array(ws_l2_name, excel_maseter_file, '<<L2_TABLE>>')
master_l3_table_array = ns_def.convert_master_to_array(ws_l3_name, excel_maseter_file, '<<L3_TABLE>>')
#convert to tuple
master_l2_table_tuple = ns_def.convert_array_to_tuple(master_l2_table_array)
master_l3_table_tuple = ns_def.convert_array_to_tuple(master_l3_table_array)
overwrite_l2_tuple = {}
overwrite_l3_tuple = {}
### make change l2/l3 tuple for overwrire
for tmp_master_l2_table_tuple in master_l2_table_tuple:
if tmp_master_l2_table_tuple[1] == 2 and tmp_master_l2_table_tuple[0] != 1 and tmp_master_l2_table_tuple[0] != 2:
tmp_device_name = master_l2_table_tuple[tmp_master_l2_table_tuple[0],tmp_master_l2_table_tuple[1]]
for tmp_update_port_num_array in self.update_port_num_array:
if tmp_update_port_num_array[0] == tmp_device_name and tmp_update_port_num_array[1] == master_l2_table_tuple[tmp_master_l2_table_tuple[0],4]:
overwrite_l2_tuple[tmp_master_l2_table_tuple[0],4] = tmp_update_port_num_array[2]
break
for tmp_master_l3_table_tuple in master_l3_table_tuple:
if tmp_master_l3_table_tuple[1] == 2 and tmp_master_l3_table_tuple[0] != 1 and tmp_master_l3_table_tuple[0] != 2:
tmp_device_name = master_l3_table_tuple[tmp_master_l3_table_tuple[0], tmp_master_l3_table_tuple[1]]
for tmp_update_port_num_array in self.update_port_num_array:
if tmp_update_port_num_array[0] == tmp_device_name and tmp_update_port_num_array[1] == master_l3_table_tuple[tmp_master_l3_table_tuple[0], 3]:
overwrite_l3_tuple[tmp_master_l3_table_tuple[0], 3] = tmp_update_port_num_array[2]
break
#print('--- overwrite_l2_tuple ,overwrite_l3_tuple---')
#print(overwrite_l2_tuple,overwrite_l3_tuple)
### write master l2/l3
master_excel_meta = overwrite_l2_tuple
excel_file_path = excel_maseter_file
worksheet_name = ws_l2_name
section_write_to = '<<L2_TABLE>>'
offset_row = 0
offset_column = 0
ns_def.overwrite_excel_meta(master_excel_meta, excel_file_path, worksheet_name, section_write_to,offset_row, offset_column)
master_excel_meta = overwrite_l3_tuple
excel_file_path = excel_maseter_file
worksheet_name = ws_l3_name
section_write_to = '<<L3_TABLE>>'
offset_row = 0
offset_column = 0
ns_def.overwrite_excel_meta(master_excel_meta, excel_file_path, worksheet_name, section_write_to,offset_row, offset_column)
def l1_sketch_device_name_sync_with_l2l3_master(self):
ws_l2_name = 'Master_Data_L2'
ws_l3_name = 'Master_Data_L3'
excel_maseter_file = self.full_filepath
master_l2_table_array = ns_def.convert_master_to_array(ws_l2_name, excel_maseter_file, '<<L2_TABLE>>')
master_l3_table_array = ns_def.convert_master_to_array(ws_l3_name, excel_maseter_file, '<<L3_TABLE>>')
#convert to tuple
master_l2_table_tuple = ns_def.convert_array_to_tuple(master_l2_table_array)
master_l3_table_tuple = ns_def.convert_array_to_tuple(master_l3_table_array)
#clear section
tmp_ws_name = ws_l2_name
ppt_meta_file = excel_maseter_file
clear_section_taple = master_l2_table_tuple
ns_def.clear_section_sheet(tmp_ws_name, ppt_meta_file, clear_section_taple)
tmp_ws_name = ws_l3_name
ppt_meta_file = excel_maseter_file
clear_section_taple = master_l3_table_tuple
ns_def.clear_section_sheet(tmp_ws_name, ppt_meta_file, clear_section_taple)
#update device name in Master_Data_L2 sheet
for index_l2_1 , tmp_master_l2_table_array in enumerate(master_l2_table_array):
for index_l2_2, tmp_tmp_master_l2_table_array in enumerate(tmp_master_l2_table_array[1]):
if index_l2_2 == 0 or index_l2_2 == 1:
for tmp_updated_name_array in self.updated_name_array:
if tmp_updated_name_array[0] == tmp_tmp_master_l2_table_array:
master_l2_table_array[index_l2_1][1][index_l2_2] = tmp_updated_name_array[1]
#print('# update# ', master_l2_table_array[index_l2_1][1][index_l2_2] , tmp_tmp_master_l2_table_array)
#update device name in Master_Data_L3 sheet
for index_l3_1 , tmp_master_l3_table_array in enumerate(master_l3_table_array):
for index_l3_2, tmp_tmp_master_l3_table_array in enumerate(tmp_master_l3_table_array[1]):
if index_l3_2 == 0 or index_l3_2 == 1:
for tmp_updated_name_array in self.updated_name_array:
if tmp_updated_name_array[0] == tmp_tmp_master_l3_table_array:
master_l3_table_array[index_l3_1][1][index_l3_2] = tmp_updated_name_array[1]
#print('# update# ', master_l3_table_array[index_l3_1][1][index_l3_2], tmp_tmp_master_l3_table_array)
#convert to tuple
master_l2_table_tuple = ns_def.convert_array_to_tuple(master_l2_table_array)
master_l3_table_tuple = ns_def.convert_array_to_tuple(master_l3_table_array)
#write updated array in Master_Data_L2/L3 sheet
master_excel_meta = master_l2_table_tuple
excel_file_path = excel_maseter_file
worksheet_name = ws_l2_name
section_write_to = '<<L2_TABLE>>'
offset_row = 0
offset_column = 0
ns_def.overwrite_excel_meta(master_excel_meta, excel_file_path, worksheet_name, section_write_to,offset_row, offset_column)
master_excel_meta = master_l3_table_tuple
excel_file_path = excel_maseter_file
worksheet_name = ws_l3_name
section_write_to = '<<L3_TABLE>>'
offset_row = 0
offset_column = 0
ns_def.overwrite_excel_meta(master_excel_meta, excel_file_path, worksheet_name, section_write_to,offset_row, offset_column)
def l1_master_device_and_line_sync_with_l2l3_master(self):
#print('l1_master_device_and_line_sync_with_l2l3_master')
### get exist L2 table sheet in master file
ws_l2_name = 'Master_Data_L2'
ws_l3_name = 'Master_Data_L3'
excel_maseter_file = self.full_filepath
original_master_l2_table_array = ns_def.convert_master_to_array(ws_l2_name, excel_maseter_file, '<<L2_TABLE>>')
original_master_l3_table_array = ns_def.convert_master_to_array(ws_l3_name, excel_maseter_file, '<<L3_TABLE>>')
del original_master_l2_table_array[:2]
del original_master_l3_table_array[:2]
#print(original_master_l2_table_array)
#print(original_master_l3_table_array)
for index_l2,tmp_original_master_l2_table_array in enumerate(original_master_l2_table_array):
tmp_original_master_l2_table_array[1].extend(['','','','','','','',''])
del tmp_original_master_l2_table_array[1][8:]
original_master_l2_table_array[index_l2] = tmp_original_master_l2_table_array
for index_l3,tmp_original_master_l3_table_array in enumerate(original_master_l3_table_array):
tmp_original_master_l3_table_array[1].extend(['','','','','','','',''])
del tmp_original_master_l3_table_array[1][7:] # bug fix ns-010 at 2.3.2(b)
original_master_l3_table_array[index_l3] = tmp_original_master_l3_table_array
#print(original_master_l2_table_array)
#print(original_master_l3_table_array)
'''
sync with Mater sheet L2
'''
### Master sheet L2 re create from L1 sheet
ns_def.remove_excel_sheet(excel_maseter_file, ws_l2_name)
ns_def.remove_excel_sheet(excel_maseter_file, ws_l3_name)
click_value = 'self.sub1_1_button_1'
push_array = ['','']
network_sketcher.ns_front_run.click_action_sub1_1(self, click_value, push_array)
### get re-created Master sheet L2/L3
recreate_master_l2_table_array = ns_def.convert_master_to_array(ws_l2_name, excel_maseter_file, '<<L2_TABLE>>')
del recreate_master_l2_table_array[:2]
for index_l2,tmp_recreate_master_l2_table_array in enumerate(recreate_master_l2_table_array):
tmp_recreate_master_l2_table_array[1].extend(['','','','','','','',''])
del tmp_recreate_master_l2_table_array[1][8:]
recreate_master_l2_table_array[index_l2] = tmp_recreate_master_l2_table_array
#print(recreate_master_l2_table_array)
### Update Master sheet L2
new_master_l2_table_array = []
for tmp_recreate_master_l2_table_array in recreate_master_l2_table_array:
flag_match_line_l2 = False
for tmp_original_master_l2_table_array in original_master_l2_table_array:
if tmp_original_master_l2_table_array[1][3] != '':
if tmp_original_master_l2_table_array[1][0] == tmp_recreate_master_l2_table_array[1][0] and tmp_original_master_l2_table_array[1][1] == tmp_recreate_master_l2_table_array[1][1] and tmp_original_master_l2_table_array[1][3] == tmp_recreate_master_l2_table_array[1][3]:
tmp_original_master_l2_table_array[1].append(ns_def.get_if_value(tmp_original_master_l2_table_array[1][3]))
tmp_original_master_l2_table_array[1].extend([str(ns_def.split_portname(tmp_original_master_l2_table_array[1][3])[0])])
new_master_l2_table_array.append(tmp_original_master_l2_table_array[1])
flag_match_line_l2 = True
break
if flag_match_line_l2 == False:
tmp_recreate_master_l2_table_array[1].append(ns_def.get_if_value(tmp_recreate_master_l2_table_array[1][3]))
tmp_recreate_master_l2_table_array[1].extend([str(ns_def.split_portname(tmp_recreate_master_l2_table_array[1][3])[0])])
new_master_l2_table_array.append(tmp_recreate_master_l2_table_array[1])
for tmp_original_master_l2_table_array in original_master_l2_table_array:
if tmp_original_master_l2_table_array[1][3] == '':
tmp_original_master_l2_table_array[1].append(0)
tmp_original_master_l2_table_array[1].append('')
new_master_l2_table_array.append( tmp_original_master_l2_table_array[1])
new_master_l2_table_array = sorted(new_master_l2_table_array , reverse=False, key=lambda x: (x[0], x[1], x[9], x[8], x[5], x[7], x[6])) # sort l2 table
last_l2_table_array = []
last_l2_table_array.append([1, ['<<L2_TABLE>>']])
last_l2_table_array.append([2, ['Area', 'Device Name', 'Port Mode', 'Port Name', 'Virtual Port Mode', 'Virtual Port Name', 'Connected L2 Segment Name(Comma Separated)', 'L2 Name directly received by L3 Virtual Port (Comma Separated)']])
for index_l2_num, tmp_new_master_l2_table_array in enumerate(new_master_l2_table_array):
del tmp_new_master_l2_table_array[-2:]
last_l2_table_array.append([index_l2_num + 3 ,tmp_new_master_l2_table_array])
#print([index_l2_num + 3 ,tmp_new_master_l2_table_array])
### Re-Write L2 sheet
last_master_l2_table_tuple = ns_def.convert_array_to_tuple(last_l2_table_array )
tmp_ws_name = ws_l2_name
ppt_meta_file = excel_maseter_file
clear_section_taple = last_master_l2_table_tuple
ns_def.clear_section_sheet(tmp_ws_name, ppt_meta_file, clear_section_taple)
master_excel_meta = last_master_l2_table_tuple
excel_file_path = excel_maseter_file
worksheet_name = ws_l2_name
section_write_to = '<<L2_TABLE>>'
offset_row = 0
offset_column = 0
ns_def.overwrite_excel_meta(master_excel_meta, excel_file_path, worksheet_name, section_write_to,offset_row, offset_column)
'''
sync with Mater sheet L3
'''
### Master sheet L3 re create from L1L2 sheet
ns_def.remove_excel_sheet(excel_maseter_file, ws_l3_name)
### run L3-1-2 in network_sketcher_dev , add l3 master sheet
self.click_value = 'L3-1-2'
self.inFileTxt_L3_1_1.delete(0, tkinter.END)
self.inFileTxt_L3_1_1.insert(tk.END, excel_maseter_file)
network_sketcher_dev.ns_front_run.click_action(self, 'L3-1-2')
### get re-created Master sheet L2/L3
recreate_master_l3_table_array = ns_def.convert_master_to_array(ws_l3_name, excel_maseter_file, '<<L3_TABLE>>')
del recreate_master_l3_table_array[:2]
for index_l3,tmp_recreate_master_l3_table_array in enumerate(recreate_master_l3_table_array):
tmp_recreate_master_l3_table_array[1].extend(['','','','','','','',''])
del tmp_recreate_master_l3_table_array[1][5:]
recreate_master_l3_table_array[index_l3] = tmp_recreate_master_l3_table_array
#print(recreate_master_l3_table_array)
### Update Master sheet L3
new_master_l3_table_array = []
for tmp_recreate_master_l3_table_array in recreate_master_l3_table_array:
flag_match_line_l3 = False
for tmp_original_master_l3_table_array in original_master_l3_table_array:
if tmp_original_master_l3_table_array[1][0] == tmp_recreate_master_l3_table_array[1][0] and tmp_original_master_l3_table_array[1][1] == tmp_recreate_master_l3_table_array[1][1] and tmp_original_master_l3_table_array[1][2] == tmp_recreate_master_l3_table_array[1][2]:
tmp_original_master_l3_table_array[1].append(ns_def.get_if_value(tmp_original_master_l3_table_array[1][2]))
tmp_original_master_l3_table_array[1].extend([str(ns_def.split_portname(tmp_original_master_l3_table_array[1][2])[0])])
new_master_l3_table_array.append(tmp_original_master_l3_table_array[1])
flag_match_line_l3 = True
break
if flag_match_line_l3 == False:
tmp_recreate_master_l3_table_array[1].append(ns_def.get_if_value(tmp_recreate_master_l3_table_array[1][2]))
tmp_recreate_master_l3_table_array[1].extend([str(ns_def.split_portname(tmp_recreate_master_l3_table_array[1][2])[0])])
new_master_l3_table_array.append(tmp_recreate_master_l3_table_array[1])
new_master_l3_table_array = sorted(new_master_l3_table_array, reverse=False, key=lambda x: (x[0], x[1], x[3], x[6], x[5], x[4])) # sort l3 table
last_l3_table_array = []
last_l3_table_array.append([1, ['<<L3_TABLE>>']])
last_l3_table_array.append([2, ['Area', 'Device Name', 'L3 IF Name','L3 Instance Name', 'IP Address / Subnet mask (Comma Separated)']])
for index_l3_num, tmp_new_master_l3_table_array in enumerate(new_master_l3_table_array):
del tmp_new_master_l3_table_array[-2:]
last_l3_table_array.append([index_l3_num + 3, tmp_new_master_l3_table_array])
#print([index_l3_num + 2 ,tmp_new_master_l3_table_array])
### Re-Write L3 sheet
last_master_l3_table_tuple = ns_def.convert_array_to_tuple(last_l3_table_array)
tmp_ws_name = ws_l3_name
ppt_meta_file = excel_maseter_file
clear_section_taple = last_master_l3_table_tuple
ns_def.clear_section_sheet(tmp_ws_name, ppt_meta_file, clear_section_taple)
master_excel_meta = last_master_l3_table_tuple
excel_file_path = excel_maseter_file
worksheet_name = ws_l3_name
section_write_to = '<<L3_TABLE>>'
offset_row = 0
offset_column = 0
ns_def.overwrite_excel_meta(master_excel_meta, excel_file_path, worksheet_name, section_write_to, offset_row, offset_column)
# remove exist L3/ file
if os.path.isfile(self.inFileTxt_L2_1_1.get().replace('[MASTER]', '[L3_TABLE]')) == True:
os.remove(self.inFileTxt_L2_1_1.get().replace('[MASTER]', '[L3_TABLE]'))