Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/modules/dellemc_idrac_storage_volume.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Dell OpenManage Ansible Modules
6 # Version 7.1.0
7 # Copyright (C) 2019-2025 Dell Inc. or its subsidiaries. All Rights Reserved.
8
9 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
10 #
11
12
13 from __future__ import (absolute_import, division, print_function)
14 __metaclass__ = type
15
16 DOCUMENTATION = r'''
17 ---
18 module: dellemc_idrac_storage_volume
19 short_description: Configures the RAID configuration attributes
20 version_added: "2.0.0"
21 deprecated:
22 removed_at_date: "2026-03-31"
23 why: Replaced with M(dellemc.openmanage.idrac_storage_volume).
24 alternative: Use M(dellemc.openmanage.idrac_storage_volume) instead.
25 removed_from_collection: dellemc.openmanage
26 description:
27 - This module is responsible for configuring the RAID attributes.
28 extends_documentation_fragment:
29 - dellemc.openmanage.idrac_auth_options
30 options:
31 state:
32 type: str
33 description:
34 - C(create), performs create volume operation.
35 - C(delete), performs remove volume operation.
36 - C(view), returns storage view.
37 choices: ['create', 'delete', 'view']
38 default: 'view'
39 span_depth:
40 type: int
41 description:
42 - Number of spans in the RAID configuration.
43 - I(span_depth) is required for C(create) and its value depends on I(volume_type).
44 default: 1
45 span_length:
46 type: int
47 description:
48 - Number of disks in a span.
49 - I(span_length) is required for C(create) and its value depends on I(volume_type).
50 default: 1
51 number_dedicated_hot_spare:
52 type: int
53 description: Number of Dedicated Hot Spare.
54 default: 0
55 volume_type:
56 type: str
57 description: Provide the the required RAID level.
58 choices: ['RAID 0', 'RAID 1', 'RAID 5', 'RAID 6', 'RAID 10', 'RAID 50', 'RAID 60']
59 default: 'RAID 0'
60 disk_cache_policy:
61 type: str
62 description: Disk Cache Policy.
63 choices: ["Default", "Enabled", "Disabled"]
64 default: "Default"
65 write_cache_policy:
66 type: str
67 description: Write cache policy.
68 choices: ["WriteThrough", "WriteBack", "WriteBackForce"]
69 default: "WriteThrough"
70 read_cache_policy:
71 type: str
72 description: Read cache policy.
73 choices: ["NoReadAhead", "ReadAhead", "AdaptiveReadAhead"]
74 default: "NoReadAhead"
75 stripe_size:
76 type: int
77 description: Stripe size value to be provided in multiples of 64 * 1024.
78 default: 65536
79 controller_id:
80 type: str
81 description:
82 - >-
83 Fully Qualified Device Descriptor (FQDD) of the storage controller, for example 'RAID.Integrated.1-1'.
84 Controller FQDD is required for C(create) RAID configuration.
85 media_type:
86 type: str
87 description: Media type.
88 choices: ['HDD', 'SSD']
89 protocol:
90 type: str
91 description: Bus protocol.
92 choices: ['SAS', 'SATA']
93 volume_id:
94 type: str
95 description:
96 - >-
97 Fully Qualified Device Descriptor (FQDD) of the virtual disk, for example 'Disk.virtual.0:RAID.Slot.1-1'.
98 This option is used to get the virtual disk information.
99 volumes:
100 type: list
101 elements: dict
102 description:
103 - >-
104 A list of virtual disk specific iDRAC attributes. This is applicable for C(create) and C(delete) operations.
105 - >-
106 For C(create) operation, name and drives are applicable options, other volume options can also be specified.
107 - >-
108 The drives is a required option for C(create) operation and accepts either location (list of drive slot)
109 or id (list of drive fqdd).
110 - >-
111 For C(delete) operation, only name option is applicable.
112 - See the examples for more details.
113 capacity:
114 type: float
115 description: Virtual disk size in GB.
116 raid_reset_config:
117 type: str
118 description:
119 - >-
120 This option represents whether a reset config operation needs to be performed on the RAID controller.
121 Reset Config operation deletes all the virtual disks present on the RAID controller.
122 choices: ['True', 'False']
123 default: 'False'
124 raid_init_operation:
125 type: str
126 description: This option represents initialization configuration operation to be performed on the virtual disk.
127 choices: [None, Fast]
128
129 requirements:
130 - "omsdk >= 1.2.488"
131 - "python >= 3.9.6"
132 author: "Felix Stephen (@felixs88)"
133 notes:
134 - Run this module from a system that has direct access to Dell iDRAC.
135 - This module supports both IPv4 and IPv6 address for I(idrac_ip).
136 - This module supports C(check_mode).
137 '''
138
139 EXAMPLES = r'''
140 ---
141 - name: Create single volume
142 dellemc.openmanage.dellemc_idrac_storage_volume:
143 idrac_ip: "192.168.0.1"
144 idrac_user: "username"
145 idrac_password: "password"
146 ca_path: "/path/to/ca_cert.pem"
147 state: "create"
148 controller_id: "RAID.Slot.1-1"
149 volumes:
150 - drives:
151 location: [5]
152
153 - name: Create multiple volume
154 dellemc.openmanage.dellemc_idrac_storage_volume:
155 idrac_ip: "192.168.0.1"
156 idrac_user: "username"
157 idrac_password: "password"
158 ca_path: "/path/to/ca_cert.pem"
159 raid_reset_config: "True"
160 state: "create"
161 controller_id: "RAID.Slot.1-1"
162 volume_type: "RAID 1"
163 span_depth: 1
164 span_length: 2
165 number_dedicated_hot_spare: 1
166 disk_cache_policy: "Enabled"
167 write_cache_policy: "WriteBackForce"
168 read_cache_policy: "ReadAhead"
169 stripe_size: 65536
170 capacity: 100
171 raid_init_operation: "Fast"
172 volumes:
173 - name: "volume_1"
174 drives:
175 id: ["Disk.Bay.1:Enclosure.Internal.0-1:RAID.Slot.1-1", "Disk.Bay.2:Enclosure.Internal.0-1:RAID.Slot.1-1"]
176 - name: "volume_2"
177 volume_type: "RAID 5"
178 span_length: 3
179 span_depth: 1
180 drives:
181 location: [7, 3, 5]
182 disk_cache_policy: "Disabled"
183 write_cache_policy: "WriteBack"
184 read_cache_policy: "NoReadAhead"
185 stripe_size: 131072
186 capacity: "200"
187 raid_init_operation: "None"
188
189 - name: View all volume details
190 dellemc.openmanage.dellemc_idrac_storage_volume:
191 idrac_ip: "192.168.0.1"
192 idrac_user: "username"
193 idrac_password: "password"
194 ca_path: "/path/to/ca_cert.pem"
195 state: "view"
196
197 - name: View specific volume details
198 dellemc.openmanage.dellemc_idrac_storage_volume:
199 idrac_ip: "192.168.0.1"
200 idrac_user: "username"
201 idrac_password: "password"
202 ca_path: "/path/to/ca_cert.pem"
203 state: "view"
204 controller_id: "RAID.Slot.1-1"
205 volume_id: "Disk.Virtual.0:RAID.Slot.1-1"
206
207 - name: Delete single volume
208 dellemc.openmanage.dellemc_idrac_storage_volume:
209 idrac_ip: "192.168.0.1"
210 idrac_user: "username"
211 idrac_password: "password"
212 ca_path: "/path/to/ca_cert.pem"
213 state: "delete"
214 volumes:
215 - name: "volume_1"
216
217 - name: Delete multiple volume
218 dellemc.openmanage.dellemc_idrac_storage_volume:
219 idrac_ip: "192.168.0.1"
220 idrac_user: "username"
221 idrac_password: "password"
222 ca_path: "/path/to/ca_cert.pem"
223 state: "delete"
224 volumes:
225 - name: "volume_1"
226 - name: "volume_2"
227 '''
228
229 RETURN = r'''
230 ---
231 msg:
232 type: str
233 description: Overall status of the storage configuration operation.
234 returned: always
235 sample: "Successfully completed the view storage volume operation"
236 storage_status:
237 type: dict
238 description: Storage configuration job and progress details from the iDRAC.
239 returned: success
240 sample:
241 {
242 "Id": "JID_XXXXXXXXX",
243 "JobState": "Completed",
244 "JobType": "ImportConfiguration",
245 "Message": "Successfully imported and applied Server Configuration Profile.",
246 "MessageId": "XXX123",
247 "Name": "Import Configuration",
248 "PercentComplete": 100,
249 "StartTime": "TIME_NOW",
250 "Status": "Success",
251 "TargetSettingsURI": null,
252 "retval": true
253 }
254 '''
255
256
257 import os
258 import tempfile
259 import copy
260 from ansible_collections.dellemc.openmanage.plugins.module_utils.dellemc_idrac import iDRACConnection, idrac_auth_params
261 from ansible.module_utils.basic import AnsibleModule
262 try:
263 from omdrivers.types.iDRAC.RAID import RAIDactionTypes, RAIDdefaultReadPolicyTypes, RAIDinitOperationTypes, \
264 DiskCachePolicyTypes, RAIDresetConfigTypes
265 from omsdk.sdkfile import file_share_manager
266 except ImportError:
267 pass
268
269
270 def error_handling_for_negative_num(option, val):
271 return "{0} cannot be a negative number or zero,got {1}".format(option, val)
272
273
274 def set_liason_share(idrac, module):
275 idrac.use_redfish = True
276 share_name = tempfile.gettempdir() + os.sep
277 storage_share = file_share_manager.create_share_obj(share_path=share_name,
278 isFolder=True)
279 set_liason = idrac.config_mgr.set_liason_share(storage_share)
280 if set_liason['Status'] == "Failed":
281 liason_data = set_liason.get('Data', set_liason)
282 module.fail_json(msg=liason_data.get('Message', "Failed to set Liason share"))
283
284
285 def view_storage(idrac, module):
286 idrac.get_entityjson()
287 storage_status = idrac.config_mgr.RaidHelper.view_storage(controller=module.params["controller_id"],
288 virtual_disk=module.params['volume_id'])
289 if storage_status['Status'] == 'Failed':
290 module.fail_json(msg="Failed to fetch storage details", storage_status=storage_status)
291 return storage_status
292
293
294 def create_storage(idrac, module):
295 pd_filter = '((disk.parent.parent is Controller and ' \
296 'disk.parent.parent.FQDD._value == "{0}")' \
297 .format(module.params["controller_id"])
298 pd_filter += ' or (disk.parent is Controller and ' \
299 'disk.parent.FQDD._value == "{0}"))' \
300 .format(module.params["controller_id"])
301
302 vd_values = []
303 if module.params['volumes'] is not None:
304 for each in module.params['volumes']:
305 mod_args = copy.deepcopy(module.params)
306 each_vd = multiple_vd_config(mod_args=mod_args,
307 each_vd=each, pd_filter=pd_filter)
308 vd_values.append(each_vd)
309 else:
310 each_vd = multiple_vd_config(mod_args=module.params,
311 pd_filter=pd_filter)
312 vd_values.append(each_vd)
313 storage_status = idrac.config_mgr.RaidHelper.new_virtual_disk(multiple_vd=vd_values,
314 apply_changes=not module.check_mode)
315 return storage_status
316
317
318 def delete_storage(idrac, module):
319 names = [key.get("name") for key in module.params['volumes']]
320 storage_status = idrac.config_mgr.RaidHelper.delete_virtual_disk(vd_names=names,
321 apply_changes=not module.check_mode)
322 return storage_status
323
324
325 def _validate_options(options):
326 if options['state'] == "create":
327 if options["controller_id"] is None or options["controller_id"] == "":
328 raise ValueError('Controller ID is required.')
329 capacity = options.get("capacity")
330 if capacity is not None:
331 size_check = float(capacity)
332 if size_check <= 0:
333 raise ValueError(error_handling_for_negative_num("capacity", capacity))
334 stripe_size = options.get('stripe_size')
335 if stripe_size is not None:
336 stripe_size_check = int(stripe_size)
337 if stripe_size_check <= 0:
338 raise ValueError(error_handling_for_negative_num("stripe_size", stripe_size))
339 # validating for each vd options
340 if options['volumes'] is not None:
341 for each in options['volumes']:
342 drives = each.get("drives")
343 if drives:
344 if "id" in drives and "location" in drives:
345 raise ValueError("Either {0} or {1} is allowed".format("id", "location"))
346 elif "id" not in drives and "location" not in drives:
347 raise ValueError("Either {0} or {1} should be specified".format("id", "location"))
348 else:
349 raise ValueError("Drives must be defined for volume creation.")
350 capacity = each.get("capacity")
351 if capacity is not None:
352 size_check = float(capacity)
353 if size_check <= 0:
354 raise ValueError(error_handling_for_negative_num("capacity", capacity))
355 stripe_size = each.get('stripe_size')
356 if stripe_size is not None:
357 stripe_size_check = int(stripe_size)
358 if stripe_size_check <= 0:
359 raise ValueError(error_handling_for_negative_num("stripe_size", stripe_size))
360 elif options['state'] == "delete":
361 message = "Virtual disk name is a required parameter for remove virtual disk operations."
362 if options['volumes'] is None or None in options['volumes']:
363 raise ValueError(message)
364 elif options['volumes']:
365 if not all("name" in each for each in options['volumes']):
366 raise ValueError(message)
367
368
369 def multiple_vd_config(mod_args=None, pd_filter="", each_vd=None):
370 if mod_args is None:
371 mod_args = {}
372 if each_vd is None:
373 each_vd = {}
374 if each_vd:
375 mod_args.update(each_vd)
376 disk_size = None
377 location_list = []
378 id_list = []
379 size = mod_args.get("capacity")
380 drives = mod_args.get("drives")
381 if drives:
382 if "location" in drives:
383 location_list = drives.get("location")
384 elif "id" in drives:
385 id_list = drives.get("id")
386 if size is not None:
387 size_check = float(size)
388 disk_size = "{0}".format(int(size_check * 1073741824))
389
390 if mod_args['media_type'] is not None:
391 pd_filter += ' and disk.MediaType == "{0}"'.format(mod_args['media_type'])
392 if mod_args["protocol"] is not None:
393 pd_filter += ' and disk.BusProtocol == "{0}"'.format(mod_args["protocol"])
394 pd_selection = pd_filter
395
396 if location_list:
397 slots = ""
398 for i in location_list:
399 slots += "\"" + str(i) + "\","
400 slots_list = "[" + slots[0:-1] + "]"
401 pd_selection += " and disk.Slot._value in " + slots_list
402 elif id_list:
403 pd_selection += " and disk.FQDD._value in " + str(id_list)
404
405 raid_init_operation, raid_reset_config = "None", "False"
406 if mod_args['raid_init_operation'] == "None":
407 raid_init_operation = RAIDinitOperationTypes.T_None
408 if mod_args['raid_init_operation'] == "Fast":
409 raid_init_operation = RAIDinitOperationTypes.Fast
410
411 if mod_args['raid_reset_config'] == "False":
412 raid_reset_config = RAIDresetConfigTypes.T_False
413 if mod_args['raid_reset_config'] == "True":
414 raid_reset_config = RAIDresetConfigTypes.T_True
415
416 vd_value = dict(
417 Name=mod_args.get("name"),
418 SpanDepth=int(mod_args['span_depth']),
419 SpanLength=int(mod_args['span_length']),
420 NumberDedicatedHotSpare=int(mod_args['number_dedicated_hot_spare']),
421 RAIDTypes=mod_args["volume_type"],
422 DiskCachePolicy=DiskCachePolicyTypes[mod_args['disk_cache_policy']],
423 RAIDdefaultWritePolicy=mod_args['write_cache_policy'],
424 RAIDdefaultReadPolicy=RAIDdefaultReadPolicyTypes[mod_args['read_cache_policy']],
425 StripeSize=int(mod_args['stripe_size']),
426 RAIDforeignConfig="Clear",
427 RAIDaction=RAIDactionTypes.Create,
428 PhysicalDiskFilter=pd_selection,
429 Size=disk_size,
430 RAIDresetConfig=raid_reset_config,
431 RAIDinitOperation=raid_init_operation,
432 PDSlots=location_list,
433 ControllerFQDD=mod_args.get("controller_id"),
434 mediatype=mod_args['media_type'],
435 busprotocol=mod_args["protocol"],
436 FQDD=id_list
437 )
438 return vd_value
439
440
441 def run_server_raid_config(idrac, module):
442 if module.params['state'] == "view":
443 storage_status = view_storage(idrac, module)
444 if module.params['state'] == "create":
445 set_liason_share(idrac, module)
446 storage_status = create_storage(idrac, module)
447 if module.params['state'] == "delete":
448 set_liason_share(idrac, module)
449 storage_status = delete_storage(idrac, module)
450 return storage_status
451
452
453 def main():
454 specs = {
455 "state": {"required": False, "choices": ['create', 'delete', 'view'], "default": 'view'},
456 "volume_id": {"required": False, "type": 'str'},
457 "volumes": {"required": False, "type": 'list', "elements": 'dict'},
458 "span_depth": {"required": False, "type": 'int', "default": 1},
459 "span_length": {"required": False, "type": 'int', "default": 1},
460 "number_dedicated_hot_spare": {"required": False, "type": 'int', "default": 0},
461 "volume_type": {"required": False,
462 "choices": ['RAID 0', 'RAID 1', 'RAID 5', 'RAID 6', 'RAID 10', 'RAID 50', 'RAID 60'],
463 "default": 'RAID 0'},
464 "disk_cache_policy": {"required": False, "choices": ["Default", "Enabled", "Disabled"],
465 "default": "Default"},
466 "write_cache_policy": {"required": False, "choices": ["WriteThrough", "WriteBack", "WriteBackForce"],
467 "default": "WriteThrough"},
468 "read_cache_policy": {"required": False, "choices": ["NoReadAhead", "ReadAhead", "AdaptiveReadAhead"],
469 "default": "NoReadAhead"},
470 "stripe_size": {"required": False, "type": 'int', "default": 64 * 1024},
471 "capacity": {"required": False, "type": 'float'},
472 "controller_id": {"required": False, "type": 'str'},
473 "media_type": {"required": False, "choices": ['HDD', 'SSD']},
474 "protocol": {"required": False, "choices": ['SAS', 'SATA']},
475 "raid_reset_config": {"required": False, "choices": ['True', 'False'], "default": 'False'},
476 "raid_init_operation": {"required": False, "choices": ['None', 'Fast']}
477 }
478 specs.update(idrac_auth_params)
479 module = AnsibleModule(
480 argument_spec=specs,
481 supports_check_mode=True)
482
483 try:
484 _validate_options(module.params)
485 with iDRACConnection(module.params) as idrac:
486 storage_status = run_server_raid_config(idrac, module)
487 changed = False
488 if 'changes_applicable' in storage_status:
489 changed = storage_status['changes_applicable']
490 elif module.params['state'] != 'view':
491 if storage_status.get("Status", "") == "Success":
492 changed = True
493 if storage_status.get("Message", "") == "No changes found to commit!" \
494 or storage_status.get("Message", "") == "Unable to find the virtual disk":
495 changed = False
496 module.exit_json(msg=storage_status.get('Message', ""),
497 changed=changed, storage_status=storage_status)
498 elif storage_status.get("Status") == "Failed":
499 module.fail_json(msg=storage_status.get("Message"))
500 else:
501 module.fail_json(msg="Failed to perform storage operation")
502 except (ImportError, ValueError, RuntimeError, TypeError) as e:
503 module.fail_json(msg=str(e))
504 msg = "Successfully completed the {0} storage volume operation".format(module.params['state'])
505 if module.check_mode and module.params['state'] != 'view':
506 msg = storage_status.get("Message", "")
507 module.exit_json(msg=msg, changed=changed, storage_status=storage_status)
508
509
510 if __name__ == '__main__':
511 main()