| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
ANSIBLE_METADATA = { |
| 12 |
"metadata_version": "1.1", |
| 13 |
"status": ["preview"], |
| 14 |
"supported_by": "community", |
| 15 |
} |
| 16 |
|
| 17 |
DOCUMENTATION = r""" |
| 18 |
--- |
| 19 |
module: purefa_vg |
| 20 |
version_added: '1.0.0' |
| 21 |
short_description: Manage volume groups on Pure Storage FlashArrays |
| 22 |
description: |
| 23 |
- Create, delete or modify volume groups on Pure Storage FlashArrays. |
| 24 |
author: |
| 25 |
- Pure Storage Ansible Team (@sdodsley) <[email protected]> |
| 26 |
options: |
| 27 |
name: |
| 28 |
description: |
| 29 |
- The name of the volume group. |
| 30 |
- Multi-volume-group support available from Purity//FA 6.0.0 |
| 31 |
B(***NOTE***) Manual deletion or eradication of individual volume groups created |
| 32 |
using multi-volume-group will cause idempotency to fail |
| 33 |
- Multi-volume-group support only exists for volume group creation |
| 34 |
type: str |
| 35 |
required: true |
| 36 |
state: |
| 37 |
description: |
| 38 |
- Define whether the volume group should exist or not. |
| 39 |
type: str |
| 40 |
default: present |
| 41 |
choices: [ absent, present ] |
| 42 |
eradicate: |
| 43 |
description: |
| 44 |
- Define whether to eradicate the volume group on delete and leave in trash. |
| 45 |
type : bool |
| 46 |
default: false |
| 47 |
bw_qos: |
| 48 |
description: |
| 49 |
- Bandwidth limit for vgroup in M or G units. |
| 50 |
M will set MB/s |
| 51 |
G will set GB/s |
| 52 |
To clear an existing QoS setting use 0 (zero) |
| 53 |
type: str |
| 54 |
iops_qos: |
| 55 |
description: |
| 56 |
- IOPs limit for vgroup - use value or K or M |
| 57 |
K will mean 1000 |
| 58 |
M will mean 1000000 |
| 59 |
To clear an existing IOPs setting use 0 (zero) |
| 60 |
type: str |
| 61 |
count: |
| 62 |
description: |
| 63 |
- Number of volume groups to be created in a multiple volume group creation |
| 64 |
- Only supported from Purity//FA v6.0.0 and higher |
| 65 |
type: int |
| 66 |
start: |
| 67 |
description: |
| 68 |
- Number at which to start the multiple volume group creation index |
| 69 |
- Only supported from Purity//FA v6.0.0 and higher |
| 70 |
type: int |
| 71 |
default: 0 |
| 72 |
digits: |
| 73 |
description: |
| 74 |
- Number of digits to use for multiple volume group count. This |
| 75 |
will pad the index number with zeros where necessary |
| 76 |
- Only supported from Purity//FA v6.0.0 and higher |
| 77 |
- Range is between 1 and 10 |
| 78 |
type: int |
| 79 |
default: 1 |
| 80 |
suffix: |
| 81 |
description: |
| 82 |
- Suffix string, if required, for multiple volume group create |
| 83 |
- Volume group names will be formed as I(<name>#I<suffix>), where |
| 84 |
I(#) is a placeholder for the volume index |
| 85 |
See associated descriptions |
| 86 |
- Only supported from Purity//FA v6.0.0 and higher |
| 87 |
type: str |
| 88 |
priority_operator: |
| 89 |
description: |
| 90 |
- DMM Priority Adjustment operator |
| 91 |
type: str |
| 92 |
choices: [ +, '-' ] |
| 93 |
default: + |
| 94 |
version_added: '1.13.0' |
| 95 |
priority_value: |
| 96 |
description: |
| 97 |
- DMM Priority Adjustment value |
| 98 |
type: int |
| 99 |
choices: [ 0, 10 ] |
| 100 |
default: 0 |
| 101 |
version_added: '1.13.0' |
| 102 |
rename: |
| 103 |
description: |
| 104 |
- Value to rename the specified volume group to |
| 105 |
type: str |
| 106 |
version_added: '1.22.0' |
| 107 |
context: |
| 108 |
description: |
| 109 |
- Name of fleet member on which to perform the operation. |
| 110 |
- This requires the array receiving the request is a member of a fleet |
| 111 |
and the context name to be a member of the same fleet. |
| 112 |
type: str |
| 113 |
default: "" |
| 114 |
version_added: '1.33.0' |
| 115 |
extends_documentation_fragment: |
| 116 |
- purestorage.flasharray.purestorage.fa |
| 117 |
""" |
| 118 |
|
| 119 |
EXAMPLES = r""" |
| 120 |
- name: Create new volume group |
| 121 |
purestorage.flasharray.purefa_vg: |
| 122 |
name: foo |
| 123 |
bw_qos: 50M |
| 124 |
iops_qos: 100 |
| 125 |
fa_url: 10.10.10.2 |
| 126 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 127 |
|
| 128 |
- name: Create 10 volume groups of pattern foo#bar with QoS |
| 129 |
purestorage.flasharray.purefa_vg: |
| 130 |
name: foo |
| 131 |
suffix: bar |
| 132 |
count: 10 |
| 133 |
start: 10 |
| 134 |
digits: 3 |
| 135 |
bw_qos: 50M |
| 136 |
iops_qos: 100 |
| 137 |
fa_url: 10.10.10.2 |
| 138 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 139 |
|
| 140 |
- name: Update volume group QoS limits |
| 141 |
purestorage.flasharray.purefa_vg: |
| 142 |
name: foo |
| 143 |
bw_qos: 0 |
| 144 |
iops_qos: 5555 |
| 145 |
fa_url: 10.10.10.2 |
| 146 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 147 |
|
| 148 |
- name: Update volume group DMM Priority Adjustment (Purity//FA 6.1.2+) |
| 149 |
purestorage.flasharray.purefa_vg: |
| 150 |
name: foo |
| 151 |
priority_operator: '-' |
| 152 |
priority_value: 10 |
| 153 |
fa_url: 10.10.10.2 |
| 154 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 155 |
|
| 156 |
- name: Destroy volume group |
| 157 |
purestorage.flasharray.purefa_vg: |
| 158 |
name: foo |
| 159 |
fa_url: 10.10.10.2 |
| 160 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 161 |
state: absent |
| 162 |
|
| 163 |
- name: Recover deleted volume group - no changes are made to the volume group on recovery |
| 164 |
purestorage.flasharray.purefa_vg: |
| 165 |
name: foo |
| 166 |
fa_url: 10.10.10.2 |
| 167 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 168 |
|
| 169 |
- name: Destroy and Eradicate volume group |
| 170 |
purestorage.flasharray.purefa_vg: |
| 171 |
name: foo |
| 172 |
eradicate: true |
| 173 |
fa_url: 10.10.10.2 |
| 174 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 175 |
state: absent |
| 176 |
|
| 177 |
- name: Rename volume group foo to bar |
| 178 |
purestorage.flasharray.purefa_vg: |
| 179 |
name: foo |
| 180 |
rename: bar |
| 181 |
fa_url: 10.10.10.2 |
| 182 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 183 |
""" |
| 184 |
|
| 185 |
RETURN = r""" |
| 186 |
""" |
| 187 |
|
| 188 |
HAS_PURESTORAGE = True |
| 189 |
try: |
| 190 |
from pypureclient.flasharray import ( |
| 191 |
VolumeGroupPost, |
| 192 |
VolumeGroupPatch, |
| 193 |
Qos, |
| 194 |
PriorityAdjustment, |
| 195 |
) |
| 196 |
except ImportError: |
| 197 |
HAS_PURESTORAGE = False |
| 198 |
|
| 199 |
from ansible.module_utils.basic import AnsibleModule |
| 200 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.purefa import ( |
| 201 |
get_array, |
| 202 |
purefa_argument_spec, |
| 203 |
) |
| 204 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.common import ( |
| 205 |
human_to_bytes, |
| 206 |
human_to_real, |
| 207 |
) |
| 208 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.version import ( |
| 209 |
LooseVersion, |
| 210 |
) |
| 211 |
|
| 212 |
PRIORITY_API_VERSION = "2.11" |
| 213 |
CONTEXT_API_VERSION = "2.38" |
| 214 |
MIN_BWS = 1048576 |
| 215 |
MIN_IOPS = 100 |
| 216 |
MAX_BWS = 549755813888 |
| 217 |
MAX_IOPS = 100000000 |
| 218 |
|
| 219 |
|
| 220 |
def rename_exists(module, array): |
| 221 |
"""Determine if rename target already exists""" |
| 222 |
api_version = array.get_rest_version() |
| 223 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 224 |
res = array.get_volume_groups( |
| 225 |
names=[module.params["rename"]], context_names=[module.params["context"]] |
| 226 |
) |
| 227 |
else: |
| 228 |
res = array.get_volume_groups(names=[module.params["rename"]]) |
| 229 |
return bool(res.status_code == 200) |
| 230 |
|
| 231 |
|
| 232 |
def get_multi_vgroups(module, array): |
| 233 |
"""Return True is all volume groups exist or None""" |
| 234 |
api_version = array.get_rest_version() |
| 235 |
names = [] |
| 236 |
for vg_num in range( |
| 237 |
module.params["start"], module.params["count"] + module.params["start"] |
| 238 |
): |
| 239 |
names.append( |
| 240 |
module.params["name"] |
| 241 |
+ str(vg_num).zfill(module.params["digits"]) |
| 242 |
+ module.params["suffix"] |
| 243 |
) |
| 244 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 245 |
res = array.get_volume_groups( |
| 246 |
names=names, context_names=[module.params["context"]], destroyed=False |
| 247 |
) |
| 248 |
else: |
| 249 |
res = array.get_volume_groups(names=names, destroyed=False) |
| 250 |
return bool(res.status_code == 200) |
| 251 |
|
| 252 |
|
| 253 |
def get_pending_vgroup(module, array): |
| 254 |
"""Get Deleted Volume Group""" |
| 255 |
api_version = array.get_rest_version() |
| 256 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 257 |
res = array.get_volume_groups( |
| 258 |
names=[module.params["name"]], |
| 259 |
destroyed=True, |
| 260 |
context_names=[module.params["context"]], |
| 261 |
) |
| 262 |
else: |
| 263 |
res = array.get_volume_groups(names=[module.params["name"]], destroyed=True) |
| 264 |
return bool(res.status_code == 200) |
| 265 |
|
| 266 |
|
| 267 |
def get_vgroup(module, array): |
| 268 |
"""Get Volume Group""" |
| 269 |
api_version = array.get_rest_version() |
| 270 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 271 |
res = array.get_volume_groups( |
| 272 |
names=[module.params["name"]], |
| 273 |
destroyed=False, |
| 274 |
context_names=[module.params["context"]], |
| 275 |
) |
| 276 |
else: |
| 277 |
res = array.get_volume_groups(names=[module.params["name"]], destroyed=False) |
| 278 |
return bool(res.status_code == 200) |
| 279 |
|
| 280 |
|
| 281 |
def rename_vgroup(module, array): |
| 282 |
changed = False |
| 283 |
api_version = array.get_rest_version() |
| 284 |
if not rename_exists(module, array): |
| 285 |
changed = True |
| 286 |
if not module.check_mode: |
| 287 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 288 |
res = array.patch_volume_groups( |
| 289 |
names=[module.params["name"]], |
| 290 |
context_names=[module.params["context"]], |
| 291 |
volume_group=VolumeGroupPatch(name=module.params["rename"]), |
| 292 |
) |
| 293 |
else: |
| 294 |
res = array.patch_volume_groups( |
| 295 |
names=[module.params["name"]], |
| 296 |
volume_group=VolumeGroupPatch(name=module.params["rename"]), |
| 297 |
) |
| 298 |
if res.status_code != 200: |
| 299 |
module.fail_json( |
| 300 |
msg="Rename to {0} failed. Error: {1}".format( |
| 301 |
module.params["rename"], res.errors[0].message |
| 302 |
) |
| 303 |
) |
| 304 |
module.exit_json(changed=changed) |
| 305 |
|
| 306 |
|
| 307 |
def make_vgroup(module, array): |
| 308 |
"""Create Volume Group""" |
| 309 |
api_version = array.get_rest_version() |
| 310 |
changed = True |
| 311 |
if module.params["bw_qos"] and not module.params["iops_qos"]: |
| 312 |
if int(human_to_bytes(module.params["bw_qos"])) in range(MIN_BWS, MAX_BWS): |
| 313 |
changed = True |
| 314 |
if not module.check_mode: |
| 315 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 316 |
res = array.post_volume_groups( |
| 317 |
context_names=[module.params["context"]], |
| 318 |
names=[module.params["name"]], |
| 319 |
volume_group=VolumeGroupPost( |
| 320 |
qos=Qos( |
| 321 |
bandwidth_limit=int( |
| 322 |
human_to_bytes(module.params["bw_qos"]) |
| 323 |
) |
| 324 |
) |
| 325 |
), |
| 326 |
) |
| 327 |
else: |
| 328 |
res = array.post_volume_groups( |
| 329 |
names=[module.params["name"]], |
| 330 |
volume_group=VolumeGroupPost( |
| 331 |
qos=Qos( |
| 332 |
bandwidth_limit=int( |
| 333 |
human_to_bytes(module.params["bw_qos"]) |
| 334 |
) |
| 335 |
) |
| 336 |
), |
| 337 |
) |
| 338 |
if res.status_code != 200: |
| 339 |
module.fail_json( |
| 340 |
msg="Vgroup {0} creation failed. Error: {1}".format( |
| 341 |
module.params["name"], res.errors[0].message |
| 342 |
) |
| 343 |
) |
| 344 |
else: |
| 345 |
module.fail_json( |
| 346 |
msg="Bandwidth QoS value {0} out of range.".format( |
| 347 |
module.params["bw_qos"] |
| 348 |
) |
| 349 |
) |
| 350 |
elif module.params["iops_qos"] and not module.params["bw_qos"]: |
| 351 |
if int(human_to_real(module.params["iops_qos"])) in range(MIN_IOPS, MAX_IOPS): |
| 352 |
changed = True |
| 353 |
if not module.check_mode: |
| 354 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 355 |
res = array.post_volume_groups( |
| 356 |
context_names=[module.params["context"]], |
| 357 |
names=[module.params["name"]], |
| 358 |
volume_group=VolumeGroupPost( |
| 359 |
qos=Qos( |
| 360 |
iops_limit=int(human_to_real(module.params["iops_qos"])) |
| 361 |
) |
| 362 |
), |
| 363 |
) |
| 364 |
else: |
| 365 |
res = array.post_volume_groups( |
| 366 |
names=[module.params["name"]], |
| 367 |
volume_group=VolumeGroupPost( |
| 368 |
qos=Qos( |
| 369 |
iops_limit=int(human_to_real(module.params["iops_qos"])) |
| 370 |
) |
| 371 |
), |
| 372 |
) |
| 373 |
if res.status_code != 200: |
| 374 |
module.fail_json( |
| 375 |
msg="Vgroup {0} creation failed. Error: {1}".format( |
| 376 |
module.params["name"], res.errors[0].message |
| 377 |
) |
| 378 |
) |
| 379 |
else: |
| 380 |
module.fail_json( |
| 381 |
msg="IOPs QoS value {0} out of range.".format(module.params["iops_qos"]) |
| 382 |
) |
| 383 |
elif module.params["iops_qos"] and module.params["bw_qos"]: |
| 384 |
bw_qos_size = int(human_to_bytes(module.params["bw_qos"])) |
| 385 |
if int(human_to_real(module.params["iops_qos"])) in range( |
| 386 |
MIN_IOPS, MAX_IOPS |
| 387 |
) and bw_qos_size in range(MIN_BWS, MAX_BWS): |
| 388 |
changed = True |
| 389 |
if not module.check_mode: |
| 390 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 391 |
res = array.post_volume_groups( |
| 392 |
context_names=[module.params["context"]], |
| 393 |
names=[module.params["name"]], |
| 394 |
volume_group=VolumeGroupPost( |
| 395 |
qos=Qos( |
| 396 |
iops_limit=int( |
| 397 |
human_to_real(module.params["iops_qos"]) |
| 398 |
), |
| 399 |
bandwidth_limit=int( |
| 400 |
human_to_bytes(module.params["bw_qos"]) |
| 401 |
), |
| 402 |
) |
| 403 |
), |
| 404 |
) |
| 405 |
else: |
| 406 |
res = array.post_volume_groups( |
| 407 |
names=[module.params["name"]], |
| 408 |
volume_group=VolumeGroupPost( |
| 409 |
qos=Qos( |
| 410 |
iops_limit=int( |
| 411 |
human_to_real(module.params["iops_qos"]) |
| 412 |
), |
| 413 |
bandwidth_limit=int( |
| 414 |
human_to_bytes(module.params["bw_qos"]) |
| 415 |
), |
| 416 |
) |
| 417 |
), |
| 418 |
) |
| 419 |
if res.status_code != 200: |
| 420 |
module.fail_json( |
| 421 |
msg="Vgroup {0} creation failed. Error: {1}".format( |
| 422 |
module.params["name"], res.errors[0].message |
| 423 |
) |
| 424 |
) |
| 425 |
else: |
| 426 |
module.fail_json(msg="IOPs or Bandwidth QoS value out of range.") |
| 427 |
else: |
| 428 |
changed = True |
| 429 |
if not module.check_mode: |
| 430 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 431 |
res = array.post_volume_groups( |
| 432 |
context_names=[module.params["context"]], |
| 433 |
names=[module.params["name"]], |
| 434 |
volume_group=VolumeGroupPost(), |
| 435 |
) |
| 436 |
else: |
| 437 |
res = array.post_volume_groups( |
| 438 |
names=[module.params["name"]], |
| 439 |
volume_group=VolumeGroupPost(), |
| 440 |
) |
| 441 |
if res.status_code != 200: |
| 442 |
module.fail_json( |
| 443 |
msg="Vgroup {0} creation failed. Error: {1}".format( |
| 444 |
module.params["name"], res.errors[0].message |
| 445 |
) |
| 446 |
) |
| 447 |
if LooseVersion(PRIORITY_API_VERSION) <= LooseVersion(api_version): |
| 448 |
volume_group = VolumeGroupPatch( |
| 449 |
priority_adjustment=PriorityAdjustment( |
| 450 |
priority_adjustment_operator=module.params["priority_operator"], |
| 451 |
priority_adjustment_value=module.params["priority_value"], |
| 452 |
), |
| 453 |
) |
| 454 |
if not module.check_mode: |
| 455 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 456 |
res = array.patch_volume_groups( |
| 457 |
names=[module.params["name"]], |
| 458 |
volume_group=volume_group, |
| 459 |
context_names=[module.params["context"]], |
| 460 |
) |
| 461 |
else: |
| 462 |
res = array.patch_volume_groups( |
| 463 |
names=[module.params["name"]], volume_group=volume_group |
| 464 |
) |
| 465 |
if res.status_code != 200: |
| 466 |
module.fail_json( |
| 467 |
msg="Failed to set priority adjustment for volume group {0}. Error: {1}".format( |
| 468 |
module.params["name"], res.errors[0].message |
| 469 |
) |
| 470 |
) |
| 471 |
|
| 472 |
module.exit_json(changed=changed) |
| 473 |
|
| 474 |
|
| 475 |
def make_multi_vgroups(module, array): |
| 476 |
"""Create multiple Volume Groups""" |
| 477 |
api_version = array.get_rest_version() |
| 478 |
changed = True |
| 479 |
bw_qos_size = iops_qos_size = 0 |
| 480 |
names = [] |
| 481 |
for vg_num in range( |
| 482 |
module.params["start"], module.params["count"] + module.params["start"] |
| 483 |
): |
| 484 |
names.append( |
| 485 |
module.params["name"] |
| 486 |
+ str(vg_num).zfill(module.params["digits"]) |
| 487 |
+ module.params["suffix"] |
| 488 |
) |
| 489 |
if module.params["bw_qos"]: |
| 490 |
bw_qos = int(human_to_bytes(module.params["bw_qos"])) |
| 491 |
if bw_qos in range(MIN_BWS, MAX_BWS): |
| 492 |
bw_qos_size = bw_qos |
| 493 |
else: |
| 494 |
module.fail_json(msg="Bandwidth QoS value out of range.") |
| 495 |
if module.params["iops_qos"]: |
| 496 |
iops_qos = int(human_to_real(module.params["iops_qos"])) |
| 497 |
if iops_qos in range(MIN_IOPS, MAX_IOPS): |
| 498 |
iops_qos_size = iops_qos |
| 499 |
else: |
| 500 |
module.fail_json(msg="IOPs QoS value out of range.") |
| 501 |
if bw_qos_size != 0 and iops_qos_size != 0: |
| 502 |
volume_group = VolumeGroupPost( |
| 503 |
qos=Qos(bandwidth_limit=bw_qos_size, iops_limit=iops_qos_size) |
| 504 |
) |
| 505 |
elif bw_qos_size == 0 and iops_qos_size == 0: |
| 506 |
volume_group = VolumeGroupPost() |
| 507 |
elif bw_qos_size == 0 and iops_qos_size != 0: |
| 508 |
volume_group = VolumeGroupPost(qos=Qos(iops_limit=iops_qos_size)) |
| 509 |
elif bw_qos_size != 0 and iops_qos_size == 0: |
| 510 |
volume_group = VolumeGroupPost(qos=Qos(bandwidth_limit=bw_qos_size)) |
| 511 |
if not module.check_mode: |
| 512 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 513 |
res = array.post_volume_groups( |
| 514 |
names=names, |
| 515 |
volume_group=volume_group, |
| 516 |
context_names=[module.params["context"]], |
| 517 |
) |
| 518 |
else: |
| 519 |
res = array.post_volume_groups(names=names, volume_group=volume_group) |
| 520 |
if res.status_code != 200: |
| 521 |
module.fail_json( |
| 522 |
msg="Multi-Vgroup {0}#{1} creation failed: {2}".format( |
| 523 |
module.params["name"], |
| 524 |
module.params["suffix"], |
| 525 |
res.errors[0].message, |
| 526 |
) |
| 527 |
) |
| 528 |
if LooseVersion(PRIORITY_API_VERSION) <= LooseVersion(api_version): |
| 529 |
volume_group = VolumeGroupPatch( |
| 530 |
priority_adjustment=PriorityAdjustment( |
| 531 |
priority_adjustment_operator=module.params["priority_operator"], |
| 532 |
priority_adjustment_value=module.params["priority_value"], |
| 533 |
), |
| 534 |
) |
| 535 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 536 |
res = array.patch_volume_groups( |
| 537 |
names=names, |
| 538 |
volume_group=volume_group, |
| 539 |
context_names=[module.params["context"]], |
| 540 |
) |
| 541 |
else: |
| 542 |
res = array.patch_volume_groups(names=names, volume_group=volume_group) |
| 543 |
if res.status_code != 200: |
| 544 |
module.fail_json( |
| 545 |
msg="Failed to set priority adjustments for multi-vgroup {0}#{1}. Error: {2}".format( |
| 546 |
module.params["name"], |
| 547 |
module.params["suffix"], |
| 548 |
res.errors[0].message, |
| 549 |
) |
| 550 |
) |
| 551 |
module.exit_json(changed=changed) |
| 552 |
|
| 553 |
|
| 554 |
def update_vgroup(module, array): |
| 555 |
"""Update Volume Group safely, only marking changed if needed""" |
| 556 |
api_version = array.get_rest_version() |
| 557 |
changed = False |
| 558 |
|
| 559 |
|
| 560 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 561 |
vg_all = list( |
| 562 |
array.get_volume_groups( |
| 563 |
names=[module.params["name"]], context_names=[module.params["context"]] |
| 564 |
).items |
| 565 |
)[0] |
| 566 |
else: |
| 567 |
vg_all = list(array.get_volume_groups(names=[module.params["name"]]).items)[0] |
| 568 |
|
| 569 |
kwargs = {"names": [module.params["name"]]} |
| 570 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 571 |
kwargs["context_names"] = [module.params["context"]] |
| 572 |
|
| 573 |
|
| 574 |
if LooseVersion(PRIORITY_API_VERSION) <= LooseVersion(api_version): |
| 575 |
vg_prio = vg_all.priority_adjustment |
| 576 |
new_operator = vg_prio.priority_adjustment_operator |
| 577 |
new_value = vg_prio.priority_adjustment_value |
| 578 |
|
| 579 |
if ( |
| 580 |
module.params.get("priority_operator") is not None |
| 581 |
and vg_prio.priority_adjustment_operator |
| 582 |
!= module.params["priority_operator"] |
| 583 |
): |
| 584 |
new_operator = module.params["priority_operator"] |
| 585 |
changed = True |
| 586 |
|
| 587 |
if ( |
| 588 |
module.params.get("priority_value") is not None |
| 589 |
and vg_prio.priority_adjustment_value != module.params["priority_value"] |
| 590 |
): |
| 591 |
new_value = module.params["priority_value"] |
| 592 |
changed = True |
| 593 |
|
| 594 |
if changed and not module.check_mode: |
| 595 |
volume_group = VolumeGroupPatch( |
| 596 |
priority_adjustment=PriorityAdjustment( |
| 597 |
priority_adjustment_operator=new_operator, |
| 598 |
priority_adjustment_value=new_value, |
| 599 |
) |
| 600 |
) |
| 601 |
res = array.patch_volume_groups(**kwargs, volume_group=volume_group) |
| 602 |
if res.status_code != 200: |
| 603 |
module.fail_json( |
| 604 |
msg="Failed to change DMM Priority for volume group {0}. Error: {1}".format( |
| 605 |
module.params["name"], res.errors[0].message |
| 606 |
) |
| 607 |
) |
| 608 |
|
| 609 |
|
| 610 |
vg_qos = vg_all.qos |
| 611 |
bw_limit = getattr(vg_qos, "bandwidth_limit", MAX_BWS) |
| 612 |
iops_limit = getattr(vg_qos, "iops_limit", MAX_IOPS) |
| 613 |
|
| 614 |
if module.params.get("bw_qos") is not None: |
| 615 |
bw_input = module.params["bw_qos"] |
| 616 |
|
| 617 |
if bw_input == "0": |
| 618 |
bw_val = MAX_BWS |
| 619 |
else: |
| 620 |
bw_val = int(human_to_bytes(bw_input)) |
| 621 |
|
| 622 |
|
| 623 |
if bw_val != getattr(vg_qos, "bandwidth_limit", MAX_BWS): |
| 624 |
changed = True |
| 625 |
if not module.check_mode: |
| 626 |
res = array.patch_volume_groups( |
| 627 |
**kwargs, |
| 628 |
volume_group=VolumeGroupPatch(qos=Qos(bandwidth_limit=bw_val)), |
| 629 |
) |
| 630 |
if res.status_code != 200: |
| 631 |
module.fail_json( |
| 632 |
msg=f"Vgroup {module.params['name']} Bandwidth QoS update failed. Error: {res.errors[0].message}" |
| 633 |
) |
| 634 |
|
| 635 |
if module.params.get("iops_qos") is not None: |
| 636 |
iops_input = module.params["iops_qos"] |
| 637 |
if iops_input == "0": |
| 638 |
iops_val = MAX_IOPS |
| 639 |
else: |
| 640 |
iops_val = int(human_to_real(iops_input)) |
| 641 |
|
| 642 |
if iops_val != getattr(vg_qos, "iops_limit", MAX_IOPS): |
| 643 |
changed = True |
| 644 |
if not module.check_mode: |
| 645 |
res = array.patch_volume_groups( |
| 646 |
**kwargs, |
| 647 |
volume_group=VolumeGroupPatch(qos=Qos(iops_limit=iops_val)), |
| 648 |
) |
| 649 |
if res.status_code != 200: |
| 650 |
module.fail_json( |
| 651 |
msg=f"Vgroup {module.params['name']} IOPS QoS update failed. Error: {res.errors[0].message}" |
| 652 |
) |
| 653 |
module.exit_json(changed=changed) |
| 654 |
|
| 655 |
|
| 656 |
def recover_vgroup(module, array): |
| 657 |
"""Recover Volume Group""" |
| 658 |
api_version = array.get_rest_version() |
| 659 |
changed = True |
| 660 |
if not module.check_mode: |
| 661 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 662 |
res = array.patch_volume_groups( |
| 663 |
names=[module.params["name"]], |
| 664 |
context_names=[module.params["context"]], |
| 665 |
volume_group=VolumeGroupPatch(destroyed=False), |
| 666 |
) |
| 667 |
else: |
| 668 |
res = array.patch_volume_groups( |
| 669 |
names=[module.params["name"]], |
| 670 |
volume_group=VolumeGroupPatch(destroyed=False), |
| 671 |
) |
| 672 |
if res.status_code != 200: |
| 673 |
module.fail_json( |
| 674 |
msg="Recovery of volume group {0} failed. Error: {1}".format( |
| 675 |
module.params["name"], res.errors[0].message |
| 676 |
) |
| 677 |
) |
| 678 |
|
| 679 |
module.exit_json(changed=changed) |
| 680 |
|
| 681 |
|
| 682 |
def eradicate_vgroup(module, array): |
| 683 |
"""Eradicate Volume Group""" |
| 684 |
api_version = array.get_rest_version() |
| 685 |
changed = True |
| 686 |
if not module.check_mode: |
| 687 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 688 |
res = array.delete_volume_groups( |
| 689 |
names=[module.params["name"]], context_names=[module.params["context"]] |
| 690 |
) |
| 691 |
else: |
| 692 |
res = array.delete_volume_groups(names=[module.params["name"]]) |
| 693 |
if res.status_code != 200: |
| 694 |
module.fail_json( |
| 695 |
msg="Eradicating vgroup {0} failed. Errors: {1}".format( |
| 696 |
module.params["name"], res.errors[0].message |
| 697 |
) |
| 698 |
) |
| 699 |
module.exit_json(changed=changed) |
| 700 |
|
| 701 |
|
| 702 |
def delete_vgroup(module, array): |
| 703 |
"""Delete Volume Group""" |
| 704 |
api_version = array.get_rest_version() |
| 705 |
changed = True |
| 706 |
if not module.check_mode: |
| 707 |
if LooseVersion(CONTEXT_API_VERSION) <= LooseVersion(api_version): |
| 708 |
res = array.patch_volume_groups( |
| 709 |
names=[module.params["name"]], |
| 710 |
context_names=[module.params["context"]], |
| 711 |
volume_group=VolumeGroupPatch(destroyed=True), |
| 712 |
) |
| 713 |
else: |
| 714 |
res = array.patch_volume_groups( |
| 715 |
names=[module.params["name"]], |
| 716 |
volume_group=VolumeGroupPatch(destroyed=True), |
| 717 |
) |
| 718 |
if res.status_code != 200: |
| 719 |
module.fail_json( |
| 720 |
msg="Deletion of volume group {0} failed. Error: {1}".format( |
| 721 |
module.params["name"], res.errors[0].message |
| 722 |
) |
| 723 |
) |
| 724 |
if module.params["eradicate"]: |
| 725 |
eradicate_vgroup(module, array) |
| 726 |
|
| 727 |
module.exit_json(changed=changed) |
| 728 |
|
| 729 |
|
| 730 |
def main(): |
| 731 |
argument_spec = purefa_argument_spec() |
| 732 |
argument_spec.update( |
| 733 |
dict( |
| 734 |
name=dict(type="str", required=True), |
| 735 |
state=dict(type="str", default="present", choices=["absent", "present"]), |
| 736 |
bw_qos=dict(type="str"), |
| 737 |
iops_qos=dict(type="str"), |
| 738 |
count=dict(type="int"), |
| 739 |
start=dict(type="int", default=0), |
| 740 |
digits=dict(type="int", default=1), |
| 741 |
suffix=dict(type="str"), |
| 742 |
priority_operator=dict(type="str", choices=["+", "-"], default="+"), |
| 743 |
priority_value=dict(type="int", choices=[0, 10], default=0), |
| 744 |
eradicate=dict(type="bool", default=False), |
| 745 |
rename=dict(type="str"), |
| 746 |
context=dict(type="str", default=""), |
| 747 |
) |
| 748 |
) |
| 749 |
|
| 750 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 751 |
|
| 752 |
if not HAS_PURESTORAGE: |
| 753 |
module.fail_json( |
| 754 |
msg="py-pure-client sdk is required to support 'count' parameter" |
| 755 |
) |
| 756 |
state = module.params["state"] |
| 757 |
array = get_array(module) |
| 758 |
vgroup = get_vgroup(module, array) |
| 759 |
xvgroup = get_pending_vgroup(module, array) |
| 760 |
|
| 761 |
if module.params["count"]: |
| 762 |
if module.params["digits"] and module.params["digits"] not in range(1, 10): |
| 763 |
module.fail_json(msg="'digits' must be in the range of 1 to 10") |
| 764 |
if module.params["start"] < 0: |
| 765 |
module.fail_json(msg="'start' must be a positive number") |
| 766 |
vgroup = get_multi_vgroups(module, array) |
| 767 |
if state == "present" and not vgroup: |
| 768 |
make_multi_vgroups(module, array) |
| 769 |
elif state == "absent" and not vgroup: |
| 770 |
module.exit_json(changed=False) |
| 771 |
else: |
| 772 |
module.warn("Method not yet supported for multi-vgroup") |
| 773 |
else: |
| 774 |
if xvgroup and state == "present": |
| 775 |
recover_vgroup(module, array) |
| 776 |
elif vgroup and state == "absent": |
| 777 |
delete_vgroup(module, array) |
| 778 |
elif xvgroup and state == "absent" and module.params["eradicate"]: |
| 779 |
eradicate_vgroup(module, array) |
| 780 |
elif not vgroup and not xvgroup and state == "present": |
| 781 |
make_vgroup(module, array) |
| 782 |
elif state == "present" and vgroup and module.params["rename"] and not xvgroup: |
| 783 |
rename_vgroup(module, array) |
| 784 |
elif vgroup and state == "present": |
| 785 |
update_vgroup(module, array) |
| 786 |
elif vgroup is None and state == "absent": |
| 787 |
module.exit_json(changed=False) |
| 788 |
|
| 789 |
module.exit_json(changed=False) |
| 790 |
|
| 791 |
|
| 792 |
if __name__ == "__main__": |
| 793 |
main() |