Debian Codegraph @

ansible_collections/dellemc/unity/plugins/modules/storagepool.py

raw symbols SCIP
1 #!/usr/bin/python
2 # Copyright: (c) 2020-2025, Dell Technologies
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 """Ansible module for managing storage pool on Unity"""
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11 DOCUMENTATION = r'''
12 module: storagepool
13 version_added: '1.1.0'
14 short_description: Manage storage pool on Unity
15 description:
16 - Managing storage pool on Unity storage system contains the operations
17 Get details of storage pool,
18 Create a storage pool,
19 Modify storage pool.
20
21 extends_documentation_fragment:
22 - dellemc.unity.unity
23
24 author:
25 - Ambuj Dubey (@AmbujDube) <[email protected]>
26
27 options:
28 pool_name:
29 description:
30 - Name of the storage pool, unique in the storage system.
31 type: str
32
33 pool_id:
34 description:
35 - Unique identifier of the pool instance.
36 type: str
37
38 new_pool_name:
39 description:
40 - New name of the storage pool, unique in the storage system.
41 type: str
42
43 pool_description:
44 description:
45 - The description of the storage pool.
46 type: str
47
48 fast_cache:
49 description:
50 - Indicates whether the fast cache is enabled for the storage pool.
51 - C(Enabled) - FAST Cache is enabled for the pool.
52 - C(Disabled) - FAST Cache is disabled for the pool.
53 choices: [enabled, disabled]
54 type: str
55
56 fast_vp:
57 description:
58 - Indicates whether to enable scheduled data relocations for the pool.
59 - C(Enabled) - Enabled scheduled data relocations for the pool.
60 - C(Disabled) - Disabled scheduled data relocations for the pool.
61 choices: [enabled, disabled]
62 type: str
63
64 raid_groups:
65 description:
66 - Parameters to create RAID group from the disks and add it to the pool.
67 type: dict
68 suboptions:
69 disk_group_id:
70 description:
71 - Id of the disk group.
72 type: str
73
74 disk_num:
75 description:
76 - Number of disks.
77 type: int
78
79 raid_type:
80 description:
81 - RAID group types or RAID levels.
82 choices: [None, RAID5, RAID0, RAID1, RAID3, RAID10, RAID6, Mixed, Automatic]
83 type: str
84
85 stripe_width :
86 description:
87 - RAID group stripe widths, including parity or mirror disks.
88 choices: ['BEST_FIT', '2', '4', '5', '6', '8', '9', '10', '12', '13', '14', '16']
89 type: str
90
91 alert_threshold:
92 description:
93 - Threshold at which the system will generate alerts about the free space in the pool, specified as a percentage.
94 - Minimum threshold limit is 50.
95 - Maximum threshold limit is 84.
96 type: int
97
98 is_harvest_enabled:
99 description:
100 - Enable/Disable automatic deletion of snapshots based on pool space usage.
101 type: bool
102
103 pool_harvest_high_threshold:
104 description:
105 - Max threshold for space used in pool beyond which the system automatically starts deleting snapshots in the pool.
106 - Applies when the automatic deletion of snapshots based on pool space usage is enabled for the system and pool.
107 - Minimum pool harvest high threshold value is 1.
108 - Maximum pool harvest high threshold value is 99.
109 type: float
110
111 pool_harvest_low_threshold:
112 description:
113 - Min threshold for space used in pool below which the system automatically stops deletion of snapshots in the pool.
114 - Applies when the automatic deletion of snapshots based on pool space usage is enabled for the system and pool.
115 - Minimum pool harvest low threshold value is 0.
116 - Maximum pool harvest low threshold value is 98.
117 type: float
118
119 is_snap_harvest_enabled:
120 description:
121 - Enable/Disable automatic deletion of snapshots based on pool space usage.
122 type: bool
123
124 snap_harvest_high_threshold:
125 description:
126 - Max threshold for space used in snapshot beyond which the system automatically starts deleting snapshots in the pool.
127 - Applies when the automatic deletion of snapshots based on pool space usage is enabled for the pool.
128 - Minimum snap harvest high threshold value is 1.
129 - Maximum snap harvest high threshold value is 99.
130 type: float
131
132 snap_harvest_low_threshold:
133 description:
134 - Min threshold for space used in snapshot below which the system will stop automatically deleting snapshots in the pool.
135 - Applies when the automatic deletion of snapshots based on pool space usage is enabled for the pool.
136 - Minimum snap harvest low threshold value is 0.
137 - Maximum snap harvest low threshold value is 98.
138 type: float
139
140 pool_type:
141 description:
142 - Indicates storage pool type.
143 choices: [TRADITIONAL, DYNAMIC]
144 type: str
145
146 state:
147 description:
148 - Define whether the storage pool should exist or not.
149 - C(Present) - indicates that the storage pool should exist on the system.
150 - C(Absent) - indicates that the storage pool should not exist on the system.
151 choices: [absent, present]
152 type: str
153 required: true
154
155 notes:
156 - Deletion of storage pool is not allowed through Ansible module.
157 - The I(check_mode) is not supported.
158 '''
159
160 EXAMPLES = r'''
161 - name: Get Storage pool details using pool_name
162 storagepool:
163 unispherehost: "{{unispherehost}}"
164 username: "{{username}}"
165 password: "{{password}}"
166 validate_certs: "{{validate_certs}}"
167 pool_name: "{{pool_name}}"
168 state: "present"
169
170 - name: Get Storage pool details using pool_id
171 storagepool:
172 unispherehost: "{{unispherehost}}"
173 username: "{{username}}"
174 password: "{{password}}"
175 validate_certs: "{{validate_certs}}"
176 pool_id: "{{pool_id}}"
177 state: "present"
178
179 - name: Modify Storage pool attributes using pool_name
180 storagepool:
181 unispherehost: "{{unispherehost}}"
182 username: "{{username}}"
183 password: "{{password}}"
184 validate_certs: "{{validate_certs}}"
185 pool_name: "{{pool_name}}"
186 new_pool_name: "{{new_pool_name}}"
187 pool_description: "{{pool_description}}"
188 fast_cache: "{{fast_cache_enabled}}"
189 fast_vp: "{{fast_vp_enabled}}"
190 state: "present"
191
192 - name: Modify Storage pool attributes using pool_id
193 storagepool:
194 unispherehost: "{{unispherehost}}"
195 username: "{{username}}"
196 password: "{{password}}"
197 validate_certs: "{{validate_certs}}"
198 pool_id: "{{pool_id}}"
199 new_pool_name: "{{new_pool_name}}"
200 pool_description: "{{pool_description}}"
201 fast_cache: "{{fast_cache_enabled}}"
202 fast_vp: "{{fast_vp_enabled}}"
203 state: "present"
204
205 - name: Create a StoragePool
206 storagepool:
207 unispherehost: "{{unispherehost}}"
208 username: "{{username}}"
209 password: "{{password}}"
210 validate_certs: "{{validate_certs}}"
211 pool_name: "Test"
212 pool_description: "test pool"
213 raid_groups:
214 disk_group_id: "dg_16"
215 disk_num: 2
216 raid_type: "RAID10"
217 stripe_width: "BEST_FIT"
218 alert_threshold: 50
219 is_harvest_enabled: true
220 pool_harvest_high_threshold: 60
221 pool_harvest_low_threshold: 40
222 is_snap_harvest_enabled: true
223 snap_harvest_high_threshold: 70
224 snap_harvest_low_threshold: 50
225 fast_vp: "enabled"
226 fast_cache: "enabled"
227 pool_type: "DYNAMIC"
228 state: "present"
229 '''
230
231 RETURN = r'''
232 changed:
233 description: Whether or not the storage pool has changed.
234 returned: always
235 type: bool
236 sample: true
237
238 storage_pool_details:
239 description: The storage pool details.
240 returned: When storage pool exists.
241 type: dict
242 contains:
243 id:
244 description: Pool id, unique identifier of the pool.
245 type: str
246 name:
247 description: Pool name, unique in the storage system.
248 type: str
249 is_fast_cache_enabled:
250 description: Indicates whether the fast cache is enabled for the storage
251 pool.
252 true - FAST Cache is enabled for the pool.
253 false - FAST Cache is disabled for the pool.
254 type: bool
255 is_fast_vp_enabled:
256 description: Indicates whether to enable scheduled data relocations
257 for the storage pool.
258 true - Enabled scheduled data relocations for the pool.
259 false - Disabled scheduled data relocations for the pool.
260 type: bool
261 size_free_with_unit:
262 description: Indicates size_free with its appropriate unit
263 in human readable form.
264 type: str
265 size_subscribed_with_unit:
266 description: Indicates size_subscribed with its appropriate unit in
267 human readable form.
268 type: str
269 size_total_with_unit:
270 description: Indicates size_total with its appropriate unit in human
271 readable form.
272 type: str
273 size_used_with_unit:
274 description: Indicates size_used with its appropriate unit in human
275 readable form.
276 type: str
277 snap_size_subscribed_with_unit:
278 description: Indicates snap_size_subscribed with its
279 appropriate unit in human readable form.
280 type: str
281 snap_size_used_with_unit:
282 description: Indicates snap_size_used with its
283 appropriate unit in human readable form.
284 type: str
285 drives:
286 description: Indicates information about the drives
287 associated with the storage pool.
288 type: list
289 contains:
290 id:
291 description: Unique identifier of the drive.
292 type: str
293 name:
294 description: Indicates name of the drive.
295 type: str
296 size:
297 description: Indicates size of the drive.
298 type: str
299 disk_technology:
300 description: Indicates disk technology of the drive.
301 type: str
302 tier_type:
303 description: Indicates tier type of the drive.
304 type: str
305 sample: {
306 "alert_threshold": 50,
307 "creation_time": "2022-03-08 14:05:32+00:00",
308 "description": "",
309 "drives": [
310 {
311 "disk_technology": "SAS",
312 "id": "dpe_disk_22",
313 "name": "DPE Drive 22",
314 "size": 590860984320,
315 "tier_type": "PERFORMANCE"
316 },
317 {
318 "disk_technology": "SAS",
319 "id": "dpe_disk_23",
320 "name": "DPE Drive 23",
321 "size": 590860984320,
322 "tier_type": "PERFORMANCE"
323 },
324 {
325 "disk_technology": "SAS",
326 "id": "dpe_disk_24",
327 "name": "DPE Drive 24",
328 "size": 590860984320,
329 "tier_type": "PERFORMANCE"
330 }
331 ],
332 "existed": true,
333 "harvest_state": "UsageHarvestStateEnum.IDLE",
334 "hash": 8744642897210,
335 "health": {
336 "UnityHealth": {
337 "hash": 8744642799842
338 }
339 },
340 "id": "pool_280",
341 "is_all_flash": false,
342 "is_empty": false,
343 "is_fast_cache_enabled": false,
344 "is_fast_vp_enabled": false,
345 "is_harvest_enabled": true,
346 "is_snap_harvest_enabled": true,
347 "metadata_size_subscribed": 105763569664,
348 "metadata_size_used": 57176752128,
349 "name": "test_pool",
350 "object_id": 12884902146,
351 "pool_fast_vp": {
352 "UnityPoolFastVp": {
353 "hash": 8744647518980
354 }
355 },
356 "pool_space_harvest_high_threshold": 59.0,
357 "pool_space_harvest_low_threshold": 40.0,
358 "pool_type": "StoragePoolTypeEnum.DYNAMIC",
359 "raid_type": "RaidTypeEnum.RAID10",
360 "rebalance_progress": null,
361 "size_free": 470030483456,
362 "size_free_with_unit": "437.75 GB",
363 "size_subscribed": 447215820800,
364 "size_subscribed_with_unit": "416.5 GB",
365 "size_total": 574720311296,
366 "size_total_with_unit": "535.25 GB",
367 "size_used": 76838068224,
368 "size_used_with_unit": "71.56 GB",
369 "snap_size_subscribed": 128851369984,
370 "snap_size_subscribed_with_unit": "120.0 GB",
371 "snap_size_used": 2351104,
372 "snap_size_used_with_unit": "2.24 MB",
373 "snap_space_harvest_high_threshold": 80.0,
374 "snap_space_harvest_low_threshold": 60.0,
375 "tiers": {
376 "UnityPoolTierList": [
377 {
378 "disk_count": [
379 0,
380 3,
381 0
382 ],
383 "existed": true,
384 "hash": 8744643017382,
385 "name": [
386 "Extreme Performance",
387 "Performance",
388 "Capacity"
389 ],
390 "pool_units": [
391 null,
392 {
393 "UnityPoolUnitList": [
394 {
395 "UnityPoolUnit": {
396 "hash": 8744642786759,
397 "id": "rg_4"
398 }
399 },
400 {
401 "UnityPoolUnit": {
402 "hash": 8744642786795,
403 "id": "rg_5"
404 }
405 }
406 ]
407 },
408 null
409 ],
410 "raid_type": [
411 "RaidTypeEnum.NONE",
412 "RaidTypeEnum.RAID10",
413 "RaidTypeEnum.NONE"
414 ],
415 "size_free": [
416 0,
417 470030483456,
418 0
419 ],
420 "size_moving_down": [
421 0,
422 0,
423 0
424 ],
425 "size_moving_up": [
426 0,
427 0,
428 0
429 ],
430 "size_moving_within": [
431 0,
432 0,
433 0
434 ],
435 "size_total": [
436 0,
437 574720311296,
438 0
439 ],
440 "size_used": [
441 0,
442 104689827840,
443 0
444 ],
445 "stripe_width": [
446 null,
447 "RaidStripeWidthEnum._2",
448 null
449 ],
450 "tier_type": [
451 "TierTypeEnum.EXTREME_PERFORMANCE",
452 "TierTypeEnum.PERFORMANCE",
453 "TierTypeEnum.CAPACITY"
454 ]
455 }
456 ]
457 }
458 }
459
460 '''
461
462 from ansible.module_utils.basic import AnsibleModule
463 from ansible_collections.dellemc.unity.plugins.module_utils.storage.dell \
464 import utils
465
466 LOG = utils.get_logger('storagepool')
467
468 application_type = "Ansible/1.7.1"
469
470
471 class StoragePool(object):
472 """Class with storage pool operations"""
473
474 def __init__(self):
475 """ Define all parameters required by this module"""
476 self.module_params = utils.get_unity_management_host_parameters()
477 self.module_params.update(get_storagepool_parameters())
478
479 mutually_exclusive = [['pool_name', 'pool_id']]
480 required_one_of = [['pool_name', 'pool_id']]
481
482 # initialize the Ansible module
483 self.module = AnsibleModule(argument_spec=self.module_params,
484 supports_check_mode=False,
485 mutually_exclusive=mutually_exclusive,
486 required_one_of=required_one_of)
487 utils.ensure_required_libs(self.module)
488
489 self.conn = utils.\
490 get_unity_unisphere_connection(self.module.params, application_type)
491
492 def get_details(self, pool_id=None, pool_name=None):
493 """ Get storage pool details"""
494 try:
495 api_response = self.conn.get_pool(_id=pool_id, name=pool_name)
496 details = api_response._get_properties()
497 if details['existed'] is False:
498 self.module.exit_json(msg="Pool does not exist", failed=True)
499 is_fast_vp_enabled = api_response._get_property_from_raw(
500 'pool_fast_vp')
501 if is_fast_vp_enabled:
502 is_fast_vp_enabled = is_fast_vp_enabled.is_schedule_enabled
503 details['is_fast_vp_enabled'] = is_fast_vp_enabled
504
505 details['size_free_with_unit'] = utils.\
506 convert_size_with_unit(int(details['size_free']))
507
508 details['size_subscribed_with_unit'] = utils.\
509 convert_size_with_unit(int(details['size_subscribed']))
510
511 details['size_total_with_unit'] = utils.\
512 convert_size_with_unit(int(details['size_total']))
513
514 details['size_used_with_unit'] = utils.\
515 convert_size_with_unit(int(details['size_used']))
516
517 details['snap_size_subscribed_with_unit'] = utils.\
518 convert_size_with_unit(int(details['snap_size_subscribed']))
519
520 details['snap_size_used_with_unit'] = utils.\
521 convert_size_with_unit(int(details['snap_size_used']))
522
523 pool_instance = utils.UnityPool.get(self.conn._cli, details['id'])
524 pool_tier_list = []
525 pool_tier_list.append((pool_instance.tiers)._get_properties())
526 pool_tier_dict = {}
527 pool_tier_dict['UnityPoolTierList'] = pool_tier_list
528 details['tiers'] = pool_tier_dict
529 return details
530 except Exception as e:
531 error = str(e)
532 check_list = ['not found', 'no attribute']
533 if any(ele in error for ele in check_list):
534 error_message = "pool details are not found"
535 LOG.info(error_message)
536 return None
537 error_message = 'Get details of storage pool failed with ' \
538 'error: {0}'.format(str(e))
539 LOG.error(error_message)
540 self.module.fail_json(msg=error_message)
541
542 def is_pool_modification_required(self, storage_pool_details):
543 """ Check if attributes of storage pool needs to be modified
544 """
545 try:
546 if self.module.params['new_pool_name'] and \
547 self.module.params['new_pool_name'] != \
548 storage_pool_details['name']:
549 return True
550
551 if self.module.params['pool_description'] is not None and \
552 self.module.params['pool_description'] != \
553 storage_pool_details['description']:
554 return True
555
556 if self.module.params['fast_cache']:
557 if (self.module.params['fast_cache'] == "enabled" and
558 not storage_pool_details['is_fast_cache_enabled']) or\
559 (self.module.params['fast_cache'] == "disabled" and storage_pool_details['is_fast_cache_enabled']):
560 return True
561
562 if self.module.params['fast_vp']:
563 if (self.module.params['fast_vp'] == "enabled" and
564 not storage_pool_details['is_fast_vp_enabled']) or \
565 (self.module.params['fast_vp'] == "disabled" and
566 storage_pool_details['is_fast_vp_enabled']):
567 return True
568
569 LOG.info("modify not required")
570 return False
571
572 except Exception as e:
573 error_message = 'Failed to determine if any modification'\
574 'required for pool attributes with error: {0}'.format(str(e))
575 LOG.error(error_message)
576 self.module.fail_json(msg=error_message)
577
578 def pool_modify(self, id, new_pool_name,
579 pool_description, fast_cache, fast_vp):
580 """ Modify attributes of storage pool """
581 pool_obj = utils.UnityPool.get(self.conn._cli, id)
582 try:
583 pool_obj.modify(name=new_pool_name, description=pool_description,
584 is_fast_cache_enabled=fast_cache,
585 is_fastvp_enabled=fast_vp)
586 new_storage_pool_details = self.get_details(pool_id=id,
587 pool_name=None)
588 LOG.info("Modification Successful")
589 return new_storage_pool_details
590 except Exception as e:
591 if self.module.params['pool_id']:
592 pool_identifier = self.module.params['pool_id']
593 else:
594 pool_identifier = self.module.params['pool_name']
595 error_message = 'Modify attributes of storage pool {0} ' \
596 'failed with error: {1}'.format(pool_identifier, str(e))
597 LOG.error(error_message)
598 self.module.fail_json(msg=error_message)
599
600 def get_pool_drives(self, pool_id=None, pool_name=None):
601 """ Get pool drives attached to pool"""
602 pool_identifier = pool_id or pool_name
603 pool_drives_list = []
604 try:
605 drive_instances = utils.UnityDiskList.get(self.conn._cli)
606 if drive_instances:
607 for drive in drive_instances:
608 if drive.pool and (drive.pool.id == pool_identifier or drive.pool.name == pool_identifier):
609 pool_drive = {"id": drive.id, "name": drive.name, "size": drive.size,
610 "disk_technology": drive.disk_technology.name,
611 "tier_type": drive.tier_type.name}
612 pool_drives_list.append(pool_drive)
613 LOG.info("Successfully retrieved pool drive details")
614 return pool_drives_list
615 except Exception as e:
616 error_message = 'Get details of pool drives failed with ' \
617 'error: {0}'.format(str(e))
618 LOG.error(error_message)
619 self.module.fail_json(msg=error_message)
620
621 def get_raid_type_enum(self, raid_type):
622 """ Get raid_type_enum.
623 :param raid_type: The raid_type
624 :return: raid_type enum
625 """
626
627 if raid_type in utils.RaidTypeEnum.__members__:
628 return utils.RaidTypeEnum[raid_type]
629 else:
630 errormsg = "Invalid choice %s for Raid Type" % raid_type
631 LOG.error(errormsg)
632 self.module.fail_json(msg=errormsg)
633
634 def get_raid_stripe_width_enum(self, stripe_width):
635 """ Get raid_stripe_width enum.
636 :param stripe_width: The raid_stripe_width
637 :return: raid_stripe_width enum
638 """
639 if stripe_width != "BEST_FIT":
640 stripe_width = "_" + stripe_width
641 if stripe_width in utils.RaidStripeWidthEnum.__members__:
642 return utils.RaidStripeWidthEnum[stripe_width]
643 else:
644 errormsg = "Invalid choice %s for stripe width" % stripe_width
645 LOG.error(errormsg)
646 self.module.fail_json(msg=errormsg)
647
648 def get_pool_type_enum(self, pool_type):
649 """ Get the storage pool_type enum.
650 :param pool_type: The pool_type
651 :return: pool_type enum
652 """
653
654 if pool_type == "TRADITIONAL":
655 return 1
656 elif pool_type == "DYNAMIC":
657 return 2
658 else:
659 errormsg = "Invalid choice %s for Storage Pool Type" % pool_type
660 LOG.error(errormsg)
661 self.module.fail_json(msg=errormsg)
662
663 def get_raid_groups(self, raid_groups):
664 """ Get the raid groups for creating pool"""
665 try:
666 disk_obj = utils.UnityDiskGroup.get(self.conn._cli, _id=raid_groups['disk_group_id'])
667 disk_num = raid_groups['disk_num']
668 raid_type = raid_groups['raid_type']
669 raid_type = self.get_raid_type_enum(raid_type) \
670 if raid_type else None
671 stripe_width = raid_groups['stripe_width']
672 stripe_width = self.get_raid_stripe_width_enum(stripe_width) \
673 if stripe_width else None
674 raid_group = utils.RaidGroupParameter(disk_group=disk_obj,
675 disk_num=disk_num, raid_type=raid_type,
676 stripe_width=stripe_width)
677 raid_groups = [raid_group]
678 return raid_groups
679 except Exception as e:
680 error_message = 'Failed to create storage pool with error: %s' % str(e)
681 LOG.error(error_message)
682 self.module.fail_json(msg=error_message)
683
684 def validate_create_pool_params(self, alert_threshold=None,
685 pool_harvest_high_threshold=None,
686 pool_harvest_low_threshold=None,
687 snap_harvest_high_threshold=None,
688 snap_harvest_low_threshold=None):
689 """ Validates params for creating pool"""
690 if alert_threshold and (alert_threshold < 50 or alert_threshold > 84):
691 errormsg = "Alert threshold is not in the allowed value range of 50 - 84"
692 LOG.error(errormsg)
693 self.module.fail_json(msg=errormsg)
694 if pool_harvest_high_threshold and (pool_harvest_high_threshold < 1 or pool_harvest_high_threshold > 99):
695 errormsg = "Pool harvest high threshold is not in the allowed value range of 1 - 99"
696 LOG.error(errormsg)
697 self.module.fail_json(msg=errormsg)
698 if pool_harvest_low_threshold and (pool_harvest_low_threshold < 0 or pool_harvest_low_threshold > 98):
699 errormsg = "Pool harvest low threshold is not in the allowed value range of 0 - 98"
700 LOG.error(errormsg)
701 self.module.fail_json(msg=errormsg)
702 if snap_harvest_high_threshold and (snap_harvest_high_threshold < 1 or snap_harvest_high_threshold > 99):
703 errormsg = "Snap harvest high threshold is not in the allowed value range of 1 - 99"
704 LOG.error(errormsg)
705 self.module.fail_json(msg=errormsg)
706 if snap_harvest_low_threshold and (snap_harvest_low_threshold < 0 or snap_harvest_low_threshold > 98):
707 errormsg = "Snap harvest low threshold is not in the allowed value range of 0 - 98"
708 LOG.error(errormsg)
709 self.module.fail_json(msg=errormsg)
710
711 def create_pool(self, name, raid_groups):
712 """ Creates a StoragePool"""
713 try:
714 pool_obj = utils.UnityPool.get(self.conn._cli)
715 pool_description = self.module.params['pool_description']
716 raid_groups = self.get_raid_groups(raid_groups) \
717 if raid_groups else None
718 alert_threshold = self.module.params['alert_threshold']
719 pool_harvest_high_threshold = None
720 pool_harvest_low_threshold = None
721 snap_harvest_high_threshold = None
722 snap_harvest_low_threshold = None
723 is_harvest_enabled = self.module.params['is_harvest_enabled']
724 if is_harvest_enabled:
725 pool_harvest_high_threshold = self.module.params['pool_harvest_high_threshold']
726 pool_harvest_low_threshold = self.module.params['pool_harvest_low_threshold']
727 is_snap_harvest_enabled = self.module.params['is_snap_harvest_enabled']
728 if is_snap_harvest_enabled:
729 snap_harvest_high_threshold = self.module.params['snap_harvest_high_threshold']
730 snap_harvest_low_threshold = self.module.params['snap_harvest_low_threshold']
731 self.validate_create_pool_params(alert_threshold=alert_threshold,
732 pool_harvest_high_threshold=pool_harvest_high_threshold,
733 pool_harvest_low_threshold=pool_harvest_low_threshold,
734 snap_harvest_high_threshold=snap_harvest_high_threshold,
735 snap_harvest_low_threshold=snap_harvest_low_threshold)
736 pool_type = self.module.params['pool_type']
737 pool_type = self.get_pool_type_enum(pool_type) \
738 if pool_type else None
739 fast_vp = self.module.params['fast_vp']
740 if fast_vp:
741 if fast_vp == "enabled":
742 fast_vp = True
743 else:
744 fast_vp = False
745
746 pool_obj.create(self.conn._cli, name=name, description=pool_description, raid_groups=raid_groups,
747 alert_threshold=alert_threshold,
748 is_harvest_enabled=is_harvest_enabled,
749 is_snap_harvest_enabled=is_snap_harvest_enabled,
750 pool_harvest_high_threshold=pool_harvest_high_threshold,
751 pool_harvest_low_threshold=pool_harvest_low_threshold,
752 snap_harvest_high_threshold=snap_harvest_high_threshold,
753 snap_harvest_low_threshold=snap_harvest_low_threshold,
754 is_fastvp_enabled=fast_vp,
755 pool_type=pool_type)
756 LOG.info("Creation of storage pool successful")
757 storage_pool_details = self.get_details(pool_name=name)
758 changed = True
759 return changed, storage_pool_details
760 except Exception as e:
761 error_message = 'Failed to create storage pool with error: %s' % str(e)
762 LOG.error(error_message)
763 self.module.fail_json(msg=error_message)
764
765 def perform_module_operation(self):
766 """
767 Perform different actions on storage pool module based on parameters
768 chosen in playbook
769 """
770 pool_name = self.module.params['pool_name']
771 pool_id = self.module.params['pool_id']
772 new_pool_name = self.module.params['new_pool_name']
773 pool_description = self.module.params['pool_description']
774 fast_cache = self.module.params['fast_cache']
775 fast_vp = self.module.params['fast_vp']
776 state = self.module.params['state']
777 raid_groups = self.module.params['raid_groups']
778 if fast_cache:
779 if fast_cache == "enabled":
780 fast_cache = True
781 else:
782 fast_cache = False
783
784 if fast_vp:
785 if fast_vp == "enabled":
786 fast_vp = True
787 else:
788 fast_vp = False
789
790 # result is a dictionary that contains changed status and storage pool details
791 result = dict(
792 changed=False,
793 storage_pool_details={}
794 )
795
796 storage_pool_details = self.get_details(pool_id, pool_name)
797 result['storage_pool_details'] = storage_pool_details
798
799 if state == 'absent' and storage_pool_details:
800 error_message = 'Deletion of storage pool is not allowed through'\
801 ' Ansible module'
802 LOG.error(error_message)
803 self.module.fail_json(msg=error_message)
804
805 # Create storage pool
806 if state == 'present' and not storage_pool_details:
807 if pool_name is not None and len(pool_name) != 0:
808 result['changed'], storage_pool_details \
809 = self.create_pool(name=pool_name, raid_groups=raid_groups)
810 result['storage_pool_details'] = storage_pool_details
811 else:
812 error_message = 'The parameter pool_name length is 0. It'\
813 ' is too short. The min length is 1'
814 LOG.error(error_message)
815 self.module.fail_json(msg=error_message)
816
817 # Get pool drive details
818 if result['storage_pool_details']:
819 result['storage_pool_details']['drives'] = self.get_pool_drives(pool_id=pool_id, pool_name=pool_name)
820
821 if state == 'present' and storage_pool_details:
822 if new_pool_name is not None and len(new_pool_name) == 0:
823 error_message = 'The parameter new_pool_name length is 0. It'\
824 ' is too short. The min length is 1'
825 LOG.error(error_message)
826 self.module.fail_json(msg=error_message)
827 pool_modify_flag = self.\
828 is_pool_modification_required(storage_pool_details)
829 LOG.info("Storage pool modification flag %s",
830 str(pool_modify_flag))
831
832 if pool_modify_flag:
833 result['storage_pool_details'] = \
834 self.pool_modify(storage_pool_details['id'], new_pool_name,
835 pool_description, fast_cache, fast_vp)
836 result['changed'] = True
837 self.module.exit_json(**result)
838
839
840 def get_storagepool_parameters():
841 """This method provides parameters required for the ansible storage pool
842 module on Unity"""
843 return dict(
844 pool_name=dict(required=False, type='str'),
845 pool_id=dict(required=False, type='str'),
846 new_pool_name=dict(required=False, type='str'),
847 pool_description=dict(required=False, type='str'),
848 fast_cache=dict(required=False, type='str', choices=['enabled',
849 'disabled']),
850 fast_vp=dict(required=False, type='str', choices=['enabled',
851 'disabled']),
852 state=dict(required=True, type='str', choices=['present', 'absent']),
853 raid_groups=dict(required=False, type='dict', options=dict(
854 disk_group_id=dict(required=False, type='str'),
855 disk_num=dict(required=False, type='int'),
856 raid_type=dict(required=False, type='str', choices=['None', 'RAID5', 'RAID0', 'RAID1', 'RAID3', 'RAID10',
857 'RAID6', 'Mixed', 'Automatic']),
858 stripe_width=dict(required=False, type='str', choices=['BEST_FIT', '2', '4', '5',
859 '6', '8', '9', '10', '12', '13', '14', '16']))),
860 alert_threshold=dict(required=False, type='int'),
861 is_harvest_enabled=dict(required=False, type='bool'),
862 pool_harvest_high_threshold=dict(required=False, type='float'),
863 pool_harvest_low_threshold=dict(required=False, type='float'),
864 is_snap_harvest_enabled=dict(required=False, type='bool'),
865 snap_harvest_high_threshold=dict(required=False, type='float'),
866 snap_harvest_low_threshold=dict(required=False, type='float'),
867 pool_type=dict(required=False, type='str', choices=['TRADITIONAL', 'DYNAMIC'])
868 )
869
870
871 def main():
872 """ Create Unity storage pool object and perform action on it
873 based on user input from playbook"""
874 obj = StoragePool()
875 obj.perform_module_operation()
876
877
878 if __name__ == '__main__':
879 main()