forked from scotttyso/intersight_iac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_pools.py
1235 lines (1074 loc) · 69.2 KB
/
class_pools.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 pkg_resources
import re
import validating
from easy_functions import exit_default_no, exit_loop_default_yes
from easy_functions import naming_rule_fabric
from easy_functions import policy_descr, policy_name
from easy_functions import variablesFromAPI
from easy_functions import variablesFromAPI
from easy_functions import variablesFromAPI
from easy_functions import varBoolLoop
from easy_functions import varNumberLoop
from easy_functions import varStringLoop
from easy_functions import write_to_template
ucs_template_path = pkg_resources.resource_filename('class_pools', 'Templates/')
class pools(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
#==============================================
# IP Pools Module
#==============================================
def ip_pools(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
name_suffix = 'ip_pool'
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'IP Pool'
templateVars = {}
templateVars["header"] = '%s Variables' % (policy_type)
templateVars["initial_write"] = True
templateVars["org"] = org
templateVars["policy_type"] = policy_type
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'ip_pools'
tfDir = kwargs['tfDir']
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
configure_loop = False
while configure_loop == False:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' At a minimum you will need one IP Pool for KVM Access to Servers. Currently out-of-band')
print(f' management is not supported for KVM access. This IP Pool will need to be associated to a ')
print(f' VLAN assigned to the VLAN Pool of the Domain.\n')
print(f' This wizard will save the configuration for this section to the following file:')
if opSystem == 'Windows':
print(f' - {tfDir}\\{org}\\{self.type}\\{templateVars["template_type"]}.auto.tfvars')
else:
print(f' - {tfDir}/{org}/{self.type}/{templateVars["template_type"]}.auto.tfvars')
print(f'\n-------------------------------------------------------------------------------------------\n')
configure = input(f'Do You Want to Configure an {policy_type}? Enter "Y" or "N" [Y]: ')
if configure == 'Y' or configure == '':
policy_loop = False
while policy_loop == False:
if not name_prefix == '':
name = '%s_%s' % (name_prefix, name_suffix)
else:
name = '%s_%s' % (org, name_suffix)
templateVars["name"] = policy_name(name, policy_type)
templateVars["descr"] = policy_descr(templateVars["name"], policy_type)
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['pool.AbstractPool']['allOf'][1]['properties']
templateVars["var_description"] = jsonVars['AssignmentOrder']['description']
templateVars["jsonVars"] = sorted(jsonVars['AssignmentOrder']['enum'])
templateVars["defaultVar"] = jsonVars['AssignmentOrder']['default']
templateVars["varType"] = 'Assignment Order'
templateVars["assignment_order"] = variablesFromAPI(**templateVars)
valid = False
while valid == False:
config_ipv4 = input('Do you want to configure IPv4 for this Pool? Enter "Y" or "N" [Y]: ')
if config_ipv4 == 'Y' or config_ipv4 == '':
valid = True
elif config_ipv4 == 'N':
valid = True
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please enter "Y" or "N".')
print(f'\n-------------------------------------------------------------------------------------------\n')
if config_ipv4 == 'Y' or config_ipv4 == '':
jsonVars = jsonData['components']['schemas']['ippool.IpV4Block']['allOf'][1]['properties']
templateVars["Description"] = 'The Gateway/Prefix to Assign to the Pool'
templateVars["varDefault"] = '198.18.0.1/24'
templateVars["varInput"] = 'What is the Gateway/Prefix to Assign to the Pool? [198.18.0.1/24]:'
templateVars["varName"] = 'Gateway/Prefix'
templateVars["varRegex"] = '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.{3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\/[0-9]{1,2}$'
templateVars["minLength"] = 7
templateVars["maxLength"] = 20
network_prefix = varStringLoop(**templateVars)
gateway = str(ipaddress.IPv4Interface(network_prefix).ip)
netmask = str(ipaddress.IPv4Interface(network_prefix).netmask)
network = str(ipaddress.IPv4Interface(network_prefix).network)
prefix = network_prefix.split('/')[1]
templateVars["Description"] = jsonVars['From']['description']
templateVars["varDefault"] = '198.18.0.2'
templateVars["varInput"] = 'What is the Starting IP Address to Assign to the Pool? [198.18.0.2]:'
templateVars["varName"] = 'Starting IP Address'
templateVars["varRegex"] = jsonVars['From']['pattern']
templateVars["minLength"] = 7
templateVars["maxLength"] = 15
pool_from = varStringLoop(**templateVars)
jsonVars = jsonData['components']['schemas']['pool.AbstractBlockType']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['Size']['description']
templateVars["varInput"] = 'How Many IP Addresses should be added to the Pool? Range is 1-1000.'
templateVars["varDefault"] = 253
templateVars["varName"] = 'Pool Size'
templateVars["minNum"] = jsonVars['Size']['minimum']
templateVars["maxNum"] = jsonVars['Size']['maximum']
pool_size = varNumberLoop(**templateVars)
jsonVars = jsonData['components']['schemas']['ippool.IpV4Config']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['PrimaryDns']['description']
templateVars["varDefault"] = '208.67.220.220'
templateVars["varInput"] = 'What is your Primary DNS Server? [208.67.220.220]:'
templateVars["varName"] = 'Primary Dns'
templateVars["varRegex"] = jsonVars['PrimaryDns']['pattern']
templateVars["minLength"] = 7
templateVars["maxLength"] = 15
primary_dns = varStringLoop(**templateVars)
templateVars["Description"] = jsonVars['SecondaryDns']['description']
templateVars["varDefault"] = ''
templateVars["varInput"] = 'What is your Secondary DNS Server? [press enter to skip]:'
templateVars["varName"] = 'Secondary Dns'
templateVars["varRegex"] = jsonVars['SecondaryDns']['pattern']
templateVars["minLength"] = 7
templateVars["maxLength"] = 15
secondary_dns = varStringLoop(**templateVars)
beginx = int(ipaddress.IPv4Address(pool_from))
add_dec = (beginx + int(pool_size) - 1)
pool_to = str(ipaddress.IPv4Address(add_dec))
templateVars["ipv4_blocks"] = [
{
'from':pool_from,
'size':pool_size,
'to':pool_to
}
]
templateVars["ipv4_configuration"] = {
'gateway':gateway,
'netmask':netmask,
'primary_dns':primary_dns,
'secondary_dns':secondary_dns
}
valid = False
while valid == False:
config_ipv6 = input('Do you want to configure IPv6 for this Pool? Enter "Y" or "N" [N]: ')
if config_ipv6 == 'Y':
valid = True
elif config_ipv6 == 'N' or config_ipv6 == '':
valid = True
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please enter "Y" or "N".')
print(f'\n-------------------------------------------------------------------------------------------\n')
if config_ipv6 == 'Y':
jsonVars = jsonData['components']['schemas']['ippool.IpV6Block']['allOf'][1]['properties']
templateVars["Description"] = 'The Gateway/Prefix to Assign to the Pool'
templateVars["varDefault"] = '2001:0002::1/64'
templateVars["varInput"] = 'What is the Gateway/Prefix to Assign to the Pool? [2001:0002::1/64]:'
templateVars["varName"] = 'Gateway/Prefix'
templateVars["varRegex"] = '^$|^(([0-9A-Fa-f]{1,4}:([0-9A-Fa-f]{1,4}:([0-9A-Fa-f]{1,4}:([0-9A-Fa-f]{1,4}:([0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{0,4}|:[0-9A-Fa-f]{1,4})?|(:[0-9A-Fa-f]{1,4}){0,2})|(:[0-9A-Fa-f]{1,4}){0,3})|(:[0-9A-Fa-f]{1,4}){0,4})|:(:[0-9A-Fa-f]{1,4}){0,5})((:[0-9A-Fa-f]{1,4}){2}|:(25[0-5]|(2[0-4]|1[0-9]|[1-9])?[0-9])(\\.(25[0-5]|(2[0-4]|1[0-9]|[1-9])?[0-9])){3})|(([0-9A-Fa-f]{1,4}:){1,6}|:):[0-9A-Fa-f]{0,4}|([0-9A-Fa-f]{1,4}:){7}:)\/[0-9]{1,3}$'
templateVars["minLength"] = 6
templateVars["maxLength"] = 164
network_prefix = varStringLoop(**templateVars)
# broadcast = str(ipaddress.IPv4Interface(network_prefix).broadcast_address)
gateway = str(ipaddress.IPv6Interface(network_prefix).ip)
if re.search('[a-z]+', gateway):
gateway = gateway.upper()
network = str(ipaddress.IPv6Interface(network_prefix).network)
prefix = network_prefix.split('/')[1]
templateVars["Description"] = jsonVars['From']['description']
templateVars["varDefault"] = '2001:0002::2'
templateVars["varInput"] = 'What is the Starting IP Address to Assign to the Pool? [2001:0002::2]:'
templateVars["varName"] = 'Starting IPv6 Address'
templateVars["varRegex"] = jsonVars['From']['pattern']
templateVars["minLength"] = 3
templateVars["maxLength"] = 164
starting = varStringLoop(**templateVars)
jsonVars = jsonData['components']['schemas']['pool.AbstractBlockType']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['Size']['description']
templateVars["varInput"] = 'How Many IPv6 Addresses should be added to the Pool? Range is 1-1000.'
templateVars["varDefault"] = 1000
templateVars["varName"] = 'Pool Size'
templateVars["minNum"] = jsonVars['Size']['minimum']
templateVars["maxNum"] = jsonVars['Size']['maximum']
pool_size = varNumberLoop(**templateVars)
jsonVars = jsonData['components']['schemas']['ippool.IpV6Config']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['PrimaryDns']['description']
templateVars["varDefault"] = '2620:119:53::53'
templateVars["varInput"] = 'What is your Primary DNS Server? [2620:119:53::53]:'
templateVars["varName"] = 'Primary Dns'
templateVars["varRegex"] = jsonVars['PrimaryDns']['pattern']
templateVars["minLength"] = 3
templateVars["maxLength"] = 164
primary_dns = varStringLoop(**templateVars)
templateVars["Description"] = jsonVars['SecondaryDns']['description']
templateVars["varDefault"] = ''
templateVars["varInput"] = 'What is your Secondary DNS Server? [press enter to skip]:'
templateVars["varName"] = 'Secondary Dns'
templateVars["varRegex"] = jsonVars['SecondaryDns']['pattern']
templateVars["minLength"] = 3
templateVars["maxLength"] = 164
secondary_dns = varStringLoop(**templateVars)
beginx = int(ipaddress.IPv6Address(starting))
add_dec = (beginx + int(pool_size) - 1)
ending = str(ipaddress.IPv6Address(add_dec))
templateVars["ipv6_blocks"] = [
{
'from':starting,
'size':pool_size,
'to':ending
}
]
templateVars["ipv6_configuration"] = {
'gateway':gateway,
'prefix':prefix,
'primary_dns':primary_dns,
'secondary_dns':secondary_dns
}
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' assignment_order = "{templateVars["assignment_order"]}"')
print(f' description = "{templateVars["descr"]}"')
print(f' name = "{templateVars["name"]}"')
if config_ipv4 == 'Y' or config_ipv4 == '':
print(f' ipv4_blocks = ''[')
for item in templateVars["ipv4_blocks"]:
print(' {')
for k, v in item.items():
if k == 'from':
print(f' from = "{v}" ')
elif k == 'size':
print(f' size = {v}')
elif k == 'to':
print(f' to = "{v}"')
print(' }')
print(f' '']')
print(' ipv4_configuration = {')
print(' [')
for k, v in templateVars["ipv4_configuration"].items():
if k == 'gateway':
print(f' gateway = "{v}"')
elif k == 'netmask':
print(f' netmask = "{v}"')
elif k == 'primary_dns':
print(f' primary_dns = "{v}"')
elif k == 'secondary_dns':
print(f' secondary_dns = "{v}"')
print(' }')
print(' ]')
if config_ipv6 == 'Y':
print(f' ipv6_blocks = ''{')
for item in templateVars["ipv6_blocks"]:
print(' [')
for k, v in item.items():
if k == 'from':
print(f' from = "{v}"')
elif k == 'size':
print(f' size = {v}')
elif k == 'to':
print(f' to = "{v}"')
print(' }')
print(f' '']')
print(' ipv6_configuration = [')
print(' {')
for k, v in templateVars["ipv6_configuration"].items():
if k == 'gateway':
print(f' gateway = "{v}"')
elif k == 'prefix':
print(f' prefix = "{v}"')
elif k == 'primary_dns':
print(f' primary_dns = "{v}"')
elif k == 'secondary_dns':
print(f' secondary_dns = "{v}"')
print(' }')
print(' ]')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid_confirm = False
while valid_confirm == False:
confirm_policy = input('Do you want to accept the configuration above? Enter "Y" or "N" [Y]: ')
if confirm_policy == 'Y' or confirm_policy == '':
confirm_policy = 'Y'
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
configure_loop, policy_loop = exit_default_no(templateVars["policy_type"])
valid_confirm = True
elif confirm_policy == 'N':
print(f'\n------------------------------------------------------\n')
print(f' Starting {templateVars["policy_type"]} 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')
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#==============================================
# IQN Pools Module
#==============================================
def iqn_pools(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
name_suffix = 'iqn_pool'
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'IQN Pool'
templateVars = {}
templateVars["header"] = '%s Variables' % (policy_type)
templateVars["initial_write"] = True
templateVars["org"] = org
templateVars["policy_type"] = policy_type
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'iqn_pools'
tfDir = kwargs['tfDir']
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
configure_loop = False
while configure_loop == False:
print(f'\n-------------------------------------------------------------------------------------------\n')
configure = input(f'Do You Want to Configure a {policy_type}. Enter "Y" or "N" [Y]: ')
if configure == 'Y' or configure == '':
policy_loop = False
while policy_loop == False:
if not name_prefix == '':
name = '%s_%s' % (name_prefix, name_suffix)
else:
name = '%s_%s' % (org, name_suffix)
templateVars["name"] = policy_name(name, policy_type)
templateVars["descr"] = policy_descr(templateVars["name"], policy_type)
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['pool.AbstractPool']['allOf'][1]['properties']
templateVars["var_description"] = jsonVars['AssignmentOrder']['description']
templateVars["jsonVars"] = sorted(jsonVars['AssignmentOrder']['enum'])
templateVars["defaultVar"] = jsonVars['AssignmentOrder']['default']
templateVars["varType"] = 'Assignment Order'
templateVars["assignment_order"] = variablesFromAPI(**templateVars)
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' The iSCSI Qualified Name (IQN) format is: iqn.yyyy-mm.naming-authority:unique name, where:')
print(f' - literal iqn (iSCSI Qualified Name) - always iqn')
print(f' - date (yyyy-mm) that the naming authority took ownership of the domain')
print(f' - reversed domain name of the authority (e.g. org.linux, com.example, com.cisco)')
print(f' - unique name is any name you want to use, for example, the name of your host. The naming')
print(f' authority must make sure that any names assigned following the colon are unique, such as:')
print(f' * iqn.1984-12.com.cisco:lnx1')
print(f' * iqn.1984-12.com.cisco:win-server1')
print(f' * iqn.1984-12.com.cisco:win-server1')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid = False
while valid == False:
jsonVars = jsonData['components']['schemas']['iqnpool.Pool']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['Prefix']['description']
templateVars["varDefault"] = 'iqn.1984-12.com.cisco'
templateVars["varInput"] = 'What is the IQN Prefix you would like to assign to the Pool? [iqn.1984-12.com.cisco]:'
templateVars["varName"] = 'IQN Prefix'
templateVars["varRegex"] = '^$|^(?:iqn\\.[0-9]{4}-[0-9]{2}(?:\\.[A-Za-z](?:[A-Za-z0-9\\-]*[A-Za-z0-9])?)+?'
templateVars["minLength"] = 7
templateVars["maxLength"] = 64
templateVars["prefix"] = varStringLoop(**templateVars)
jsonVars = jsonData['components']['schemas']['iqnpool.IqnSuffixBlock']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['From']['description']
templateVars["varInput"] = jsonVars['From']['description']
templateVars["varDefault"] = 0
templateVars["varName"] = 'Starting Suffix'
templateVars["minNum"] = 0
templateVars["maxNum"] = 60000000000
pool_from = varNumberLoop(**templateVars)
templateVars["Description"] = jsonVars['Suffix']['description']
templateVars["varDefault"] = 'ucs-host'
templateVars["varInput"] = 'What is the IQN Suffix you would like to assign to the Pool? [ucs-host]:'
templateVars["varName"] = 'IQN Suffix'
templateVars["varRegex"] = '[0-9a-zA-Z]'
templateVars["minLength"] = 3
templateVars["maxLength"] = 32
suffix = varStringLoop(**templateVars)
jsonVars = jsonData['components']['schemas']['pool.AbstractBlockType']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['Size']['description']
templateVars["varInput"] = 'How Many IP Addresses should be added to the Pool? Range is 1-1000.'
templateVars["varDefault"] = 1000
templateVars["varName"] = 'Pool Size'
templateVars["minNum"] = jsonVars['Size']['minimum']
templateVars["maxNum"] = jsonVars['Size']['maximum']
pool_size = varNumberLoop(**templateVars)
pool_to = pool_from + pool_size - 1
from_iqn = '%s:%s%s' % (templateVars['prefix'], suffix, pool_from)
to_iqn = '%s:%s%s' % (templateVars['prefix'], suffix, pool_to)
valid_starting_iqn = validating.iqn_address('IQN Staring Address', from_iqn)
valid_ending_iqn = validating.iqn_address('IQN Ending Address', to_iqn)
if valid_starting_iqn == True and valid_ending_iqn == True:
valid = True
templateVars["iqn_blocks"] = [
{
'from':pool_from,
'size':pool_size,
'suffix':suffix,
'to':pool_to
}
]
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' assignment_order = "{templateVars["assignment_order"]}"')
print(f' description = "{templateVars["descr"]}"')
print(f' name = "{templateVars["name"]}"')
print(f' prefix = "{templateVars["prefix"]}"')
print(f' iqn_blocks = ''[')
for i in templateVars["iqn_blocks"]:
print(f' ''{')
for k, v in i.items():
if k == 'from':
print(f' from = {v}')
elif k == 'size':
print(f' size = {v}')
elif k == 'suffix':
print(f' suffix = "{v}"')
elif k == 'to':
print(f' to = {v}')
print(f' ''}')
print(f' '']')
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 == '':
confirm_policy = 'Y'
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
configure_loop, policy_loop = exit_default_no(templateVars["policy_type"])
valid_confirm = True
elif confirm_policy == 'N':
print(f'\n------------------------------------------------------\n')
print(f' Starting {templateVars["policy_type"]} 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')
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#==============================================
# MAC Pools Module
#==============================================
def mac_pools(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'MAC Pool'
templateVars = {}
templateVars["header"] = '%s Variables' % (policy_type)
templateVars["initial_write"] = True
templateVars["org"] = org
templateVars["policy_type"] = policy_type
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'mac_pools'
tfDir = kwargs['tfDir']
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
configure_loop = False
while configure_loop == False:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' MAC Pool Convention Recommendations:')
print(f' - Leverage the Cisco UCS OUI of 00:25:B5 for the MAC Pool Prefix.')
print(f' - For MAC Pools; create a pool for each Fabric.')
print(f' - Pool Size can be between 1 and 1000 addresses.')
print(f' - Refer to "UCS Naming Conventions 0.5.ppsx" in the Repository for further guidance.\n')
print(f' This wizard will save the configuration for this section to the following file:')
if opSystem == 'Windows':
print(f' - {tfDir}\\{org}\\{self.type}\\{templateVars["template_type"]}.auto.tfvars')
else:
print(f' - {tfDir}/{org}/{self.type}/{templateVars["template_type"]}.auto.tfvars')
print(f'\n-------------------------------------------------------------------------------------------\n')
loop_count = 0
policy_loop = False
while policy_loop == False:
name = naming_rule_fabric(loop_count, name_prefix, org)
templateVars["name"] = policy_name(name, policy_type)
templateVars["descr"] = policy_descr(templateVars["name"], policy_type)
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['pool.AbstractPool']['allOf'][1]['properties']
templateVars["var_description"] = jsonVars['AssignmentOrder']['description']
templateVars["jsonVars"] = sorted(jsonVars['AssignmentOrder']['enum'])
templateVars["defaultVar"] = jsonVars['AssignmentOrder']['default']
templateVars["varType"] = 'Assignment Order'
templateVars["assignment_order"] = variablesFromAPI(**templateVars)
jsonVars = jsonData['components']['schemas']['macpool.Block']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['From']['description']
if loop_count % 2 == 0:
templateVars["varDefault"] = '00:25:B5:0A:00:00'
templateVars["varInput"] = 'What is the Starting MAC Address to Assign to the Pool? [00:25:B5:0A:00:00]:'
else:
templateVars["varDefault"] = '00:25:B5:0B:00:00'
templateVars["varInput"] = 'What is the Starting MAC Address to Assign to the Pool? [00:25:B5:0B:00:00]:'
templateVars["varName"] = 'Starting MAC Address'
templateVars["varRegex"] = '^([0-9a-zA-Z]{2}:){5}[0-9a-zA-Z]{2}$'
templateVars["minLength"] = 17
templateVars["maxLength"] = 17
pool_from = varStringLoop(**templateVars)
jsonVars = jsonData['components']['schemas']['pool.AbstractBlockType']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['Size']['description']
templateVars["varInput"] = 'How Many IP Addresses should be added to the Pool? Range is 1-1000.'
templateVars["varDefault"] = 1000
templateVars["varName"] = 'Pool Size'
templateVars["minNum"] = jsonVars['Size']['minimum']
templateVars["maxNum"] = jsonVars['Size']['maximum']
pool_size = varNumberLoop(**templateVars)
if re.search('[a-z]', pool_from):
pool_from = pool_from.upper()
beginx = int(pool_from.replace(':', ''), 16)
add_dec = (beginx + int(pool_size) - 1)
pool_to = ':'.join(['{}{}'.format(a, b)
for a, b
in zip(*[iter('{:012x}'.format(add_dec))]*2)])
pool_to = pool_to.upper()
templateVars["mac_blocks"] = [
{
'from':pool_from,
'size':pool_size,
'to':pool_to
}
]
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' assignment_order = "{templateVars["assignment_order"]}"')
print(f' description = "{templateVars["descr"]}"')
print(f' name = "{templateVars["name"]}"')
print(f' mac_blocks = ''[')
for item in templateVars["mac_blocks"]:
print(' {')
for k, v in item.items():
if k == 'from':
print(f' from = "{v}" ')
elif k == 'size':
print(f' size = {v}')
elif k == 'to':
print(f' to = "{v}"')
print(' }')
print(f' '']')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid_confirm = False
while valid_confirm == False:
confirm_policy = input('Do you want to accept the configuration above? Enter "Y" or "N" [Y]: ')
if confirm_policy == 'Y' or confirm_policy == '':
confirm_policy = 'Y'
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
configure_loop, loop_count, policy_loop = exit_loop_default_yes(loop_count, policy_type)
valid_confirm = True
elif confirm_policy == 'N':
print(f'\n------------------------------------------------------\n')
print(f' Starting {policy_type} 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')
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#==============================================
# Resource Pool Module
#==============================================
def resource_pools(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
name_suffix = 'resource'
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'Resource Pool'
templateVars = {}
templateVars["header"] = '%s Variables' % (policy_type)
templateVars["initial_write"] = True
templateVars["org"] = org
templateVars["policy_type"] = policy_type
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'resource_pools'
tfDir = kwargs['tfDir']
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
configure_loop = False
while configure_loop == False:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' The {policy_type} represents a collection of resources that can be associated to ')
print(f' the configuration entities such as server profiles.\n')
print(f' This wizard will save the configuration for this section to the following file:')
if opSystem == 'Windows':
print(f' - {tfDir}\\{org}\\{self.type}\\{templateVars["template_type"]}.auto.tfvars')
else:
print(f' - {tfDir}/{org}/{self.type}/{templateVars["template_type"]}.auto.tfvars')
print(f'\n-------------------------------------------------------------------------------------------\n')
configure = input(f'Do You Want to Configure a {policy_type}? Enter "Y" or "N" [Y]: ')
if configure == 'Y' or configure == '':
policy_loop = False
while policy_loop == False:
if not name_prefix == '':
name = '%s_%s' % (name_prefix, name_suffix)
else:
name = '%s_%s' % (org, name_suffix)
templateVars["name"] = policy_name(name, policy_type)
templateVars["descr"] = policy_descr(templateVars["name"], policy_type)
# Pull in the Policies for iSCSI Boot
templateVars["multi_select"] = False
# Assignment Order
jsonVars = jsonData['components']['schemas']['pool.AbstractPool']['allOf'][1]['properties']
templateVars["var_description"] = jsonVars['AssignmentOrder']['description']
templateVars["jsonVars"] = sorted(jsonVars['AssignmentOrder']['enum'])
templateVars["defaultVar"] = jsonVars['AssignmentOrder']['default']
templateVars["varType"] = 'Assignment Order'
templateVars["assignment_order"] = variablesFromAPI(**templateVars)
# List of Serial Numbers
templateVars['serial_number_list'] = []
valid = False
while valid == False:
templateVars["Description"] = 'A List of Serial Numbers to add to the Resource Pool.'
templateVars["varDefault"] = ''
templateVars["varInput"] = 'Enter the Server Serial Number:'
templateVars["varName"] = 'Serial Number'
templateVars["varRegex"] = '^[A-Z]{3}[2-3][\\d]([0][1-9]|[1-4][0-9]|[5][1-3])[\\dA-Z]{4}$'
templateVars["minLength"] = 11
templateVars["maxLength"] = 11
templateVars['serial_number_list'].append(varStringLoop(**templateVars))
templateVars["Description"] = 'Add Additional Serial Numbers.'
templateVars["varInput"] = f'Do you want to add another Serial Number?'
templateVars["varDefault"] = 'N'
templateVars["varName"] = 'Additional Serial Numbers'
valid = varBoolLoop(**templateVars)
# Server Type
jsonVars = easy_jsonData['pools']['resourcepool.Pool']
templateVars["var_description"] = jsonVars['server_type']['description']
templateVars["jsonVars"] = sorted(jsonVars['server_type']['enum'])
templateVars["defaultVar"] = jsonVars['server_type']['default']
templateVars["varType"] = 'Server Type'
templateVars["server_type"] = variablesFromAPI(**templateVars)
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' assignment_order = "{templateVars["assignment_order"]}"')
print(f' description = "{templateVars["descr"]}"')
print(f' name = "{templateVars["name"]}"')
print(f' serial_number_list = {templateVars["serial_number_list"]}')
print(f' server_type = "{templateVars["server_type"]}"')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid_confirm = False
while valid_confirm == False:
confirm_policy = input('Do you want to accept the configuration above? Enter "Y" or "N" [Y]: ')
if confirm_policy == 'Y' or confirm_policy == '':
confirm_policy = 'Y'
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
configure_loop, policy_loop = exit_default_no(templateVars["policy_type"])
valid_confirm = True
elif confirm_policy == 'N':
print(f'\n------------------------------------------------------\n')
print(f' Starting {templateVars["policy_type"]} 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')
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#==============================================
# UUID Pools Module
#==============================================
def uuid_pools(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
name_suffix = 'uuid_pool'
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'UUID Pool'
templateVars = {}
templateVars["header"] = '%s Variables' % (policy_type)
templateVars["initial_write"] = True
templateVars["org"] = org
templateVars["policy_type"] = policy_type
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'uuid_pools'
tfDir = kwargs['tfDir']
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
configure_loop = False
while configure_loop == False:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' The Universally Unique Identifier (UUID) are written in 5 groups of hexadecimal digits')
print(f' separated by hyphens. The length of each group is: 8-4-4-4-12. UUIDs are fixed length.')
print(f'\n-------------------------------------------------------------------------------------------\n')
configure = input(f'Do You Want to Configure a {policy_type}. Enter "Y" or "N" [Y]: ')
if configure == 'Y' or configure == '':
policy_loop = False
while policy_loop == False:
if not name_prefix == '':
name = '%s_%s' % (name_prefix, name_suffix)
else:
name = '%s_%s' % (org, name_suffix)
templateVars["name"] = policy_name(name, policy_type)
templateVars["descr"] = policy_descr(templateVars["name"], policy_type)
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['pool.AbstractPool']['allOf'][1]['properties']
templateVars["var_description"] = jsonVars['AssignmentOrder']['description']
templateVars["jsonVars"] = sorted(jsonVars['AssignmentOrder']['enum'])
templateVars["defaultVar"] = jsonVars['AssignmentOrder']['default']
templateVars["varType"] = 'Assignment Order'
templateVars["assignment_order"] = variablesFromAPI(**templateVars)
jsonVars = jsonData['components']['schemas']['uuidpool.Pool']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['Prefix']['description']
templateVars["varDefault"] = '000025B5-0000-0000'
templateVars["varInput"] = 'What is the UUID Prefix you would like to assign to the Pool? [000025B5-0000-0000]:'
templateVars["varName"] = 'UUID Prefix'
templateVars["varRegex"] = jsonVars['Prefix']['pattern']
templateVars["minLength"] = 18
templateVars["maxLength"] = 18
templateVars["prefix"] = varStringLoop(**templateVars)
jsonVars = jsonData['components']['schemas']['uuidpool.UuidBlock']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['From']['description']
templateVars["varDefault"] = '0000-000000000000'
templateVars["varInput"] = 'What is the First UUID Suffix in the Block? [0000-000000000000]:'
templateVars["varName"] = 'UUID First Suffix'
templateVars["varRegex"] = jsonVars['From']['pattern']
templateVars["minLength"] = 17
templateVars["maxLength"] = 17
pool_from = varStringLoop(**templateVars)
jsonVars = jsonData['components']['schemas']['pool.AbstractBlockType']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['Size']['description']
templateVars["varInput"] = 'How Many IP Addresses should be added to the Pool? Range is 1-1000.'
templateVars["varDefault"] = 1000
templateVars["varName"] = 'Pool Size'
templateVars["minNum"] = jsonVars['Size']['minimum']
templateVars["maxNum"] = jsonVars['Size']['maximum']
pool_size = varNumberLoop(**templateVars)
if re.search('[a-z]', pool_from):
pool_from = pool_from.upper()
from_split = pool_from.split('-')
pool_to = hex(int(from_split[1], 16) + pool_size - 1).split('x')[-1]
add_zeros = 12 - len(pool_to)
if not add_zeros == 0:
pool_to = str(from_split[0]) + '-' + ('0' * add_zeros) + pool_to
pool_to = pool_to.upper()
templateVars["uuid_blocks"] = [
{
'from':pool_from,
'size':pool_size,
'to':pool_to
}
]
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' assignment_order = "{templateVars["assignment_order"]}"')
print(f' description = "{templateVars["descr"]}"')
print(f' name = "{templateVars["name"]}"')
print(f' prefix = "{templateVars["prefix"]}"')
print(f' uuid_blocks = ''[')
for i in templateVars["uuid_blocks"]:
print(f' ''{')
for k, v in i.items():
if k == 'from':
print(f' from = "{v}"')
elif k == 'size':
print(f' size = {v}')
elif k == 'to':
print(f' to = "{v}"')
print(f' ''}')
print(f' '']')
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 == '':
confirm_policy = 'Y'
# Write Policies to Template File
templateVars["template_file"] = '%s.jinja2' % (templateVars["template_type"])
write_to_template(self, **templateVars)
configure_loop, policy_loop = exit_default_no(templateVars["policy_type"])
valid_confirm = True
elif confirm_policy == 'N':
print(f'\n------------------------------------------------------\n')
print(f' Starting {templateVars["policy_type"]} 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')
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#==============================================
# WWNN Pools Module
#==============================================
def wwnn_pools(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
name_suffix = 'wwnn_pool'
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'WWNN Pool'
templateVars = {}
templateVars["header"] = '%s Variables' % (policy_type)
templateVars["initial_write"] = True
templateVars["org"] = org
templateVars["policy_type"] = policy_type
templateVars["template_file"] = 'template_open.jinja2'
templateVars["template_type"] = 'wwnn_pools'
tfDir = kwargs['tfDir']
# Open the Template file
write_to_template(self, **templateVars)
templateVars["initial_write"] = False
configure_loop = False
while configure_loop == False:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' WWNN Pool Convention Recommendations:')
print(f' - Leverage the Cisco UCS OUI of 20:00:00:25:B5 for the WWNN Pool Prefix.')
print(f' - Pool Size can be between 1 and 1000 addresses.')
print(f' - Refer to "UCS Naming Conventions 0.5.ppsx" in the Repository for further guidance.\n')
print(f' This wizard will save the configuration for this section to the following file:')
if opSystem == 'Windows':
print(f' - {tfDir}\\{org}\\{self.type}\\{templateVars["template_type"]}.auto.tfvars')
else:
print(f' - {tfDir}/{org}/{self.type}/{templateVars["template_type"]}.auto.tfvars')
print(f'\n-------------------------------------------------------------------------------------------\n')
configure = input(f'Do You Want to Configure a {policy_type}? Enter "Y" or "N" [Y]: ')
if configure == 'Y' or configure == '':
policy_loop = False
while policy_loop == False:
if not name_prefix == '':
name = '%s_%s' % (name_prefix, name_suffix)
else:
name = '%s_%s' % (org, name_suffix)
templateVars["name"] = policy_name(name, policy_type)
templateVars["descr"] = policy_descr(templateVars["name"], policy_type)
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['pool.AbstractPool']['allOf'][1]['properties']
templateVars["var_description"] = jsonVars['AssignmentOrder']['description']
templateVars["jsonVars"] = sorted(jsonVars['AssignmentOrder']['enum'])
templateVars["defaultVar"] = jsonVars['AssignmentOrder']['default']
templateVars["varType"] = 'Assignment Order'
templateVars["assignment_order"] = variablesFromAPI(**templateVars)
jsonVars = jsonData['components']['schemas']['fcpool.Block']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['From']['description']