-
Notifications
You must be signed in to change notification settings - Fork 0
/
nlead_package.py
9071 lines (8407 loc) · 449 KB
/
nlead_package.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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import absolute_import
import re
import codecs
import csv
import os
from math import ceil
import collections
from django.conf import settings
from django.db.models import Q
if not settings.configured:
settings.configure('mysite', DEBUG=True)
from mysite.nlead_library.ent_com import *
from mysite.nlead_library.aci_api_functions import *
from mysite.nlead_library.service_now import *
TS_LEVEL = 0
# print TS_LEVEL
# global preso_variable_output
# global glb_multi_inputs
global glb_tech_options
global glb_template_dir
global glb_plat_specific_tech
global tech_with_vrf
global customer_type
# vendor customer (with multicast customers and partners, more detail/platform troubleshootin
vendor_customers = ['cisco']
# partners (with multiple customers, configuration is more important)
partner_customers = ['eplus', 'groupware']
# enterprise customers (default)
enterprise_customers = ['stanford']
# Alpa customers (evaluation/testing)
evaluating_customer = ['stanford']
customer_type = 'cisco'
tech_with_vrf = ['mvpn', 'l3vpn']
preso_variable_output = {}
glb_tech_options = {'ipversion': ['dhcp', 'mcast', 'bgp', 'ospf', 'isis']}
glb_template_dir = "./mysite/user_templates"
# glb_template_dir = "/home/ubuntu/prepro/mysite/mysite/user_templates"
# glb_template_dir = "/home/netserv/Webapp/Netserv/mysite/user_templates"
glb_plat_specific_tech = ['vxlan']
# import datetime
# import json
try:
from mysite.models import combimatin_db
from mysite.models import template_db
from mysite.models import InputValueDb
from mysite.models import UserInputValueDb, SwitchMigrationDB
from mysite.models import Training
from mysite.models import SetupParameters
from mysite.models import ACIInterfaceStatusDB
except ValueError:
print "Need to figure it out"
# settings.configure()
# from mysite.models import combimatin_db
global glb_nx9k_nonsupported
class NleadData():
'''
Description :
This function is used to get IoS list and get platform of IoS
Inputs :
ios
Output:
Return the output based on function call
'''
def __init__(self, ios=''):
''' ios, platform, tech and type combination.
users:c1_checked
input:
output:
'''
demo_flag = False
if demo_flag:
key_plat = []
covered_plat = []
non_nx = []
xr_plat = []
glb_nx9k_nonsupported = ['MPLS', 'L2FWD', 'L3VPN', 'OTV']
self.all_combinations = {1: {'tech': 'IPv4', 'type': ['fwd', 'flap'], 'ios': 'any', 'plat': ['any'],
'area': 'Core Technologies'}}
any_plat = ['Any_Platform']
self.ios_list = ['Any_IOS', 'ASA', 'XR-IOS']
self.xr_plat_list = ['ASR9000']
self.nx_plat_list = []
self.os_plat_list = []
self.eos_plat_list = []
self.asa_plat_list = ['Any ASA Platform', '5505', '5585']
self.nos_plat_list = []
sp_plat_list = ['ASR9000', 'C6500', 'CRS', 'ASR1000']
else:
key_plat = ['NX7000', 'ASR9000', 'C6800', 'C6500', 'CRS', 'C4500', 'C3750']
covered_plat = ['NX7000', 'ASR9000', 'C6800', 'C6500', 'CRS', 'ASR1000', 'C4500', 'C3750']
tac_isp_plat = ['ASR9000', 'C6800', 'C6500', 'CRS', 'ASR1000', 'C4500', 'C3750']
non_nx = ['ASR9000', 'C6500', 'CRS', 'ASR1000']
xr_plat = ['ASR9000', 'CRS']
self.junos_plat = ['EX Series', 'QFX Series', 'ACX Series', 'MX Series']
# junos_rtr_plat = ['ACX Series', 'MX Series']
# junos_sw_plat = ['EX Series', 'QFX Series']
sp_plat_list = ['ASR9000', 'C6800', 'C6500', 'CRS', 'ASR1000', 'C4500', 'C3750']
self.fw_plat_list = ['ASA5500-X', 'ASA5585-X', 'Any ASA Platform']
glb_nx9k_nonsupported = ['MPLS', 'L2FWD', 'L3VPN', 'OTV']
nx_plat_list = ['NX9300', 'NX9500', 'NX7000', 'NX5000', 'NX3000', 'Any_NX_Platform']
self.all_combinations = {
1: {'tech': 'IPv4', 'type': ['eastwest', 'fwd', 'con', 'loss', 'latency'], 'ios': 'any',
'plat': ['any'], 'area': 'Core Technologies'},
2: {'tech': 'VXLAN (BGP-EVPN)', 'type': [], 'ios': 'any',
'plat': ['NX9300', 'ASR1000', 'CSR', 'ASR9000', 'ARISTA', 'VDX'], 'area': 'Data Center'},
# 3: {'tech': 'FabricPath', 'type': ['fwd'], 'ios': 'any', 'plat': ['NX5000', 'NX7000', 'NX6000'],'area':'Data Center'},
29: {'tech': 'MPLS', 'type': ['fwd'], 'ios': 'any', 'plat': covered_plat, 'area': 'Service Provider'},
# 4: {'tech': 'PWHE', 'type': ['fwd'], 'ios': 'XR-IOS', 'plat': xr_plat,'area':'Service Providers'},
5: {'tech': 'Multicast', 'type': ['fwd'], 'ios': 'any', 'plat': ['any'], 'area': 'Core Technologies'},
# 6: {'tech': 'IPv6 6VPE', 'type': ['ifwd', 'dfwd', 'fwd'], 'ios': 'any', 'plat': non_nx,'area':'Service Providers'},
8: {'tech': 'VPLS', 'type': ['ifwd', 'dfwd', 'fwd'], 'ios': 'any', 'plat': key_plat,
'area': 'Service Provider'},
9: {'tech': 'Layer-2 VPN', 'type': ['ifwd', 'dfwd', 'fwd'], 'ios': 'any', 'plat': 'any',
'area': 'Service Provider'},
10: {'tech': 'MPLS TE', 'type': ['fwd'], 'ios': 'any', 'plat': covered_plat,
'area': 'Service Provider'},
# 11: {'tech': 'IPv6 Neighbor Discovery', 'type': ['fwd'], 'ios': 'any', 'plat': ['any'],'area':'Core Technologies'},
# 12: {'tech': 'Layer3 QOS', 'type': ['fwd'], 'ios': 'any', 'plat': key_plat,'area':'Core Technologies'},
13: {'tech': 'IPv6', 'type': ['fwd'], 'ios': 'any', 'plat': ['any'], 'area': 'Core Technologies'},
14: {'tech': 'HealthCheck', 'type': ['Overall Health-Check'], 'ios': 'any',
'plat': ['NX9300', 'NX9500'], 'area': 'Others'},
15: {'tech': 'High CPU', 'type': ['High CPU'], 'ios': 'any',
'plat': covered_plat + ['NX9300', 'NX9500'], 'area': 'Others'},
16: {'tech': 'MPLS LDP', 'type': ['fwd'], 'ios': 'any', 'plat': covered_plat,
'area': 'Service Providers'},
17: {'tech': 'BFD', 'type': ['down', 'flap', 'cfg'], 'ios': 'any', 'plat': ['any'],
'area': 'Core Technologies'},
18: {'tech': 'MP-BGP', 'type': ['down', 'flap', 'receive', 'send', 'install'], 'ios': 'any',
'plat': ['any'], 'area': 'Core Technologies'},
19: {'tech': 'OSPF/OSPFv3', 'type': ['down', 'flap', 'missing', 'wrong', 'install', 'cfg'],
'ios': 'any', 'plat': ['any'], 'area': 'Core Technologies'},
20: {'tech': 'ISIS', 'type': ['down', 'flap', 'receive', 'send', 'install', 'cfg'], 'ios': 'any',
'plat': non_nx, 'area': 'Core Technologies'},
21: {'tech': 'DHCP/DHCPV6', 'type': ['proxy', 'relay', 'snoop'], 'ios': 'XR-IOS', 'plat': xr_plat,
'area': 'Core Technologies'},
# 22: {'tech': 'Quality of Service (QoS)', 'type': ['fwd'], 'ios': 'any', 'plat': sp_plat_list,'area':'Core Technologies'},
# 22: {'tech': 'IPv6 6PE', 'type': ['fwd'], 'ios': 'any', 'plat': sp_plat_list,'area':'Service Providers'},
23: {'tech': 'Layer2 Multicast (IGMP)', 'type': ['fwd'], 'ios': 'any',
'plat': key_plat + ['NX9300', 'NX9500', 'NX5000'], 'area': 'Core Technologies'},
24: {'tech': 'MVPN', 'type': ['fwd'], 'ios': 'any', 'plat': tac_isp_plat, 'area': 'Service Providers'},
25: {'tech': 'Layer2 Forwarding', 'type': ['fwd'], 'ios': 'any',
'plat': key_plat + ['NX9300', 'NX9500', 'NX5000'], 'area': 'Core Technologies'},
26: {'tech': 'OTV', 'type': ['ifwd', 'dfwd', 'fwd'], 'ios': 'any',
'plat': ['NX7000', 'ASR1000'], 'area': 'Data Center'},
27: {'tech': 'ACL', 'type': [], 'ios': 'Firewalls', 'plat': self.fw_plat_list, 'area': 'Security'},
28: {'tech': 'Network Address Translation (NAT)', 'type': [], 'ios': 'Firewalls',
'plat': self.fw_plat_list, 'area': 'Security'},
30: {'tech': 'VPN', 'type': [], 'ios': 'Firewalls', 'plat': self.fw_plat_list, 'area': 'Security'},
31: {'tech': 'L3VPN', 'type': ['ifwd', 'dfwd', 'fwd'], 'ios': 'any', 'plat': tac_isp_plat,
'area': 'Service Providers'},
32: {'tech': 'ACL', 'type': [], 'ios': 'IOS', 'plat': ['ASR1000'], 'area': 'Security'},
33: {'tech': 'Firewall', 'type': [], 'ios': 'IOS', 'plat': ['ASR1000'], 'area': 'Security'},
34: {'tech': 'VPN', 'type': [], 'ios': 'IOS', 'plat': ['ASR1000'], 'area': 'Security'},
35: {'tech': 'VPN', 'type': [], 'ios': 'SD-WAN', 'plat': ['VCE'], 'area': 'SD-WAN'},
36: {'tech': 'VPN', 'type': ['sdown'], 'ios': 'Enterprise-1', 'plat': ['any'], 'area': 'Services'},
37: {'tech': 'Segment Routing', 'type': [''], 'ios': 'any',
'plat': ['Any_NX_Platform'] + ['NX7000', 'NX3000', 'NX5000', 'NX6000', 'NX9300'],
'area': 'Data Center'},
# 38: {'tech': 'Virtual PortChannel (vPC)', 'type': [''], 'ios': 'any',
# 'plat': ['Any_NX_Platform'] + ['NX7000', 'NX5000', 'NX6000', 'NX9300'],
# 'area':'Data Center'},
39: {'tech': 'Fabric Extender', 'type': [''], 'ios': 'any',
'plat': ['Any_NX_Platform'] + ['NX7000', 'NX5000', 'NX6000', 'NX9300'],
'area': 'Data Center'},
40: {'tech': 'Intelligent Traffic Director (ITD)', 'type': [''], 'ios': 'any',
'plat': ['Any_NX_Platform'] + ['NX7000', 'NX3000', 'NX5000', 'NX6000', 'NX9300'],
'area': 'Data Center'},
41: {'tech': 'Load Balancer', 'type': [''], 'ios': 'F5',
'plat': ['BIG-IP 12000, BIG-IP 10000, BIG-IP 7000'],
'area': 'Layer4-7 Services'},
42: {'tech': 'Firewall', 'type': [''], 'ios': 'CP',
'plat': ['CP5600', 'CP5800'],
'area': 'Security'},
43: {'tech': 'IPv4', 'type': [''], 'ios': 'Linux',
'plat': ['Linux', 'MAC'],
'area': 'Wireless'},
43: {'tech': 'IPv4', 'type': [''], 'ios': 'Windows',
'plat': ['Server', 'Desktop'],
'area': 'Wireless'},
44: {'tech': 'Cisco', 'type': [''], 'ios': 'Cisco WLC',
'plat': ['C8540', 'C5520'],
'area': 'Wireless'}
}
any_plat = ['Any_Platform']
self.ios_list = ['IOS', 'NX-IOS', 'XR-IOS', 'ASA Firewall', 'F5', 'EOS', 'NOS', 'Linux', 'Windows',
'Multiple Devices',
'Enterprise-1']
# self.ios_list = ['Any_IOS','NX-IOS', 'IOS', 'XR-IOS', 'ASA Firewall', 'EOS', 'NOS', 'Enterprise-1']
# self.xr_plat_list = ['ASR9000', 'CRS', '12000-XR', 'Any_XR_Platform']
self.xr_plat_list = ['ASR9000', 'CRS', '12000-XR', 'Any XR Platform']
self.nx_plat_list = ['NX9500', 'NX9300', 'NX7000', 'NX5000', 'NX3000', 'Any NX Platform']
# self.nx_plat_list = ['NX7000', 'NX3000', 'NX5000', 'NX6000', 'NX9300', 'Any_NX_Platform']
self.os_plat_list = ['ASR1000', 'C6800', 'C6500', 'C7600', 'C3750 C3850', 'C4500', 'C3900 C2900',
'C3800 C2800', 'Any IOS Platform']
self.F5_plat_list = ['BIG-IP 12000', 'BIG-IP 10000', 'BIG-IP 7000']
self.Linux_plat_list = ['Linux', 'MAC']
self.Windows_plat_list = ['Server', 'Desktop']
self.CP_plat_list = ['CP5600', 'CP5800']
self.CWLC_plat_list = ['C8540', 'C5520']
self.CWLC_plat_list = ['C8540', 'C5520']
self.eos_plat_list = ['ARISTA']
self.sdwan_plat_list = ['VCE']
self.enterprise_plat_list = ['Any_Platform']
self.nos_plat_list = ['VDX']
self.all_plat_list = any_plat + self.nx_plat_list + self.xr_plat_list + self.os_plat_list \
+ self.eos_plat_list + self.nos_plat_list + self.Windows_plat_list + self.Linux_plat_list
def getIosList(self):
'''
Description:
Function used to declare ios data and get that data into list
Inputs:
ios
Output:
Return IoS list
'''
# self.ios_list = {"meta": {"label": "", "default": ""}, "sections":
# [{"name": "Campus", "options": [
# {"label": "Patching Matrix", "value": "Patching Matrix"},
# ]}]}
self.ios_list = {"meta": {"label": "", "default": ""}, "sections":
[{"name": "Router and Switches", "options": [
{"label": "NX IOS", "value": "NX-IOS"},
{"label": "IOS", "value": "IOS"},
{"label": "XR IOS", "value": "XR-IOS"},
{"label": "JUNOS", "value": "JUNOS"},
{"label": "Arista EOS", "value": "EOS"},
{"label": "Brocade EOS", "value": "NOS"},
{"label": "ACI", "value": "ACI"},
{"label": "Fabric Configuration", "value": "fabric configuration"}
]},
{"name": "Other Network Devices", "options": [
{"label": "ASA Firewall", "value": "ASA Firewall"},
{"label": "Check Point Firewall", "value": "CP"},
{"label": "F5 Load Balancer", "value": "F5"},
{"label": "Cisco Wireless", "value": "Cisco WLC"}]},
# {"label": "Any IOS", "value": "Any_IOS"}]},
# {"name": "Server and Desktop",
# "options": [{"label": "Linux", "value": "Linux"},
# {"label": "Windows", "value": "Windows"}]},
# {"name": "Multiple Devices",
# "options": [{"label": "Multiple Devices Config", "value": "Multiple_Devices"}]},
{"name": "Network Config and T/S",
"options": [{"label": "Enterprise Network T/S", "value": "Enterprise-1"},
{"label": "Deployment", "value": "Deployment"},
{"label": "Fabric Configuration", "value": "fabric configuration"},
{"label": 'Enterprise Firewalls',
"value": "Enterprise_Firewalls"},
{"label": "Multiple Devices Config", "value": "Multiple_Devices"}
]}]}
return self.ios_list
def getAllPlatfromList(self):
return self.all_plat_list
def getAllTechList(self):
return self.all_tech_list
def getPlatfromList(self, usr_ios):
self.plat_list = []
print '+ usr_ios +'
print usr_ios
if usr_ios == 'XR-IOS':
self.plat_list = self.xr_plat_list
# self.plat_list = ['ASR9000', 'CRS', '12000-XR', 'Any XR Platform']
elif usr_ios == 'NX-IOS':
self.plat_list = self.nx_plat_list
# self.plat_list = ['NX7000', 'NX3000', 'NX5000', 'NX6000', 'NX9300', 'Any NX Platform']
elif usr_ios == 'IOS':
self.plat_list = self.os_plat_list
elif usr_ios == 'Firewalls' or usr_ios == 'ASA Firewall':
self.plat_list = self.fw_plat_list
elif usr_ios == 'SD-WAN':
self.plat_list = self.sdwan_plat_list
elif usr_ios == 'Enterprise-1':
self.plat_list = self.enterprise_plat_list
elif usr_ios == 'EOS':
self.plat_list = self.eos_plat_list
elif usr_ios == 'NOS':
self.plat_list = self.nos_plat_list
elif usr_ios == 'Linux':
self.plat_list = self.Linux_plat_list
elif usr_ios == 'Windows':
self.plat_list = self.Windows_plat_list
elif usr_ios == 'F5':
self.plat_list = self.F5_plat_list
elif usr_ios == 'CP':
self.plat_list = self.CP_plat_list
elif usr_ios == 'JUNOS':
self.plat_list = self.junos_plat
elif usr_ios == 'ACI':
self.plat_list = ['na']
elif usr_ios == 'Cisco WLC':
self.plat_list = self.CWLC_plat_list
elif usr_ios == 'Multiple_Devices' or usr_ios == 'Multiple Devices':
self.plat_list = ['na']
elif usr_ios == 'Enterprise_Firewalls' or usr_ios == 'Enterprise Firewalls':
self.plat_list = ['na']
elif usr_ios == 'fabric_configuration' or usr_ios == 'Fabric Configuration':
self.plat_list = ["East-DC", "West-DC"]
elif usr_ios == 'Any_IOS':
self.plat_list = self.all_plat_list
# else:
# return -1
return self.plat_list
def getTechList(self, user_ios, user_plat):
self.tech_list = []
for id in self.all_combinations.keys():
if self.all_combinations[id]['ios'] == user_ios or self.all_combinations[id][
'ios'] == 'any' or user_ios == 'Any_IOS' or user_ios == 'Multiple_Devices':
if user_plat:
if self.all_combinations[id]['plat'].__contains__(user_plat) or \
self.all_combinations[id]['plat'].__contains__('any') \
or user_plat == 'Any_Platform' or user_ios == 'Multiple_Devices':
if not self.tech_list.__contains__(self.all_combinations[id]['tech']):
self.tech_list.append(self.all_combinations[id]['tech'])
else:
if not self.tech_list.__contains__(self.all_combinations[id]['tech']):
self.tech_list.append(self.all_combinations[id]['tech'])
return self.tech_list
def getTechSectionDict(self, user_ios, user_plat):
self.tech_list = []
tech_list_sp = []
tech_list_dc = []
tech_list_core = []
tech_list_sec = []
tech_list_services = []
tech_list_other = []
self.tech_dct = {}
for id in self.all_combinations.keys():
if self.all_combinations[id]['ios'] == user_ios or self.all_combinations[id][
'ios'] == 'any' or user_ios == 'Any_IOS':
if self.all_combinations[id]['ios'] == 'any' and user_ios == 'SD-WAN':
continue
elif self.all_combinations[id]['ios'] == user_plat:
if self.all_combinations[id].has_key('area'):
if self.all_combinations[id].get('area') == "Data Center":
if not tech_list_dc.__contains__(self.all_combinations[id]['tech']):
tech_list_dc.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Service Providers":
if not tech_list_sp.__contains__(self.all_combinations[id]['tech']):
tech_list_sp.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Core Technologies":
if not tech_list_core.__contains__(self.all_combinations[id]['tech']):
tech_list_core.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Security":
if not tech_list_sec.__contains__(self.all_combinations[id]['tech']):
tech_list_sec.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "SD-WAN":
if not tech_list_sec.__contains__(self.all_combinations[id]['tech']):
tech_list_sec.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Services":
if not tech_list_services.__contains__(self.all_combinations[id]['tech']):
tech_list_services.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Others":
if not tech_list_other.__contains__(self.all_combinations[id]['tech']):
tech_list_other.append(self.all_combinations[id]['tech'])
else:
if user_plat:
if self.all_combinations[id]['plat'].__contains__(user_plat) or self.all_combinations[id][
'plat'].__contains__('any') or user_plat == 'Any_Platform':
if self.all_combinations[id].has_key('area'):
if self.all_combinations[id].get('area') == "Data Center":
if not tech_list_dc.__contains__(self.all_combinations[id]['tech']):
tech_list_dc.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Service Providers":
if not tech_list_sp.__contains__(self.all_combinations[id]['tech']):
tech_list_sp.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Core Technologies":
if not tech_list_core.__contains__(self.all_combinations[id]['tech']):
tech_list_core.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Security":
if not tech_list_sec.__contains__(self.all_combinations[id]['tech']):
tech_list_sec.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "SD-WAN":
if not tech_list_sec.__contains__(self.all_combinations[id]['tech']):
tech_list_sec.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Services":
if not tech_list_services.__contains__(self.all_combinations[id]['tech']):
tech_list_services.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Others":
if not tech_list_other.__contains__(self.all_combinations[id]['tech']):
tech_list_other.append(self.all_combinations[id]['tech'])
else:
if not self.tech_list.__contains__(self.all_combinations[id]['tech']):
if self.all_combinations[id].has_key('area'):
if self.all_combinations[id].get('area') == "Data Center":
if not tech_list_dc.__contains__(self.all_combinations[id]['tech']):
tech_list_dc.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Service Providers":
if not tech_list_sp.__contains__(self.all_combinations[id]['tech']):
tech_list_sp.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Core Technologies":
if not tech_list_core.__contains__(self.all_combinations[id]['tech']):
tech_list_core.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Security":
if not tech_list_sec.__contains__(self.all_combinations[id]['tech']):
tech_list_sec.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "SD-WAN":
if not tech_list_sec.__contains__(self.all_combinations[id]['tech']):
tech_list_sec.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Services":
if not tech_list_services.__contains__(self.all_combinations[id]['tech']):
tech_list_services.append(self.all_combinations[id]['tech'])
elif self.all_combinations[id].get('area') == "Others":
if not tech_list_other.__contains__(self.all_combinations[id]['tech']):
tech_list_other.append(self.all_combinations[id]['tech'])
# only if not empty
if tech_list_dc:
self.tech_dct['Data Center'] = tech_list_dc
if tech_list_sp:
self.tech_dct['Service Providers'] = tech_list_sp
if tech_list_core:
self.tech_dct['Core Technologies'] = tech_list_core
if tech_list_sec:
self.tech_dct['Security'] = tech_list_sec
if tech_list_services:
self.tech_dct['Services'] = tech_list_services
if tech_list_other:
self.tech_dct['Others'] = tech_list_other
return self.tech_dct
def getTypeList(self, user_ios, user_plat, user_tech):
print 'user_tech'
print user_tech
self.type_list = []
for id in self.all_combinations.keys():
if self.all_combinations[id]['ios'] == user_ios or self.all_combinations[id]['ios'].__contains__(
'any') or user_ios == 'Any_IOS':
if self.all_combinations[id]['tech'] == user_tech:
for ty in self.all_combinations[id]['type']:
type_el = ConvertDbToUser('type', ty)
if type_el:
self.type_list.append(type_el)
# ConvertUeseInputs
# self.type_list = self.all_combinations[id]['type']
self.type_list.append('Add New Template')
self.type_list.append('Delete Existing Template')
self.type_list.append('Modify Existing Template')
return self.type_list
# user_dict['link_section'] = {"label": "Recommended Training",
# "options": [{"ABC": "http://google.com"},
# {"XYZ": "http://facebook.com"}]}
#
# sym_list = {"meta": {"label": "", "default": "", "na": ""},
# "sections": [{"name": "Configuration", "options":
# [{"label": "Firewall Rules with New Object Groups", "value": "New Object Groups"},
# {"label": "Firewall Rules with Existing Object Groups",
# "value": "Existing Object Groups"},
# ]}]}
def getTypeAndTpDictOld(self, user_ios, user_plat, user_tech, template_list=[], training_dict={}):
self.type_and_tp = {}
type_list = []
training_list = []
if user_tech == 'L2FWD':
user_tech = 'Layer2 Forwarding'
elif user_tech == 'MCAST':
user_tech = 'Multicast'
elif user_tech == 'L2MCAST':
user_tech = 'Layer2 Multicast (IGMP)'
elif user_tech == 'VXLAN':
user_tech = 'VXLAN (BGP-EVPN)'
for id in self.all_combinations.keys():
if self.all_combinations[id]['ios'] == user_ios or self.all_combinations[id]['ios'].__contains__(
'any') or user_ios == 'Any_IOS':
if self.all_combinations[id]['tech'] == user_tech:
for ty in self.all_combinations[id]['type']:
type_el = ConvertDbToUser('type', ty)
if type_el:
type_list.append(type_el)
type_list.append('Problem Solving')
if training_dict:
for training_name in training_dict:
training_info = {}
training_info[training_name] = training_dict.get(training_name)
training_list.append(training_info)
# self.type_and_tp["Recommended Training"]=training_dict
self.type_and_tp["link_section"] = {"label": "Recommended Training", "options": training_list}
for template_name in template_list:
if not template_name.find('Troubleshooting') == -1:
type_list.append(template_name)
template_list.remove(template_name)
self.type_and_tp["Troubleshooting"] = type_list
if template_list:
# self.type_and_tp["User Options"]=['Add New Template', 'Modify Existing Template', 'Delete Existing Template', 'Fork Existing Template']
self.type_and_tp["User Options"] = ['Add New Template', 'Delete Existing Template']
self.type_and_tp["Configurations"] = template_list
else:
self.type_and_tp["User Options"] = ['Add New Template']
return self.type_and_tp
def getTypeAndTpDict(self, user_ios, user_plat, user_tech, template_list=[], training_dict={}):
'''
Description :
Function used to creating options for troubleshooting.
Inputs :
user_ios, user_plat, user_tech, templat list, training_dict
Output :
Loads inputs for troubleshooting.
:param user_ios:
:param user_plat:
:param user_tech:
:param template_list:
:param training_dict:
:return:
'''
self.type_and_tp = {}
type_list = []
training_list = []
all_data_list = []
all_data = {}
to_return = {}
template_dict_1 = {}
template_list_1 = []
if template_list:
# self.type_and_tp["User Options"]=['Add New Template', 'Modify Existing Template', 'Delete Existing Template', 'Fork Existing Template']
# all_data['name'] = 'User Options'
# all_data['options'] = [{"label": "Add New Template","value":"Add New Template"}]
for template_name in template_list:
template_dict_1["label"] = template_name
template_dict_1["value"] = template_name
template_list_1.append(template_dict_1.copy())
all_data['name'] = 'Configurations'
all_data['options'] = template_list_1
all_data_list.append(all_data.copy())
# self.type_and_tp["User Options"]=['Add New Template']
# self.type_and_tp["Configurations"]=template_list
self.type_and_tp["User Options"] = ['Add New Template', 'Delete Existing Template']
all_data['name'] = 'User Options'
all_data['options'] = [{"label": "Add New Template", "value": "Add New Template"},
{"label": "Delete Existing Template", "value": "Delete Existing Template"},
{"label": "Modify Existing Template", "value": "Modify Existing Template"}]
all_data_list.append(all_data.copy())
troubleshooting_dict = {}
troubleshooting_list = []
for id in self.all_combinations.keys():
if self.all_combinations[id]['ios'] == user_ios or self.all_combinations[id]['ios'].__contains__(
'any') or user_ios == 'Any_IOS':
if self.all_combinations[id]['tech'] == user_tech:
for ty in self.all_combinations[id]['type']:
type_el = ConvertDbToUser('type', ty)
if type_el:
print 'type_el'
print type_el
troubleshooting_dict['label'] = type_el
troubleshooting_dict['value'] = type_el
print 'troubleshooting_dict'
print troubleshooting_dict
troubleshooting_list.append(troubleshooting_dict.copy())
print troubleshooting_list
# type_list.append('Problem Solving')
# #self.type_and_tp["Recommended Training"]=training_dict
# self.type_and_tp["link_section"]={"label": "Recommended Training","options": training_list}
# troubleshooting_dict = {}
# troubleshooting_list = []
for template_name in template_list:
if not template_name.find('Troubleshooting') == -1:
type_list.append(template_name)
troubleshooting_dict['label'] = template_name
troubleshooting_dict['value'] = template_name
troubleshooting_list.append(troubleshooting_dict.copy())
template_list.remove(template_name)
print troubleshooting_list
all_data['name'] = 'Troubleshooting'
all_data['options'] = troubleshooting_list
all_data_list.append(all_data.copy())
# self.type_and_tp["Troubleshooting"]=type_list
training_dict_1 = {}
training_list_1 = []
print 'training_dict'
print training_dict
if training_dict:
for training_name in training_dict:
# for k,v in training_dict.iterateitems():
training_info = {}
training_info[training_name] = training_dict.get(training_name)
training_list.append(training_info)
training_dict_1['label'] = training_name
training_dict_1['value'] = training_dict.get(training_name)
training_list_1.append(training_dict_1.copy())
all_data['name'] = 'Recommended Training'
all_data['options'] = training_list_1
all_data_list.append(all_data.copy())
to_return["meta"] = {"label": "", "default": "", "na": ""}
to_return["sections"] = all_data_list
print all_data_list
return to_return
def format_filter_script_output(output, user_sel={}):
global TS_LEVEL
global preso_variable_output
# global glb_input_list_for_script
new_output = []
# NEED TO REMOVE AFTER FIXING THE Recovery PART!!
if user_sel.get('user_role'):
user_role = user_sel.get('user_role')
else:
user_role = ''
plat = user_sel.get('plat')
tech = user_sel.get('tech')
for line in output:
skip_flag = False
line = re.sub('<in_lc>', '<ingress_linecard_num>', line)
line = re.sub('<ou_lc>', '<egress_linecard_num>', line)
line = re.sub('<out_lc>', '<egress_linecard_num>', line)
# Need to add for escalation
if not user_role == 'esc':
if plat == '7000' and tech == 'mcast':
if re.search('hardware internal', line):
continue
if re.search('Following are the links', line):
continue
if re.search('^\{##', line):
continue
if re.search('##', line):
continue
if re.search('End STR', line) or re.search('Non Imp', line):
# line = ' !<-- Additional Data -->!'
continue
#
if re.search('End of STR|www-tac|wwwin|cisco\.com|Recovery !!', line):
skip_flag = True
if re.search('For more information refer following link|Mailers:|EDCS', line):
skip_flag = True
if not re.search('!<-- ', line):
line = re.sub('^!+', '-', line)
else:
line = re.sub('!<-- ', '<span style="color:rgb(237, 125, 49);">!<-- ', line)
line = re.sub(' -->!', ' -->! </span>', line)
if get_key_value(preso_variable_output, 'in_int', 'output'):
line = re.sub('in_int', get_key_value(preso_variable_output, 'in_int', 'output'), line)
if get_key_value(preso_variable_output, 'ou_int', 'output'):
line = re.sub('out_int', get_key_value(preso_variable_output, 'ou_int', 'output'), line)
if get_key_value(preso_variable_output, 'out_int', 'output'):
line = re.sub('out_int', get_key_value(preso_variable_output, 'out_int', 'output'), line)
if get_key_value(preso_variable_output, 'des_ip', 'output'):
line = re.sub('des_ip', get_key_value(preso_variable_output, 'des_ip', 'output'), line)
if get_key_value(preso_variable_output, 'des_net', 'output'):
line = re.sub('des_net', get_key_value(preso_variable_output, 'des_net', 'output'), line)
if get_key_value(preso_variable_output, 'dst_ml', 'output'):
line = re.sub('dst_ml', get_key_value(preso_variable_output, 'dst_ml', 'output'), line)
if not skip_flag:
new_output.append(line)
return new_output
def get_key_value(my_dict, item1, item2=False):
value = ""
result = ""
try:
if my_dict.get(item1):
value = my_dict.get(item1)
if item2:
if type(value) is dict:
if value.get(item2):
value = value.get(item2)
else:
return result
else:
return result
except Exception as err:
raise err
return value
class ConvertUserToDbVar:
'''
Description :
This class used to convert user to database var.
Inputs :
user_ios, user_plat, user_tech, user_type, template_name
Output :
Return the output based on function call
'''
def __init__(self, user_ios, user_plat, user_tech, user_type, template_name=''):
'''
Get the parameters for DB and TCL
Get template list
Get Problem type list
:param user_ios:
:param user_plat:
:param user_tech:
:param user_type:
:return: dictionary
'''
self.type = '';
self.plat = '';
self.ios = '';
self.type = ''
self.ios = ConvertUeseInputs('ios', user_ios)
self.tech = ConvertUeseInputs('tech', user_tech)
self.plat = ConvertUeseInputs('plat', user_plat)
if user_type:
self.type = ConvertUeseInputs('ios', user_type)
self.db_inputs = {'ios': self.ios, 'plat': self.plat, 'tech': self.tech, 'type': self.type}
self.user_plat = user_plat
def getUserToDbDict(self):
return self.db_inputs
def getIos(self):
return self.ios
def getTech(self):
return self.tech
def getPlat(self):
return self.plat
def getType(self):
return self.type
def deleteTpFromDb(self, template_name, customer):
flag = False
entry = template_db.objects.filter(ios=self.ios, plat=self.plat, tech=self.tech, template=template_name)
if entry:
entry.delete()
file_name = template_name.replace(' ', '_')
if customer != "common":
if glb_plat_specific_tech.__contains__(self.tech):
file_name = glb_template_dir + "/" + customer + "/" + file_name + "_" + self.ios + "_" + self.plat + "_" + self.tech
else:
file_name = glb_template_dir + "/" + customer + "/" + file_name + "_" + self.ios + "_" + self.tech
else:
if glb_plat_specific_tech.__contains__(self.tech):
file_name = glb_template_dir + "/" + file_name + "_" + self.ios + "_" + self.plat + "_" + self.tech
else:
file_name = glb_template_dir + "/" + file_name + "_" + self.ios + "_" + self.tech
os.remove(file_name)
return ' Template " %s " Deleted Successfully' % template_name
# entry2 = combimatin_db.objects.filter(ios=self.ios, plat=self.plat, tech=self.tech, type=self.type)
# if entry2:
# entry2.delete()
# flag = True
# if flag:
# return True
# else:
return 'Template " %s " - Does not exist' % template_name
def getTrainingList(self):
training_list = []
self.training_dict = {}
entry = Training.objects.filter(ios=self.ios, plat=self.plat, tech=' '.join(self.tech.split()))
if entry:
for el in entry:
if not training_list.__contains__(el.description):
training_list.append(el.description)
self.training_dict[el.description] = el.link
entry = Training.objects.filter(ios=self.ios, plat='any', tech=' '.join(self.tech.split()))
if entry:
for el in entry:
if not training_list.__contains__(el.description):
training_list.append(el.description)
self.training_dict[el.description] = el.link
# return self.training_list
return self.training_dict
def getTpList(self):
print self.ios
print self.plat
print self.tech
self.template_list = []
if self.ios == 'Any_IOS' and self.plat == 'Any_Platform':
entry = template_db.objects.filter(tech=self.tech)
if entry:
for el in entry:
plat = el.plat
if plat == '9000':
plat = "ASR9000"
elif plat == 'asr':
plat = "ASR1000"
elif plat == 'asr':
plat = "ASR1000"
elif plat == 'nx9k':
plat = "NX9300"
elif plat == '7000':
plat = "NX7000"
if el.template:
self.template_list.append(plat + '_' + el.template)
else:
entry = template_db.objects.filter(ios=self.ios, plat__in=['any', self.plat], tech=self.tech, type=1)
if entry:
for el in entry:
if not self.template_list.__contains__(el.template):
self.template_list.append(el.template)
if self.ios == 'ios':
entry = template_db.objects.filter(ios=self.ios, plat='Any_IOS_Platform', tech=self.tech)
elif self.ios == 'nx':
entry = template_db.objects.filter(ios=self.ios, plat='Any_NX_Platform', tech=self.tech)
elif self.ios == 'xr':
entry = template_db.objects.filter(ios=self.ios, plat='Any_XR_Platform', tech=self.tech)
elif self.ios == 'Firewalls':
entry = template_db.objects.filter(ios=self.ios, plat='Any_ASA_Platform', tech=self.tech)
if entry:
for el in entry:
if not self.template_list.__contains__(el.template):
self.template_list.append(el.template)
print 'self.template_list'
print self.template_list
return self.template_list
def addDictToDb(self):
entry = combimatin_db.objects.filter(ios=self.ios, plat=self.plat, tech=self.tech)
if not entry:
p1 = combimatin_db(ios=self.ios, plat=self.plat, tech=self.tech, type=self.type)
p1.save()
return True
else:
print 'entry already exists'
return False
def updateTpToTypeList(self, val):
# if combimatin_db.objects.filter(ios=self.ios, plat=self.plat, tech=self.tech, type=val):
# print "matching db entry already exists no need to add type"
# # entry = combimatin_db.objects.get(ios=self.ios, plat=self.plat, tech=self.tech, type=val)
if combimatin_db.objects.filter(ios=self.ios, plat=self.plat, tech=self.tech):
entry2 = combimatin_db.objects.get(ios=self.ios, plat=self.plat, tech=self.tech)
old_type = entry2.type
if old_type:
old_type_list = old_type.split(" ")
if val in old_type_list:
print 'template already exists'
else:
new_type = old_type + " " + val
combimatin_db.objects.filter(id=entry2.id).update(type=new_type)
else:
new_type = val
combimatin_db.objects.filter(id=entry2.id).update(type=new_type)
else:
print "No matching entry - need to add"
def is_it_new_type(self, val):
# if combimatin_db.objects.filter(ios=self.ios, plat=self.plat, tech=self.tech, type=val):
# print "matching db entry already exists no need to add type"
# # entry = combimatin_db.objects.get(ios=self.ios, plat=self.plat, tech=self.tech, type=val)
# NEED TO REMOVE True - ONLY FOR TESTING
# return True
if combimatin_db.objects.filter(ios=self.ios, plat=self.plat, tech=self.tech):
entry2 = combimatin_db.objects.get(ios=self.ios, plat=self.plat, tech=self.tech)
old_type = entry2.type
if old_type:
old_type_list = old_type.split(" ")
if val in old_type_list:
return False
else:
return True
return True
def showMatchingEntry(self):
entry = combimatin_db.objects.get(ios=self.ios, plat=self.plat, tech=self.tech)
if entry:
print "ios:" + self.ios
print "plat:" + self.plat
print "tech:" + self.tech
print "type:" + self.type
else:
print 'There is not matching db enty'
def getTypeFromDb(self):
self.db_type = ""
# NEED TO REMOVE - Only for Demo
if self.ios == 'Any_IOS' and self.plat == 'Any_Platform':
entry = combimatin_db.objects.filter(tech=self.tech)
new_type_list = []
if entry:
for el in entry:
plat = el.plat
if el.type:
type_list = el.type.split(' ')
for type in type_list:
new_type = plat + "_" + type
new_type_list.append(new_type)
self.db_type = ' '.join(new_type_list)
else:
if combimatin_db.objects.filter(ios=self.ios, plat=self.plat, tech=self.tech):
entry = combimatin_db.objects.get(ios=self.ios, plat=self.plat, tech=self.tech)
if entry:
self.db_type = entry.type
return self.db_type
# def updateDbEntry(self, field, val):
# if field == "type":
# p1 = combimatin_db(ios=self.ios, plat=self.plat, tech=self.tech, type=self.type)
return self.db_inputs
def getUserToDbIos(self):
return self.db_inputs
def getUserToDbPlat(self):
return self.db_inputs
def getUserToDbTech(self):
return self.db_inputs
def getUserToDbType(self):
return self.db_inputs
# global glb_non_common_que
class GetInputVariable:
def __init__(self, user_ios, user_plat, user_tech, user_type):
# global glb_non_common_que
''' Run TCL script to get the needed input parameters, filter platform specific, change the default values
and description more user friendly and appropriate convert them into dict format'''
# com_dict = {'ip': {'ios': 'nx', 'plat': '7000', 'type': 'forwarding'}}
glb_non_common_que = {}
self.non_common_que = {}
glb_input_list_for_script = []
com_dict = {user_tech: {'ios': user_ios, 'plat': user_plat, 'type': user_type}}
self.combine_list = []
if user_tech == 'L2FWD2':
combine_list = ['src_ip', 'src_mac', 'in_int', 'vlan_id', 'out_int', 'dst_mac', 'des_ip']
if user_plat == 'NX7000':
combine_list.append('in_lc')
combine_list.append('ou_lc')
self.non_common_que = {'in_l3': 'Enter line-card <in_lc> type [m108 m132 m148 m224 m206 m202 f248]',
'ou_l3': 'Enter line-card <out_lc> type [m108 m132 m148 m224 m206 m202 f248]'}
elif user_tech == 'L2MCAST2':
combine_list = ['src_ip', 'src_mac', 'in_int', 'vlan_id', 'out_int', 'dst_mac', 'des_ip']
if user_plat == 'NX7000':
combine_list.append('in_lc')
combine_list.append('ou_lc')
self.non_common_que = {'in_l3': 'Enter line-card <in_lc> type [m108 m132 m148 m224 m206 m202 f248]',
'ou_l3': 'Enter line-card <out_lc> type [m108 m132 m148 m224 m206 m202 f248]'}
else:
for tech2 in com_dict.keys():
tech = ConvertUeseInputs('tech', tech2)
type = ConvertUeseInputs('type', com_dict.get(tech2).get('type'))
plat = ConvertUeseInputs('plat', com_dict.get(tech2).get('plat'))
ios = ConvertUeseInputs('ios', com_dict.get(tech2).get('ios'))
print ios, tech, type, plat
if type == 'jjj' and ios == 'SD-WAN':
print '!!!!! change the type to value !!!!'
combine_list = []
type = type.strip(' ').replace(' ', '_')
if type == 'loss' and tech == 'ip':
tech = 'loss'
print " New ... tclsh /home/ubuntu/nlead/run_from_py.tcl %s %s %s %s" % (plat, tech, ios, type)
p = subprocess.Popen(
"tclsh /home/ubuntu/nlead/run_from_py.tcl %s %s %s %s" % (plat, tech, ios, type),
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
inputlist = stdout.splitlines()
flag = 0
for line in inputlist: