| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
"""Ansible module for managing storage pool on Dell Technologies (Dell) PowerFlex 5.x""" |
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
DOCUMENTATION = r''' |
| 12 |
--- |
| 13 |
module: storagepool_v2 |
| 14 |
version_added: '3.0.0' |
| 15 |
short_description: Managing storage pool on Dell PowerFlex 5.x |
| 16 |
|
| 17 |
description: |
| 18 |
- Dell PowerFlex storage pool module includes getting the details of |
| 19 |
storage pool, creating a new storage pool, and modifying the attribute of |
| 20 |
a storage pool. |
| 21 |
|
| 22 |
extends_documentation_fragment: |
| 23 |
- dellemc.powerflex.powerflex_v2 |
| 24 |
|
| 25 |
author: |
| 26 |
- Luis Liu (@vangork) <[email protected]> |
| 27 |
- Yiming Bao (@baoy1) <[email protected]> |
| 28 |
|
| 29 |
options: |
| 30 |
storage_pool_name: |
| 31 |
description: |
| 32 |
- The name of the storage pool. |
| 33 |
- If more than one storage pool is found with the same name then |
| 34 |
protection domain id/name is required to perform the task. |
| 35 |
- Mutually exclusive with I(storage_pool_id). |
| 36 |
type: str |
| 37 |
storage_pool_id: |
| 38 |
description: |
| 39 |
- The id of the storage pool. |
| 40 |
- It is auto generated, hence should not be provided during |
| 41 |
creation of a storage pool. |
| 42 |
- Mutually exclusive with I(storage_pool_name). |
| 43 |
type: str |
| 44 |
storage_pool_new_name: |
| 45 |
description: |
| 46 |
- New name for the storage pool can be provided. |
| 47 |
- This parameter is used for renaming the storage pool. |
| 48 |
type: str |
| 49 |
protection_domain_name: |
| 50 |
description: |
| 51 |
- The name of the protection domain. |
| 52 |
- During creation of a pool, either protection domain name or id must be |
| 53 |
mentioned. |
| 54 |
- Mutually exclusive with I(protection_domain_id). |
| 55 |
type: str |
| 56 |
protection_domain_id: |
| 57 |
description: |
| 58 |
- The id of the protection domain. |
| 59 |
- During creation of a pool, either protection domain name or id must |
| 60 |
be mentioned. |
| 61 |
- Mutually exclusive with I(protection_domain_name). |
| 62 |
type: str |
| 63 |
device_group_id: |
| 64 |
description: |
| 65 |
- The ID of the device group. |
| 66 |
required: false |
| 67 |
type: str |
| 68 |
device_group_name: |
| 69 |
description: |
| 70 |
- The name of the device group. |
| 71 |
required: false |
| 72 |
type: str |
| 73 |
cap_alert_thresholds: |
| 74 |
description: |
| 75 |
- The capacity alert thresholds. |
| 76 |
required: false |
| 77 |
type: dict |
| 78 |
suboptions: |
| 79 |
high_threshold: |
| 80 |
description: |
| 81 |
- The high threshold. |
| 82 |
required: false |
| 83 |
type: int |
| 84 |
critical_threshold: |
| 85 |
description: |
| 86 |
- The critical threshold. |
| 87 |
required: false |
| 88 |
type: int |
| 89 |
compression_method: |
| 90 |
description: |
| 91 |
- The compression method. |
| 92 |
required: false |
| 93 |
type: str |
| 94 |
choices: ['None', 'Normal'] |
| 95 |
over_provisioning_factor: |
| 96 |
description: |
| 97 |
- The over-provisioning factor. |
| 98 |
required: false |
| 99 |
type: int |
| 100 |
physical_size_gb: |
| 101 |
description: |
| 102 |
- The physical size in GB. |
| 103 |
- If 'use_all_available_capacity' is set to true, this parameter cannot be specified. |
| 104 |
- If 'use_all_available_capacity' is set to false, this parameter is required. |
| 105 |
required: false |
| 106 |
type: int |
| 107 |
use_all_available_capacity: |
| 108 |
description: |
| 109 |
- Whether to use all available capacity for storage pool. |
| 110 |
- When set to true, the 'physical_size_gb' parameter cannot be specified. |
| 111 |
- When set to false, the 'physical_size_gb' parameter is required. |
| 112 |
required: false |
| 113 |
type: bool |
| 114 |
protection_scheme: |
| 115 |
description: |
| 116 |
- The protection scheme. |
| 117 |
required: false |
| 118 |
type: str |
| 119 |
choices: ['TwoPlusTwo', 'EightPlusTwo'] |
| 120 |
state: |
| 121 |
description: |
| 122 |
- The state of the storage pool. Can be 'present' or 'absent'. |
| 123 |
required: true |
| 124 |
choices: ['present', 'absent'] |
| 125 |
type: str |
| 126 |
notes: |
| 127 |
- This module is supported on Dell PowerFlex 5.x and later versions. |
| 128 |
- The I(check_mode) is supported. |
| 129 |
''' |
| 130 |
|
| 131 |
EXAMPLES = r''' |
| 132 |
- name: Get the details of storage pool by name |
| 133 |
dellemc.powerflex.storagepool_v2: |
| 134 |
hostname: "{{hostname}}" |
| 135 |
username: "{{username}}" |
| 136 |
password: "{{password}}" |
| 137 |
validate_certs: "{{validate_certs}}" |
| 138 |
storage_pool_name: "sample_pool_name" |
| 139 |
protection_domain_name: "sample_protection_domain" |
| 140 |
state: "present" |
| 141 |
|
| 142 |
- name: Get the details of storage pool by id |
| 143 |
dellemc.powerflex.storagepool_v2: |
| 144 |
hostname: "{{hostname}}" |
| 145 |
username: "{{username}}" |
| 146 |
password: "{{password}}" |
| 147 |
validate_certs: "{{validate_certs}}" |
| 148 |
storage_pool_id: "abcd1234ab12r" |
| 149 |
state: "present" |
| 150 |
|
| 151 |
- name: Create a new Storage pool |
| 152 |
dellemc.powerflex.storagepool_v2: |
| 153 |
hostname: "{{ hostname }}" |
| 154 |
username: "{{ username }}" |
| 155 |
password: "{{ password }}" |
| 156 |
validate_certs: "{{ validate_certs }}" |
| 157 |
storage_pool_name: "{{ pool_name }}" |
| 158 |
protection_domain_name: "{{ protection_domain_name }}" |
| 159 |
device_group_name: "{{ device_group_name }}" |
| 160 |
cap_alert_thresholds: |
| 161 |
high_threshold: 80 |
| 162 |
critical_threshold: 90 |
| 163 |
compression_method: Normal |
| 164 |
over_provisioning_factor: 2 |
| 165 |
physical_size_gb: 100 |
| 166 |
protection_scheme: TwoPlusTwo |
| 167 |
state: "present" |
| 168 |
|
| 169 |
- name: Modify a Storage pool by name |
| 170 |
dellemc.powerflex.storagepool_v2: |
| 171 |
hostname: "{{ hostname }}" |
| 172 |
username: "{{ username }}" |
| 173 |
password: "{{ password }}" |
| 174 |
validate_certs: "{{ validate_certs }}" |
| 175 |
storage_pool_name: "{{ pool_name }}" |
| 176 |
protection_domain_name: "{{ protection_domain_name }}" |
| 177 |
storage_pool_new_name: "pool_name_new" |
| 178 |
cap_alert_thresholds: |
| 179 |
high_threshold: 85 |
| 180 |
critical_threshold: 95 |
| 181 |
compression_method: None |
| 182 |
state: "present" |
| 183 |
''' |
| 184 |
|
| 185 |
RETURN = r''' |
| 186 |
changed: |
| 187 |
description: Whether or not the resource has changed. |
| 188 |
returned: always |
| 189 |
type: bool |
| 190 |
sample: 'false' |
| 191 |
storage_pool_details: |
| 192 |
description: Details of the storage pool. |
| 193 |
returned: When storage pool exists |
| 194 |
type: dict |
| 195 |
contains: |
| 196 |
id: |
| 197 |
description: ID of the storage pool. |
| 198 |
type: str |
| 199 |
name: |
| 200 |
description: Name of the storage pool. |
| 201 |
type: str |
| 202 |
protectionDomainId: |
| 203 |
description: ID of the protection domain in which the storage pool resides. |
| 204 |
type: str |
| 205 |
zeroPaddingEnabled: |
| 206 |
description: Indicates whether zero padding is enabled for the storage pool. |
| 207 |
type: bool |
| 208 |
capacityAlertHighThreshold: |
| 209 |
description: High threshold for capacity alert (percentage). |
| 210 |
type: int |
| 211 |
capacityAlertCriticalThreshold: |
| 212 |
description: Critical threshold for capacity alert (percentage). |
| 213 |
type: int |
| 214 |
capacityUsageState: |
| 215 |
description: Current capacity usage state of the storage pool. |
| 216 |
type: str |
| 217 |
capacityUsageType: |
| 218 |
description: Type of capacity usage being monitored. |
| 219 |
type: str |
| 220 |
addressSpaceUsage: |
| 221 |
description: Current address space usage state. |
| 222 |
type: str |
| 223 |
addressSpaceUsageType: |
| 224 |
description: Type of address space usage limit. |
| 225 |
type: str |
| 226 |
fragmentationEnabled: |
| 227 |
description: Indicates whether fragmentation is enabled for the storage pool. |
| 228 |
type: bool |
| 229 |
inflightRequestsFactor: |
| 230 |
description: In-flight requests factor for performance tuning. |
| 231 |
type: int |
| 232 |
inflightBandwidthFactor: |
| 233 |
description: In-flight bandwidth factor for performance tuning. |
| 234 |
type: int |
| 235 |
compressionMethod: |
| 236 |
description: Compression method used in the storage pool. |
| 237 |
type: str |
| 238 |
spClass: |
| 239 |
description: Class of the storage pool. |
| 240 |
type: str |
| 241 |
genType: |
| 242 |
description: Data protection generation type of the storage pool. |
| 243 |
type: str |
| 244 |
deviceGroupId: |
| 245 |
description: ID of the device group associated with the storage pool. |
| 246 |
type: str |
| 247 |
wrcDeviceGroupId: |
| 248 |
description: ID of the WRC device group. |
| 249 |
type: str |
| 250 |
rawSizeGb: |
| 251 |
description: Raw size of the storage pool in GB. |
| 252 |
type: int |
| 253 |
numDataSlices: |
| 254 |
description: Number of data slices used in erasure coding. |
| 255 |
type: int |
| 256 |
numProtectionSlices: |
| 257 |
description: Number of protection slices used in erasure coding. |
| 258 |
type: int |
| 259 |
physicalSizeGb: |
| 260 |
description: Physical size of the storage pool in GB. |
| 261 |
type: int |
| 262 |
overProvisioningFactor: |
| 263 |
description: Over-provisioning factor for the storage pool. |
| 264 |
type: int |
| 265 |
protectionScheme: |
| 266 |
description: Data protection scheme used in the storage pool. |
| 267 |
type: str |
| 268 |
spHealthState: |
| 269 |
description: Health state of the storage pool. |
| 270 |
type: str |
| 271 |
statistics: |
| 272 |
description: Statistics details of the storage pool. |
| 273 |
type: dict |
| 274 |
contains: |
| 275 |
"capacityInUseInKb": |
| 276 |
description: Total capacity of the storage pool. |
| 277 |
type: str |
| 278 |
"unusedCapacityInKb": |
| 279 |
description: Unused capacity of the storage pool. |
| 280 |
type: str |
| 281 |
"deviceIds": |
| 282 |
description: Device Ids of the storage pool. |
| 283 |
type: list |
| 284 |
sample: { |
| 285 |
"addressSpaceUsage": "Normal", |
| 286 |
"addressSpaceUsageType": "TypeHardLimit", |
| 287 |
"backgroundScannerBWLimitKBps": null, |
| 288 |
"backgroundScannerMode": null, |
| 289 |
"bgScannerCompareErrorAction": "Invalid", |
| 290 |
"bgScannerReadErrorAction": "Invalid", |
| 291 |
"capacityAlertCriticalThreshold": 90, |
| 292 |
"capacityAlertHighThreshold": 80, |
| 293 |
"capacityUsageState": "Normal", |
| 294 |
"capacityUsageType": "NetCapacity", |
| 295 |
"checksumEnabled": false, |
| 296 |
"compressionMethod": "Normal", |
| 297 |
"dataLayout": "ErasureCoding", |
| 298 |
"deviceGroupId": "39a898be00000000", |
| 299 |
"deviceGroupName": "DG1", |
| 300 |
"externalAccelerationType": "None", |
| 301 |
"fglAccpId": null, |
| 302 |
"fglExtraCapacity": null, |
| 303 |
"fglMaxCompressionRatio": null, |
| 304 |
"fglMetadataSizeXx100": null, |
| 305 |
"fglNvdimmMetadataAmortizationX100": null, |
| 306 |
"fglNvdimmWriteCacheSizeInMb": null, |
| 307 |
"fglOverProvisioningFactor": null, |
| 308 |
"fglPerfProfile": null, |
| 309 |
"fglWriteAtomicitySize": null, |
| 310 |
"fragmentationEnabled": false, |
| 311 |
"genType": "EC", |
| 312 |
"id": "5dabf3f800000000", |
| 313 |
"links": [ |
| 314 |
{ |
| 315 |
"href": "/api/instances/StoragePool::5dabf3f800000000", |
| 316 |
"rel": "self" |
| 317 |
}, |
| 318 |
{ |
| 319 |
"body": { |
| 320 |
"ids": [ |
| 321 |
"5dabf3f800000000" |
| 322 |
], |
| 323 |
"resource_type": "storage_pool" |
| 324 |
}, |
| 325 |
"href": "/dtapi/rest/v1/metrics/query", |
| 326 |
"rel": "/dtapi/rest/v1/metrics/query" |
| 327 |
}, |
| 328 |
{ |
| 329 |
"href": "/api/instances/StoragePool::5dabf3f800000000/relationships/SpSds", |
| 330 |
"rel": "/api/StoragePool/relationship/SpSds" |
| 331 |
}, |
| 332 |
{ |
| 333 |
"href": "/api/instances/StoragePool::5dabf3f800000000/relationships/Volume", |
| 334 |
"rel": "/api/StoragePool/relationship/Volume" |
| 335 |
}, |
| 336 |
{ |
| 337 |
"href": "/api/instances/StoragePool::5dabf3f800000000/relationships/Device", |
| 338 |
"rel": "/api/StoragePool/relationship/Device" |
| 339 |
}, |
| 340 |
{ |
| 341 |
"href": "/api/instances/StoragePool::5dabf3f800000000/relationships/VTree", |
| 342 |
"rel": "/api/StoragePool/relationship/VTree" |
| 343 |
}, |
| 344 |
{ |
| 345 |
"href": "/api/instances/ProtectionDomain::f3d03dcf00000000", |
| 346 |
"rel": "/api/parent/relationship/protectionDomainId" |
| 347 |
}, |
| 348 |
{ |
| 349 |
"href": "/api/instances/DeviceGroup::39a898be00000000", |
| 350 |
"rel": "/api/parent/relationship/deviceGroupId" |
| 351 |
}, |
| 352 |
{ |
| 353 |
"href": "/api/instances/WrcDeviceGroup::39a898be00000000", |
| 354 |
"rel": "/api/parent/relationship/wrcDeviceGroupId" |
| 355 |
} |
| 356 |
], |
| 357 |
"mediaType": null, |
| 358 |
"name": "SP_EC", |
| 359 |
"numOfParallelRebuildRebalanceJobsPerDevice": null, |
| 360 |
"overProvisioningFactor": 0, |
| 361 |
"persistentChecksumBuilderLimitKb": null, |
| 362 |
"persistentChecksumEnabled": false, |
| 363 |
"persistentChecksumState": "StateInvalid", |
| 364 |
"persistentChecksumValidateOnRead": null, |
| 365 |
"physicalSizeGB": 5120, |
| 366 |
"protectedMaintenanceModeIoPriorityAppBwPerDeviceThresholdInKbps": null, |
| 367 |
"protectedMaintenanceModeIoPriorityAppIopsPerDeviceThreshold": null, |
| 368 |
"protectedMaintenanceModeIoPriorityBwLimitPerDeviceInKbps": null, |
| 369 |
"protectedMaintenanceModeIoPriorityNumOfConcurrentIosPerDevice": null, |
| 370 |
"protectedMaintenanceModeIoPriorityPolicy": null, |
| 371 |
"protectedMaintenanceModeIoPriorityQuietPeriodInMsec": null, |
| 372 |
"protectionDomainId": "f3d03dcf00000000", |
| 373 |
"protectionDomainName": "PD_EC", |
| 374 |
"protectionScheme": "TwoPlusTwo", |
| 375 |
"rawSizeGB": 10240, |
| 376 |
"rebalanceEnabled": null, |
| 377 |
"rebalanceIoPriorityAppBwPerDeviceThresholdInKbps": null, |
| 378 |
"rebalanceIoPriorityAppIopsPerDeviceThreshold": null, |
| 379 |
"rebalanceIoPriorityBwLimitPerDeviceInKbps": null, |
| 380 |
"rebalanceIoPriorityNumOfConcurrentIosPerDevice": null, |
| 381 |
"rebalanceIoPriorityPolicy": null, |
| 382 |
"rebalanceIoPriorityQuietPeriodInMsec": null, |
| 383 |
"rebuildEnabled": null, |
| 384 |
"rebuildIoPriorityAppBwPerDeviceThresholdInKbps": null, |
| 385 |
"rebuildIoPriorityAppIopsPerDeviceThreshold": null, |
| 386 |
"rebuildIoPriorityBwLimitPerDeviceInKbps": null, |
| 387 |
"rebuildIoPriorityNumOfConcurrentIosPerDevice": null, |
| 388 |
"rebuildIoPriorityPolicy": null, |
| 389 |
"rebuildIoPriorityQuietPeriodInMsec": null, |
| 390 |
"replicationCapacityMaxRatio": null, |
| 391 |
"rmcacheWriteHandlingMode": "Invalid", |
| 392 |
"spClass": "Default", |
| 393 |
"spHealthState": "Protected", |
| 394 |
"sparePercentage": null, |
| 395 |
"statistics": { |
| 396 |
"format": "ID_TIMESTAMP_METRIC", |
| 397 |
"resource_type": "storage_pool", |
| 398 |
"resources": [ |
| 399 |
{ |
| 400 |
"id": "5dabf3f800000000", |
| 401 |
"metrics": [ |
| 402 |
{ |
| 403 |
"name": "physical_free", |
| 404 |
"values": [ |
| 405 |
5443871047680 |
| 406 |
] |
| 407 |
}, |
| 408 |
{ |
| 409 |
"name": "logical_provisioned", |
| 410 |
"values": [ |
| 411 |
0 |
| 412 |
] |
| 413 |
}, |
| 414 |
{ |
| 415 |
"name": "raw_used", |
| 416 |
"values": [ |
| 417 |
10995116277760 |
| 418 |
] |
| 419 |
}, |
| 420 |
{ |
| 421 |
"name": "logical_used", |
| 422 |
"values": [ |
| 423 |
0 |
| 424 |
] |
| 425 |
}, |
| 426 |
{ |
| 427 |
"name": "physical_total", |
| 428 |
"values": [ |
| 429 |
5497558138880 |
| 430 |
] |
| 431 |
}, |
| 432 |
{ |
| 433 |
"name": "physical_used", |
| 434 |
"values": [ |
| 435 |
0 |
| 436 |
] |
| 437 |
}, |
| 438 |
{ |
| 439 |
"name": "over_provisioning_limit", |
| 440 |
"values": [ |
| 441 |
4611686017353646080 |
| 442 |
] |
| 443 |
} |
| 444 |
] |
| 445 |
} |
| 446 |
], |
| 447 |
"timestamps": [ |
| 448 |
"2025-08-25T05:24:06Z" |
| 449 |
] |
| 450 |
}, |
| 451 |
"useRfcache": false, |
| 452 |
"useRmcache": false, |
| 453 |
"vtreeMigrationIoPriorityAppBwPerDeviceThresholdInKbps": null, |
| 454 |
"vtreeMigrationIoPriorityAppIopsPerDeviceThreshold": null, |
| 455 |
"vtreeMigrationIoPriorityBwLimitPerDeviceInKbps": null, |
| 456 |
"vtreeMigrationIoPriorityNumOfConcurrentIosPerDevice": null, |
| 457 |
"vtreeMigrationIoPriorityPolicy": null, |
| 458 |
"vtreeMigrationIoPriorityQuietPeriodInMsec": null, |
| 459 |
"wrcDeviceGroupId": "39a898be00000000", |
| 460 |
"zeroPaddingEnabled": true |
| 461 |
} |
| 462 |
''' |
| 463 |
|
| 464 |
import copy |
| 465 |
from ansible.module_utils.basic import AnsibleModule |
| 466 |
from ansible_collections.dellemc.powerflex.plugins.module_utils. \ |
| 467 |
storage.dell.libraries.configuration import Configuration |
| 468 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.libraries.powerflex_base \ |
| 469 |
import PowerFlexBase, powerflex_compatibility |
| 470 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell \ |
| 471 |
import utils |
| 472 |
|
| 473 |
LOG = utils.get_logger('storagepool_v2') |
| 474 |
|
| 475 |
|
| 476 |
@powerflex_compatibility(min_ver='5.0', predecessor='storagepool') |
| 477 |
class PowerFlexStoragePoolV2(PowerFlexBase): |
| 478 |
"""Class with storage pool operations""" |
| 479 |
|
| 480 |
def __init__(self): |
| 481 |
""" Define all parameters required by this module""" |
| 482 |
argument_spec = dict( |
| 483 |
storage_pool_name=dict(required=False, type='str'), |
| 484 |
storage_pool_id=dict(required=False, type='str'), |
| 485 |
storage_pool_new_name=dict(required=False, type='str'), |
| 486 |
protection_domain_name=dict(required=False, type='str'), |
| 487 |
protection_domain_id=dict(type='str'), |
| 488 |
device_group_id=dict(type='str'), |
| 489 |
device_group_name=dict(type='str'), |
| 490 |
cap_alert_thresholds=dict(type='dict', options=dict( |
| 491 |
high_threshold=dict(type='int'), |
| 492 |
critical_threshold=dict(type='int'), |
| 493 |
)), |
| 494 |
compression_method=dict(type='str', choices=['None', 'Normal']), |
| 495 |
over_provisioning_factor=dict(type='int'), |
| 496 |
physical_size_gb=dict(type='int'), |
| 497 |
use_all_available_capacity=dict(type='bool'), |
| 498 |
protection_scheme=dict(type='str', choices=[ |
| 499 |
'TwoPlusTwo', 'EightPlusTwo']), |
| 500 |
state=dict(required=True, type='str', |
| 501 |
choices=['present', 'absent']), |
| 502 |
) |
| 503 |
|
| 504 |
mutually_exclusive = [['storage_pool_name', 'storage_pool_id'], |
| 505 |
['protection_domain_name', 'protection_domain_id'], |
| 506 |
['storage_pool_id', 'protection_domain_name'], |
| 507 |
['storage_pool_id', 'protection_domain_id']] |
| 508 |
required_one_of = [['storage_pool_name', 'storage_pool_id']] |
| 509 |
|
| 510 |
module_params = { |
| 511 |
'argument_spec': argument_spec, |
| 512 |
'supports_check_mode': True, |
| 513 |
'mutually_exclusive': mutually_exclusive, |
| 514 |
'required_one_of': required_one_of |
| 515 |
} |
| 516 |
|
| 517 |
super().__init__(AnsibleModule, module_params) |
| 518 |
super().check_module_compatibility() |
| 519 |
|
| 520 |
def get(self, storage_pool_id, storage_pool_name, protection_domain_id): |
| 521 |
""" |
| 522 |
Get storage pool details |
| 523 |
:param storage_pool_id: Storage pool ID |
| 524 |
:type storage_pool_id: str |
| 525 |
:param storage_pool_name: Storage pool name |
| 526 |
:type storage_pool_name: str |
| 527 |
:param protection_domain_id: Protection domain ID |
| 528 |
:type protection_domain_id: str |
| 529 |
:return: Storage pool details |
| 530 |
""" |
| 531 |
name_or_id = storage_pool_id if storage_pool_id else storage_pool_name |
| 532 |
try: |
| 533 |
if storage_pool_id: |
| 534 |
sp_details = self.powerflex_conn.storage_pool.get_by_id( |
| 535 |
storage_pool_id) |
| 536 |
else: |
| 537 |
sp_details = self.powerflex_conn.storage_pool.get_by_name( |
| 538 |
protection_domain_id, storage_pool_name) |
| 539 |
return sp_details |
| 540 |
except Exception as e: |
| 541 |
error_msg = f"Failed to get the storage pool {name_or_id} with error {str(e)}" |
| 542 |
LOG.error(error_msg) |
| 543 |
self.module.fail_json(msg=error_msg) |
| 544 |
|
| 545 |
def delete(self, storage_pool): |
| 546 |
""" |
| 547 |
Delete storage pool |
| 548 |
:param storage_pool: Storage pool |
| 549 |
:type storage_pool: dict |
| 550 |
:rtype: None |
| 551 |
""" |
| 552 |
try: |
| 553 |
storage_pool_id = storage_pool["id"] |
| 554 |
self.powerflex_conn.storage_pool.delete(storage_pool_id) |
| 555 |
LOG.info("Storage pool deleted successfully.") |
| 556 |
except Exception as e: |
| 557 |
error_msg = f"Delete storage pool {storage_pool['name']} operation failed " \ |
| 558 |
f"with error {str(e)}" |
| 559 |
LOG.error(error_msg) |
| 560 |
self.module.fail_json(msg=error_msg) |
| 561 |
|
| 562 |
def create(self, storage_pool): |
| 563 |
""" |
| 564 |
Create storage pool |
| 565 |
:param storage_pool: Dict of the storage pool |
| 566 |
:type storage_pool: dict |
| 567 |
:return: Dict representation of the created storage pool |
| 568 |
""" |
| 569 |
try: |
| 570 |
LOG.info("Creating storage pool with name: %s ", |
| 571 |
storage_pool['name']) |
| 572 |
|
| 573 |
if storage_pool.get("useAllAvailableCapacity") and \ |
| 574 |
storage_pool.get("physicalSizeGB") is not None: |
| 575 |
self.module.fail_json( |
| 576 |
msg="When creating or updating storage pool, physical_size_gb must not be specified" |
| 577 |
" if use_all_available_capacity is true.") |
| 578 |
if not storage_pool.get("useAllAvailableCapacity") and \ |
| 579 |
storage_pool.get("physicalSizeGB") is None: |
| 580 |
self.module.fail_json( |
| 581 |
msg="When creating or updating storage pool, physical_size_gb must be specified" |
| 582 |
" unless use_all_available_capacity is true.") |
| 583 |
|
| 584 |
self.powerflex_conn.storage_pool.check_create_params(storage_pool) |
| 585 |
if self.module.check_mode: |
| 586 |
return storage_pool |
| 587 |
return self.powerflex_conn.storage_pool.create(storage_pool) |
| 588 |
except Exception as e: |
| 589 |
error_msg = f"Create storage pool '{storage_pool['name']}' operation failed" \ |
| 590 |
f" with error '{str(e)}'" |
| 591 |
LOG.error(error_msg) |
| 592 |
self.module.fail_json(msg=error_msg) |
| 593 |
|
| 594 |
def update(self, storage_pool, current_storage_pool): |
| 595 |
""" |
| 596 |
Modify storage pool attributes |
| 597 |
:param current_storage_pool: Dictionary containing the attributes of |
| 598 |
storage pool which are to be updated |
| 599 |
:type storage_pool: dict |
| 600 |
:return: Bool to indicate if storage pool is updated, |
| 601 |
Dict representation of the updated storage pool |
| 602 |
""" |
| 603 |
try: |
| 604 |
LOG.info("Updating storage pool with id: %s ", |
| 605 |
storage_pool['id']) |
| 606 |
|
| 607 |
if storage_pool.get("use_all_available_capacity") and storage_pool.get("physical_size_gb") is not None: |
| 608 |
self.module.fail_json( |
| 609 |
msg="When creating or updating storage pool, physical_size_gb must not be specified" |
| 610 |
" if use_all_available_capacity is true.") |
| 611 |
|
| 612 |
self.powerflex_conn.storage_pool.check_update_params(storage_pool, current_storage_pool) |
| 613 |
if self.module.check_mode: |
| 614 |
storage_pool["name"] = storage_pool.get("storage_pool_new_name", storage_pool["name"]) |
| 615 |
storage_pool.pop("storage_pool_new_name", None) |
| 616 |
need_update, changes = self.powerflex_conn.storage_pool.need_update(storage_pool, current_storage_pool) |
| 617 |
if storage_pool.get("useAllAvailableCapacity"): |
| 618 |
changes["physicalSizeGB"] = "Computed after update" |
| 619 |
need_update = True |
| 620 |
return need_update, current_storage_pool | changes |
| 621 |
return self.powerflex_conn.storage_pool.update(storage_pool, current_storage_pool) |
| 622 |
except Exception as e: |
| 623 |
err_msg = f"Failed to update the storage pool {storage_pool['id']}" \ |
| 624 |
f" with error {str(e)}" |
| 625 |
LOG.error(err_msg) |
| 626 |
self.module.fail_json(msg=err_msg) |
| 627 |
|
| 628 |
def verify_device_group(self, sp_details): |
| 629 |
""" |
| 630 |
Verify device group details with the storage pool details |
| 631 |
""" |
| 632 |
if not sp_details: |
| 633 |
return |
| 634 |
|
| 635 |
dg_name = self.module.params['device_group_name'] |
| 636 |
dg_id = self.module.params['device_group_id'] |
| 637 |
if dg_id and dg_id != sp_details['deviceGroupId']: |
| 638 |
self.module.fail_json(msg="Entered device group id does not" |
| 639 |
" match with the storage pool's" |
| 640 |
" device group id. Please enter" |
| 641 |
" a correct device group id.") |
| 642 |
dg = self.get_device_group(device_group_name=None, |
| 643 |
device_group_id=sp_details['deviceGroupId']) |
| 644 |
if dg_name and dg_name != dg['name']: |
| 645 |
self.module.fail_json(msg="Entered device group name does" |
| 646 |
" not match with the storage pool's" |
| 647 |
" device group name. Please enter" |
| 648 |
" a correct device group name.") |
| 649 |
pass |
| 650 |
|
| 651 |
def verify_protection_domain(self, sp_details): |
| 652 |
""" |
| 653 |
Verify protection domain details with the storage pool details |
| 654 |
""" |
| 655 |
if not sp_details: |
| 656 |
return |
| 657 |
|
| 658 |
pd_name = self.module.params['protection_domain_name'] |
| 659 |
pd_id = self.module.params['protection_domain_id'] |
| 660 |
if pd_id and pd_id != sp_details['protectionDomainId']: |
| 661 |
self.module.fail_json(msg="Entered protection domain id does not" |
| 662 |
" match with the storage pool's" |
| 663 |
" protection domain id. Please enter" |
| 664 |
" a correct protection domain id.") |
| 665 |
pd = self.get_protection_domain(protection_domain_name=None, |
| 666 |
protection_domain_id=sp_details['protectionDomainId']) |
| 667 |
if pd_name and pd_name != pd['name']: |
| 668 |
self.module.fail_json(msg="Entered protection domain name does" |
| 669 |
" not match with the storage pool's" |
| 670 |
" protection domain name. Please enter" |
| 671 |
" a correct protection domain name.") |
| 672 |
|
| 673 |
def perform_module_operation(self): |
| 674 |
""" |
| 675 |
Perform different actions on protection domain based on parameters |
| 676 |
passed in the playbook |
| 677 |
""" |
| 678 |
storage_pool_id = self.module.params['storage_pool_id'] |
| 679 |
storage_pool_name = self.module.params['storage_pool_name'] |
| 680 |
storage_pool_new_name = self.module.params['storage_pool_new_name'] |
| 681 |
protection_domain_id = self.module.params['protection_domain_id'] |
| 682 |
protection_domain_name = self.module.params['protection_domain_name'] |
| 683 |
device_group_id = self.module.params['device_group_id'] |
| 684 |
device_group_name = self.module.params['device_group_name'] |
| 685 |
cap_alert_thresholds = self.module.params['cap_alert_thresholds'] |
| 686 |
cap_alert_high_threshold = None if cap_alert_thresholds is None else cap_alert_thresholds[ |
| 687 |
'high_threshold'] |
| 688 |
cap_alert_critical_threshold = None if cap_alert_thresholds is None else cap_alert_thresholds[ |
| 689 |
'critical_threshold'] |
| 690 |
over_provisioning_factor = self.module.params['over_provisioning_factor'] |
| 691 |
physical_size_gb = self.module.params['physical_size_gb'] |
| 692 |
use_all_available_capacity = self.module.params['use_all_available_capacity'] |
| 693 |
protection_scheme = self.module.params['protection_scheme'] |
| 694 |
compression_method = self.module.params['compression_method'] |
| 695 |
state = self.module.params['state'] |
| 696 |
|
| 697 |
result = dict( |
| 698 |
changed=False, |
| 699 |
storage_pool_details=None |
| 700 |
) |
| 701 |
|
| 702 |
if storage_pool_name and not (protection_domain_id or protection_domain_name): |
| 703 |
self.module.fail_json( |
| 704 |
msg="Either protection_domain_id or protection_domain_name" |
| 705 |
" must be provided when storage_pool_name is specified." |
| 706 |
) |
| 707 |
|
| 708 |
if not protection_domain_id and protection_domain_name: |
| 709 |
pd = self.get_protection_domain(protection_domain_name, |
| 710 |
protection_domain_id) |
| 711 |
protection_domain_id = pd['id'] |
| 712 |
|
| 713 |
if not device_group_id and device_group_name: |
| 714 |
device_group = self.get_device_group(device_group_name=device_group_name) |
| 715 |
device_group_id = device_group['id'] |
| 716 |
|
| 717 |
sp_details = self.get( |
| 718 |
storage_pool_id, |
| 719 |
storage_pool_name, |
| 720 |
protection_domain_id |
| 721 |
) |
| 722 |
|
| 723 |
if state == 'absent': |
| 724 |
if sp_details: |
| 725 |
result['changed'] = True |
| 726 |
result["diff"] = dict(before=sp_details, after={}) |
| 727 |
if not self.module.check_mode: |
| 728 |
self.delete(sp_details) |
| 729 |
self.module.exit_json(**result) |
| 730 |
|
| 731 |
storage_pool = { |
| 732 |
'name': storage_pool_name, |
| 733 |
'storage_pool_new_name': storage_pool_new_name, |
| 734 |
'protectionDomainId': protection_domain_id, |
| 735 |
'deviceGroupId': device_group_id, |
| 736 |
'capacityAlertHighThreshold': cap_alert_high_threshold, |
| 737 |
'capacityAlertCriticalThreshold': cap_alert_critical_threshold, |
| 738 |
'overProvisioningFactor': over_provisioning_factor, |
| 739 |
'physicalSizeGB': physical_size_gb, |
| 740 |
'useAllAvailableCapacity': use_all_available_capacity, |
| 741 |
'protectionScheme': protection_scheme, |
| 742 |
'compressionMethod': compression_method, |
| 743 |
} |
| 744 |
storage_pool = {k: v for k, v in storage_pool.items() if v is not None} |
| 745 |
|
| 746 |
self.verify_protection_domain(sp_details) |
| 747 |
self.verify_device_group(sp_details) |
| 748 |
|
| 749 |
if not sp_details: |
| 750 |
sp = self.create(storage_pool) |
| 751 |
changed = True |
| 752 |
else: |
| 753 |
storage_pool['id'] = sp_details['id'] |
| 754 |
changed, sp = self.update(storage_pool, sp_details) |
| 755 |
|
| 756 |
result["diff"] = dict(before=sp_details if sp_details else {}, after=copy.deepcopy(sp)) |
| 757 |
self.post_process(sp) |
| 758 |
result['storage_pool_details'] = sp |
| 759 |
result['changed'] = changed |
| 760 |
|
| 761 |
self.module.exit_json(**result) |
| 762 |
|
| 763 |
def get_device_group(self, device_group_name=None, device_group_id=None): |
| 764 |
"""Get the details of a device group in a given PowerFlex storage |
| 765 |
system""" |
| 766 |
|
| 767 |
name_or_id = ( |
| 768 |
device_group_id if device_group_id else device_group_name |
| 769 |
) |
| 770 |
|
| 771 |
try: |
| 772 |
if device_group_id: |
| 773 |
device_groups = self.powerflex_conn.device_group.get( |
| 774 |
filter_fields={"id": device_group_id} |
| 775 |
) |
| 776 |
|
| 777 |
else: |
| 778 |
device_groups = self.powerflex_conn.device_group.get( |
| 779 |
filter_fields={"name": device_group_name} |
| 780 |
) |
| 781 |
|
| 782 |
if len(device_groups) == 0: |
| 783 |
error_msg = f"Unable to find device group with '{name_or_id}'." |
| 784 |
LOG.error(error_msg) |
| 785 |
self.module.fail_json(msg=error_msg) |
| 786 |
|
| 787 |
return device_groups[0] |
| 788 |
|
| 789 |
except Exception as e: |
| 790 |
error_msg = f"Failed to get device group '{name_or_id}' with error '{str(e)}'" |
| 791 |
LOG.error(error_msg) |
| 792 |
self.module.fail_json(msg=error_msg) |
| 793 |
|
| 794 |
def get_protection_domain(self, protection_domain_name=None, protection_domain_id=None): |
| 795 |
"""Get the details of a protection domain in a given PowerFlex storage |
| 796 |
system""" |
| 797 |
return Configuration(self.powerflex_conn, self.module).get_protection_domain( |
| 798 |
protection_domain_name=protection_domain_name, protection_domain_id=protection_domain_id) |
| 799 |
|
| 800 |
def query_metrics(self, storage_pool_id): |
| 801 |
try: |
| 802 |
metrics = ['raw_used', 'physical_used', 'physical_free', 'physical_total', |
| 803 |
'logical_provisioned', 'over_provisioning_limit', 'logical_used'] |
| 804 |
statistics = self.powerflex_conn.utility.query_metrics('storage_pool', [storage_pool_id], metrics) |
| 805 |
return statistics |
| 806 |
except Exception as e: |
| 807 |
error_msg = f"Failed to query statistics with error {str(e)}" |
| 808 |
LOG.error(error_msg) |
| 809 |
self.module.fail_json(msg=error_msg) |
| 810 |
|
| 811 |
def post_process(self, sp_details): |
| 812 |
"""Post-processing function to add more details to the result""" |
| 813 |
if self.module.check_mode: |
| 814 |
return |
| 815 |
pd = self.get_protection_domain(protection_domain_name=None, |
| 816 |
protection_domain_id=sp_details['protectionDomainId']) |
| 817 |
sp_details['protectionDomainName'] = pd['name'] |
| 818 |
dg = self.get_device_group(device_group_name=None, device_group_id=sp_details['deviceGroupId']) |
| 819 |
sp_details['deviceGroupName'] = dg['name'] |
| 820 |
|
| 821 |
statistics = self.query_metrics(sp_details['id']) |
| 822 |
sp_details['statistics'] = statistics if statistics else {} |
| 823 |
|
| 824 |
|
| 825 |
def main(): |
| 826 |
""" Create PowerFlex storage pool object and perform action on it |
| 827 |
based on user input from playbook""" |
| 828 |
|
| 829 |
|
| 830 |
obj = PowerFlexStoragePoolV2() |
| 831 |
obj.perform_module_operation() |
| 832 |
|
| 833 |
|
| 834 |
if __name__ == '__main__': |
| 835 |
main() |