forked from scotttyso/intersight_iac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp_coding.py
641 lines (583 loc) · 43.1 KB
/
temp_coding.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
#!/usr/bin/env python3
import jinja2
import json
import os
import pkg_resources
import re
import stdiomask
import subprocess
import validating
from easy_functions import exit_default_no, exit_default_yes
from easy_functions import policy_descr, policy_name
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('temp_coding', 'Templates/')
class temp_coding(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
#========================================
# Storage Policy Module
#========================================
def storage_policies(self, jsonData, easy_jsonData):
name_prefix = self.name_prefix
name_suffix = 'storage'
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'
# 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:')
print(f' - Intersight/{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']
templateVars["varDefault"] = ''
templateVars["varInput"] = 'Specify the disks that are to be used as hot spares,\n globally,'\
' for all the Drive Groups. [press enter to skip]:'
templateVars["varName"] = 'Global Hot Spares'
templateVars["varRegex"] = jsonVars['GlobalHotSpares']['pattern']
templateVars["minLength"] = 0
templateVars["maxLength"] = 128
templateVars["global_hot_spares"] = varStringLoop(**templateVars)
# Obtain Unused Disks State
templateVars["var_description"] = jsonVars['UnusedDisksState']['description']
templateVars["jsonVars"] = sorted(jsonVars['UnusedDisksState']['enum'])
templateVars["defaultVar"] = jsonVars['UnusedDisksState']['default']
templateVars["varType"] = 'Unused Disks State'
templateVars["unused_disks_state"] = variablesFromAPI(**templateVars)
# Configure the Global Host Spares Setting
templateVars["Description"] = jsonVars['UseJbodForVdCreation']['description']
templateVars["varInput"] = f'Do you want to Use JBOD drives for Virtual Drive creation?'
templateVars["varDefault"] = 'N'
templateVars["varName"] = 'Use Jbod For Vd Creation'
templateVars["use_jbod_for_vd_creation"] = varBoolLoop(**templateVars)
# Ask if Drive Groups should be configured
templateVars["Description"] = 'Drive Group Configuration - Enable to add RAID drive groups that can be used to create'\
' virtual drives. You can also specify the Global Hot Spares information.'
templateVars["varInput"] = f'Do you want to Configure Drive Groups?'
templateVars["varDefault"] = 'N'
templateVars["varName"] = 'Drive Groups'
driveGroups = varBoolLoop(**templateVars)
# If True configure Drive Groups
if driveGroups == True:
templateVars["drive_groups"] = []
inner_loop_count = 1
drive_group = []
drive_group_loop = False
while drive_group_loop == False:
jsonVars = jsonData['components']['schemas']['storage.DriveGroup']['allOf'][1]['properties']
# Request Drive Group Name
templateVars["Description"] = jsonVars['Name']['description']
templateVars["varDefault"] = f'dg{inner_loop_count - 1}'
templateVars["varInput"] = f'Enter the Drive Group Name. [{templateVars["varDefault"]}]:'
templateVars["varName"] = 'Drive Group Name'
templateVars["varRegex"] = jsonVars['Name']['pattern']
templateVars["minLength"] = 1
templateVars["maxLength"] = 60
dgName = varStringLoop(**templateVars)
# Obtain Raid Level for Drive Group
templateVars["var_description"] = jsonVars['RaidLevel']['description']
templateVars["jsonVars"] = sorted(jsonVars['RaidLevel']['enum'])
templateVars["defaultVar"] = jsonVars['RaidLevel']['default']
templateVars["varType"] = 'Raid Level'
RaidLevel = variablesFromAPI(**templateVars)
jsonVars = jsonData['components']['schemas']['storage.ManualDriveGroup']['allOf'][1]['properties']
# If Raid Level is anything other than Raid0 ask for Hot Spares
if not RaidLevel == 'Raid0':
templateVars["Description"] = jsonVars['DedicatedHotSpares']['description']
templateVars["varInput"] = 'Enter the Drives to add as Dedicated Hot Spares [press enter to skip]:'
templateVars["varName"] = 'Dedicated Hot Spares'
templateVars["varRegex"] = jsonVars['DedicatedHotSpares']['pattern']
templateVars["minLength"] = 1
templateVars["maxLength"] = 60
DedicatedHotSpares = varStringLoop(**templateVars)
else:
DedicatedHotSpares = ''
# Configure Span Slots
SpanSlots = []
# If Riad is 10, 50 or 60 allow multiple Span Slots
if re.fullmatch('^Raid(10|50|60)$', RaidLevel):
templateVars["var_description"] = jsonVars['SpanGroups']['items']['description']
templateVars["jsonVars"] = [2, 4, 6, 8]
templateVars["defaultVar"] = 2
templateVars["varType"] = 'Span Groups'
SpanGroups = variablesFromAPI(**templateVars)
if SpanGroups == 2:
SpanGroups = [0, 1]
elif SpanGroups == 4:
SpanGroups = [0, 1, 2, 3]
elif SpanGroups == 6:
SpanGroups = [0, 1, 2, 3, 4, 5]
elif SpanGroups == 8:
SpanGroups = [0, 1, 2, 3, 4, 5, 6, 7]
for span in SpanGroups:
jsonVars = jsonData['components']['schemas']['storage.SpanDrives']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['Slots']['description']
if re.fullmatch('^Raid10$', RaidLevel):
Drive1 = (inner_loop_count * 2) - 1
Drive2 = (inner_loop_count * 2)
templateVars["varDefault"] = f'{Drive1}-{Drive2}'
elif re.fullmatch('^Raid50$', RaidLevel):
Drive1 = (inner_loop_count * 3) - 2
Drive2 = (inner_loop_count * 3)
templateVars["varDefault"] = f'{Drive1}-{Drive2}'
elif re.fullmatch('^Raid60$', RaidLevel):
Drive1 = (inner_loop_count * 4) - 3
Drive2 = (inner_loop_count * 4)
templateVars["varDefault"] = f'{Drive1}-{Drive2}'
templateVars["varInput"] = f'Enter the Drive Slots for Drive Array Span {span}. [{templateVars["varDefault"]}]:'
templateVars["varName"] = 'Drive Slots'
templateVars["varRegex"] = jsonVars['Slots']['pattern']
templateVars["minLength"] = 1
templateVars["maxLength"] = 10
SpanSlots.append({'slots':varStringLoop(**templateVars)})
elif re.fullmatch('^Raid(0|1|5|6)$', RaidLevel):
jsonVars = jsonData['components']['schemas']['storage.SpanDrives']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['Slots']['description']
if re.fullmatch('^Raid(0|1)$', RaidLevel):
Drive1 = (inner_loop_count * 2) - 1
Drive2 = (inner_loop_count * 2)
templateVars["varDefault"] = f'{Drive1}-{Drive2}'
elif re.fullmatch('^Raid5$', RaidLevel):
Drive1 = (inner_loop_count * 3) - 2
Drive2 = (inner_loop_count * 3)
templateVars["varDefault"] = f'{Drive1}-{Drive2}'
elif re.fullmatch('^Raid6$', RaidLevel):
Drive1 = (inner_loop_count * 4) - 3
Drive2 = (inner_loop_count * 4)
templateVars["varDefault"] = f'{Drive1}-{Drive2}'
templateVars["varInput"] = f'Enter the Drive Slots for Drive Array Span 0. [{templateVars["varDefault"]}]:'
templateVars["varName"] = 'Drive Slots'
templateVars["varRegex"] = jsonVars['Slots']['pattern']
templateVars["minLength"] = 1
templateVars["maxLength"] = 10
SpanSlots.append({'slots':varStringLoop(**templateVars)})
virtualDrives = []
sub_loop_count = 0
sub_loop = False
while sub_loop == False:
jsonVars = jsonData['components']['schemas']['storage.VirtualDriveConfiguration']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['Name']['description']
templateVars["varDefault"] = f'vd{sub_loop_count}'
templateVars["varInput"] = f'Enter the name of the Virtual Drive. [vd{sub_loop_count}]'
templateVars["varName"] = 'Drive Group Name'
templateVars["varRegex"] = jsonVars['Name']['pattern']
templateVars["minLength"] = 1
templateVars["maxLength"] = 60
vd_name = varStringLoop(**templateVars)
templateVars["Description"] = jsonVars['ExpandToAvailable']['description']
templateVars["varInput"] = f'Do you want to expand to all the space in the drive group?'
templateVars["varDefault"] = 'Y'
templateVars["varName"] = 'Expand To Available'
ExpandToAvailable = varBoolLoop(**templateVars)
# If Expand to Available is Disabled obtain Virtual Drive disk size
if ExpandToAvailable == False:
templateVars["Description"] = jsonVars['Size']['description']
templateVars["varDefault"] = '1'
templateVars["varInput"] = 'What is the Size for this Virtual Drive?'
templateVars["varName"] = 'Size'
templateVars["varRegex"] = '[0-9]+'
templateVars["minNum"] = jsonVars['Size']['minimum']
templateVars["maxNum"] = 9999999999
vdSize = varNumberLoop(**templateVars)
else:
vdSize = 1
templateVars["Description"] = jsonVars['BootDrive']['description']
templateVars["varInput"] = f'Do you want to configure {vd_name} as a boot drive?'
templateVars["varDefault"] = 'Y'
templateVars["varName"] = 'Boot Drive'
BootDrive = varBoolLoop(**templateVars)
jsonVars = jsonData['components']['schemas']['storage.VirtualDrivePolicy']['allOf'][1]['properties']
templateVars["var_description"] = jsonVars['AccessPolicy']['description']
templateVars["jsonVars"] = sorted(jsonVars['AccessPolicy']['enum'])
templateVars["defaultVar"] = jsonVars['AccessPolicy']['default']
templateVars["varType"] = 'Access Policy'
AccessPolicy = variablesFromAPI(**templateVars)
templateVars["var_description"] = jsonVars['DriveCache']['description']
templateVars["jsonVars"] = sorted(jsonVars['DriveCache']['enum'])
templateVars["defaultVar"] = jsonVars['DriveCache']['default']
templateVars["varType"] = 'Drive Cache'
DriveCache = variablesFromAPI(**templateVars)
templateVars["var_description"] = jsonVars['ReadPolicy']['description']
templateVars["jsonVars"] = sorted(jsonVars['ReadPolicy']['enum'])
templateVars["defaultVar"] = jsonVars['ReadPolicy']['default']
templateVars["varType"] = 'Read Policy'
ReadPolicy = variablesFromAPI(**templateVars)
templateVars["var_description"] = jsonVars['StripSize']['description']
templateVars["jsonVars"] = sorted(jsonVars['StripSize']['enum'])
templateVars["defaultVar"] = jsonVars['StripSize']['default']
templateVars["varType"] = 'Strip Size'
StripSize = variablesFromAPI(**templateVars)
templateVars["var_description"] = jsonVars['WritePolicy']['description']
templateVars["jsonVars"] = sorted(jsonVars['WritePolicy']['enum'])
templateVars["defaultVar"] = jsonVars['WritePolicy']['default']
templateVars["varType"] = 'Write Policy'
WritePolicy = variablesFromAPI(**templateVars)
virtual_drive = {
'access_policy':AccessPolicy,
'boot_drive':BootDrive,
'disk_cache':DriveCache,
'expand_to_available':ExpandToAvailable,
'name':vd_name,
'read_policy':ReadPolicy,
'size':vdSize,
'strip_size':StripSize,
'write_policy':WritePolicy,
}
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' "{virtual_drive["name"]}" = ''{')
print(f' access_policy = "{virtual_drive["access_policy"]}"')
print(f' boot_drive = {virtual_drive["boot_drive"]}')
print(f' disk_cache = "{virtual_drive["disk_cache"]}"')
print(f' expand_to_available = {virtual_drive["expand_to_available"]}')
print(f' read_policy = "{virtual_drive["read_policy"]}"')
print(f' size = {virtual_drive["size"]}')
print(f' strip_size = "{virtual_drive["strip_size"]}"')
print(f' write_policy = "{virtual_drive["write_policy"]}"')
print(f' ''}')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid_confirm = False
while valid_confirm == False:
confirm_v = input('Do you want to accept the above configuration? Enter "Y" or "N" [Y]: ')
if confirm_v == 'Y' or confirm_v == '':
virtualDrives.append(virtual_drive)
valid_exit = False
while valid_exit == False:
loop_exit = input(f'Would You like to Configure another Virtual Drive for {dgName}? Enter "Y" or "N" [N]: ')
if loop_exit == 'Y':
inner_loop_count += 1
valid_confirm = True
valid_exit = True
elif loop_exit == 'N' or loop_exit == '':
drive_group_loop = True
valid_confirm = True
valid_exit = True
else:
print(f'\n------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please enter "Y" or "N".')
print(f'\n------------------------------------------------------\n')
elif confirm_v == 'N':
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Starting Virtual Drive Configuration 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')
drive_group = {
'drive_group_name':dgName,
'manual_drive_selection':{
'dedicated_hot_spares':DedicatedHotSpares,
'drive_array_spans':[
SpanSlots
]
},
'raid_level':RaidLevel,
'virtual_drives':virtualDrives
}
dg_count = 0
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' "{drive_group["drive_group_name"]}" = ''{')
print(f' manual_drive_group = ''{')
print(f' "{dg_count}" = ''{')
print(f' dedicated_hot_spares = "{drive_group["manual_drive_group"]["dedicated_hot_spares"]}"')
print(f' drive_array_spans = ''{')
span_count = 0
for i in drive_group["manual_drive_group"]["drive_array_spans"]:
print(f' "span_{span_count}" = ''{slots = "'f'{i["slots"]}"''}')
span_count += 1
print(f' ''}')
print(f' ''}')
print(f' ''}')
print(f' ''}')
print(f' ''}')
print(f' ''}')
print(f' raid_level = "{RaidLevel}"')
print(f' virtual_drives = ''{')
for virtual_drive in virtualDrives:
print(f' "{virtual_drive["name"]}" = ''{')
print(f' access_policy = "{virtual_drive["access_policy"]}"')
print(f' boot_drive = "{virtual_drive["boot_drive"]}"')
print(f' disk_cache = "{virtual_drive["disk_cache"]}"')
print(f' expand_to_available = {virtual_drive["expand_to_available"]}')
print(f' read_policy = "{virtual_drive["read_policy"]}"')
print(f' size = {virtual_drive["size"]}')
print(f' strip_size = "{virtual_drive["strip_size"]}"')
print(f' write_policy = "{virtual_drive["write_policy"]}"')
print(f' ''}')
print(f' ''}')
print(f' ''}')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid_confirm = False
while valid_confirm == False:
confirm_v = input('Do you want to accept the above configuration? Enter "Y" or "N" [Y]: ')
if confirm_v == 'Y' or confirm_v == '':
templateVars["drive_groups"].append(drive_group)
valid_exit = False
while valid_exit == False:
loop_exit = input(f'Would You like to Configure another Drive Group? Enter "Y" or "N" [N]: ')
if loop_exit == 'Y':
inner_loop_count += 1
valid_confirm = True
valid_exit = True
elif loop_exit == 'N' or loop_exit == '':
drive_group_loop = True
valid_confirm = True
valid_exit = True
else:
print(f'\n------------------------------------------------------\n')
print(f' Error!! Invalid Value. Please enter "Y" or "N".')
print(f'\n------------------------------------------------------\n')
elif confirm_v == 'N':
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Starting Drive Group Configuration 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')
else:
templateVars["drive_group"] = []
# Ask if M2 should be configured
templateVars["Description"] = jsonVars['M2VirtualDrive']['description']
templateVars["varInput"] = f'Do you want to Enable the M.2 Virtual Drive Configuration?'
templateVars["varDefault"] = 'Y'
templateVars["varName"] = 'M.2 Virtual Drive'
M2VirtualDrive = varBoolLoop(**templateVars)
# Configure M2 if it is True if not Pop it from the list
if M2VirtualDrive == True:
jsonVars = jsonData['components']['schemas']['storage.M2VirtualDriveConfig']['allOf'][1]['properties']
templateVars["var_description"] = jsonVars['ControllerSlot']['description']
templateVars["jsonVars"] = sorted(jsonVars['ControllerSlot']['enum'])
templateVars["defaultVar"] = 'MSTOR-RAID-1,MSTOR-RAID-2'
templateVars["varType"] = 'Controller Slot'
ControllerSlot = variablesFromAPI(**templateVars)
templateVars["m2_configuration"] = {
'controller_slot':ControllerSlot,
'enable':True
}
else:
templateVars.pop('m2_configuration')
# Ask if Drive Groups should be configured
templateVars["Description"] = 'Enable to create RAID0 virtual drives on each physical drive..'
templateVars["varInput"] = f"Do you want to Configure Single Drive RAID's?"
templateVars["varDefault"] = 'N'
templateVars["varName"] = 'Single Drive RAID'
singledriveRaid = varBoolLoop(**templateVars)
# If True configure Drive Groups
if singledriveRaid == True:
single_drive_loop = False
while single_drive_loop == False:
# Obtain the Single Drive Raid Slots
jsonVars = jsonData['components']['schemas']['storage.R0Drive']['allOf'][1]['properties']
templateVars["Description"] = jsonVars['DriveSlots']['description']
templateVars["varDefault"] = f'{Drive1}-{Drive2}'
templateVars["varInput"] = f'Enter the Drive Slots for Drive Array Span 0. [{templateVars["varDefault"]}]:'
templateVars["varName"] = 'Drive Slots'
templateVars["varRegex"] = jsonVars['DriveSlots']['pattern']
templateVars["minLength"] = 1
templateVars["maxLength"] = 64
DriveSlots = varStringLoop(**templateVars)
# Obtain the Virtual Drive Policies
jsonVars = jsonData['components']['schemas']['storage.VirtualDrivePolicy']['allOf'][1]['properties']
# Access Policy
templateVars["var_description"] = jsonVars['AccessPolicy']['description']
templateVars["jsonVars"] = sorted(jsonVars['AccessPolicy']['enum'])
templateVars["defaultVar"] = jsonVars['AccessPolicy']['default']
templateVars["varType"] = 'Access Policy'
AccessPolicy = variablesFromAPI(**templateVars)
# Drive Cache
templateVars["var_description"] = jsonVars['DriveCache']['description']
templateVars["jsonVars"] = sorted(jsonVars['DriveCache']['enum'])
templateVars["defaultVar"] = jsonVars['DriveCache']['default']
templateVars["varType"] = 'Drive Cache'
DriveCache = variablesFromAPI(**templateVars)
# Read Policy
templateVars["var_description"] = jsonVars['ReadPolicy']['description']
templateVars["jsonVars"] = sorted(jsonVars['ReadPolicy']['enum'])
templateVars["defaultVar"] = jsonVars['ReadPolicy']['default']
templateVars["varType"] = 'Read Policy'
ReadPolicy = variablesFromAPI(**templateVars)
# Strip Size
templateVars["var_description"] = jsonVars['StripSize']['description']
templateVars["jsonVars"] = sorted(jsonVars['StripSize']['enum'])
templateVars["defaultVar"] = jsonVars['StripSize']['default']
templateVars["varType"] = 'Strip Size'
StripSize = variablesFromAPI(**templateVars)
# Write Policy
templateVars["var_description"] = jsonVars['WritePolicy']['description']
templateVars["jsonVars"] = sorted(jsonVars['WritePolicy']['enum'])
templateVars["defaultVar"] = jsonVars['WritePolicy']['default']
templateVars["varType"] = 'Write Policy'
WritePolicy = variablesFromAPI(**templateVars)
templateVars["single_drive_raid_configuration"] = {
'access_policy':AccessPolicy,
'disk_cache':DriveCache,
'drive_slots':DriveSlots,
'enable':True,
'read_policy':ReadPolicy,
'strip_size':StripSize,
'write_policy':WritePolicy,
}
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' "0" = ''{')
print(f' access_policy = "{templateVars["single_drive_raid_configuration"]["access_policy"]}"')
print(f' disk_cache = "{templateVars["single_drive_raid_configuration"]["disk_cache"]}"')
print(f' drive_slots = "{templateVars["single_drive_raid_configuration"]["expand_to_available"]}"')
print(f' enable = {templateVars["single_drive_raid_configuration"]["enable"]}')
print(f' read_policy = "{templateVars["single_drive_raid_configuration"]["read_policy"]}"')
print(f' strip_size = "{templateVars["single_drive_raid_configuration"]["strip_size"]}"')
print(f' write_policy = "{templateVars["single_drive_raid_configuration"]["write_policy"]}"')
print(f' ''}')
print(f'\n-------------------------------------------------------------------------------------------\n')
valid_confirm = False
while valid_confirm == False:
confirm_v = input('Do you want to accept the above configuration? Enter "Y" or "N" [Y]: ')
if confirm_v == 'Y' or confirm_v == '':
single_drive_loop = True
valid_confirm = True
valid_exit = True
elif confirm_v == 'N':
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' Starting Single Drive RAID Configuration 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')
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' description = "{templateVars["descr"]}"')
print(f' global_hot_spares = "{templateVars["global_hot_spares"]}"')
print(f' unused_disks_state = "{templateVars["unused_disks_state"]}"')
print(f' use_jbod_for_vd_creation = "{templateVars["use_jbod_for_vd_creation"]}"')
dg_count = 0
if len(templateVars["drive_groups"]) > 0:
print(f' drive_groups = ''{')
for drive_group in templateVars["drive_groups"]:
print(f'\n-------------------------------------------------------------------------------------------\n')
print(f' "{drive_group["drive_group_name"]}" = ''{')
print(f' manual_drive_group = ''{')
print(f' "{dg_count}" = ''{')
print(f' dedicated_hot_spares = "{drive_group["manual_drive_group"]["dedicated_hot_spares"]}"')
print(f' drive_array_spans = ''{')
span_count = 0
for i in drive_group["manual_drive_group"]["drive_array_spans"]:
print(f' "span_{span_count}" = ''{slots = "'f'{i["slots"]}"''}')
span_count += 1
print(f' ''}')
print(f' ''}')
print(f' ''}')
print(f' ''}')
print(f' ''}')
print(f' ''}')
print(f' raid_level = "{RaidLevel}"')
print(f' virtual_drives = ''{')
for virtual_drive in virtualDrives:
print(f' "{virtual_drive["name"]}" = ''{')
print(f' access_policy = "{virtual_drive["access_policy"]}"')
print(f' boot_drive = "{virtual_drive["boot_drive"]}"')
print(f' disk_cache = "{virtual_drive["disk_cache"]}"')
print(f' expand_to_available = {virtual_drive["expand_to_available"]}')
print(f' read_policy = "{virtual_drive["read_policy"]}"')
print(f' size = {virtual_drive["size"]}')
print(f' strip_size = "{virtual_drive["strip_size"]}"')
print(f' write_policy = "{virtual_drive["write_policy"]}"')
print(f' ''}')
print(f' ''}')
print(f' ''}')
dg_count += 1
print(f' ''}')
else:
print(f' drive_groups = ''{}')
if templateVars.get("m2_configuration"):
print(f' m2_configuration = ''{')
print(f' "0" = ''{')
print(f' controller_slot = "{templateVars["m2_configuration"]["controller_slot"]}"')
print(f' ''}')
print(f' ''}')
else:
print(f' m2_configuration = ''{}')
if templateVars.get("single_drive_raid_configuration"):
print(f' single_drive_raid_configuration = ''{')
print(f' "0" = ''{')
print(f' access_policy = "{templateVars["single_drive_raid_configuration"]["access_policy"]}"')
print(f' disk_cache = "{templateVars["single_drive_raid_configuration"]["disk_cache"]}"')
print(f' drive_slots = "{templateVars["single_drive_raid_configuration"]["drive_slots"]}"')
print(f' enable = {templateVars["single_drive_raid_configuration"]["enable"]}')
print(f' read_policy = "{templateVars["single_drive_raid_configuration"]["read_policy"]}"')
print(f' strip_size = "{templateVars["single_drive_raid_configuration"]["strip_size"]}"')
print(f' write_policy = "{templateVars["single_drive_raid_configuration"]["write_policy"]}"')
print(f' ''}')
else:
print(f' single_drive_raid_configuration = ''{}')
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)
# Add Template Name to Policies Output
policy_names.append(templateVars["name"])
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)