Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2
3 # Copyright: (c) 2021-24, Dell Technologies
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 """Ansible module for managing Dell Technologies (Dell) PowerFlex storage pool"""
7
8 from __future__ import absolute_import, division, print_function
9
10 __metaclass__ = type
11
12 DOCUMENTATION = r'''
13 ---
14 module: storagepool
15
16 version_added: '1.0.0'
17
18 short_description: Managing Dell PowerFlex storage pool
19
20 description:
21 - Dell PowerFlex storage pool module includes getting the details of
22 storage pool, creating a new storage pool, and modifying the attribute of
23 a storage pool.
24
25 extends_documentation_fragment:
26 - dellemc.powerflex.powerflex
27
28 author:
29 - Arindam Datta (@dattaarindam) <[email protected]>
30 - P Srinivas Rao (@srinivas-rao5) <[email protected]>
31 - Trisha Datta (@trisha-dell) <[email protected]>
32
33 options:
34 storage_pool_name:
35 description:
36 - The name of the storage pool.
37 - If more than one storage pool is found with the same name then
38 protection domain id/name is required to perform the task.
39 - Mutually exclusive with I(storage_pool_id).
40 type: str
41 storage_pool_id:
42 description:
43 - The id of the storage pool.
44 - It is auto generated, hence should not be provided during
45 creation of a storage pool.
46 - Mutually exclusive with I(storage_pool_name).
47 type: str
48 protection_domain_name:
49 description:
50 - The name of the protection domain.
51 - During creation of a pool, either protection domain name or id must be
52 mentioned.
53 - Mutually exclusive with I(protection_domain_id).
54 type: str
55 protection_domain_id:
56 description:
57 - The id of the protection domain.
58 - During creation of a pool, either protection domain name or id must
59 be mentioned.
60 - Mutually exclusive with I(protection_domain_name).
61 type: str
62 media_type:
63 description:
64 - Type of devices in the storage pool.
65 type: str
66 choices: ['HDD', 'SSD', 'TRANSITIONAL']
67 storage_pool_new_name:
68 description:
69 - New name for the storage pool can be provided.
70 - This parameter is used for renaming the storage pool.
71 type: str
72 use_rfcache:
73 description:
74 - Enable/Disable RFcache on a specific storage pool.
75 type: bool
76 use_rmcache:
77 description:
78 - Enable/Disable RMcache on a specific storage pool.
79 type: bool
80 enable_zero_padding:
81 description:
82 - Enable/Disable zero padding on a specific storage pool.
83 type: bool
84 rep_cap_max_ratio:
85 description:
86 - Set replication journal capacity of a storage pool.
87 type: int
88 enable_rebalance:
89 description:
90 - Enable/Disable rebalance on a specific storage pool.
91 type: bool
92 spare_percentage:
93 description:
94 - Set the spare percentage of a specific storage pool.
95 type: int
96 rmcache_write_handling_mode :
97 description:
98 - Set RM cache write handling mode of a storage pool.
99 - I(Passthrough) Writes skip the cache and are stored in storage only.
100 - I(Cached) Writes are stored in both cache and storage (the default).
101 - Caching is only performed for IOs whose size is a multiple of 4k bytes.
102 type: str
103 choices: ['Cached', 'Passthrough']
104 default: 'Cached'
105 enable_rebuild:
106 description:
107 - Enable/Disable rebuild of a specific storage pool.
108 type: bool
109 enable_fragmentation:
110 description:
111 - Enable/Disable fragmentation of a specific storage pool.
112 type: bool
113 parallel_rebuild_rebalance_limit:
114 description:
115 - Set rebuild/rebalance parallelism limit of a storage pool.
116 type: int
117 persistent_checksum:
118 description:
119 - Enable/Disable persistent checksum of a specific storage pool.
120 type: dict
121 suboptions:
122 enable:
123 description:
124 - Enable / disable persistent checksum.
125 type: bool
126 validate_on_read:
127 description:
128 - Validate checksum upon reading data.
129 type: bool
130 builder_limit:
131 description:
132 - Bandwidth limit in KB/s for the checksum building process.
133 - Valid range is 1024 to 10240.
134 default: 3072
135 type: int
136 protected_maintenance_mode_io_priority_policy:
137 description:
138 - Set protected maintenance mode I/O priority policy of a storage pool.
139 type: dict
140 suboptions:
141 policy:
142 description:
143 - The I/O priority policy for protected maintenance mode.
144 - C(unlimited) Protected maintenance mode IOPS are not limited
145 - C(limitNumOfConcurrentIos)Limit the number of allowed concurrent protected maintenance mode
146 migration I/Os to the value defined for I(concurrent_ios_per_device).
147 - C(favorAppIos) Always limit the number of allowed concurrent protected maintenance mode
148 migration I/Os to value defined for I(concurrent_ios_per_device).
149 - If application I/Os are in progress, should also limit the bandwidth of
150 protected maintenance mode migration I/Os to the limit defined for the I(bw_limit_per_device).
151 type: str
152 choices: ['unlimited', 'limitNumOfConcurrentIos', 'favorAppIos']
153 default: 'limitNumOfConcurrentIos'
154 concurrent_ios_per_device:
155 description:
156 - The maximum number of concurrent protected maintenance mode migration I/Os per device.
157 - Valid range is 1 to 20.
158 type: int
159 bw_limit_per_device:
160 description:
161 - The maximum bandwidth of protected maintenance mode migration I/Os,
162 in KB per second, per device.
163 - Valid range is 1024 to 1048576.
164 type: int
165 vtree_migration_io_priority_policy:
166 description:
167 - Set the I/O priority policy for V-Tree migration for a specific Storage Pool.
168 type: dict
169 suboptions:
170 policy:
171 description:
172 - The I/O priority policy for protected maintenance mode.
173 - C(limitNumOfConcurrentIos) Limit the number of allowed concurrent V-Tree
174 migration I/Os (default) to the I(concurrent_ios_per_device).
175 - C(favorAppIos) Always limit the number of allowed concurrent
176 V-Tree migration I/Os to defined for I(concurrent_ios_per_device).
177 - If application I/Os are in progress, should also limit the bandwidth of
178 V-Tree migration I/Os to the limit defined for the I(bw_limit_per_device).
179 type: str
180 choices: ['limitNumOfConcurrentIos', 'favorAppIos']
181 concurrent_ios_per_device:
182 description:
183 - The maximum number of concurrent V-Tree migration I/Os per device.
184 - Valid range is 1 to 20
185 type: int
186 bw_limit_per_device:
187 description:
188 - The maximum bandwidth of V-Tree migration I/Os,
189 in KB per second, per device.
190 - Valid range is 1024 to 25600.
191 type: int
192 rebalance_io_priority_policy:
193 description:
194 - Set the rebalance I/O priority policy for a Storage Pool.
195 type: dict
196 suboptions:
197 policy:
198 description:
199 - Policy to use for rebalance I/O priority.
200 - C(unlimited) Rebalance I/Os are not limited.
201 - C(limitNumOfConcurrentIos) Limit the number of allowed concurrent rebalance I/Os.
202 - C(favorAppIos) Limit the number and bandwidth of rebalance I/Os when application I/Os are in progress.
203 type: str
204 choices: ['unlimited', 'limitNumOfConcurrentIos', 'favorAppIos']
205 default: 'favorAppIos'
206 concurrent_ios_per_device:
207 description:
208 - The maximum number of concurrent rebalance I/Os per device.
209 - Valid range is 1 to 20.
210 type: int
211 bw_limit_per_device:
212 description:
213 - The maximum bandwidth of rebalance I/Os, in KB/s, per device.
214 - Valid range is 1024 to 1048576.
215 type: int
216 cap_alert_thresholds:
217 description:
218 - Set the threshold for triggering capacity usage alerts.
219 - Alerts thresholds are calculated from each Storage Pool
220 capacity after deducting the defined amount of spare capacity.
221 type: dict
222 suboptions:
223 high_threshold:
224 description:
225 - Threshold of the non-spare capacity of the Storage Pool that will trigger a
226 high-priority alert, expressed as a percentage.
227 - This value must be lower than the I(critical_threshold).
228 type: int
229 critical_threshold:
230 description:
231 - Threshold of the non-spare capacity of the Storage Pool that will trigger a
232 critical-priority alert, expressed as a percentage.
233 type: int
234 state:
235 description:
236 - State of the storage pool.
237 type: str
238 choices: ["present", "absent"]
239 required: true
240 notes:
241 - TRANSITIONAL media type is supported only during modification.
242 - The I(check_mode) is supported.
243 '''
244
245 EXAMPLES = r'''
246 - name: Get the details of storage pool by name
247 dellemc.powerflex.storagepool:
248 hostname: "{{hostname}}"
249 username: "{{username}}"
250 password: "{{password}}"
251 validate_certs: "{{validate_certs}}"
252 storage_pool_name: "sample_pool_name"
253 protection_domain_name: "sample_protection_domain"
254 state: "present"
255
256 - name: Get the details of storage pool by id
257 dellemc.powerflex.storagepool:
258 hostname: "{{hostname}}"
259 username: "{{username}}"
260 password: "{{password}}"
261 validate_certs: "{{validate_certs}}"
262 storage_pool_id: "abcd1234ab12r"
263 state: "present"
264
265 - name: Create a new Storage pool
266 dellemc.powerflex.storagepool:
267 hostname: "{{ hostname }}"
268 username: "{{ username }}"
269 password: "{{ password }}"
270 validate_certs: "{{ validate_certs }}"
271 storage_pool_name: "{{ pool_name }}"
272 protection_domain_name: "{{ protection_domain_name }}"
273 cap_alert_thresholds:
274 high_threshold: 30
275 critical_threshold: 50
276 media_type: "TRANSITIONAL"
277 enable_zero_padding: true
278 rep_cap_max_ratio: 40
279 rmcache_write_handling_mode: "Passthrough"
280 spare_percentage: 80
281 enable_rebalance: false
282 enable_fragmentation: false
283 enable_rebuild: false
284 use_rmcache: true
285 use_rfcache: true
286 parallel_rebuild_rebalance_limit: 3
287 protected_maintenance_mode_io_priority_policy:
288 policy: "unlimited"
289 rebalance_io_priority_policy:
290 policy: "unlimited"
291 vtree_migration_io_priority_policy:
292 policy: "limitNumOfConcurrentIos"
293 concurrent_ios_per_device: 10
294 persistent_checksum:
295 enable: false
296 state: "present"
297
298 - name: Modify a Storage pool by name
299 dellemc.powerflex.storagepool:
300 hostname: "{{ hostname }}"
301 username: "{{ username }}"
302 password: "{{ password }}"
303 validate_certs: "{{ validate_certs }}"
304 storage_pool_name: "{{ pool_name }}"
305 protection_domain_name: "{{ protection_domain_name }}"
306 storage_pool_new_name: "pool_name_new"
307 cap_alert_thresholds:
308 high_threshold: 50
309 critical_threshold: 70
310 enable_zero_padding: false
311 rep_cap_max_ratio: 60
312 rmcache_write_handling_mode: "Passthrough"
313 spare_percentage: 90
314 enable_rebalance: true
315 enable_fragmentation: true
316 enable_rebuild: true
317 use_rmcache: true
318 use_rfcache: true
319 parallel_rebuild_rebalance_limit: 6
320 protected_maintenance_mode_io_priority_policy:
321 policy: "limitNumOfConcurrentIos"
322 concurrent_ios_per_device: 4
323 rebalance_io_priority_policy:
324 policy: "favorAppIos"
325 concurrent_ios_per_device: 10
326 bw_limit_per_device: 4096
327 vtree_migration_io_priority_policy:
328 policy: "limitNumOfConcurrentIos"
329 concurrent_ios_per_device: 10
330 persistent_checksum:
331 enable: true
332 validate_on_read: true
333 builder_limit: 1024
334 state: "present"
335 '''
336
337 RETURN = r'''
338 changed:
339 description: Whether or not the resource has changed.
340 returned: always
341 type: bool
342 sample: 'false'
343 storage_pool_details:
344 description: Details of the storage pool.
345 returned: When storage pool exists
346 type: dict
347 contains:
348 mediaType:
349 description: Type of devices in the storage pool.
350 type: str
351 useRfcache:
352 description: Enable/Disable RFcache on a specific storage pool.
353 type: bool
354 useRmcache:
355 description: Enable/Disable RMcache on a specific storage pool.
356 type: bool
357 id:
358 description: ID of the storage pool under protection domain.
359 type: str
360 name:
361 description: Name of the storage pool under protection domain.
362 type: str
363 protectionDomainId:
364 description: ID of the protection domain in which pool resides.
365 type: str
366 protectionDomainName:
367 description: Name of the protection domain in which pool resides.
368 type: str
369 "statistics":
370 description: Statistics details of the storage pool.
371 type: dict
372 contains:
373 "capacityInUseInKb":
374 description: Total capacity of the storage pool.
375 type: str
376 "unusedCapacityInKb":
377 description: Unused capacity of the storage pool.
378 type: str
379 "deviceIds":
380 description: Device Ids of the storage pool.
381 type: list
382 sample: {
383 "addressSpaceUsage": "Normal",
384 "addressSpaceUsageType": "DeviceCapacityLimit",
385 "backgroundScannerBWLimitKBps": 3072,
386 "backgroundScannerMode": "DataComparison",
387 "bgScannerCompareErrorAction": "ReportAndFix",
388 "bgScannerReadErrorAction": "ReportAndFix",
389 "capacityAlertCriticalThreshold": 90,
390 "capacityAlertHighThreshold": 80,
391 "capacityUsageState": "Normal",
392 "capacityUsageType": "NetCapacity",
393 "checksumEnabled": false,
394 "compressionMethod": "Invalid",
395 "dataLayout": "MediumGranularity",
396 "externalAccelerationType": "None",
397 "fglAccpId": null,
398 "fglExtraCapacity": null,
399 "fglMaxCompressionRatio": null,
400 "fglMetadataSizeXx100": null,
401 "fglNvdimmMetadataAmortizationX100": null,
402 "fglNvdimmWriteCacheSizeInMb": null,
403 "fglOverProvisioningFactor": null,
404 "fglPerfProfile": null,
405 "fglWriteAtomicitySize": null,
406 "fragmentationEnabled": true,
407 "id": "e0d8f6c900000000",
408 "links": [
409 {
410 "href": "/api/instances/StoragePool::e0d8f6c900000000",
411 "rel": "self"
412 },
413 {
414 "href": "/api/instances/StoragePool::e0d8f6c900000000
415 /relationships/Statistics",
416 "rel": "/api/StoragePool/relationship/Statistics"
417 },
418 {
419 "href": "/api/instances/StoragePool::e0d8f6c900000000
420 /relationships/SpSds",
421 "rel": "/api/StoragePool/relationship/SpSds"
422 },
423 {
424 "href": "/api/instances/StoragePool::e0d8f6c900000000
425 /relationships/Volume",
426 "rel": "/api/StoragePool/relationship/Volume"
427 },
428 {
429 "href": "/api/instances/StoragePool::e0d8f6c900000000
430 /relationships/Device",
431 "rel": "/api/StoragePool/relationship/Device"
432 },
433 {
434 "href": "/api/instances/StoragePool::e0d8f6c900000000
435 /relationships/VTree",
436 "rel": "/api/StoragePool/relationship/VTree"
437 },
438 {
439 "href": "/api/instances/ProtectionDomain::9300c1f900000000",
440 "rel": "/api/parent/relationship/protectionDomainId"
441 }
442 ],
443 "statistics": {
444 "BackgroundScannedInMB": 3466920,
445 "activeBckRebuildCapacityInKb": 0,
446 "activeEnterProtectedMaintenanceModeCapacityInKb": 0,
447 "aggregateCompressionLevel": "Uncompressed",
448 "atRestCapacityInKb": 1248256,
449 "backgroundScanCompareErrorCount": 0,
450 "backgroundScanFixedCompareErrorCount": 0,
451 "bckRebuildReadBwc": {
452 "numOccured": 0,
453 "numSeconds": 0,
454 "totalWeightInKb": 0
455 },
456 "bckRebuildWriteBwc": {
457 "numOccured": 0,
458 "numSeconds": 0,
459 "totalWeightInKb": 0
460 },
461 "capacityAvailableForVolumeAllocationInKb": 369098752,
462 "capacityInUseInKb": 2496512,
463 "capacityInUseNoOverheadInKb": 2496512,
464 "capacityLimitInKb": 845783040,
465 "compressedDataCompressionRatio": 0.0,
466 "compressionRatio": 1.0,
467 "currentFglMigrationSizeInKb": 0,
468 "deviceIds": [
469 ],
470 "enterProtectedMaintenanceModeCapacityInKb": 0,
471 "enterProtectedMaintenanceModeReadBwc": {
472 "numOccured": 0,
473 "numSeconds": 0,
474 "totalWeightInKb": 0
475 },
476 "enterProtectedMaintenanceModeWriteBwc": {
477 "numOccured": 0,
478 "numSeconds": 0,
479 "totalWeightInKb": 0
480 },
481 "exitProtectedMaintenanceModeReadBwc": {
482 "numOccured": 0,
483 "numSeconds": 0,
484 "totalWeightInKb": 0
485 },
486 "exitProtectedMaintenanceModeWriteBwc": {
487 "numOccured": 0,
488 "numSeconds": 0,
489 "totalWeightInKb": 0
490 },
491 "exposedCapacityInKb": 0,
492 "failedCapacityInKb": 0,
493 "fwdRebuildReadBwc": {
494 "numOccured": 0,
495 "numSeconds": 0,
496 "totalWeightInKb": 0
497 },
498 "fwdRebuildWriteBwc": {
499 "numOccured": 0,
500 "numSeconds": 0,
501 "totalWeightInKb": 0
502 },
503 "inMaintenanceCapacityInKb": 0,
504 "inMaintenanceVacInKb": 0,
505 "inUseVacInKb": 184549376,
506 "inaccessibleCapacityInKb": 0,
507 "logWrittenBlocksInKb": 0,
508 "maxCapacityInKb": 845783040,
509 "migratingVolumeIds": [
510 ],
511 "migratingVtreeIds": [
512 ],
513 "movingCapacityInKb": 0,
514 "netCapacityInUseInKb": 1248256,
515 "normRebuildCapacityInKb": 0,
516 "normRebuildReadBwc": {
517 "numOccured": 0,
518 "numSeconds": 0,
519 "totalWeightInKb": 0
520 },
521 "normRebuildWriteBwc": {
522 "numOccured": 0,
523 "numSeconds": 0,
524 "totalWeightInKb": 0
525 },
526 "numOfDeviceAtFaultRebuilds": 0,
527 "numOfDevices": 3,
528 "numOfIncomingVtreeMigrations": 0,
529 "numOfVolumes": 8,
530 "numOfVolumesInDeletion": 0,
531 "numOfVtrees": 8,
532 "overallUsageRatio": 73.92289,
533 "pendingBckRebuildCapacityInKb": 0,
534 "pendingEnterProtectedMaintenanceModeCapacityInKb": 0,
535 "pendingExitProtectedMaintenanceModeCapacityInKb": 0,
536 "pendingFwdRebuildCapacityInKb": 0,
537 "pendingMovingCapacityInKb": 0,
538 "pendingMovingInBckRebuildJobs": 0,
539 "persistentChecksumBuilderProgress": 100.0,
540 "persistentChecksumCapacityInKb": 414720,
541 "primaryReadBwc": {
542 "numOccured": 0,
543 "numSeconds": 0,
544 "totalWeightInKb": 0
545 },
546 "primaryReadFromDevBwc": {
547 "numOccured": 0,
548 "numSeconds": 0,
549 "totalWeightInKb": 0
550 },
551 "primaryReadFromRmcacheBwc": {
552 "numOccured": 0,
553 "numSeconds": 0,
554 "totalWeightInKb": 0
555 },
556 "primaryVacInKb": 92274688,
557 "primaryWriteBwc": {
558 "numOccured": 0,
559 "numSeconds": 0,
560 "totalWeightInKb": 0
561 },
562 "protectedCapacityInKb": 2496512,
563 "protectedVacInKb": 184549376,
564 "provisionedAddressesInKb": 2496512,
565 "rebalanceCapacityInKb": 0,
566 "rebalanceReadBwc": {
567 "numOccured": 0,
568 "numSeconds": 0,
569 "totalWeightInKb": 0
570 },
571 "rebalanceWriteBwc": {
572 "numOccured": 0,
573 "numSeconds": 0,
574 "totalWeightInKb": 0
575 },
576 "rfacheReadHit": 0,
577 "rfacheWriteHit": 0,
578 "rfcacheAvgReadTime": 0,
579 "rfcacheAvgWriteTime": 0,
580 "rfcacheIoErrors": 0,
581 "rfcacheIosOutstanding": 0,
582 "rfcacheIosSkipped": 0,
583 "rfcacheReadMiss": 0,
584 "rmPendingAllocatedInKb": 0,
585 "rmPendingThickInKb": 0,
586 "rplJournalCapAllowed": 0,
587 "rplTotalJournalCap": 0,
588 "rplUsedJournalCap": 0,
589 "secondaryReadBwc": {
590 "numOccured": 0,
591 "numSeconds": 0,
592 "totalWeightInKb": 0
593 },
594 "secondaryReadFromDevBwc": {
595 "numOccured": 0,
596 "numSeconds": 0,
597 "totalWeightInKb": 0
598 },
599 "secondaryReadFromRmcacheBwc": {
600 "numOccured": 0,
601 "numSeconds": 0,
602 "totalWeightInKb": 0
603 },
604 "secondaryVacInKb": 92274688,
605 "secondaryWriteBwc": {
606 "numOccured": 0,
607 "numSeconds": 0,
608 "totalWeightInKb": 0
609 },
610 "semiProtectedCapacityInKb": 0,
611 "semiProtectedVacInKb": 0,
612 "snapCapacityInUseInKb": 0,
613 "snapCapacityInUseOccupiedInKb": 0,
614 "snapshotCapacityInKb": 0,
615 "spSdsIds": [
616 "abdfe71b00030001",
617 "abdce71d00040001",
618 "abdde71e00050001"
619 ],
620 "spareCapacityInKb": 84578304,
621 "targetOtherLatency": {
622 "numOccured": 0,
623 "numSeconds": 0,
624 "totalWeightInKb": 0
625 },
626 "targetReadLatency": {
627 "numOccured": 0,
628 "numSeconds": 0,
629 "totalWeightInKb": 0
630 },
631 "targetWriteLatency": {
632 "numOccured": 0,
633 "numSeconds": 0,
634 "totalWeightInKb": 0
635 },
636 "tempCapacityInKb": 0,
637 "tempCapacityVacInKb": 0,
638 "thickCapacityInUseInKb": 0,
639 "thinAndSnapshotRatio": 73.92289,
640 "thinCapacityAllocatedInKm": 184549376,
641 "thinCapacityInUseInKb": 0,
642 "thinUserDataCapacityInKb": 2496512,
643 "totalFglMigrationSizeInKb": 0,
644 "totalReadBwc": {
645 "numOccured": 0,
646 "numSeconds": 0,
647 "totalWeightInKb": 0
648 },
649 "totalWriteBwc": {
650 "numOccured": 0,
651 "numSeconds": 0,
652 "totalWeightInKb": 0
653 },
654 "trimmedUserDataCapacityInKb": 0,
655 "unreachableUnusedCapacityInKb": 0,
656 "unusedCapacityInKb": 758708224,
657 "userDataCapacityInKb": 2496512,
658 "userDataCapacityNoTrimInKb": 2496512,
659 "userDataReadBwc": {
660 "numOccured": 0,
661 "numSeconds": 0,
662 "totalWeightInKb": 0
663 },
664 "userDataSdcReadLatency": {
665 "numOccured": 0,
666 "numSeconds": 0,
667 "totalWeightInKb": 0
668 },
669 "userDataSdcTrimLatency": {
670 "numOccured": 0,
671 "numSeconds": 0,
672 "totalWeightInKb": 0
673 },
674 "userDataSdcWriteLatency": {
675 "numOccured": 0,
676 "numSeconds": 0,
677 "totalWeightInKb": 0
678 },
679 "userDataTrimBwc": {
680 "numOccured": 0,
681 "numSeconds": 0,
682 "totalWeightInKb": 0
683 },
684 "userDataWriteBwc": {
685 "numOccured": 0,
686 "numSeconds": 0,
687 "totalWeightInKb": 0
688 },
689 "volMigrationReadBwc": {
690 "numOccured": 0,
691 "numSeconds": 0,
692 "totalWeightInKb": 0
693 },
694 "volMigrationWriteBwc": {
695 "numOccured": 0,
696 "numSeconds": 0,
697 "totalWeightInKb": 0
698 },
699 "volumeAddressSpaceInKb": 922XXXXX,
700 "volumeAllocationLimitInKb": 3707XXXXX,
701 "volumeIds": [
702 "456afc7900XXXXXXXX"
703 ],
704 "vtreeAddresSpaceInKb": 92274688,
705 "vtreeIds": [
706 "32b1681bXXXXXXXX",
707 ]
708 },
709 "mediaType": "HDD",
710 "name": "pool1",
711 "numOfParallelRebuildRebalanceJobsPerDevice": 2,
712 "persistentChecksumBuilderLimitKb": 3072,
713 "persistentChecksumEnabled": true,
714 "persistentChecksumState": "Protected",
715 "persistentChecksumValidateOnRead": false,
716 "protectedMaintenanceModeIoPriorityAppBwPerDeviceThresholdInKbps": null,
717 "protectedMaintenanceModeIoPriorityAppIopsPerDeviceThreshold": null,
718 "protectedMaintenanceModeIoPriorityBwLimitPerDeviceInKbps": 10240,
719 "protectedMaintenanceModeIoPriorityNumOfConcurrentIosPerDevice": 1,
720 "protectedMaintenanceModeIoPriorityPolicy": "limitNumOfConcurrentIos",
721 "protectedMaintenanceModeIoPriorityQuietPeriodInMsec": null,
722 "protectionDomainId": "9300c1f900000000",
723 "protectionDomainName": "domain1",
724 "rebalanceEnabled": true,
725 "rebalanceIoPriorityAppBwPerDeviceThresholdInKbps": null,
726 "rebalanceIoPriorityAppIopsPerDeviceThreshold": null,
727 "rebalanceIoPriorityBwLimitPerDeviceInKbps": 10240,
728 "rebalanceIoPriorityNumOfConcurrentIosPerDevice": 1,
729 "rebalanceIoPriorityPolicy": "favorAppIos",
730 "rebalanceIoPriorityQuietPeriodInMsec": null,
731 "rebuildEnabled": true,
732 "rebuildIoPriorityAppBwPerDeviceThresholdInKbps": null,
733 "rebuildIoPriorityAppIopsPerDeviceThreshold": null,
734 "rebuildIoPriorityBwLimitPerDeviceInKbps": 10240,
735 "rebuildIoPriorityNumOfConcurrentIosPerDevice": 1,
736 "rebuildIoPriorityPolicy": "limitNumOfConcurrentIos",
737 "rebuildIoPriorityQuietPeriodInMsec": null,
738 "replicationCapacityMaxRatio": 32,
739 "rmcacheWriteHandlingMode": "Cached",
740 "sparePercentage": 10,
741 "useRfcache": false,
742 "useRmcache": false,
743 "vtreeMigrationIoPriorityAppBwPerDeviceThresholdInKbps": null,
744 "vtreeMigrationIoPriorityAppIopsPerDeviceThreshold": null,
745 "vtreeMigrationIoPriorityBwLimitPerDeviceInKbps": 10240,
746 "vtreeMigrationIoPriorityNumOfConcurrentIosPerDevice": 1,
747 "vtreeMigrationIoPriorityPolicy": "favorAppIos",
748 "vtreeMigrationIoPriorityQuietPeriodInMsec": null,
749 "zeroPaddingEnabled": true
750 }
751 '''
752
753 from ansible.module_utils.basic import AnsibleModule
754 from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.libraries.powerflex_base \
755 import PowerFlexBase, powerflex_compatibility
756 from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.libraries.configuration \
757 import Configuration
758 from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell \
759 import utils
760
761 LOG = utils.get_logger('storagepool')
762
763
764 @powerflex_compatibility(min_ver='3.6', max_ver='5.0', successor='storagepool_v2')
765 class PowerFlexStoragePool(PowerFlexBase):
766 """Class with StoragePool operations"""
767
768 def __init__(self):
769 """ Define all parameters required by this module"""
770 """ initialize the ansible module """
771 mutually_exclusive = [['storage_pool_name', 'storage_pool_id'],
772 ['protection_domain_name', 'protection_domain_id'],
773 ['storage_pool_id', 'protection_domain_name'],
774 ['storage_pool_id', 'protection_domain_id']]
775
776 required_one_of = [['storage_pool_name', 'storage_pool_id']]
777
778 ansible_module_params = {
779 'argument_spec': get_powerflex_storagepool_parameters(),
780 'supports_check_mode': True,
781 'mutually_exclusive': mutually_exclusive,
782 'required_one_of': required_one_of
783 }
784 super().__init__(AnsibleModule, ansible_module_params)
785 super().check_module_compatibility()
786
787 # utils.ensure_required_libs(self.module)
788 self.result = dict(
789 changed=False,
790 storage_pool_details={}
791 )
792
793 def get_protection_domain(
794 self, protection_domain_name=None, protection_domain_id=None
795 ):
796 """Get the details of a protection domain in a given PowerFlex storage
797 system"""
798 return Configuration(self.powerflex_conn, self.module).get_protection_domain(
799 protection_domain_name=protection_domain_name, protection_domain_id=protection_domain_id)
800
801 def get_storage_pool(self, storage_pool_id=None, storage_pool_name=None,
802 pd_id=None):
803 """Get storage pool details
804 :param pd_id: ID of the protection domain
805 :param storage_pool_name: The name of the storage pool
806 :param storage_pool_id: The storage pool id
807 :return: Storage pool details
808 """
809 name_or_id = storage_pool_id if storage_pool_id \
810 else storage_pool_name
811 try:
812 filter_fields = {}
813 if storage_pool_id:
814 filter_fields = {'id': storage_pool_id}
815 if storage_pool_name:
816 filter_fields.update({'name': storage_pool_name})
817 if pd_id:
818 filter_fields.update({'protectionDomainId': pd_id})
819 pool_details = self.powerflex_conn.storage_pool.get(
820 filter_fields=filter_fields)
821 if pool_details != []:
822 if len(pool_details) > 1:
823
824 err_msg = "More than one storage pool found with {0}," \
825 " Please provide protection domain Name/Id" \
826 " to fetch the unique" \
827 " storage pool".format(storage_pool_name)
828 LOG.error(err_msg)
829 self.module.fail_json(msg=err_msg)
830 elif len(pool_details) == 1:
831 pool_details = pool_details[0]
832 statistics = self.powerflex_conn.storage_pool.get_statistics(
833 pool_details['id'])
834 pool_details['statistics'] = statistics if statistics else {}
835 pd_id = pool_details['protectionDomainId']
836 pd_name = self.get_protection_domain(
837 protection_domain_id=pd_id)['name']
838 # adding protection domain name in the pool details
839 pool_details['protectionDomainName'] = pd_name
840 return pool_details
841
842 return None
843
844 except Exception as e:
845 errormsg = "Failed to get the storage pool {0} with error " \
846 "{1}".format(name_or_id, str(e))
847 LOG.error(errormsg)
848 self.module.fail_json(msg=errormsg)
849
850 def create_storage_pool(self, pool_name, pd_id, media_type,
851 use_rfcache=None, use_rmcache=None):
852 """
853 Create a storage pool
854 :param pool_name: Name of the storage pool
855 :param pd_id: ID of the storage pool
856 :param media_type: Type of storage device in the pool
857 :param use_rfcache: Enable/Disable RFcache on pool
858 :param use_rmcache: Enable/Disable RMcache on pool
859 :return: True, if the operation is successful
860 """
861 try:
862 if media_type == "Transitional":
863 self.module.fail_json(msg="TRANSITIONAL media type is not"
864 " supported during creation."
865 " Please enter a valid media type")
866
867 if pd_id is None:
868 self.module.fail_json(
869 msg="Please provide protection domain details for "
870 "creation of a storage pool")
871 if not self.module.check_mode:
872 pool_id = self.powerflex_conn.storage_pool.create(
873 media_type=media_type,
874 protection_domain_id=pd_id, name=pool_name,
875 use_rfcache=use_rfcache, use_rmcache=use_rmcache)['id']
876
877 return self.get_storage_pool(storage_pool_id=pool_id,
878 pd_id=pd_id)
879
880 except Exception as e:
881 errormsg = "Failed to create the storage pool {0} with error " \
882 "{1}".format(pool_name, str(e))
883 LOG.error(errormsg)
884 self.module.fail_json(msg=errormsg)
885
886 def verify_protection_domain(self, pool_details):
887 """
888 :param pool_details: Details of the storage pool
889 :param pd_name: Name of the protection domain
890 :param pd_id: Id of the protection domain
891 """
892 pd_name = self.module.params['protection_domain_name']
893 pd_id = self.module.params['protection_domain_id']
894 if pool_details is not None:
895 if pd_id and pd_id != pool_details['protectionDomainId']:
896 self.module.fail_json(msg="Entered protection domain id does not"
897 " match with the storage pool's "
898 "protection domain id. Please enter "
899 "a correct protection domain id.")
900
901 if pd_name and pd_name != pool_details['protectionDomainName']:
902 self.module.fail_json(msg="Entered protection domain name does"
903 " not match with the storage pool's "
904 "protection domain name. Please enter"
905 " a correct protection domain name.")
906
907 def verify_storage_pool_name(self):
908 if (self.module.params['storage_pool_name'] is not None and
909 (len(self.module.params['storage_pool_name'].strip()) == 0)) or \
910 (self.module.params['storage_pool_new_name'] is not None and
911 (len(self.module.params['storage_pool_new_name'].strip()) == 0)):
912 self.module.fail_json(
913 msg="Empty or white spaced string provided for "
914 "storage pool name. Provide valid storage"
915 " pool name.")
916
917 def set_persistent_checksum(self, pool_details, pool_params):
918 try:
919 if pool_params['persistent_checksum']['enable']:
920 if pool_details['persistentChecksumEnabled'] is not True:
921 self.powerflex_conn.storage_pool.set_persistent_checksum(
922 storage_pool_id=pool_details['id'],
923 enable=pool_params['persistent_checksum']['enable'],
924 validate=pool_params['persistent_checksum']['validate_on_read'],
925 builder_limit=pool_params['persistent_checksum']['builder_limit'])
926 else:
927 self.powerflex_conn.storage_pool.modify_persistent_checksum(
928 storage_pool_id=pool_details['id'],
929 validate=pool_params['persistent_checksum']['validate_on_read'],
930 builder_limit=pool_params['persistent_checksum']['builder_limit'])
931
932 pool_details = self.get_storage_pool(
933 storage_pool_id=pool_details['id'])
934 return pool_details
935
936 except Exception as e:
937 err_msg = "Failed to set persistent checksum with error " \
938 "{0}".format(str(e))
939 LOG.error(err_msg)
940 self.module.fail_json(msg=err_msg)
941
942 def to_modify_persistent_checksum(self, pool_details, pool_params):
943 checksum_dict = dict()
944 if pool_params['persistent_checksum']['enable'] is not None and \
945 pool_params['persistent_checksum']['enable'] != pool_details['persistentChecksumEnabled']:
946 checksum_dict['enable'] = pool_params['persistent_checksum']['enable']
947
948 if pool_params['persistent_checksum']['validate_on_read'] is not None and \
949 pool_params['persistent_checksum']['validate_on_read'] != pool_details['persistentChecksumValidateOnRead'] and \
950 pool_params['persistent_checksum']['enable'] is True:
951 checksum_dict['validate_on_read'] = pool_params['persistent_checksum']['validate_on_read']
952
953 if pool_params['persistent_checksum']['builder_limit'] is not None and \
954 pool_params['persistent_checksum']['builder_limit'] != pool_details['persistentChecksumBuilderLimitKb'] and \
955 pool_params['persistent_checksum']['enable'] is True:
956 checksum_dict['builder_limit'] = pool_params['persistent_checksum']['builder_limit']
957
958 return checksum_dict
959
960 def to_modify_rebalance_io_priority_policy(self, pool_details, pool_params):
961
962 policy_dict = {
963 'policy': None,
964 'concurrent_ios': None,
965 'bw_limit': None
966 }
967 modify = False
968 if pool_params['rebalance_io_priority_policy']['policy'] is not None and \
969 pool_params['rebalance_io_priority_policy']['policy'] != pool_details['rebalanceIoPriorityPolicy']:
970 policy_dict['policy'] = pool_params['rebalance_io_priority_policy']['policy']
971 modify = True
972
973 if pool_params['rebalance_io_priority_policy']['concurrent_ios_per_device'] is not None and \
974 pool_params['rebalance_io_priority_policy']['concurrent_ios_per_device'] != pool_details['rebalanceIoPriorityNumOfConcurrentIosPerDevice']:
975 policy_dict['concurrent_ios'] = str(
976 pool_params['rebalance_io_priority_policy']['concurrent_ios_per_device'])
977
978 if pool_params['rebalance_io_priority_policy']['bw_limit_per_device'] is not None and \
979 pool_params['rebalance_io_priority_policy']['bw_limit_per_device'] != pool_details['rebalanceIoPriorityBwLimitPerDeviceInKbps']:
980 policy_dict['bw_limit'] = str(
981 pool_params['rebalance_io_priority_policy']['bw_limit_per_device'])
982
983 if policy_dict['policy'] is None and (policy_dict['concurrent_ios'] is not None or policy_dict['bw_limit'] is not None):
984 policy_dict['policy'] = pool_details['rebalanceIoPriorityPolicy']
985 modify = True
986
987 if modify is True:
988 return policy_dict
989 else:
990 return None
991
992 def to_modify_vtree_migration_io_priority_policy(self, pool_details, pool_params):
993 policy_dict = {
994 'policy': None,
995 'concurrent_ios': None,
996 'bw_limit': None
997 }
998 modify = False
999 if pool_params['vtree_migration_io_priority_policy']['policy'] is not None and \
1000 pool_params['vtree_migration_io_priority_policy']['policy'] != pool_details['vtreeMigrationIoPriorityPolicy']:
1001 policy_dict['policy'] = pool_params['vtree_migration_io_priority_policy']['policy']
1002 modify = True
1003
1004 if pool_params['vtree_migration_io_priority_policy']['concurrent_ios_per_device'] is not None and \
1005 pool_params['vtree_migration_io_priority_policy']['concurrent_ios_per_device'] != \
1006 pool_details['vtreeMigrationIoPriorityNumOfConcurrentIosPerDevice']:
1007 policy_dict['concurrent_ios'] = str(
1008 pool_params['vtree_migration_io_priority_policy']['concurrent_ios_per_device'])
1009
1010 if pool_params['vtree_migration_io_priority_policy']['bw_limit_per_device'] is not None and \
1011 pool_params['vtree_migration_io_priority_policy']['bw_limit_per_device'] != \
1012 pool_details['vtreeMigrationIoPriorityBwLimitPerDeviceInKbps']:
1013 policy_dict['bw_limit'] = str(
1014 pool_params['vtree_migration_io_priority_policy']['bw_limit_per_device'])
1015
1016 if policy_dict['policy'] is None and (policy_dict['concurrent_ios'] is not None or policy_dict['bw_limit'] is not None):
1017 policy_dict['policy'] = pool_details['vtreeMigrationIoPriorityPolicy']
1018 modify = True
1019
1020 if modify is True:
1021 return policy_dict
1022 else:
1023 return None
1024
1025 def to_modify_protected_maintenance_mode_io_priority_policy(self, pool_details, pool_params):
1026
1027 policy_dict = {
1028 'policy': None,
1029 'concurrent_ios': None,
1030 'bw_limit': None
1031 }
1032 modify = False
1033 if pool_params['protected_maintenance_mode_io_priority_policy']['policy'] is not None and \
1034 pool_params['protected_maintenance_mode_io_priority_policy']['policy'] != pool_details['protectedMaintenanceModeIoPriorityPolicy']:
1035 policy_dict['policy'] = pool_params['protected_maintenance_mode_io_priority_policy']['policy']
1036 modify = True
1037
1038 if pool_params['protected_maintenance_mode_io_priority_policy']['concurrent_ios_per_device'] is not None and \
1039 pool_params['protected_maintenance_mode_io_priority_policy']['concurrent_ios_per_device'] != \
1040 pool_details['protectedMaintenanceModeIoPriorityNumOfConcurrentIosPerDevice']:
1041 policy_dict['concurrent_ios'] = str(
1042 pool_params['protected_maintenance_mode_io_priority_policy']['concurrent_ios_per_device'])
1043
1044 if pool_params['protected_maintenance_mode_io_priority_policy']['bw_limit_per_device'] is not None and \
1045 pool_params['protected_maintenance_mode_io_priority_policy']['bw_limit_per_device'] != \
1046 pool_details['protectedMaintenanceModeIoPriorityBwLimitPerDeviceInKbps']:
1047 policy_dict['bw_limit'] = str(
1048 pool_params['protected_maintenance_mode_io_priority_policy']['bw_limit_per_device'])
1049
1050 if policy_dict['policy'] is None and (policy_dict['concurrent_ios'] is not None or policy_dict['bw_limit'] is not None):
1051 policy_dict['policy'] = pool_details['protectedMaintenanceModeIoPriorityPolicy']
1052 modify = True
1053
1054 if modify is True:
1055 return policy_dict
1056 else:
1057 return None
1058
1059 def to_modify_capacity_alert_thresholds(self, pool_details, pool_params, thresholds):
1060 modify = False
1061 threshold = dict()
1062 if pool_params['cap_alert_thresholds']['high_threshold'] is not None and pool_params['cap_alert_thresholds'][
1063 'high_threshold'] != pool_details['capacityAlertHighThreshold']:
1064 threshold['high'] = str(
1065 pool_params['cap_alert_thresholds']['high_threshold'])
1066 modify = True
1067 if pool_params['cap_alert_thresholds']['critical_threshold'] is not None and \
1068 pool_params['cap_alert_thresholds']['critical_threshold'] != pool_details[
1069 'capacityAlertCriticalThreshold']:
1070 threshold['critical'] = str(
1071 pool_params['cap_alert_thresholds']['critical_threshold'])
1072 modify = True
1073 if modify is True:
1074 if 'high' not in threshold:
1075 threshold['high'] = str(
1076 pool_details['capacityAlertHighThreshold'])
1077 if 'critical' not in threshold:
1078 threshold['critical'] = str(
1079 pool_details['capacityAlertCriticalThreshold'])
1080
1081 return threshold
1082
1083
1084 def get_powerflex_storagepool_parameters():
1085 """This method provides parameters required for the ansible
1086 Storage Pool module on powerflex"""
1087 return dict(
1088 storage_pool_name=dict(required=False, type='str'),
1089 storage_pool_id=dict(required=False, type='str'),
1090 protection_domain_name=dict(required=False, type='str'),
1091 protection_domain_id=dict(required=False, type='str'),
1092 media_type=dict(required=False, type='str',
1093 choices=['HDD', 'SSD', 'TRANSITIONAL']),
1094 use_rfcache=dict(required=False, type='bool'),
1095 use_rmcache=dict(required=False, type='bool'),
1096 enable_zero_padding=dict(type='bool'),
1097 rep_cap_max_ratio=dict(type='int'),
1098 rmcache_write_handling_mode=dict(
1099 choices=['Cached', 'Passthrough'], default='Cached'),
1100 spare_percentage=dict(type='int'),
1101 enable_rebalance=dict(type='bool'),
1102 enable_fragmentation=dict(type='bool'),
1103 enable_rebuild=dict(type='bool'),
1104 storage_pool_new_name=dict(required=False, type='str'),
1105 parallel_rebuild_rebalance_limit=dict(type='int'),
1106 cap_alert_thresholds=dict(type='dict', options=dict(
1107 high_threshold=dict(type='int'),
1108 critical_threshold=dict(type='int'))),
1109 protected_maintenance_mode_io_priority_policy=dict(type='dict', options=dict(
1110 policy=dict(choices=['unlimited', 'limitNumOfConcurrentIos',
1111 'favorAppIos'], default='limitNumOfConcurrentIos'),
1112 concurrent_ios_per_device=dict(type='int'),
1113 bw_limit_per_device=dict(type='int'))),
1114 rebalance_io_priority_policy=dict(type='dict', options=dict(
1115 policy=dict(choices=[
1116 'unlimited', 'limitNumOfConcurrentIos', 'favorAppIos'], default='favorAppIos'),
1117 concurrent_ios_per_device=dict(type='int'),
1118 bw_limit_per_device=dict(type='int'))),
1119 vtree_migration_io_priority_policy=dict(type='dict', options=dict(
1120 policy=dict(choices=['limitNumOfConcurrentIos', 'favorAppIos']),
1121 concurrent_ios_per_device=dict(type='int'),
1122 bw_limit_per_device=dict(type='int'))),
1123 persistent_checksum=dict(type='dict', options=dict(
1124 enable=dict(type='bool'),
1125 validate_on_read=dict(type='bool'),
1126 builder_limit=dict(type='int', default=3072))),
1127 state=dict(required=True, type='str', choices=['present', 'absent']))
1128
1129
1130 class StoragePoolExitHandler():
1131 def handle(self, pool_obj, pool_details):
1132 if pool_details:
1133 pool_details = pool_obj.get_storage_pool(
1134 storage_pool_id=pool_details['id'])
1135 pool_obj.result['storage_pool_details'] = pool_details
1136
1137 pool_obj.module.exit_json(**pool_obj.result)
1138
1139
1140 class StoragePoolDeleteHandler():
1141 def handle(self, pool_obj, pool_params, pool_details):
1142 if pool_params['state'] == 'absent' and pool_details:
1143 msg = "Deleting storage pool is not supported through" \
1144 " ansible module."
1145 LOG.error(msg)
1146 pool_obj.module.fail_json(msg=msg)
1147
1148 StoragePoolExitHandler().handle(pool_obj, pool_details)
1149
1150
1151 class StoragePoolModifyPersistentChecksumHandler():
1152 def handle(self, pool_obj, pool_params, pool_details):
1153 try:
1154 if pool_params['state'] == 'present' and pool_details:
1155 if pool_params['persistent_checksum'] is not None:
1156 checksum_dict = pool_obj.to_modify_persistent_checksum(
1157 pool_details=pool_details,
1158 pool_params=pool_params)
1159 if checksum_dict != {}:
1160 if not pool_obj.module.check_mode:
1161 pool_details = pool_obj.set_persistent_checksum(
1162 pool_details=pool_details,
1163 pool_params=pool_params)
1164 pool_obj.result['changed'] = True
1165
1166 StoragePoolDeleteHandler().handle(pool_obj, pool_params, pool_details)
1167
1168 except Exception as e:
1169 error_msg = (f"Modify Persistent Checksum failed "
1170 f"with error {str(e)}")
1171 LOG.error(error_msg)
1172 pool_obj.module.fail_json(msg=error_msg)
1173
1174
1175 class StoragePoolModifyRebalanceIOPriorityPolicyHandler():
1176 def handle(self, pool_obj, pool_params, pool_details):
1177 try:
1178 if pool_params['state'] == 'present' and pool_details:
1179 if pool_params['rebalance_io_priority_policy'] is not None:
1180 policy_dict = pool_obj.to_modify_rebalance_io_priority_policy(
1181 pool_details=pool_details,
1182 pool_params=pool_params
1183 )
1184 if policy_dict is not None:
1185 if not pool_obj.module.check_mode:
1186 pool_details = pool_obj.powerflex_conn.storage_pool.rebalance_io_priority_policy(
1187 storage_pool_id=pool_details['id'],
1188 policy=policy_dict['policy'],
1189 concurrent_ios_per_device=policy_dict['concurrent_ios'],
1190 bw_limit_per_device=policy_dict['bw_limit'])
1191 pool_obj.result['changed'] = True
1192
1193 StoragePoolModifyPersistentChecksumHandler().handle(
1194 pool_obj, pool_params, pool_details)
1195
1196 except Exception as e:
1197 error_msg = (f"Modify rebalance IO Priority Policy failed "
1198 f"with error {str(e)}")
1199 LOG.error(error_msg)
1200 pool_obj.module.fail_json(msg=error_msg)
1201
1202
1203 class StoragePoolSetVtreeMigrationIOPriorityPolicyHandler():
1204 def handle(self, pool_obj, pool_params, pool_details):
1205 try:
1206 if pool_params['state'] == 'present' and pool_details:
1207 if pool_params['vtree_migration_io_priority_policy'] is not None:
1208 policy_dict = pool_obj.to_modify_vtree_migration_io_priority_policy(
1209 pool_details=pool_details,
1210 pool_params=pool_params
1211 )
1212 if policy_dict is not None:
1213 if not pool_obj.module.check_mode:
1214 pool_details = pool_obj.powerflex_conn.storage_pool.set_vtree_migration_io_priority_policy(
1215 storage_pool_id=pool_details['id'],
1216 policy=policy_dict['policy'],
1217 concurrent_ios_per_device=policy_dict['concurrent_ios'],
1218 bw_limit_per_device=policy_dict['bw_limit'])
1219 pool_obj.result['changed'] = True
1220
1221 StoragePoolModifyRebalanceIOPriorityPolicyHandler().handle(
1222 pool_obj, pool_params, pool_details)
1223
1224 except Exception as e:
1225 error_msg = (f"Set Vtree Migration I/O Priority Policy operation failed "
1226 f"with error {str(e)}")
1227 LOG.error(error_msg)
1228 pool_obj.module.fail_json(msg=error_msg)
1229
1230
1231 class StoragePoolSetProtectedMaintenanceModeIOPriorityPolicyHandler():
1232 def handle(self, pool_obj, pool_params, pool_details):
1233 try:
1234 if pool_params['state'] == 'present' and pool_details:
1235 if pool_params['protected_maintenance_mode_io_priority_policy'] is not None:
1236 policy_dict = pool_obj.to_modify_protected_maintenance_mode_io_priority_policy(
1237 pool_details=pool_details,
1238 pool_params=pool_params
1239 )
1240 if policy_dict is not None:
1241 if not pool_obj.module.check_mode:
1242 pool_details = pool_obj.powerflex_conn.storage_pool.set_protected_maintenance_mode_io_priority_policy(
1243 storage_pool_id=pool_details['id'],
1244 policy=policy_dict['policy'],
1245 concurrent_ios_per_device=policy_dict['concurrent_ios'],
1246 bw_limit_per_device=policy_dict['bw_limit'])
1247 pool_obj.result['changed'] = True
1248
1249 StoragePoolSetVtreeMigrationIOPriorityPolicyHandler().handle(
1250 pool_obj, pool_params, pool_details)
1251
1252 except Exception as e:
1253 error_msg = (f"Set Protected Maintenance Mode IO Priority Policy operation failed "
1254 f"with error {str(e)}")
1255 LOG.error(error_msg)
1256 pool_obj.module.fail_json(msg=error_msg)
1257
1258
1259 class StoragePoolModifyCapacityAlertThresholdsHandler():
1260 def handle(self, pool_obj, pool_params, pool_details):
1261 try:
1262 if pool_params['state'] == 'present' and pool_details:
1263 if pool_params['cap_alert_thresholds'] is not None:
1264 threshold = pool_obj.to_modify_capacity_alert_thresholds(pool_details=pool_details,
1265 pool_params=pool_params,
1266 thresholds=pool_params[
1267 'cap_alert_thresholds'])
1268 if threshold != {}:
1269 if not pool_obj.module.check_mode:
1270 pool_details = pool_obj.powerflex_conn.storage_pool.set_cap_alert_thresholds(
1271 storage_pool_id=pool_details['id'],
1272 cap_alert_high_threshold=threshold['high'],
1273 cap_alert_critical_threshold=threshold['critical'])
1274 pool_obj.result['changed'] = True
1275
1276 StoragePoolSetProtectedMaintenanceModeIOPriorityPolicyHandler().handle(
1277 pool_obj, pool_params, pool_details)
1278
1279 except Exception as e:
1280 error_msg = (f"Modify Capacity Alert Thresholds operation failed "
1281 f"with error {str(e)}")
1282 LOG.error(error_msg)
1283 pool_obj.module.fail_json(msg=error_msg)
1284
1285
1286 class StoragePoolModifyRebuildRebalanceParallelismLimitHandler():
1287 def handle(self, pool_obj, pool_params, pool_details):
1288 try:
1289 if pool_params['state'] == 'present' and pool_details:
1290 if pool_params['parallel_rebuild_rebalance_limit'] is not None and \
1291 pool_params['parallel_rebuild_rebalance_limit'] != pool_details['numOfParallelRebuildRebalanceJobsPerDevice']:
1292 if not pool_obj.module.check_mode:
1293 pool_details = pool_obj.powerflex_conn.storage_pool.set_rebuild_rebalance_parallelism_limit(
1294 pool_details['id'], str(pool_params['parallel_rebuild_rebalance_limit']))
1295 pool_obj.result['changed'] = True
1296
1297 StoragePoolModifyCapacityAlertThresholdsHandler().handle(
1298 pool_obj, pool_params, pool_details)
1299
1300 except Exception as e:
1301 error_msg = (f"Modify Rebuild/Rebalance Parallelism Limit operation failed "
1302 f"with error {str(e)}")
1303 LOG.error(error_msg)
1304 pool_obj.module.fail_json(msg=error_msg)
1305
1306
1307 class StoragePoolModifyRMCacheWriteHandlingModeHandler():
1308 def handle(self, pool_obj, pool_params, pool_details):
1309 try:
1310 if pool_params['state'] == 'present' and pool_details:
1311 if pool_params['rmcache_write_handling_mode'] is not None and \
1312 pool_params['rmcache_write_handling_mode'] != pool_details['rmcacheWriteHandlingMode']:
1313 if not pool_obj.module.check_mode:
1314 pool_details = pool_obj.powerflex_conn.storage_pool.set_rmcache_write_handling_mode(
1315 pool_details['id'], pool_params['rmcache_write_handling_mode'])
1316 pool_obj.result['changed'] = True
1317
1318 StoragePoolModifyRebuildRebalanceParallelismLimitHandler().handle(
1319 pool_obj, pool_params, pool_details)
1320
1321 except Exception as e:
1322 error_msg = (f"Modify RMCache Write Handling Mode failed "
1323 f"with error {str(e)}")
1324 LOG.error(error_msg)
1325 pool_obj.module.fail_json(msg=error_msg)
1326
1327
1328 class StoragePoolModifySparePercentageHandler():
1329 def handle(self, pool_obj, pool_params, pool_details):
1330 try:
1331 if pool_params['state'] == 'present' and pool_details:
1332 if pool_params['spare_percentage'] is not None and pool_params['spare_percentage'] != pool_details['sparePercentage']:
1333 if not pool_obj.module.check_mode:
1334 pool_details = pool_obj.powerflex_conn.storage_pool.set_spare_percentage(
1335 pool_details['id'], str(pool_params['spare_percentage']))
1336 pool_obj.result['changed'] = True
1337
1338 StoragePoolModifyRMCacheWriteHandlingModeHandler().handle(
1339 pool_obj, pool_params, pool_details)
1340
1341 except Exception as e:
1342 error_msg = (f"Modify Spare Percentage operation failed "
1343 f"with error {str(e)}")
1344 LOG.error(error_msg)
1345 pool_obj.module.fail_json(msg=error_msg)
1346
1347
1348 class StoragePoolEnableFragmentationHandler():
1349 def handle(self, pool_obj, pool_params, pool_details):
1350 try:
1351 if pool_params['state'] == 'present' and pool_details:
1352 if pool_params['enable_fragmentation'] is not None and pool_params['enable_fragmentation'] != pool_details['fragmentationEnabled']:
1353 if not pool_obj.module.check_mode:
1354 pool_details = pool_obj.powerflex_conn.storage_pool.set_fragmentation_enabled(
1355 pool_details['id'], pool_params['enable_fragmentation'])
1356 pool_obj.result['changed'] = True
1357
1358 StoragePoolModifySparePercentageHandler().handle(
1359 pool_obj, pool_params, pool_details)
1360
1361 except Exception as e:
1362
1363 error_msg = (f"Enable/Disable Fragmentation operation failed "
1364 f"with error {str(e)}")
1365 LOG.error(error_msg)
1366 pool_obj.module.fail_json(msg=error_msg)
1367
1368
1369 class StoragePoolEnableRebuildHandler():
1370 def handle(self, pool_obj, pool_params, pool_details):
1371 try:
1372 if pool_params['state'] == 'present' and pool_details:
1373 if pool_params['enable_rebuild'] is not None and pool_params['enable_rebuild'] != pool_details['rebuildEnabled']:
1374 if not pool_obj.module.check_mode:
1375 pool_details = pool_obj.powerflex_conn.storage_pool.set_rebuild_enabled(
1376 pool_details['id'], pool_params['enable_rebuild'])
1377 pool_obj.result['changed'] = True
1378
1379 StoragePoolEnableFragmentationHandler().handle(
1380 pool_obj, pool_params, pool_details)
1381
1382 except Exception as e:
1383 error_msg = (f"Enable/Disable Rebuild operation failed "
1384 f"with error {str(e)}")
1385 LOG.error(error_msg)
1386 pool_obj.module.fail_json(msg=error_msg)
1387
1388
1389 class StoragePoolEnableRebalanceHandler():
1390 def handle(self, pool_obj, pool_params, pool_details):
1391 try:
1392 if pool_params['state'] == 'present' and pool_details:
1393 if pool_params['enable_rebalance'] is not None and pool_params['enable_rebalance'] != pool_details['rebalanceEnabled']:
1394 if not pool_obj.module.check_mode:
1395 pool_details = pool_obj.powerflex_conn.storage_pool.set_rebalance_enabled(
1396 pool_details['id'], pool_params['enable_rebalance'])
1397 pool_obj.result['changed'] = True
1398
1399 StoragePoolEnableRebuildHandler().handle(pool_obj, pool_params, pool_details)
1400
1401 except Exception as e:
1402 error_msg = (f"Enable/Disable Rebalance failed "
1403 f"with error {str(e)}")
1404 LOG.error(error_msg)
1405 pool_obj.module.fail_json(msg=error_msg)
1406
1407
1408 class StoragePoolModifyRepCapMaxRatioHandler():
1409 def handle(self, pool_obj, pool_params, pool_details):
1410 try:
1411 if pool_params['state'] == 'present' and pool_details:
1412 if pool_params['rep_cap_max_ratio'] is not None and pool_params['rep_cap_max_ratio'] != pool_details['replicationCapacityMaxRatio']:
1413 if not pool_obj.module.check_mode:
1414 pool_details = pool_obj.powerflex_conn.storage_pool.set_rep_cap_max_ratio(
1415 pool_details['id'], str(pool_params['rep_cap_max_ratio']))
1416 pool_obj.result['changed'] = True
1417
1418 StoragePoolEnableRebalanceHandler().handle(pool_obj, pool_params, pool_details)
1419
1420 except Exception as e:
1421 error_msg = (f"Modify Replication Capacity max ratio operation failed "
1422 f"with error {str(e)}")
1423 LOG.error(error_msg)
1424 pool_obj.module.fail_json(msg=error_msg)
1425
1426
1427 class StoragePoolEnableZeroPaddingHandler():
1428 def handle(self, pool_obj, pool_params, pool_details):
1429 try:
1430 if pool_params['state'] == 'present' and pool_details:
1431 if pool_params['enable_zero_padding'] is not None and pool_params['enable_zero_padding'] != pool_details['zeroPaddingEnabled']:
1432 if not pool_obj.module.check_mode:
1433 pool_details = pool_obj.powerflex_conn.storage_pool.set_zero_padding_policy(
1434 pool_details['id'], pool_params['enable_zero_padding'])
1435 pool_obj.result['changed'] = True
1436
1437 StoragePoolModifyRepCapMaxRatioHandler().handle(
1438 pool_obj, pool_params, pool_details)
1439
1440 except Exception as e:
1441 error_msg = (f"Enable/Disable zero padding operation failed "
1442 f"with error {str(e)}")
1443 LOG.error(error_msg)
1444 pool_obj.module.fail_json(msg=error_msg)
1445
1446
1447 class StoragePoolUseRFCacheHandler():
1448 def handle(self, pool_obj, pool_params, pool_details):
1449 try:
1450 if pool_params['state'] == 'present' and pool_details:
1451 if pool_params['use_rfcache'] is not None and pool_params['use_rfcache'] != pool_details['useRfcache']:
1452 if not pool_obj.module.check_mode:
1453 pool_details = pool_obj.powerflex_conn.storage_pool.set_use_rfcache(
1454 pool_details['id'], pool_params['use_rfcache'])
1455 pool_obj.result['changed'] = True
1456
1457 StoragePoolEnableZeroPaddingHandler().handle(
1458 pool_obj, pool_params, pool_details)
1459
1460 except Exception as e:
1461 error_msg = (f"Modify RF cache operation failed "
1462 f"with error {str(e)}")
1463 LOG.error(error_msg)
1464 pool_obj.module.fail_json(msg=error_msg)
1465
1466
1467 class StoragePoolUseRMCacheHandler():
1468 def handle(self, pool_obj, pool_params, pool_details):
1469 try:
1470 if pool_params['state'] == 'present' and pool_details:
1471 if pool_params['use_rmcache'] is not None and pool_params['use_rmcache'] != pool_details['useRmcache']:
1472 if not pool_obj.module.check_mode:
1473 pool_details = pool_obj.powerflex_conn.storage_pool.set_use_rmcache(
1474 pool_details['id'], pool_params['use_rmcache'])
1475 pool_obj.result['changed'] = True
1476
1477 StoragePoolUseRFCacheHandler().handle(pool_obj, pool_params, pool_details)
1478
1479 except Exception as e:
1480 error_msg = (f"Modify RM cache operation failed "
1481 f"with error {str(e)}")
1482 LOG.error(error_msg)
1483 pool_obj.module.fail_json(msg=error_msg)
1484
1485
1486 class StoragePoolRenameHandler():
1487 def handle(self, pool_obj, pool_params, pool_details):
1488 try:
1489 if pool_params['state'] == 'present' and pool_details:
1490 if pool_params['storage_pool_new_name'] is not None and pool_params['storage_pool_new_name'] != pool_details['name']:
1491 if not pool_obj.module.check_mode:
1492 pool_obj.powerflex_conn.storage_pool.rename(
1493 pool_details['id'], pool_params['storage_pool_new_name'])
1494 pool_obj.result['changed'] = True
1495
1496 StoragePoolUseRMCacheHandler().handle(pool_obj, pool_params, pool_details)
1497
1498 except Exception as e:
1499 error_msg = (f"Modify storage pool name failed "
1500 f"with error {str(e)}")
1501 LOG.error(error_msg)
1502 pool_obj.module.fail_json(msg=error_msg)
1503
1504
1505 class StoragePoolModifyMediaTypeHandler():
1506 def handle(self, pool_obj, pool_params, pool_details, media_type):
1507 try:
1508 if pool_params['state'] == 'present' and pool_details:
1509 if media_type is not None and media_type != pool_details['mediaType']:
1510 if not pool_obj.module.check_mode:
1511 pool_details = pool_obj.powerflex_conn.storage_pool.set_media_type(
1512 pool_details['id'], media_type)
1513 pool_obj.result['changed'] = True
1514
1515 StoragePoolRenameHandler().handle(pool_obj, pool_params, pool_details)
1516
1517 except Exception as e:
1518 error_msg = (f"Modify Media Type failed "
1519 f"with error {str(e)}")
1520 LOG.error(error_msg)
1521 pool_obj.module.fail_json(msg=error_msg)
1522
1523
1524 class StoragePoolCreateHandler():
1525 def handle(self, pool_obj, pool_params, pool_details, pd_id, media_type):
1526 if pool_params['state'] == 'present' and pool_details is None:
1527 if not pool_obj.module.check_mode:
1528 LOG.info("Creating new storage pool")
1529 if pool_params['storage_pool_id']:
1530 self.module.fail_json(
1531 msg="storage_pool_name is missing & name required to "
1532 "create a storage pool. Please enter a valid "
1533 "storage_pool_name.")
1534
1535 pool_details = pool_obj.create_storage_pool(
1536 pool_name=pool_params['storage_pool_name'],
1537 pd_id=pd_id,
1538 media_type=media_type,
1539 use_rfcache=pool_params['use_rfcache'],
1540 use_rmcache=pool_params['use_rmcache'])
1541
1542 pool_obj.result['changed'] = True
1543
1544 StoragePoolModifyMediaTypeHandler().handle(
1545 pool_obj, pool_params, pool_details, media_type)
1546
1547
1548 class StoragePoolHandler():
1549 def handle(self, pool_obj, pool_params):
1550 pool_obj.verify_storage_pool_name()
1551 media_type = pool_params['media_type']
1552 if media_type == "TRANSITIONAL":
1553 media_type = 'Transitional'
1554 pd_id = None
1555 if pool_params['protection_domain_id'] or pool_params['protection_domain_name']:
1556 pd_id = pool_obj.get_protection_domain(
1557 protection_domain_id=pool_params['protection_domain_id'],
1558 protection_domain_name=pool_params['protection_domain_name'])['id']
1559 pool_details = pool_obj.get_storage_pool(storage_pool_id=pool_params['storage_pool_id'],
1560 storage_pool_name=pool_params['storage_pool_name'],
1561 pd_id=pd_id)
1562 pool_obj.verify_protection_domain(pool_details=pool_details)
1563 StoragePoolCreateHandler().handle(pool_obj, pool_params,
1564 pool_details, pd_id, media_type)
1565
1566
1567 def main():
1568 """ Create PowerFlex storage pool object and perform action on it
1569 based on user input from playbook"""
1570 obj = PowerFlexStoragePool()
1571 StoragePoolHandler().handle(obj, obj.module.params)
1572
1573
1574 if __name__ == '__main__':
1575 main()