forked from scotttyso/intersight_iac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_policies_p3.py
2660 lines (2399 loc) · 167 KB
/
class_policies_p3.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 jinja2
import json
import os
import pkg_resources
import re
import stdiomask
import validating
from easy_functions import exit_default_no, exit_default_yes
from easy_functions import policy_descr, policy_name
from easy_functions import snmp_trap_servers, snmp_users
from easy_functions import syslog_servers
from easy_functions import varBoolLoop
from easy_functions import variablesFromAPI
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_policies_p3', 'Templates/')
class policies_p3(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
#==============================================
# Power Policy Module
#==============================================
def power_policies(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'Power Policy'
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"] = 'power_policies'
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' A {policy_type} will configure the Power Redundancy Policies for Chassis and Servers.')
print(f' For Servers it will configure the Power Restore State.\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 = 1
policy_loop = False
while policy_loop == False:
print('staring loop again')
templateVars["multi_select"] = False
templateVars["var_description"] = easy_jsonData['policies']['power.Policy']['systemType']['description']
templateVars["jsonVars"] = sorted(easy_jsonData['policies']['power.Policy']['systemType']['enum'])
templateVars["defaultVar"] = easy_jsonData['policies']['power.Policy']['systemType']['default']
templateVars["varType"] = 'System Type'
system_type = variablesFromAPI(**templateVars)
if not name_prefix == '':
name = '%s_%s' % (name_prefix, system_type)
else:
name = '%s_%s' % (org, system_type)
templateVars["name"] = policy_name(name, policy_type)
templateVars["descr"] = policy_descr(templateVars["name"], policy_type)
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['power.Policy']['allOf'][1]['properties']
if system_type == '9508':
valid = False
while valid == False:
templateVars["power_allocation"] = input('What is the Power Budget you would like to Apply?\n'
'This should be a value between 2800 Watts and 16800 Watts. [5600]: ')
if templateVars["power_allocation"] == '':
templateVars["power_allocation"] = 5600
valid = validating.number_in_range('Chassis Power Budget', templateVars["power_allocation"], 2800, 16800)
templateVars["var_description"] = jsonVars['DynamicRebalancing']['description']
templateVars["jsonVars"] = sorted(jsonVars['DynamicRebalancing']['enum'])
templateVars["defaultVar"] = jsonVars['DynamicRebalancing']['default']
templateVars["varType"] = 'Dynamic Power Rebalancing'
templateVars["dynamic_power_rebalancing"] = variablesFromAPI(**templateVars)
templateVars["var_description"] = jsonVars['PowerSaveMode']['description']
templateVars["jsonVars"] = sorted(jsonVars['PowerSaveMode']['enum'])
templateVars["defaultVar"] = jsonVars['PowerSaveMode']['default']
templateVars["varType"] = 'Power Save Mode'
templateVars["power_save_mode"] = variablesFromAPI(**templateVars)
else:
templateVars["power_allocation"] = 0
templateVars["dynamic_power_rebalancing"] = 'Enabled'
templateVars["power_save_mode"] = 'Enabled'
if system_type == 'Server':
templateVars["var_description"] = jsonVars['PowerPriority']['description']
templateVars["jsonVars"] = sorted(jsonVars['PowerPriority']['enum'])
templateVars["defaultVar"] = jsonVars['PowerPriority']['default']
templateVars["varType"] = 'Power Priority'
templateVars["power_priority"] = variablesFromAPI(**templateVars)
templateVars["var_description"] = jsonVars['PowerProfiling']['description']
templateVars["jsonVars"] = sorted(jsonVars['PowerProfiling']['enum'])
templateVars["defaultVar"] = jsonVars['PowerProfiling']['default']
templateVars["varType"] = 'Power Profiling'
templateVars["power_profiling"] = variablesFromAPI(**templateVars)
templateVars["var_description"] = jsonVars['PowerRestoreState']['description']
templateVars["jsonVars"] = sorted(jsonVars['PowerRestoreState']['enum'])
templateVars["defaultVar"] = jsonVars['PowerRestoreState']['default']
templateVars["varType"] = 'Power Restore'
templateVars["power_restore"] = variablesFromAPI(**templateVars)
if system_type == '5108':
templateVars["popList"] = ['N+2']
elif system_type == 'Server':
templateVars["popList"] = ['N+1','N+2']
templateVars["var_description"] = jsonVars['RedundancyMode']['description']
templateVars["jsonVars"] = sorted(jsonVars['RedundancyMode']['enum'])
templateVars["defaultVar"] = jsonVars['RedundancyMode']['default']
templateVars["varType"] = 'Power Redundancy Mode'
templateVars["power_redundancy"] = variablesFromAPI(**templateVars)
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' description = "{templateVars["descr"]}"')
print(f' name = "{templateVars["name"]}"')
if system_type == '9508':
# print(f' dynamic_power_rebalancing = "{templateVars["dynamic_power_rebalancing"]}"')
print(f' power_allocation = {templateVars["power_allocation"]}')
# print(f' power_save_mode = "{templateVars["power_save_mode"]}"')
if system_type == 'Server':
# print(f' power_priority = "{templateVars["power_priority"]}"')
print(f' power_profiling = "{templateVars["power_profiling"]}"')
print(f' power_restore = "{templateVars["power_restore"]}"')
print(f' power_redundancy = "{templateVars["power_redundancy"]}"')
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)
if loop_count < 3:
configure_loop, policy_loop = exit_default_yes(templateVars["policy_type"])
else:
configure_loop, policy_loop = exit_default_no(templateVars["policy_type"])
loop_count += 1
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')
# Close the Template file
templateVars["template_file"] = 'template_close.jinja2'
write_to_template(self, **templateVars)
#==============================================
# SD Card Policy Module
#==============================================
def sd_card_policies(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
name_suffix = 'sdcard'
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'SD Card Policy'
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"] = 'sd_card_policies'
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["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)
exit_answer = input(f'Would You like to Configure another {policy_type}? Enter "Y" or "N" [N]: ')
if exit_answer == 'N' or exit_answer == '':
policy_loop = True
configure_loop = True
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)
#==============================================
# Serial over LAN Policy Module
#==============================================
def serial_over_lan_policies(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
name_suffix = 'sol'
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'Serial over LAN Policy'
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"] = 'serial_over_lan_policies'
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' A {policy_type} will configure the Server to allow access to the Communications Port over')
print(f' Ethernet. Settings include:')
print(f' - Baud Rate')
print(f' - COM Port')
print(f' - SSH Port\n')
print(f' This Policy is not required to standup a server but is a good practice for day 2 support.')
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["enabled"] = True
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['sol.Policy']['allOf'][1]['properties']
templateVars["var_description"] = jsonVars['BaudRate']['description']
templateVars["jsonVars"] = sorted(jsonVars['BaudRate']['enum'])
templateVars["defaultVar"] = jsonVars['BaudRate']['default']
templateVars["varType"] = 'Baud Rate'
templateVars["baud_rate"] = variablesFromAPI(**templateVars)
templateVars["var_description"] = jsonVars['ComPort']['description']
templateVars["jsonVars"] = sorted(jsonVars['ComPort']['enum'])
templateVars["defaultVar"] = jsonVars['ComPort']['default']
templateVars["varType"] = 'Com Port'
templateVars["com_port"] = variablesFromAPI(**templateVars)
valid = False
while valid == False:
templateVars["ssh_port"] = input('What is the SSH Port you would like to assign?\n'
'This should be a value between 1024-65535. [2400]: ')
if templateVars["ssh_port"] == '':
templateVars["ssh_port"] = 2400
valid = validating.number_in_range('SSH Port', templateVars["ssh_port"], 1024, 65535)
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' baud_rate = "{templateVars["baud_rate"]}"')
print(f' com_port = "{templateVars["com_port"]}"')
print(f' description = "{templateVars["descr"]}"')
print(f' enabled = "{templateVars["enabled"]}"')
print(f' name = "{templateVars["name"]}"')
print(f' ssh_port = "{templateVars["ssh_port"]}"')
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)
#==============================================
# SMTP Policy Module
#==============================================
def smtp_policies(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
name_suffix = 'smtp'
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'SMTP Policy'
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"] = 'smtp_policies'
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' An {policy_type} sends server faults as email alerts to the configured SMTP server.')
print(f' You can specify the preferred settings for outgoing communication and select the fault ')
print(f' severity level to report and the mail recipients.\n\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["enable_smtp"] = True
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' IP address or hostname of the SMTP server. The SMTP server is used by the managed device ')
print(f' to send email notifications.')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid = False
while valid == False:
templateVars["smtp_server_address"] = input('What is the SMTP Server Address? ')
if re.search(r'^[a-zA-Z0-9]:', templateVars["smtp_server_address"]):
valid = validating.ip_address('SMTP Server Address', templateVars["smtp_server_address"])
if re.search(r'[a-zA-Z]', templateVars["smtp_server_address"]):
valid = validating.dns_name('SMTP Server Address', templateVars["smtp_server_address"])
elif re.search (r'^([0-9]{1,3}\.){3}[0-9]{1,3}$'):
valid = validating.ip_address('SMTP Server Address', templateVars["smtp_server_address"])
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' "{templateVars["smtp_server_address"]}" is not a valid address.')
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Port number used by the SMTP server for outgoing SMTP communication.')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid = False
while valid == False:
templateVars["smtp_port"] = input('What is the SMTP Port? [25]: ')
if templateVars["smtp_port"] == '':
templateVars["smtp_port"] = 25
if re.search(r'[\d]+', str(templateVars["smtp_port"])):
valid = validating.number_in_range('SMTP Port', templateVars["smtp_port"], 1, 65535)
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' "{templateVars["smtp_port"]}" is not a valid port.')
print(f'\n-------------------------------------------------------------------------------------------\n')
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['smtp.Policy']['allOf'][1]['properties']
templateVars["var_description"] = jsonVars['MinSeverity']['description']
templateVars["jsonVars"] = sorted(jsonVars['MinSeverity']['enum'])
templateVars["defaultVar"] = jsonVars['MinSeverity']['default']
templateVars["varType"] = 'Minimum Severity'
templateVars["minimum_severity"] = variablesFromAPI(**templateVars)
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' The email address entered here will be displayed as the from address (mail received from ')
print(f' address) of all the SMTP mail alerts that are received. If not configured, the hostname ')
print(f' of the server is used in the from address field.')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid = False
while valid == False:
templateVars["smtp_alert_sender_address"] = input(f'What is the SMTP Alert Sender Address? '\
'[press enter to use server hostname]: ')
if templateVars["smtp_alert_sender_address"] == '':
templateVars["smtp_alert_sender_address"] = ''
valid = True
else:
valid = validating.email('SMTP Alert Sender Address', templateVars["smtp_alert_sender_address"])
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' List of email addresses that will receive notifications for faults.')
print(f'\n-------------------------------------------------------------------------------------------\n')
templateVars["mail_alert_recipients"] = []
valid = False
while valid == False:
mail_recipient = input(f'What is address you would like to send these notifications to? ')
valid_email = validating.email('Mail Alert Recipient', mail_recipient)
if valid_email == True:
templateVars["mail_alert_recipients"].append(mail_recipient)
valid_answer = False
while valid_answer == False:
add_another = input(f'Would you like to add another E-mail? Enter "Y" or "N" [N]: ')
if add_another == '' or add_another == 'N':
valid = True
valid_answer = True
elif add_another == 'Y':
valid_answer = True
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please enter "Y" or "N".')
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' description = "{templateVars["descr"]}"')
print(f' enable_smtp = {templateVars["enable_smtp"]}')
print(f' mail_alert_recipients = [')
for x in templateVars["mail_alert_recipients"]:
print(f' "{x}",')
print(f' ]')
print(f' minimum_severity = "{templateVars["minimum_severity"]}"')
print(f' name = "{templateVars["name"]}"')
print(f' smtp_alert_sender_address = "{templateVars["smtp_alert_sender_address"]}"')
print(f' smtp_port = {templateVars["smtp_port"]}')
print(f' smtp_server_address = "{templateVars["smtp_server_address"]}"')
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)
#==============================================
# SNMP Policy Module
#==============================================
def snmp_policies(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
name_suffix = 'snmp'
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'SNMP Policy'
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"] = 'snmp_policies'
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' An {policy_type} will configure chassis, domains, and servers with SNMP parameters.')
print(f' This Policy is not required to standup a server but is a good practice for day 2 support.')
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 == '':
loop_count = 1
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["enabled"] = True
valid = False
while valid == False:
templateVars["port"] = input(f'Note: The following Ports cannot be chosen: [22, 23, 80, 123, 389, 443, 623, 636, 2068, 3268, 3269]\n'\
'Enter the Port to Assign to this SNMP Policy. Valid Range is 1-65535. [161]: ')
if templateVars["port"] == '':
templateVars["port"] = 161
if re.search(r'[0-9]{1,4}', str(templateVars["port"])):
valid = validating.snmp_port('SNMP Port', templateVars["port"], 1, 65535)
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Invalid Entry! Please Enter a valid Port in the range of 1-65535.')
print(f' Excluding [22, 23, 80, 123, 389, 443, 623, 636, 2068, 3268, 3269].')
print(f'\n-------------------------------------------------------------------------------------------\n')
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['snmp.Policy']['allOf'][1]['properties']
# SNMP Contact
templateVars["Description"] = jsonVars['SysContact']['description']
templateVars["varDefault"] = 'UCS Admins'
templateVars["varInput"] = 'SNMP System Contact:'
templateVars["varName"] = 'SNMP System Contact'
templateVars["varRegex"] = '.*'
templateVars["minLength"] = 1
templateVars["maxLength"] = jsonVars['SysContact']['maxLength']
templateVars["system_contact"] = varStringLoop(**templateVars)
# SNMP Location
templateVars["Description"] = jsonVars['SysLocation']['description']
templateVars["varDefault"] = 'Data Center'
templateVars["varInput"] = 'What is the Location of the host on which the SNMP agent (server) runs?'
templateVars["varName"] = 'System Location'
templateVars["varRegex"] = '.*'
templateVars["minLength"] = 1
templateVars["maxLength"] = jsonVars['SysLocation']['maxLength']
templateVars["system_location"] = varStringLoop(**templateVars)
templateVars["access_community_string"] = ''
valid = False
while valid == False:
question = input(f'Would you like to configure an SNMP Access Community String? Enter "Y" or "N" [N]: ')
if question == 'Y':
input_valid = False
while input_valid == False:
input_string = stdiomask.getpass(f'What is your SNMP Access Community String? ')
if not input_string == '':
input_valid = validating.snmp_string('SNMP Access Community String', input_string)
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please Re-enter the SNMP Access Community String.')
print(f'\n-------------------------------------------------------------------------------------------\n')
templateVars["access_community_string"] = loop_count
TF_VAR = 'TF_VAR_access_community_string_%s' % (loop_count)
os.environ[TF_VAR] = '%s' % (input_string)
valid = True
elif question == '' or question == 'N':
valid = True
else:
print(f'\n------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please enter "Y" or "N".')
print(f'\n------------------------------------------------------\n')
if not templateVars["access_community_string"] == '':
templateVars["var_description"] = jsonVars['CommunityAccess']['description']
templateVars["jsonVars"] = sorted(jsonVars['CommunityAccess']['enum'])
templateVars["defaultVar"] = jsonVars['CommunityAccess']['default']
templateVars["varType"] = 'Community Access'
templateVars["community_access"] = variablesFromAPI(**templateVars)
else:
templateVars["community_access"] = 'Disabled'
templateVars["trap_community_string"] = ''
valid = False
while valid == False:
question = input(f'Would you like to configure an SNMP Trap Community String? Enter "Y" or "N" [N]: ')
if question == 'Y':
input_valid = False
while input_valid == False:
input_string = stdiomask.getpass(f'What is your SNMP Trap Community String? ')
if not input_string == '':
input_valid = validating.snmp_string('SNMP Trap Community String', input_string)
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please Re-enter the SNMP Trap Community String.')
print(f'\n-------------------------------------------------------------------------------------------\n')
templateVars["trap_community_string"] = loop_count
TF_VAR = 'TF_VAR_snmp_trap_community_%s' % (loop_count)
os.environ[TF_VAR] = '%s' % (input_string)
valid = True
elif question == '' or question == 'N':
valid = True
else:
print(f'\n------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please enter "Y" or "N".')
print(f'\n------------------------------------------------------\n')
templateVars["engine_input_id"] = ''
valid = False
while valid == False:
question = input(f'Note: By default this is derived from the BMC serial number.\n'\
'Would you like to configure a Unique string to identify the device for administration purpose? Enter "Y" or "N" [N]: ')
if question == 'Y':
input_valid = False
while input_valid == False:
input_string = input(f'What is the SNMP Engine Input ID? ')
if not input_string == '':
input_valid = validating.string_length('SNMP Engine Input ID', input_string, 1, 27)
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please Re-enter the SNMP Engine Input ID.')
print(f'\n-------------------------------------------------------------------------------------------\n')
templateVars["snmp_engine_input_id"] = input_string
valid = True
elif question == '' or question == 'N':
valid = True
else:
print(f'\n------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please enter "Y" or "N".')
print(f'\n------------------------------------------------------\n')
# SNMP Users
ilCount = 1
snmp_user_list = []
templateVars["Description"] = 'Configure SNMP Users'
templateVars["varInput"] = f'Would you like to configure an SNMPv3 User?'
templateVars["varDefault"] = 'Y'
templateVars["varName"] = 'Enable Trunking'
configure_snmp_users = varBoolLoop(**templateVars)
if configure_snmp_users == True:
snmp_loop = False
while snmp_loop == False:
snmp_user_list,snmp_loop = snmp_users(jsonData, ilCount, **templateVars)
# SNMP Trap Destinations
ilCount = 1
snmp_dests = []
snmp_loop = False
while snmp_loop == False:
question = input(f'Would you like to configure SNMP Trap Destionations? Enter "Y" or "N" [Y]: ')
if question == '' or question == 'Y':
snmp_dests,snmp_loop = snmp_trap_servers(jsonData, ilCount, snmp_user_list, **templateVars)
elif question == 'N':
snmp_loop = True
else:
print(f'\n------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please enter "Y" or "N".')
print(f'\n------------------------------------------------------\n')
templateVars["trap_destinations"] = snmp_dests
print(f'\n-------------------------------------------------------------------------------------------\n')
if not templateVars["access_community_string"] == '':
print(f' access_community_string = "Sensitive"')
print(f' description = "{templateVars["descr"]}"')
print(f' enable_snmp = {templateVars["enabled"]}')
print(f' name = "{templateVars["name"]}"')
print(f' snmp_community_access = "{templateVars["community_access"]}"')
print(f' snmp_engine_input_id = "{templateVars["engine_input_id"]}"')
print(f' snmp_port = {templateVars["port"]}')
if len(templateVars["trap_destinations"]) > 0:
print(f' snmp_trap_destinations = ''{')
for item in templateVars["trap_destinations"]:
for k, v in item.items():
if k == 'destination_address':
print(f' "{v}" = ''{')
for k, v in item.items():
if k == 'community':
print(f' community_string = "Sensitive"')
elif k == 'destination_address':
print(f' destination_address = "{v}"')
elif k == 'enabled':
print(f' enable = {v}')
elif k == 'port':
print(f' port = {v}')
elif k == 'trap_type':
print(f' trap_type = "{v}"')
elif k == 'user':
print(f' user = "{v}"')
elif k == 'version':
print(f' snmp_server = "{v}"')
print(f' ''}')
print(f' ''}')
if len(templateVars["users"]) > 0:
print(f' snmp_users = ''{')
for item in templateVars["users"]:
for k, v in item.items():
if k == 'name':
print(f' "{v}" = ''{')
for k, v in item.items():
if k == 'auth_password':
print(f' auth_password = "Sensitive"')
elif k == 'auth_type':
print(f' auth_type = "{v}"')
elif k == 'privacy_password':
print(f' privacy_password = "Sensitive"')
elif k == 'privacy_type':
print(f' privacy_type = "{v}"')
elif k == 'security_level':
print(f' security_level = "{v}"')
print(f' ''}')
print(f' ''}')
if not templateVars["trap_community_string"] == '':
print(f' trap_community_string = "Sensitive"')
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)
#==============================================
# SSH Policy Module
#==============================================
def ssh_policies(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
name_suffix = 'ssh'
opSystem = kwargs['opSystem']
org = self.org
policy_type = 'SSH Policy'
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"] = 'ssh_policies'
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' An {policy_type} enables an SSH client to make a secure, encrypted connection. You can ')
print(f' create one or more SSH policies that contain a specific grouping of SSH properties for a ')
print(f' server or a set of servers.\n\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["enable_ssh"] = True
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Port used for secure shell access.')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid = False
while valid == False:
templateVars["ssh_port"] = input('What is the SSH Port? [22]: ')
if templateVars["ssh_port"] == '':
templateVars["ssh_port"] = 22
if re.search(r'[\d]+', str(templateVars["ssh_port"])):
valid = validating.number_in_range('SSH Port', templateVars["ssh_port"], 1, 65535)
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' "{templateVars["ssh_port"]}" is not a valid port.')
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Number of seconds to wait before the system considers an SSH request to have timed out.')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid = False
while valid == False:
templateVars["ssh_timeout"] = input('What value do you want to set for the SSH Timeout? [1800]: ')
if templateVars["ssh_timeout"] == '':
templateVars["ssh_timeout"] = 1800
if re.search(r'[\d]+', str(templateVars["ssh_timeout"])):
valid = validating.number_in_range('SSH Timeout', templateVars["ssh_timeout"], 60, 10800)
else:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' "{templateVars["ssh_timeout"]}" is not a valid value. Must be between 60 and 10800')
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' description = "{templateVars["descr"]}"')
print(f' enable_ssh = {templateVars["enable_ssh"]}')
print(f' name = "{templateVars["name"]}"')
print(f' ssh_port = {templateVars["ssh_port"]}')
print(f' ssh_timeout = "{templateVars["ssh_timeout"]}"')
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)
#========================================
# Storage Policy Module
#========================================
def storage_policies(self, jsonData, easy_jsonData, **kwargs):
name_prefix = self.name_prefix
name_suffix = 'storage'
opSystem = kwargs['opSystem']
org = self.org
policy_names = []
policy_type = 'Storage Policy'
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"] = 'storage_policies'
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' A {policy_type} allows you to create drive groups, virtual drives, configure the ')
print(f' storage capacity of a virtual drive, and configure the M.2 RAID controllers.\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 == '':
loop_count = 1
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)
# Obtain Policy Name
templateVars["name"] = policy_name(name, policy_type)
# Obtain Policy Description
templateVars["descr"] = policy_descr(templateVars["name"], policy_type)
# Configure the Global Host Spares Setting
templateVars["multi_select"] = False
jsonVars = jsonData['components']['schemas']['storage.StoragePolicy']['allOf'][1]['properties']
# Configure the Global Host Spares Setting
templateVars["Description"] = jsonVars['GlobalHotSpares']['description']