| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
"""Ansible module for managing protection domain on Dell Technologies (Dell) PowerFlex 5.x""" |
| 7 |
|
| 8 |
from __future__ import (absolute_import, division, print_function) |
| 9 |
|
| 10 |
__metaclass__ = type |
| 11 |
|
| 12 |
DOCUMENTATION = r''' |
| 13 |
--- |
| 14 |
module: protection_domain_v2 |
| 15 |
version_added: '3.0.0' |
| 16 |
short_description: Managing protection domain on Dell PowerFlex 5.x |
| 17 |
|
| 18 |
description: |
| 19 |
- Dell PowerFlex protection domain module includes getting the details of |
| 20 |
protection domain, creating a new protection domain, and modifying the attribute of |
| 21 |
a protection domain. |
| 22 |
|
| 23 |
extends_documentation_fragment: |
| 24 |
- dellemc.powerflex.powerflex_v2 |
| 25 |
|
| 26 |
author: |
| 27 |
- Luis Liu (@vangork) <[email protected]> |
| 28 |
|
| 29 |
options: |
| 30 |
protection_domain_name: |
| 31 |
description: |
| 32 |
- The name of the protection domain. |
| 33 |
- Mandatory for create operation. |
| 34 |
- It is unique across the PowerFlex array. |
| 35 |
- Mutually exclusive with I(protection_domain_id). |
| 36 |
type: str |
| 37 |
protection_domain_id: |
| 38 |
description: |
| 39 |
- The ID of the protection domain. |
| 40 |
- Except for create operation, all other operations can be performed |
| 41 |
using protection_domain_id. |
| 42 |
- Mutually exclusive with I(protection_domain_name). |
| 43 |
type: str |
| 44 |
protection_domain_new_name: |
| 45 |
description: |
| 46 |
- Used to rename the protection domain. |
| 47 |
type: str |
| 48 |
is_active: |
| 49 |
description: |
| 50 |
- Used to indicate the state of the protection domain and to activate or deactivate it. |
| 51 |
- When set to C(true), the protection domain will be in active state. |
| 52 |
- When set to C(false), the protection domain will be in inactive state. |
| 53 |
required: false |
| 54 |
type: bool |
| 55 |
state: |
| 56 |
description: |
| 57 |
- The state of the protection domain. Can be 'present' or 'absent'. |
| 58 |
required: true |
| 59 |
choices: ['present', 'absent'] |
| 60 |
type: str |
| 61 |
notes: |
| 62 |
- This module is supported on Dell PowerFlex 5.x and later versions. |
| 63 |
- The protection domain can only be deleted if all its related objects have |
| 64 |
been dissociated from the protection domain. |
| 65 |
- If the protection domain set to inactive, then no operation can be |
| 66 |
performed on protection domain. |
| 67 |
- The I(check_mode) is supported. |
| 68 |
''' |
| 69 |
|
| 70 |
EXAMPLES = r''' |
| 71 |
- name: Create protection domain |
| 72 |
dellemc.powerflex.protection_domain_v2: |
| 73 |
hostname: "{{hostname}}" |
| 74 |
username: "{{username}}" |
| 75 |
password: "{{password}}" |
| 76 |
validate_certs: "{{validate_certs}}" |
| 77 |
protection_domain_name: "domain1" |
| 78 |
state: "present" |
| 79 |
|
| 80 |
- name: Create protection domain with all parameters |
| 81 |
dellemc.powerflex.protection_domain_v2: |
| 82 |
hostname: "{{hostname}}" |
| 83 |
username: "{{username}}" |
| 84 |
password: "{{password}}" |
| 85 |
validate_certs: "{{validate_certs}}" |
| 86 |
protection_domain_name: "domain1" |
| 87 |
is_active: true |
| 88 |
state: present |
| 89 |
|
| 90 |
- name: Get protection domain details using name |
| 91 |
dellemc.powerflex.protection_domain_v2: |
| 92 |
hostname: "{{hostname}}" |
| 93 |
username: "{{username}}" |
| 94 |
password: "{{password}}" |
| 95 |
validate_certs: "{{validate_certs}}" |
| 96 |
port: "{{port}}" |
| 97 |
protection_domain_name: "domain1" |
| 98 |
state: "present" |
| 99 |
|
| 100 |
- name: Get protection domain details using ID |
| 101 |
dellemc.powerflex.protection_domain_v2: |
| 102 |
hostname: "{{hostname}}" |
| 103 |
username: "{{username}}" |
| 104 |
password: "{{password}}" |
| 105 |
validate_certs: "{{validate_certs}}" |
| 106 |
port: "{{port}}" |
| 107 |
protection_domain_id: "5718253c00000004" |
| 108 |
state: "present" |
| 109 |
|
| 110 |
- name: Modify protection domain attributes |
| 111 |
dellemc.powerflex.protection_domain_v2: |
| 112 |
hostname: "{{hostname}}" |
| 113 |
username: "{{username}}" |
| 114 |
password: "{{password}}" |
| 115 |
validate_certs: "{{validate_certs}}" |
| 116 |
port: "{{port}}" |
| 117 |
protection_domain_name: "domain1" |
| 118 |
protection_domain_new_name: "domain1_new" |
| 119 |
state: "present" |
| 120 |
|
| 121 |
- name: Delete protection domain using name |
| 122 |
dellemc.powerflex.protection_domain_v2: |
| 123 |
hostname: "{{hostname}}" |
| 124 |
username: "{{username}}" |
| 125 |
password: "{{password}}" |
| 126 |
validate_certs: "{{validate_certs}}" |
| 127 |
port: "{{port}}" |
| 128 |
protection_domain_name: "domain1_new" |
| 129 |
state: "absent" |
| 130 |
''' |
| 131 |
|
| 132 |
RETURN = r''' |
| 133 |
changed: |
| 134 |
description: Whether or not the resource has changed. |
| 135 |
returned: always |
| 136 |
type: bool |
| 137 |
sample: 'false' |
| 138 |
protection_domain_details: |
| 139 |
description: Details of the protection domain. |
| 140 |
returned: When protection domain exists |
| 141 |
type: dict |
| 142 |
contains: |
| 143 |
fglDefaultMetadataCacheSize: |
| 144 |
description: FGL metadata cache size. |
| 145 |
type: int |
| 146 |
fglDefaultNumConcurrentWrites: |
| 147 |
description: FGL concurrent writes. |
| 148 |
type: str |
| 149 |
fglMetadataCacheEnabled: |
| 150 |
description: Whether FGL cache enabled. |
| 151 |
type: bool |
| 152 |
id: |
| 153 |
description: Protection domain ID. |
| 154 |
type: str |
| 155 |
links: |
| 156 |
description: Protection domain links. |
| 157 |
type: list |
| 158 |
contains: |
| 159 |
href: |
| 160 |
description: Protection domain instance URL. |
| 161 |
type: str |
| 162 |
rel: |
| 163 |
description: Protection domain's relationship with |
| 164 |
different entities. |
| 165 |
type: str |
| 166 |
mdmSdsNetworkDisconnectionsCounterParameters: |
| 167 |
description: MDM's SDS counter parameter. |
| 168 |
type: dict |
| 169 |
contains: |
| 170 |
longWindow: |
| 171 |
description: Long window for Counter Parameters. |
| 172 |
type: int |
| 173 |
mediumWindow: |
| 174 |
description: Medium window for Counter Parameters. |
| 175 |
type: int |
| 176 |
shortWindow: |
| 177 |
description: Short window for Counter Parameters. |
| 178 |
type: int |
| 179 |
name: |
| 180 |
description: Name of the protection domain. |
| 181 |
type: str |
| 182 |
overallIoNetworkThrottlingEnabled: |
| 183 |
description: Whether overall network throttling enabled. |
| 184 |
type: bool |
| 185 |
overallIoNetworkThrottlingInKbps: |
| 186 |
description: Overall network throttling in KBps. |
| 187 |
type: int |
| 188 |
protectedMaintenanceModeNetworkThrottlingEnabled: |
| 189 |
description: Whether protected maintenance mode network throttling |
| 190 |
enabled. |
| 191 |
type: bool |
| 192 |
protectedMaintenanceModeNetworkThrottlingInKbps: |
| 193 |
description: Protected maintenance mode network throttling in |
| 194 |
KBps. |
| 195 |
type: int |
| 196 |
protectionDomainState: |
| 197 |
description: State of protection domain. |
| 198 |
type: int |
| 199 |
rebalanceNetworkThrottlingEnabled: |
| 200 |
description: Whether rebalance network throttling enabled. |
| 201 |
type: int |
| 202 |
rebalanceNetworkThrottlingInKbps: |
| 203 |
description: Rebalance network throttling in KBps. |
| 204 |
type: int |
| 205 |
rebuildNetworkThrottlingEnabled: |
| 206 |
description: Whether rebuild network throttling enabled. |
| 207 |
type: int |
| 208 |
rebuildNetworkThrottlingInKbps: |
| 209 |
description: Rebuild network throttling in KBps. |
| 210 |
type: int |
| 211 |
rfcacheAccpId: |
| 212 |
description: Id of RF cache acceleration pool. |
| 213 |
type: str |
| 214 |
rfcacheEnabled: |
| 215 |
description: Whether RF cache is enabled or not. |
| 216 |
type: bool |
| 217 |
rfcacheMaxIoSizeKb: |
| 218 |
description: RF cache maximum I/O size in KB. |
| 219 |
type: int |
| 220 |
rfcacheOpertionalMode: |
| 221 |
description: RF cache operational mode. |
| 222 |
type: str |
| 223 |
rfcachePageSizeKb: |
| 224 |
description: RF cache page size in KB. |
| 225 |
type: bool |
| 226 |
sdrSdsConnectivityInfo: |
| 227 |
description: Connectivity info of SDR and SDS. |
| 228 |
type: dict |
| 229 |
contains: |
| 230 |
clientServerConnStatus: |
| 231 |
description: Connectivity status of client and server. |
| 232 |
type: str |
| 233 |
disconnectedClientId: |
| 234 |
description: Disconnected client ID. |
| 235 |
type: str |
| 236 |
disconnectedClientName: |
| 237 |
description: Disconnected client name. |
| 238 |
type: str |
| 239 |
disconnectedServerId: |
| 240 |
description: Disconnected server ID. |
| 241 |
type: str |
| 242 |
disconnectedServerIp: |
| 243 |
description: Disconnected server IP. |
| 244 |
type: str |
| 245 |
disconnectedServerName: |
| 246 |
description: Disconnected server name. |
| 247 |
type: str |
| 248 |
sdsSdsNetworkDisconnectionsCounterParameters: |
| 249 |
description: Counter parameter for SDS-SDS network. |
| 250 |
type: dict |
| 251 |
contains: |
| 252 |
longWindow: |
| 253 |
description: Long window for Counter Parameters. |
| 254 |
type: int |
| 255 |
mediumWindow: |
| 256 |
description: Medium window for Counter Parameters. |
| 257 |
type: int |
| 258 |
shortWindow: |
| 259 |
description: Short window for Counter Parameters. |
| 260 |
type: int |
| 261 |
systemId: |
| 262 |
description: ID of system. |
| 263 |
type: str |
| 264 |
vtreeMigrationNetworkThrottlingEnabled: |
| 265 |
description: Whether V-Tree migration network throttling enabled. |
| 266 |
type: bool |
| 267 |
vtreeMigrationNetworkThrottlingInKbps: |
| 268 |
description: V-Tree migration network throttling in KBps. |
| 269 |
type: int |
| 270 |
sample: { |
| 271 |
"genType": "EC", |
| 272 |
"rebuildNetworkThrottlingEnabled": false, |
| 273 |
"rebalanceNetworkThrottlingEnabled": false, |
| 274 |
"vtreeMigrationNetworkThrottlingEnabled": false, |
| 275 |
"overallIoNetworkThrottlingEnabled": false, |
| 276 |
"rfcacheEnabled": true, |
| 277 |
"rfcacheAccpId": null, |
| 278 |
"rebuildEnabled": true, |
| 279 |
"rebalanceEnabled": true, |
| 280 |
"name": "domain1", |
| 281 |
"systemId": "815945c41cd8460f", |
| 282 |
"sdrSdsConnectivityInfo": { |
| 283 |
"clientServerConnStatus": "CLIENT_SERVER_CONN_STATUS_ALL_CONNECTED", |
| 284 |
"disconnectedClientId": null, |
| 285 |
"disconnectedClientName": null, |
| 286 |
"disconnectedServerId": null, |
| 287 |
"disconnectedServerName": null, |
| 288 |
"disconnectedServerIp": null |
| 289 |
}, |
| 290 |
"rplCapAlertLevel": "invalid", |
| 291 |
"protectionDomainState": "Active", |
| 292 |
"rebalanceNetworkThrottlingInKbps": null, |
| 293 |
"rebuildNetworkThrottlingInKbps": null, |
| 294 |
"overallIoNetworkThrottlingInKbps": null, |
| 295 |
"vtreeMigrationNetworkThrottlingInKbps": null, |
| 296 |
"sdsDecoupledCounterParameters": { |
| 297 |
"shortWindow": { |
| 298 |
"windowSizeInSec": 60, |
| 299 |
"threshold": 300 |
| 300 |
}, |
| 301 |
"mediumWindow": { |
| 302 |
"windowSizeInSec": 3600, |
| 303 |
"threshold": 500 |
| 304 |
}, |
| 305 |
"longWindow": { |
| 306 |
"windowSizeInSec": 86400, |
| 307 |
"threshold": 700 |
| 308 |
} |
| 309 |
}, |
| 310 |
"sdsConfigurationFailureCounterParameters": { |
| 311 |
"shortWindow": { |
| 312 |
"windowSizeInSec": 60, |
| 313 |
"threshold": 300 |
| 314 |
}, |
| 315 |
"mediumWindow": { |
| 316 |
"windowSizeInSec": 3600, |
| 317 |
"threshold": 500 |
| 318 |
}, |
| 319 |
"longWindow": { |
| 320 |
"windowSizeInSec": 86400, |
| 321 |
"threshold": 700 |
| 322 |
} |
| 323 |
}, |
| 324 |
"mdmSdsNetworkDisconnectionsCounterParameters": { |
| 325 |
"shortWindow": { |
| 326 |
"windowSizeInSec": 60, |
| 327 |
"threshold": 300 |
| 328 |
}, |
| 329 |
"mediumWindow": { |
| 330 |
"windowSizeInSec": 3600, |
| 331 |
"threshold": 500 |
| 332 |
}, |
| 333 |
"longWindow": { |
| 334 |
"windowSizeInSec": 86400, |
| 335 |
"threshold": 700 |
| 336 |
} |
| 337 |
}, |
| 338 |
"sdsSdsNetworkDisconnectionsCounterParameters": { |
| 339 |
"shortWindow": { |
| 340 |
"windowSizeInSec": 60, |
| 341 |
"threshold": 300 |
| 342 |
}, |
| 343 |
"mediumWindow": { |
| 344 |
"windowSizeInSec": 3600, |
| 345 |
"threshold": 500 |
| 346 |
}, |
| 347 |
"longWindow": { |
| 348 |
"windowSizeInSec": 86400, |
| 349 |
"threshold": 700 |
| 350 |
} |
| 351 |
}, |
| 352 |
"rfcacheOpertionalMode": "WriteMiss", |
| 353 |
"rfcachePageSizeKb": 64, |
| 354 |
"rfcacheMaxIoSizeKb": 128, |
| 355 |
"sdsReceiveBufferAllocationFailuresCounterParameters": { |
| 356 |
"shortWindow": { |
| 357 |
"windowSizeInSec": 60, |
| 358 |
"threshold": 20000 |
| 359 |
}, |
| 360 |
"mediumWindow": { |
| 361 |
"windowSizeInSec": 3600, |
| 362 |
"threshold": 200000 |
| 363 |
}, |
| 364 |
"longWindow": { |
| 365 |
"windowSizeInSec": 86400, |
| 366 |
"threshold": 2000000 |
| 367 |
} |
| 368 |
}, |
| 369 |
"fglDefaultNumConcurrentWrites": 1000, |
| 370 |
"fglMetadataCacheEnabled": false, |
| 371 |
"fglDefaultMetadataCacheSize": 0, |
| 372 |
"protectedMaintenanceModeNetworkThrottlingEnabled": false, |
| 373 |
"protectedMaintenanceModeNetworkThrottlingInKbps": null, |
| 374 |
"sdtSdsConnectivityInfo": { |
| 375 |
"clientServerConnStatus": "CLIENT_SERVER_CONN_STATUS_ALL_CONNECTED", |
| 376 |
"disconnectedClientId": null, |
| 377 |
"disconnectedClientName": null, |
| 378 |
"disconnectedServerId": null, |
| 379 |
"disconnectedServerName": null, |
| 380 |
"disconnectedServerIp": null |
| 381 |
}, |
| 382 |
"overallConcurrentIoLimit": 4, |
| 383 |
"bandwidthLimitOverallIos": 400, |
| 384 |
"bandwidthLimitBgDevScanner": 10, |
| 385 |
"bandwidthLimitSinglyImpactedRebuild": 400, |
| 386 |
"bandwidthLimitDoublyImpactedRebuild": 400, |
| 387 |
"bandwidthLimitRebalance": 40, |
| 388 |
"bandwidthLimitOther": 10, |
| 389 |
"bandwidthLimitNodeNetwork": 25, |
| 390 |
"id": "e59841fd00000002", |
| 391 |
"links": [ |
| 392 |
{ |
| 393 |
"rel": "self", |
| 394 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002" |
| 395 |
}, |
| 396 |
{ |
| 397 |
"rel": "/dtapi/rest/v1/metrics/query", |
| 398 |
"href": "/dtapi/rest/v1/metrics/query", |
| 399 |
"body": { |
| 400 |
"resource_type": "protection_domain", |
| 401 |
"ids": [ |
| 402 |
"e59841fd00000002" |
| 403 |
] |
| 404 |
} |
| 405 |
}, |
| 406 |
{ |
| 407 |
"rel": "/api/ProtectionDomain/relationship/Sdr", |
| 408 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002/relationships/Sdr" |
| 409 |
}, |
| 410 |
{ |
| 411 |
"rel": "/api/ProtectionDomain/relationship/Dgwt", |
| 412 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002/relationships/Dgwt" |
| 413 |
}, |
| 414 |
{ |
| 415 |
"rel": "/api/ProtectionDomain/relationship/AccelerationPool", |
| 416 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002/relationships/AccelerationPool" |
| 417 |
}, |
| 418 |
{ |
| 419 |
"rel": "/api/ProtectionDomain/relationship/Sdt", |
| 420 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002/relationships/Sdt" |
| 421 |
}, |
| 422 |
{ |
| 423 |
"rel": "/api/ProtectionDomain/relationship/StoragePool", |
| 424 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002/relationships/StoragePool" |
| 425 |
}, |
| 426 |
{ |
| 427 |
"rel": "/api/ProtectionDomain/relationship/Sds", |
| 428 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002/relationships/Sds" |
| 429 |
}, |
| 430 |
{ |
| 431 |
"rel": "/api/ProtectionDomain/relationship/ReplicationConsistencyGroup", |
| 432 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002/relationships/ReplicationConsistencyGroup" |
| 433 |
}, |
| 434 |
{ |
| 435 |
"rel": "/api/ProtectionDomain/relationship/DeviceGroup", |
| 436 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002/relationships/DeviceGroup" |
| 437 |
}, |
| 438 |
{ |
| 439 |
"rel": "/api/ProtectionDomain/relationship/FaultSet", |
| 440 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002/relationships/FaultSet" |
| 441 |
}, |
| 442 |
{ |
| 443 |
"rel": "/api/ProtectionDomain/relationship/StorageNode", |
| 444 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002/relationships/StorageNode" |
| 445 |
}, |
| 446 |
{ |
| 447 |
"rel": "/api/ProtectionDomain/relationship/Pds", |
| 448 |
"href": "/api/instances/ProtectionDomain::e59841fd00000002/relationships/Pds" |
| 449 |
}, |
| 450 |
{ |
| 451 |
"rel": "/api/parent/relationship/systemId", |
| 452 |
"href": "/api/instances/System::815945c41cd8460f" |
| 453 |
} |
| 454 |
] |
| 455 |
} |
| 456 |
''' |
| 457 |
|
| 458 |
import copy |
| 459 |
from ansible.module_utils.basic import AnsibleModule |
| 460 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.libraries.powerflex_base \ |
| 461 |
import PowerFlexBase, powerflex_compatibility |
| 462 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell \ |
| 463 |
import utils |
| 464 |
|
| 465 |
|
| 466 |
LOG = utils.get_logger('protection_domain_v2') |
| 467 |
|
| 468 |
|
| 469 |
@powerflex_compatibility(min_ver='5.0', predecessor='protection_domain') |
| 470 |
class PowerFlexProtectionDomainV2(PowerFlexBase): |
| 471 |
"""Class with protection domain operations""" |
| 472 |
|
| 473 |
def __init__(self): |
| 474 |
""" Define all parameters required by this module""" |
| 475 |
argument_spec = dict( |
| 476 |
protection_domain_name=dict(type='str'), |
| 477 |
protection_domain_new_name=dict(type='str'), |
| 478 |
protection_domain_id=dict(type='str'), |
| 479 |
is_active=dict(type='bool'), |
| 480 |
state=dict(required=True, type='str', |
| 481 |
choices=['present', 'absent']) |
| 482 |
) |
| 483 |
|
| 484 |
mut_ex_args = [['protection_domain_name', 'protection_domain_id']] |
| 485 |
|
| 486 |
required_one_of_args = [['protection_domain_name', |
| 487 |
'protection_domain_id']] |
| 488 |
|
| 489 |
module_params = { |
| 490 |
'argument_spec': argument_spec, |
| 491 |
'supports_check_mode': True, |
| 492 |
'mutually_exclusive': mut_ex_args, |
| 493 |
'required_one_of': required_one_of_args, |
| 494 |
} |
| 495 |
|
| 496 |
super().__init__(AnsibleModule, module_params) |
| 497 |
super().check_module_compatibility() |
| 498 |
|
| 499 |
def get(self, id, name): |
| 500 |
""" |
| 501 |
Get protection domain details |
| 502 |
:param id: ID of the protection domain |
| 503 |
:type id: str |
| 504 |
:param name: Name of the protection domain |
| 505 |
:type name: str |
| 506 |
:return: Protection domain details if exists |
| 507 |
:rtype: dict |
| 508 |
""" |
| 509 |
name_or_id = id if id else name |
| 510 |
try: |
| 511 |
if id: |
| 512 |
pd_details = self.powerflex_conn.protection_domain.get_by_id( |
| 513 |
id) |
| 514 |
else: |
| 515 |
pd_details = self.powerflex_conn.protection_domain.get_by_name( |
| 516 |
name) |
| 517 |
|
| 518 |
return pd_details |
| 519 |
except Exception as e: |
| 520 |
error_msg = ( |
| 521 |
"Failed to get the protection domain '%s' with " |
| 522 |
"error '%s'" % (name_or_id, str(e)) |
| 523 |
) |
| 524 |
LOG.error(error_msg) |
| 525 |
self.module.fail_json(msg=error_msg) |
| 526 |
|
| 527 |
def delete(self, pd): |
| 528 |
""" |
| 529 |
Delete Protection Domain |
| 530 |
:param pd: protection domain |
| 531 |
:type pd: dict |
| 532 |
:rtype: None |
| 533 |
""" |
| 534 |
try: |
| 535 |
self.powerflex_conn.protection_domain.delete(pd["id"]) |
| 536 |
LOG.info("Protection domain deleted successfully.") |
| 537 |
except Exception as e: |
| 538 |
error_msg = f"Delete protection domain '{pd['name']}' operation failed with error '{str(e)}'" |
| 539 |
LOG.error(error_msg) |
| 540 |
self.module.fail_json(msg=error_msg) |
| 541 |
|
| 542 |
def create(self, protection_domain): |
| 543 |
""" |
| 544 |
Create protection domain |
| 545 |
:param protection_domain: Dict of the protection domain |
| 546 |
:type protection_domain: dict |
| 547 |
:return: Dict representation of the created protection domain |
| 548 |
""" |
| 549 |
try: |
| 550 |
LOG.info("Creating protection domain with name: %s ", |
| 551 |
protection_domain['name']) |
| 552 |
|
| 553 |
self.is_id_or_new_name_in_create() |
| 554 |
self.powerflex_conn.protection_domain.check_create_params( |
| 555 |
protection_domain) |
| 556 |
if self.module.check_mode: |
| 557 |
return protection_domain |
| 558 |
return self.powerflex_conn.protection_domain.create(protection_domain) |
| 559 |
except Exception as e: |
| 560 |
error_msg = (f"Create protection domain '{protection_domain['name']}'" |
| 561 |
f" operation failed with error '{str(e)}'") |
| 562 |
LOG.error(error_msg) |
| 563 |
self.module.fail_json(msg=error_msg) |
| 564 |
|
| 565 |
def update(self, protection_domain, current_protection_domain=None): |
| 566 |
""" |
| 567 |
Modify protection domain attributes |
| 568 |
:param protection_domain: Dictionary containing the attributes of |
| 569 |
protection domain which are to be updated |
| 570 |
:type protection_domain: dict |
| 571 |
:param current_protection_domain: Current state of protection domain |
| 572 |
:type current_protection_domain: dict |
| 573 |
:return: Bool to indicate if protection domain is updated, |
| 574 |
Dict representation of the updated protection domain |
| 575 |
""" |
| 576 |
try: |
| 577 |
LOG.info("Updating protection domain with id: %s ", |
| 578 |
protection_domain['id']) |
| 579 |
self.powerflex_conn.protection_domain.check_update_params( |
| 580 |
protection_domain, current_protection_domain) |
| 581 |
if self.module.check_mode: |
| 582 |
protection_domain["name"] = protection_domain.get( |
| 583 |
"newName", protection_domain["name"]) |
| 584 |
protection_domain.pop("newName", None) |
| 585 |
need_update, changes = self.powerflex_conn.protection_domain.need_update( |
| 586 |
protection_domain, current_protection_domain) |
| 587 |
return need_update, current_protection_domain | changes |
| 588 |
|
| 589 |
return self.powerflex_conn.protection_domain.update(protection_domain, current_protection_domain) |
| 590 |
except Exception as e: |
| 591 |
err_msg = f"Failed to update the protection domain {protection_domain['id']} with error {str(e)}" |
| 592 |
LOG.error(err_msg) |
| 593 |
self.module.fail_json(msg=err_msg) |
| 594 |
|
| 595 |
def validate_input_params(self): |
| 596 |
"""Validate the input parameters""" |
| 597 |
|
| 598 |
name_params = ['protection_domain_name', 'protection_domain_new_name', |
| 599 |
'protection_domain_id'] |
| 600 |
msg = "Please provide the valid {0}" |
| 601 |
|
| 602 |
for n_item in name_params: |
| 603 |
if self.module.params[n_item] is not None and (len( |
| 604 |
self.module.params[n_item].strip()) or self. |
| 605 |
module.params[n_item].count(" ") > 0) == 0: |
| 606 |
err_msg = msg.format(n_item) |
| 607 |
self.module.fail_json(msg=err_msg) |
| 608 |
|
| 609 |
def is_id_or_new_name_in_create(self): |
| 610 |
"""Checking if protection domain id or new names present in create """ |
| 611 |
|
| 612 |
if self.module.params['protection_domain_new_name'] or \ |
| 613 |
self.module.params['protection_domain_id']: |
| 614 |
error_msg = "protection_domain_new_name/protection_domain_id " \ |
| 615 |
"are not supported during creation of protection " \ |
| 616 |
"domain. Please try with protection_domain_name." |
| 617 |
LOG.info(error_msg) |
| 618 |
self.module.fail_json(msg=error_msg) |
| 619 |
|
| 620 |
def perform_module_operation(self): |
| 621 |
""" |
| 622 |
Perform different actions on protection domain based on parameters |
| 623 |
passed in the playbook |
| 624 |
""" |
| 625 |
protection_domain_name = self.module.params['protection_domain_name'] |
| 626 |
protection_domain_id = self.module.params['protection_domain_id'] |
| 627 |
protection_domain_new_name = self.module.params['protection_domain_new_name'] |
| 628 |
is_active = self.module.params['is_active'] |
| 629 |
state = self.module.params['state'] |
| 630 |
|
| 631 |
result = dict( |
| 632 |
changed=False, |
| 633 |
protection_domain_details=None |
| 634 |
) |
| 635 |
|
| 636 |
|
| 637 |
self.validate_input_params() |
| 638 |
|
| 639 |
pd_details = self.get( |
| 640 |
protection_domain_id, |
| 641 |
protection_domain_name, |
| 642 |
) |
| 643 |
|
| 644 |
if state == 'absent': |
| 645 |
if pd_details: |
| 646 |
result['changed'] = True |
| 647 |
result["diff"] = dict(before=pd_details, after={}) |
| 648 |
if not self.module.check_mode: |
| 649 |
self.delete(pd_details) |
| 650 |
self.module.exit_json(**result) |
| 651 |
|
| 652 |
protection_domain = { |
| 653 |
"name": protection_domain_name, |
| 654 |
"newName": protection_domain_new_name, |
| 655 |
"protectionDomainState": ( |
| 656 |
"Active" if is_active else "Inactive" |
| 657 |
) if is_active is not None else None, |
| 658 |
} |
| 659 |
protection_domain = {k: v for k, |
| 660 |
v in protection_domain.items() if v is not None} |
| 661 |
|
| 662 |
if not pd_details: |
| 663 |
pd = self.create( |
| 664 |
protection_domain) |
| 665 |
changed = True |
| 666 |
else: |
| 667 |
protection_domain['id'] = pd_details['id'] |
| 668 |
changed, pd = self.update( |
| 669 |
protection_domain, pd_details) |
| 670 |
|
| 671 |
result["diff"] = dict( |
| 672 |
before=pd_details if pd_details else {}, after=copy.deepcopy(pd)) |
| 673 |
result['protection_domain_details'] = pd |
| 674 |
result['changed'] = changed |
| 675 |
self.module.exit_json(**result) |
| 676 |
|
| 677 |
|
| 678 |
def main(): |
| 679 |
""" Create PowerFlex protection domain object and perform actions on it |
| 680 |
based on user input from playbook""" |
| 681 |
obj = PowerFlexProtectionDomainV2() |
| 682 |
obj.perform_module_operation() |
| 683 |
|
| 684 |
|
| 685 |
if __name__ == '__main__': |
| 686 |
main() |