forked from scotttyso/intersight_iac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_quick_start.py
3823 lines (3364 loc) · 220 KB
/
class_quick_start.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
#!/usr/bin/env python3
import ipaddress
import jinja2
import os
import pkg_resources
import platform
import re
import validating
from class_policies_lan import policies_lan
from class_policies_san import policies_san
from class_policies_p1 import policies_p1
from class_policies_p2 import port_list_eth, port_list_fc, port_modes_fc
from class_policies_p2 import policies_p2
from class_policies_p3 import policies_p3
from class_policies_vxan import policies_vxan
from class_pools import pools
from class_profiles import profiles
from easy_functions import choose_policy, policies_parse
from easy_functions import ipmi_key_function, local_users_function
from easy_functions import ntp_alternate, ntp_primary
from easy_functions import snmp_trap_servers, snmp_users
from easy_functions import syslog_servers
from easy_functions import ucs_domain_serials
from easy_functions import validate_vlan_in_policy
from easy_functions import variablesFromAPI
from easy_functions import varBoolLoop
from easy_functions import varNumberLoop
from easy_functions import varStringLoop
from easy_functions import vlan_list_full, vlan_pool
from easy_functions import write_to_template
ucs_template_path = pkg_resources.resource_filename('class_quick_start', 'Templates/')
class quick_start(object):
def __init__(self, name_prefix, org, type):
self.templateLoader = jinja2.FileSystemLoader(
searchpath=(ucs_template_path + '%s/') % (type))
self.templateEnv = jinja2.Environment(loader=self.templateLoader)
self.name_prefix = name_prefix
self.org = org
self.type = type
#==============================================
# UCS Domain and Policies
#==============================================
def domain_policies(self, jsonData, easy_jsonData, **kwargs):
chassis_type = 'profiles'
domain_type = 'ucs_domain_profiles'
name_prefix = self.name_prefix
opSystem = kwargs['opSystem']
org = self.org
templateVars = {}
templateVars["org"] = org
tfDir = kwargs['tfDir']
configure_loop = False
while configure_loop == False:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' The Quick Deployment Module - Domain Policies, will configure pools for a UCS Domain ')
print(f' Profile.\n')
print(f' This wizard will save the output for these pools in the following files:\n')
if opSystem == 'Windows':
print(f' - {tfDir}\\{org}\\{self.type}\\flow_control_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\link_aggregation_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\link_control_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\multicast_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\network_connectivity_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\ntp_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\port_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\system_qos_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\switch_control_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\vsan_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\vlan_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{chassis_type}\\ucs_chassis_profiles.auto.tfvars')
print(f' - {tfDir}\\{org}\\{domain_type}\\ucs_domain_profiles.auto.tfvars')
else:
print(f' - {tfDir}/{org}/{self.type}/flow_control_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/link_aggregation_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/link_control_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/multicast_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/network_connectivity_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/ntp_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/port_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/system_qos_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/switch_control_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/vsan_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/vlan_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{chassis_type}/ucs_chassis_profiles.auto.tfvars')
print(f' - {tfDir}/{org}/{domain_type}/ucs_domain_profiles.auto.tfvars')
print(f'\n-------------------------------------------------------------------------------------------\n')
configure = input(f'Do You Want to run the Quick Deployment Module - Domain Policy Configuration? \nEnter "Y" or "N" [Y]: ')
if configure == 'Y' or configure == '':
loop_count = 0
policy_loop = False
while policy_loop == False:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Below are the Questions that will be asked by the Domain Policies Portion of the wizard.')
print(f' - UCS Domain Name.')
print(f' - UCS Domain Model.')
print(f' - UCS Serial Number for both Fabrics.')
print(f' - NTP Configuration:')
print(f' * Timezone')
print(f' * NTP Servers')
print(f' - Port Configuration.')
print(f' * Ethernet Uplink Ports.')
print(f' * Fibre-Channel Uplink Ports.')
print(f' * Server Ports.')
print(f' - System MTU for the Domain.')
print(f' - VLAN Pool for the Domain.')
print(f' - VSAN ID for Fabric A.')
print(f' - VSAN ID for Fabric B.')
print(f'\n-------------------------------------------------------------------------------------------\n')
templateVars["name"] = 'Quick Deployment Module'
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['policy.AbstractProfile']['allOf'][1]['properties']
# Domain Name
templateVars["Description"] = jsonVars['Name']['description']
templateVars["varInput"] = 'What is the name for this UCS Domain?'
templateVars["varDefault"] = ''
templateVars["varName"] = 'UCS Domain Name'
templateVars["varRegex"] = jsonVars['Name']['pattern']
templateVars["minLength"] = 1
templateVars["maxLength"] = 64
templateVars["name"] = varStringLoop(**templateVars)
domain_name = templateVars["name"]
# Domain Model
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['fabric.PortPolicy']['allOf'][1]['properties']
templateVars["var_description"] = jsonVars['DeviceModel']['description']
templateVars["jsonVars"] = sorted(jsonVars['DeviceModel']['enum'])
templateVars["defaultVar"] = jsonVars['DeviceModel']['default']
templateVars["varType"] = 'Device Model'
templateVars["device_model"] = variablesFromAPI(**templateVars)
# Serial Numbers
serial_a,serial_b = ucs_domain_serials()
templateVars["serial_number_fabric_a"] = serial_a
templateVars["serial_number_fabric_b"] = serial_b
# VLAN Pool
valid = False
while valid == False:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' IMPORTANT NOTE: The FCoE VLAN will be assigned based on the VSAN Identifier.')
print(f' Be sure to exclude the VSAN for Fabric A and B from the VLAN Pool.')
print(f'\n-------------------------------------------------------------------------------------------\n')
VlanList,vlanListExpanded = vlan_pool()
nativeVlan = input('Do you want to configure one of these VLANs as the Native VLAN? [press enter to skip]: ')
if nativeVlan == '':
valid = True
else:
native_count = 0
for vlan in vlanListExpanded:
if int(nativeVlan) == int(vlan):
native_count = 1
if not native_count == 1:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Error!! The Native VLAN "{nativeVlan}" was not in the VLAN Policy List.')
print(f' VLAN Policy List is: "{VlanList}"')
print(f'\n-------------------------------------------------------------------------------------------\n')
else:
valid = True
#_______________________________________________________________________
#
# Configure Multicast Policy
#_______________________________________________________________________
templateVars["name"] = domain_name
templateVars["descr"] = f'{templateVars["name"]} Multicast Policy'
policies_vxan(name_prefix, org, 'policies').quick_start_multicast(**templateVars)
#_______________________________________________________________________
#
# Configure VLAN Policy
#_______________________________________________________________________
templateVars["multicast_policy"] = templateVars["name"]
templateVars["descr"] = f'{templateVars["name"]} VLAN Policy'
templateVars["native_vlan"] = nativeVlan
templateVars["vlan_list"] = VlanList
policies_vxan(name_prefix, org, 'policies').quick_start_vlan(**templateVars)
#_______________________________________________________________________
#
# Configure Flow Control Policy
#_______________________________________________________________________
templateVars["initial_write"] = True
templateVars["policy_type"] = 'Flow Control Policy'
templateVars["header"] = '%s Variables' % (templateVars["policy_type"])
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'flow_control_policies'
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
# Configure Flow Control Policy
name = domain_name
templateVars["name"] = name
templateVars["descr"] = f'{name} Flow Control Policy'
templateVars["priority"] = 'auto'
templateVars["receive"] = 'Disabled'
templateVars["send"] = 'Disabled'
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#_______________________________________________________________________
#
# Configure Link Aggregation Policy
#_______________________________________________________________________
templateVars["initial_write"] = True
templateVars["policy_type"] = 'Link Aggregation Policy'
templateVars["header"] = '%s Variables' % (templateVars["policy_type"])
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'link_aggregation_policies'
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
# Configure Link Aggregation Policy
name = domain_name
templateVars["name"] = name
templateVars["descr"] = f'{name} Link Aggregation Policy'
templateVars["lacp_rate"] = 'normal'
templateVars["suspend_individual"] = False
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#_______________________________________________________________________
#
# Configure Link Control Policy
#_______________________________________________________________________
templateVars["initial_write"] = True
templateVars["policy_type"] = 'Link Control Policy'
templateVars["header"] = '%s Variables' % (templateVars["policy_type"])
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'link_control_policies'
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
# Configure Link Control Policy
name = domain_name
templateVars["name"] = name
templateVars["descr"] = f'{name} Link Control Policy'
templateVars["admin_state"] = 'Enabled'
templateVars["mode"] = 'normal'
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
# Configure Fibre-Channel Unified Ports
fc_mode,ports_in_use,fc_converted_ports,port_modes = port_modes_fc(jsonData, easy_jsonData, name_prefix, **templateVars)
templateVars["fc_mode"] = fc_mode
templateVars["ports_in_use"] = ports_in_use
templateVars["fc_converted_ports"] = fc_converted_ports
templateVars["port_modes"] = port_modes
if templateVars["port_modes"].get("port_list"):
templateVars["fc_ports"] = templateVars["port_modes"]["port_list"]
else:
templateVars["fc_ports"] = []
# If Unified Ports Exist Configure VSAN Policies
if len(templateVars["fc_converted_ports"]) > 0:
# Obtain the VSAN for Fabric A/B
fabrics = ['A', 'B']
for x in fabrics:
valid = False
while valid == False:
if loop_count % 2 == 0:
vsan_id = input(f'Enter the VSAN id to add to {templateVars["name"]} Fabric {x}. [100]: ')
else:
vsan_id = input(f'Enter the VSAN id to add to {templateVars["name"]} Fabric {x}. [200]: ')
if loop_count % 2 == 0 and vsan_id == '':
vsan_id = 100
elif vsan_id == '':
vsan_id = 200
if re.search(r'[0-9]{1,4}', str(vsan_id)):
valid_count = 0
for y in vlanListExpanded:
if int(y) == int(vsan_id):
valid_count += 1
continue
if valid_count == 0:
templateVars[f"vsan_id_{x}"] = vsan_id
valid_vlan = validating.number_in_range('VSAN ID', vsan_id, 1, 4094)
if valid_vlan == True:
loop_count += 1
valid = True
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Invalid VSAN! The FCoE VLAN {x} must not be assigned to the Domain VLAN Pool.')
print(f' Choose an Alternate VSAN Value.')
print(f'\n-------------------------------------------------------------------------------------------\n')
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Invalid Entry! Please Enter a VSAN ID in the range of 1-4094.')
print(f'\n-------------------------------------------------------------------------------------------\n')
#_______________________________________________________________________
#
# Configure VSAN Policies
#_______________________________________________________________________
templateVars["initial_write"] = True
templateVars["policy_type"] = 'VSAN Policy'
templateVars["header"] = '%s Variables' % (templateVars["policy_type"])
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'vsan_policies'
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
# Configure VSAN Policy
for x in fabrics:
name = f'{domain_name}-{x}'
templateVars["name"] = name
templateVars["descr"] = f'{name} VSAN Policy'
templateVars["uplink_trunking"] = False
xlower = x.lower()
templateVars['vsans'] = []
vsans = {
'fcoe_vlan_id':templateVars[f"vsan_id_{x}"],
'name':f'{domain_name}-{xlower}',
'id':templateVars[f"vsan_id_{x}"]
}
templateVars['vsans'].append(vsans)
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' IMPORTANT NOTE: If you want to assign one of the VLANs from the Pool as the Native VLAN')
print(f' for the Port-Channel assign that here.')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid = False
while valid == False:
nativeVlan = input('What is the Native VLAN for the Ethernet Port-Channel? [press enter to skip]: ')
if nativeVlan == '':
valid = True
else:
native_count = 0
for vlan in vlanListExpanded:
if int(nativeVlan) == int(vlan):
native_count = 1
if not native_count == 1:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Error!! The Native VLAN "{nativeVlan}" was not in the VLAN Policy List.')
print(f' VLAN Policy List is: "{VlanList}"')
print(f'\n-------------------------------------------------------------------------------------------\n')
else:
valid = True
#_______________________________________________________________________
#
# Configure Ethernet Network Group Policy
#_______________________________________________________________________
templateVars["initial_write"] = True
templateVars["policy_type"] = 'Ethernet Network Group Policy'
templateVars["header"] = '%s Variables' % (templateVars["policy_type"])
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'ethernet_network_group_policies'
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
# Configure Ethernet Network Group Policy
name = f'{domain_name}'
templateVars["name"] = name
templateVars["descr"] = f'{name} Ethernet Network Group Policy'
templateVars["allowed_vlans"] = VlanList
if not nativeVlan == '':
templateVars["native_vlan"] = nativeVlan
else:
templateVars["native_vlan"] = ''
templateVars.pop('native_vlan')
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
# Ethernet Uplink Port-Channel
templateVars["name"] = domain_name
templateVars['port_type'] = 'Ethernet Uplink Port-Channel'
port_channel_ethernet_uplinks,templateVars['ports_in_use'] = port_list_eth(jsonData, easy_jsonData, name_prefix, **templateVars)
templateVars["fc_ports_in_use"] = []
templateVars["port_type"] = 'Fibre-Channel Port-Channel'
Fab_A,Fab_B,fc_ports_in_use = port_list_fc(jsonData, easy_jsonData, name_prefix, **templateVars)
Fabric_A_fc_port_channels = Fab_A
Fabric_B_fc_port_channels = Fab_B
templateVars["fc_ports_in_use"] = fc_ports_in_use
# Server Ports
templateVars['port_type'] = 'Server Ports'
port_role_servers,templateVars['ports_in_use'] = port_list_eth(jsonData, easy_jsonData, name_prefix, **templateVars)
# System MTU for System QoS Policy
templateVars["Description"] = 'This option will set the MTU to 9216 if answer is "Y" or 1500 if answer is "N".'
templateVars["varInput"] = f'Do you want to enable Jumbo MTU? Enter "Y" or "N"'
templateVars["varDefault"] = 'Y'
templateVars["varName"] = 'MTU'
answer = varBoolLoop(**templateVars)
if answer == True:
mtu = 9216
else:
mtu = 1500
# NTP Servers
primary_ntp = ntp_primary()
alternate_ntp = ntp_alternate()
templateVars["enabled"] = True
templateVars["ntp_servers"] = []
templateVars["ntp_servers"].append(primary_ntp)
if not alternate_ntp == '':
templateVars["ntp_servers"].append(alternate_ntp)
# Timezone
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['appliance.SystemInfo']['allOf'][1]['properties']['TimeZone']['enum']
tz_regions = []
for i in jsonVars:
tz_region = i.split('/')[0]
if not tz_region in tz_regions:
tz_regions.append(tz_region)
tz_regions = sorted(tz_regions)
templateVars["var_description"] = 'Timezone Regions...'
templateVars["jsonVars"] = tz_regions
templateVars["defaultVar"] = 'America'
templateVars["varType"] = 'Time Region'
time_region = variablesFromAPI(**templateVars)
region_tzs = []
for item in jsonVars:
if time_region in item:
region_tzs.append(item)
templateVars["var_description"] = 'Region Timezones...'
templateVars["jsonVars"] = sorted(region_tzs)
templateVars["defaultVar"] = ''
templateVars["varType"] = 'Region Timezones'
templateVars["timezone"] = variablesFromAPI(**templateVars)
templateVars["port_channel_ethernet_uplinks"] = port_channel_ethernet_uplinks
templateVars["Fabric_A_fc_port_channels"] = Fabric_A_fc_port_channels
templateVars["Fabric_B_fc_port_channels"] = Fabric_B_fc_port_channels
templateVars["port_role_servers"] = port_role_servers
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' UCS Domain Name = "{domain_name}"')
print(f' Device Model = "{templateVars["device_model"]}"')
print(f' Serial Number Fabric A = "{templateVars["serial_number_fabric_a"]}"')
print(f' Serial Number Fabric B = "{templateVars["serial_number_fabric_b"]}"')
print(f' Port Policy Variables:')
if len(templateVars["fc_converted_ports"]) > 0:
port_type_list = ['port_channel_ethernet_uplinks', 'Fabric_A_fc_port_channels', 'Fabric_B_fc_port_channels', 'port_role_servers']
else:
port_type_list = ['port_channel_ethernet_uplinks', 'port_role_servers']
for port_list in port_type_list:
if port_list == 'port_channel_ethernet_uplinks':
print(f' Ethernet Port-Channel Ports = [')
elif port_list == 'Fabric_A_fc_port_channels':
print(f' Fibre-Channel Port-Channel Fabric A = [')
elif port_list == 'Fabric_B_fc_port_channels':
print(f' Fibre-Channel Port-Channel Fabric B = [')
elif port_list == 'port_role_servers':
print(f' Server Ports = [')
for item in templateVars[f"{port_list}"]:
for key, value in item.items():
if key == 'admin_speed':
print(f' admin_speed = "{value}"')
elif key == 'ethernet_network_group_policy':
print(f' ethernet_network_group_policy = "{value}"')
elif key == 'fill_pattern':
print(f' fill_pattern = "{value}"')
elif key == 'flow_control_policy':
print(f' flow_control_policy = "{value}"')
elif key == 'link_aggregation_policy':
print(f' link_aggregation_policy = "{value}"')
elif key == 'link_control_policy':
print(f' link_control_policy = "{value}"')
elif key == 'link_aggregation_policy':
print(f' link_aggregation_policy = "{value}"')
elif key == 'pc_id':
print(f' pc_id = "{value}"')
elif key == 'port_list':
print(f' port_list = "{value}"')
elif key == 'slot_id':
print(f' slot_id = "{value}"')
elif key == 'interfaces':
int_count = 0
print(f' interfaces = [')
for i in value:
print(f' "{int_count}" = ''{')
for k, v in i.items():
print(f' {k} = {v}')
print(f' ''}')
int_count +=1
print(f' ]')
print(f' System MTU: {mtu}')
print(f' NTP Variables:')
print(f' timezone: "{templateVars["timezone"]}"')
if len(templateVars["ntp_servers"]) > 0:
print(f' ntp_servers = [')
for server in templateVars["ntp_servers"]:
print(f' "{server}",')
print(f' ]')
print(f' VLAN Pool: "{VlanList}"')
if len(templateVars["fc_converted_ports"]) > 0:
print(f' VSAN Fabric A: "{templateVars["vsan_id_A"]}"')
print(f' VSAN Fabric B: "{templateVars["vsan_id_B"]}"')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid_confirm = False
while valid_confirm == False:
confirm_policy = input('Do you want to accept the above configuration? Enter "Y" or "N" [Y]: ')
if confirm_policy == 'Y' or confirm_policy == '':
#_______________________________________________________________________
#
# Configure Sytem MTU Settings
#_______________________________________________________________________
templateVars["initial_write"] = True
templateVars["policy_type"] = 'System QoS Policy'
templateVars["header"] = '%s Variables' % (templateVars["policy_type"])
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'system_qos_policies'
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
# System QoS Settings
templateVars["mtu"] = mtu
name = domain_name
templateVars["name"] = name
templateVars["descr"] = f'{name} System QoS Policy'
templateVars["Platinum"] = {
'bandwidth_percent':20,
'cos':5,
'mtu':templateVars["mtu"],
'multicast_optimize':False,
'packet_drop':False,
'priority':'Platinum',
'state':'Enabled',
'weight':10,
}
templateVars["Gold"] = {
'bandwidth_percent':18,
'cos':4,
'mtu':templateVars["mtu"],
'multicast_optimize':False,
'packet_drop':True,
'priority':'Gold',
'state':'Enabled',
'weight':9,
}
templateVars["FC"] = {
'bandwidth_percent':20,
'cos':3,
'mtu':2240,
'multicast_optimize':False,
'packet_drop':False,
'priority':'FC',
'state':'Enabled',
'weight':10,
}
templateVars["Silver"] = {
'bandwidth_percent':18,
'cos':2,
'mtu':templateVars["mtu"],
'multicast_optimize':False,
'packet_drop':True,
'priority':'Silver',
'state':'Enabled',
'weight':8,
}
templateVars["Bronze"] = {
'bandwidth_percent':14,
'cos':1,
'mtu':templateVars["mtu"],
'multicast_optimize':False,
'packet_drop':True,
'priority':'Bronze',
'state':'Enabled',
'weight':7,
}
templateVars["Best Effort"] = {
'bandwidth_percent':10,
'cos':255,
'mtu':templateVars["mtu"],
'multicast_optimize':False,
'packet_drop':True,
'priority':'Best Effort',
'state':'Enabled',
'weight':5,
}
templateVars["classes"] = []
priorities = ['Platinum', 'Gold', 'FC', 'Silver', 'Bronze', 'Best Effort']
for priority in priorities:
templateVars["classes"].append(templateVars[priority])
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#_______________________________________________________________________
#
# Configure Network Connectivity Policy
#_______________________________________________________________________
templateVars["initial_write"] = True
templateVars["policy_type"] = 'Network Connectivity Policy'
templateVars["header"] = '%s Variables' % (templateVars["policy_type"])
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'network_connectivity_policies'
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
# Network Connectivity Access Settings
name = domain_name
templateVars["name"] = name
templateVars["descr"] = f'{name} Network Connectivity Policy'
templateVars["preferred_ipv4_dns_server"] = kwargs['primary_dns']
templateVars["alternate_ipv4_dns_server"] = kwargs['secondary_dns']
templateVars["enable_ipv6"] = False
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#_______________________________________________________________________
#
# Configure NTP Policy
#_______________________________________________________________________
templateVars["initial_write"] = True
templateVars["policy_type"] = 'NTP Policy'
templateVars["header"] = '%s Variables' % (templateVars["policy_type"])
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'ntp_policies'
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
# NTP Settings
name = domain_name
templateVars["name"] = name
templateVars["descr"] = f'{name} NTP Policy'
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#_______________________________________________________________________
#
# Configure Switch Control Policy
#_______________________________________________________________________
templateVars["initial_write"] = True
templateVars["policy_type"] = 'Switch Control Policy'
templateVars["header"] = '%s Variables' % (templateVars["policy_type"])
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'switch_control_policies'
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
# Switch Control Settings
name = domain_name
templateVars["name"] = name
templateVars["descr"] = f'{name} Switch Control Policy'
templateVars["mac_address_table_aging"] = 'Default'
templateVars["mac_aging_time"] = 14500
templateVars["udld_message_interval"] = 15
templateVars["udld_recovery_action"] = "reset"
templateVars["vlan_port_count_optimization"] = False
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#_______________________________________________________________________
#
# Configure Port Policy
#_______________________________________________________________________
templateVars["initial_write"] = True
templateVars["policy_type"] = 'Port Policy'
templateVars["header"] = '%s Variables' % (templateVars["policy_type"])
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'port_policies'
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
# Port Settings
name = domain_name
templateVars["name"] = name
templateVars["descr"] = f'{name} Port Policy'
templateVars["port_channel_appliances"] = []
templateVars["port_channel_ethernet_uplinks"] = port_channel_ethernet_uplinks
templateVars["port_channel_fcoe_uplinks"] = []
templateVars["port_role_appliances"] = []
templateVars["port_role_ethernet_uplinks"] = []
templateVars["port_role_fcoe_uplinks"] = []
templateVars["port_role_servers"] = port_role_servers
if len(templateVars["fc_converted_ports"]) > 0:
for x in fabrics:
xlower = x.lower()
templateVars["name"] = f'{domain_name}-{xlower}'
if x == 'A':
templateVars["port_channel_fc_uplinks"] = Fabric_A_fc_port_channels
else:
templateVars["port_channel_fc_uplinks"] = Fabric_B_fc_port_channels
templateVars["port_role_fc_uplinks"] = []
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#_______________________________________________________________________
#
# Configure UCS Chassis Profile
#_______________________________________________________________________
name = domain_name
templateVars["name"] = name
profiles(name_prefix, org, 'profiles').quick_start_chassis(easy_jsonData, **templateVars)
#_______________________________________________________________________
#
# Configure UCS Domain Profile
#_______________________________________________________________________
# UCS Domain Profile Settings
name = domain_name
templateVars["name"] = name
templateVars["descr"] = f'{name} UCS Domain Profile'
templateVars["action"] = 'No-op'
templateVars["network_connectivity_policy"] = domain_name
templateVars["ntp_policy"] = domain_name
templateVars["port_policies"] = {
'fabric_a':f'{domain_name}-a',
'fabric_b':f'{domain_name}-b'
}
templateVars["snmp_policy"] = f'{org}_domain'
templateVars["switch_control_policy"] = domain_name
templateVars["syslog_policy"] = f'{org}_domain'
templateVars["system_qos_policy"] = domain_name
templateVars["vlan_policies"] = {
'fabric_a':domain_name,
'fabric_b':domain_name
}
if len(templateVars["fc_converted_ports"]) > 0:
templateVars["vsan_policies"] = {
'fabric_a':f'{domain_name}-A',
'fabric_b':f'{domain_name}-B'
}
else:
templateVars["vsan_policies"] = {
'fabric_a':'',
'fabric_b':''
}
profiles(name_prefix, org, 'ucs_domain_profiles').quick_start_domain(**templateVars)
configure_loop = True
policy_loop = True
valid_confirm = True
elif confirm_policy == 'N':
print(f'\n------------------------------------------------------\n')
print(f' Starting Section over.')
print(f'\n------------------------------------------------------\n')
valid_confirm = True
else:
print(f'\n------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please enter "Y" or "N".')
print(f'\n------------------------------------------------------\n')
elif configure == 'N':
configure_loop = True
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please enter "Y" or "N".')
print(f'\n-------------------------------------------------------------------------------------------\n')
if configure == 'Y' or configure == '':
vlan_policy = {'vlan_policy':f'{domain_name}','vlans':VlanList,'native_vlan':nativeVlan}
if len(templateVars["fc_converted_ports"]) > 0:
vsan_a = templateVars["vsan_id_A"]
vsan_b = templateVars["vsan_id_B"]
else:
vsan_a = 0
vsan_b = 0
fc_ports = templateVars["fc_converted_ports"]
mtu = templateVars["mtu"]
configure = True
elif configure == 'N':
vlan_policy = {}
vsan_a = 0
vsan_b = 0
fc_ports = []
mtu = 1500
configure = False
return configure,vlan_policy,vsan_a,vsan_b,fc_ports,mtu
#==============================================
# LAN and SAN Policies
#==============================================
def lan_san_policies(self, jsonData, easy_jsonData, **kwargs):
if kwargs['mtu'] > 8999:
mtu = 9000
else:
mtu = 1500
opSystem = kwargs['opSystem']
org = self.org
templateVars = {}
templateVars["org"] = org
tfDir = kwargs['tfDir']
configure_loop = False
while configure_loop == False:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' The Quick Deployment Module - Network Configuration, will configure policies for the')
print(f' Network Configuration of a UCS Server Profile connected to an IMM Domain.\n')
print(f' This wizard will save the output for these pools in the following files:\n')
if opSystem == 'Windows':
print(f' - {tfDir}\\{org}\\{self.type}\\ethernet_adapter_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\ethernet_network_control_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\ethernet_network_group_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\ethernet_qos_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\fibre_channel_adapter_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\fibre_channel_network_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\fibre_channel_qos_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\lan_connectivity_policies.auto.tfvars')
print(f' - {tfDir}\\{org}\\{self.type}\\san_connectivity_policies.auto.tfvars')
else:
print(f' - {tfDir}/{org}/{self.type}/ethernet_adapter_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/ethernet_network_control_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/ethernet_network_group_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/ethernet_qos_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/fibre_channel_adapter_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/fibre_channel_network_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/fibre_channel_qos_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/lan_connectivity_policies.auto.tfvars')
print(f' - {tfDir}/{org}/{self.type}/san_connectivity_policies.auto.tfvars')
print(f'\n-------------------------------------------------------------------------------------------\n')
configure = input(f'Do You Want to run the Quick Deployment Module - Network Configuration? Enter "Y" or "N" [Y]: ')
if configure == 'Y' or configure == '':
loop_count = 1
policy_loop = False
while policy_loop == False:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Below are the Questions that will be asked by the Policies Portion of the wizard.')
print(f' - Choice to use CDP or LDP for Device Discovery.')
print(f' - Choice to enable Jumbo MTU (9000 MB) or Run standard 1500 MB MTU for vNICs.')
print(f' - LAN Connectivity Policy (vNICs):')
print(f' * VLAN ID for ESXi MGMT')
print(f' * VLAN ID for ESXi vMotion')
print(f' * VLAN ID for ESXi Storage')
print(f' * VLAN List for DATA (Virtual Machines)')
print(f' - SAN Connectivity Policy (vHBAs):')
print(f' * VSAN ID for Fabric A')
print(f' * VSAN ID for Fabric B')
print(f' ** Note: This should not overlap with any of the VLANs assigned to the')
print(f' LAN Connectivity Policies.')
print(f'\n-------------------------------------------------------------------------------------------\n')
vlan_policy = kwargs["vlan_policy"]
vlan_list = kwargs["vlans"]
templateVars["vsan_A"] = kwargs["vsan_a"]
templateVars["vsan_B"] = kwargs["vsan_b"]
fc_ports_in_use = kwargs["fc_ports"]
vlan_policy_list = vlan_list_full(vlan_list)
templateVars["multi_select"] = False
jsonVars = jsonVars = easy_jsonData['policies']['fabric.EthNetworkControlPolicy']
# Neighbor Discovery Protocol
templateVars["var_description"] = jsonVars['discoveryProtocol']['description']
templateVars["jsonVars"] = sorted(jsonVars['discoveryProtocol']['enum'])
templateVars["defaultVar"] = jsonVars['discoveryProtocol']['default']
templateVars["varType"] = 'Neighbor Discovery Protocol'
neighbor_discovery = variablesFromAPI(**templateVars)
# Management VLAN
valid = False
while valid == False:
templateVars["Description"] = 'LAN Connectivity Policy vNICs - MGMT VLAN Identifier'
templateVars["varInput"] = 'Enter the VLAN ID for MGMT:'
templateVars["varDefault"] = 1
templateVars["varName"] = 'Management VLAN ID'
templateVars["minNum"] = 1
templateVars["maxNum"] = 4094
mgmt_vlan = varNumberLoop(**templateVars)
valid = validate_vlan_in_policy(vlan_policy_list, mgmt_vlan)
# vMotion VLAN
valid = False
while valid == False:
templateVars["Description"] = 'LAN Connectivity Policy vNICs - vMotion VLAN Identifier'
templateVars["varInput"] = 'Enter the VLAN ID for vMotion:'
templateVars["varDefault"] = 2
templateVars["varName"] = 'Management VLAN ID'
templateVars["minNum"] = 1
templateVars["maxNum"] = 4094
vmotion_vlan = varNumberLoop(**templateVars)
valid = validate_vlan_in_policy(vlan_policy_list, vmotion_vlan)
# Storage VLAN
valid = False
while valid == False:
templateVars["Description"] = 'LAN Connectivity Policy vNICs - Storage VLAN Identifier'
templateVars["varInput"] = 'Enter the VLAN ID for Storage:'
templateVars["varDefault"] = 3
templateVars["varName"] = 'Storage VLAN ID'
templateVars["minNum"] = 1
templateVars["maxNum"] = 4094
storage_vlan = varNumberLoop(**templateVars)
valid = validate_vlan_in_policy(vlan_policy_list, storage_vlan)
valid = False
while valid == False:
VlanList = input('Enter the VLAN or List of VLANs to add to the DATA (Virtual Machine) vNICs: ')
if not VlanList == '':