| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
""" Ansible module for managing SDS on Dell Technologies (Dell) PowerFlex""" |
| 7 |
|
| 8 |
from __future__ import (absolute_import, division, print_function) |
| 9 |
|
| 10 |
__metaclass__ = type |
| 11 |
|
| 12 |
DOCUMENTATION = r''' |
| 13 |
module: sds |
| 14 |
version_added: '1.1.0' |
| 15 |
short_description: Manage SDS on Dell PowerFlex |
| 16 |
description: |
| 17 |
- Managing SDS on PowerFlex storage system includes |
| 18 |
creating new SDS, getting details of SDS, adding/removing IP to/from SDS, |
| 19 |
modifying attributes of SDS, and deleting SDS. |
| 20 |
author: |
| 21 |
- Rajshree Khare (@khareRajshree) <[email protected]> |
| 22 |
- Trisha Datta (@trisha-dell) <[email protected]> |
| 23 |
extends_documentation_fragment: |
| 24 |
- dellemc.powerflex.powerflex |
| 25 |
options: |
| 26 |
sds_name: |
| 27 |
description: |
| 28 |
- The name of the SDS. |
| 29 |
- Mandatory for create operation. |
| 30 |
- It is unique across the PowerFlex array. |
| 31 |
- Mutually exclusive with I(sds_id). |
| 32 |
type: str |
| 33 |
sds_id: |
| 34 |
description: |
| 35 |
- The ID of the SDS. |
| 36 |
- Except create operation, all other operations can be performed |
| 37 |
using I(sds_id). |
| 38 |
- Mutually exclusive with I(sds_name). |
| 39 |
type: str |
| 40 |
protection_domain_name: |
| 41 |
description: |
| 42 |
- The name of the protection domain. |
| 43 |
- Mutually exclusive with I(protection_domain_id). |
| 44 |
type: str |
| 45 |
protection_domain_id: |
| 46 |
description: |
| 47 |
- The ID of the protection domain. |
| 48 |
- Mutually exclusive with I(protection_domain_name). |
| 49 |
type: str |
| 50 |
sds_ip_list: |
| 51 |
description: |
| 52 |
- Dictionary of IPs and their roles for the SDS. |
| 53 |
- At least one IP-role is mandatory while creating a SDS. |
| 54 |
- IP-roles can be updated as well. |
| 55 |
type: list |
| 56 |
elements: dict |
| 57 |
suboptions: |
| 58 |
ip: |
| 59 |
description: |
| 60 |
- IP address of the SDS. |
| 61 |
type: str |
| 62 |
required: true |
| 63 |
role: |
| 64 |
description: |
| 65 |
- Role assigned to the SDS IP address. |
| 66 |
choices: ['sdsOnly', 'sdcOnly', 'all'] |
| 67 |
type: str |
| 68 |
required: true |
| 69 |
sds_ip_state: |
| 70 |
description: |
| 71 |
- State of IP with respect to the SDS. |
| 72 |
choices: ['present-in-sds', 'absent-in-sds'] |
| 73 |
type: str |
| 74 |
rfcache_enabled: |
| 75 |
description: |
| 76 |
- Whether to enable the Read Flash cache. |
| 77 |
type: bool |
| 78 |
rmcache_enabled: |
| 79 |
description: |
| 80 |
- Whether to enable the Read RAM cache. |
| 81 |
type: bool |
| 82 |
rmcache_size: |
| 83 |
description: |
| 84 |
- Read RAM cache size (in MB). |
| 85 |
- Minimum size is 128 MB. |
| 86 |
- Maximum size is 3911 MB. |
| 87 |
type: int |
| 88 |
sds_new_name: |
| 89 |
description: |
| 90 |
- SDS new name. |
| 91 |
type: str |
| 92 |
performance_profile: |
| 93 |
description: |
| 94 |
- Performance profile to apply to the SDS. |
| 95 |
- The HighPerformance profile configures a predefined set of parameters |
| 96 |
for very high performance use cases. |
| 97 |
- Default value by API is C(HighPerformance). |
| 98 |
choices: ['Compact', 'HighPerformance'] |
| 99 |
type: str |
| 100 |
fault_set_name: |
| 101 |
description: |
| 102 |
- Name of the fault set. |
| 103 |
- Mutually exclusive with I(fault_set_id). |
| 104 |
type: str |
| 105 |
fault_set_id: |
| 106 |
description: |
| 107 |
- Unique identifier of the fault set. |
| 108 |
- Mutually exclusive with I(fault_set_name). |
| 109 |
type: str |
| 110 |
state: |
| 111 |
description: |
| 112 |
- State of the SDS. |
| 113 |
choices: ['present', 'absent'] |
| 114 |
required: true |
| 115 |
type: str |
| 116 |
notes: |
| 117 |
- The maximum limit for the IPs that can be associated with an SDS is 8. |
| 118 |
- There needs to be at least 1 IP for SDS communication and 1 for SDC |
| 119 |
communication. |
| 120 |
- If only 1 IP exists, it must be with role 'all'; else 1 IP |
| 121 |
can be with role 'all'and other IPs with role 'sdcOnly'; or 1 IP must be |
| 122 |
with role 'sdsOnly' and others with role 'sdcOnly'. |
| 123 |
- There can be 1 or more IPs with role 'sdcOnly'. |
| 124 |
- There must be only 1 IP with SDS role (either with role 'all' or |
| 125 |
'sdsOnly'). |
| 126 |
- SDS can be created with RF cache disabled, but, be aware that the RF cache |
| 127 |
is not always updated. In this case, the user should re-try the operation. |
| 128 |
- The I(check_mode) is supported. |
| 129 |
''' |
| 130 |
|
| 131 |
EXAMPLES = r''' |
| 132 |
- name: Create SDS |
| 133 |
dellemc.powerflex.sds: |
| 134 |
hostname: "{{hostname}}" |
| 135 |
username: "{{username}}" |
| 136 |
password: "{{password}}" |
| 137 |
validate_certs: "{{validate_certs}}" |
| 138 |
port: "{{port}}" |
| 139 |
sds_name: "node0" |
| 140 |
protection_domain_name: "domain1" |
| 141 |
sds_ip_list: |
| 142 |
- ip: "198.10.xxx.xxx" |
| 143 |
role: "all" |
| 144 |
sds_ip_state: "present-in-sds" |
| 145 |
state: "present" |
| 146 |
|
| 147 |
- name: Create SDS with all parameters |
| 148 |
dellemc.powerflex.sds: |
| 149 |
hostname: "{{hostname}}" |
| 150 |
username: "{{username}}" |
| 151 |
password: "{{password}}" |
| 152 |
validate_certs: "{{validate_certs}}" |
| 153 |
port: "{{port}}" |
| 154 |
sds_name: "node1" |
| 155 |
protection_domain_name: "domain1" |
| 156 |
fault_set_name: "faultset1" |
| 157 |
sds_ip_list: |
| 158 |
- ip: "198.10.xxx.xxx" |
| 159 |
role: "sdcOnly" |
| 160 |
sds_ip_state: "present-in-sds" |
| 161 |
rmcache_enabled: true |
| 162 |
rmcache_size: 128 |
| 163 |
performance_profile: "HighPerformance" |
| 164 |
state: "present" |
| 165 |
|
| 166 |
- name: Get SDS details using name |
| 167 |
dellemc.powerflex.sds: |
| 168 |
hostname: "{{hostname}}" |
| 169 |
username: "{{username}}" |
| 170 |
password: "{{password}}" |
| 171 |
validate_certs: "{{validate_certs}}" |
| 172 |
port: "{{port}}" |
| 173 |
sds_name: "node0" |
| 174 |
state: "present" |
| 175 |
|
| 176 |
- name: Get SDS details using ID |
| 177 |
dellemc.powerflex.sds: |
| 178 |
hostname: "{{hostname}}" |
| 179 |
username: "{{username}}" |
| 180 |
password: "{{password}}" |
| 181 |
validate_certs: "{{validate_certs}}" |
| 182 |
port: "{{port}}" |
| 183 |
sds_id: "5718253c00000004" |
| 184 |
state: "present" |
| 185 |
|
| 186 |
- name: Modify SDS attributes using name |
| 187 |
dellemc.powerflex.sds: |
| 188 |
hostname: "{{hostname}}" |
| 189 |
username: "{{username}}" |
| 190 |
password: "{{password}}" |
| 191 |
validate_certs: "{{validate_certs}}" |
| 192 |
port: "{{port}}" |
| 193 |
sds_name: "node0" |
| 194 |
sds_new_name: "node0_new" |
| 195 |
rfcache_enabled: true |
| 196 |
rmcache_enabled: true |
| 197 |
rmcache_size: 256 |
| 198 |
performance_profile: "HighPerformance" |
| 199 |
state: "present" |
| 200 |
|
| 201 |
- name: Modify SDS attributes using ID |
| 202 |
dellemc.powerflex.sds: |
| 203 |
hostname: "{{hostname}}" |
| 204 |
username: "{{username}}" |
| 205 |
password: "{{password}}" |
| 206 |
validate_certs: "{{validate_certs}}" |
| 207 |
port: "{{port}}" |
| 208 |
sds_id: "5718253c00000004" |
| 209 |
sds_new_name: "node0_new" |
| 210 |
rfcache_enabled: true |
| 211 |
rmcache_enabled: true |
| 212 |
rmcache_size: 256 |
| 213 |
performance_profile: "HighPerformance" |
| 214 |
state: "present" |
| 215 |
|
| 216 |
- name: Add IP and role to an SDS |
| 217 |
dellemc.powerflex.sds: |
| 218 |
hostname: "{{hostname}}" |
| 219 |
username: "{{username}}" |
| 220 |
password: "{{password}}" |
| 221 |
validate_certs: "{{validate_certs}}" |
| 222 |
port: "{{port}}" |
| 223 |
sds_name: "node0" |
| 224 |
sds_ip_list: |
| 225 |
- ip: "198.10.xxx.xxx" |
| 226 |
role: "sdcOnly" |
| 227 |
sds_ip_state: "present-in-sds" |
| 228 |
state: "present" |
| 229 |
|
| 230 |
- name: Remove IP and role from an SDS |
| 231 |
dellemc.powerflex.sds: |
| 232 |
hostname: "{{hostname}}" |
| 233 |
username: "{{username}}" |
| 234 |
password: "{{password}}" |
| 235 |
validate_certs: "{{validate_certs}}" |
| 236 |
port: "{{port}}" |
| 237 |
sds_name: "node0" |
| 238 |
sds_ip_list: |
| 239 |
- ip: "198.10.xxx.xxx" |
| 240 |
role: "sdcOnly" |
| 241 |
sds_ip_state: "absent-in-sds" |
| 242 |
state: "present" |
| 243 |
|
| 244 |
- name: Delete SDS using name |
| 245 |
dellemc.powerflex.sds: |
| 246 |
hostname: "{{hostname}}" |
| 247 |
username: "{{username}}" |
| 248 |
password: "{{password}}" |
| 249 |
validate_certs: "{{validate_certs}}" |
| 250 |
port: "{{port}}" |
| 251 |
sds_name: "node0" |
| 252 |
state: "absent" |
| 253 |
|
| 254 |
- name: Delete SDS using ID |
| 255 |
dellemc.powerflex.sds: |
| 256 |
hostname: "{{hostname}}" |
| 257 |
username: "{{username}}" |
| 258 |
password: "{{password}}" |
| 259 |
validate_certs: "{{validate_certs}}" |
| 260 |
port: "{{port}}" |
| 261 |
sds_id: "5718253c00000004" |
| 262 |
state: "absent" |
| 263 |
''' |
| 264 |
|
| 265 |
RETURN = r''' |
| 266 |
changed: |
| 267 |
description: Whether or not the resource has changed. |
| 268 |
returned: always |
| 269 |
type: bool |
| 270 |
sample: 'false' |
| 271 |
sds_details: |
| 272 |
description: Details of the SDS. |
| 273 |
returned: When SDS exists |
| 274 |
type: dict |
| 275 |
contains: |
| 276 |
authenticationError: |
| 277 |
description: Indicates authentication error. |
| 278 |
type: str |
| 279 |
certificateInfo: |
| 280 |
description: Information about certificate. |
| 281 |
type: str |
| 282 |
configuredDrlMode: |
| 283 |
description: Configured DRL mode. |
| 284 |
type: str |
| 285 |
drlMode: |
| 286 |
description: DRL mode. |
| 287 |
type: str |
| 288 |
faultSetId: |
| 289 |
description: Fault set ID. |
| 290 |
type: str |
| 291 |
fglMetadataCacheSize: |
| 292 |
description: FGL metadata cache size. |
| 293 |
type: int |
| 294 |
fglMetadataCacheState: |
| 295 |
description: FGL metadata cache state. |
| 296 |
type: str |
| 297 |
fglNumConcurrentWrites: |
| 298 |
description: FGL concurrent writes. |
| 299 |
type: int |
| 300 |
id: |
| 301 |
description: SDS ID. |
| 302 |
type: str |
| 303 |
ipList: |
| 304 |
description: SDS IP list. |
| 305 |
type: list |
| 306 |
contains: |
| 307 |
ip: |
| 308 |
description: IP present in the SDS. |
| 309 |
type: str |
| 310 |
role: |
| 311 |
description: Role of the SDS IP. |
| 312 |
type: str |
| 313 |
lastUpgradeTime: |
| 314 |
description: Last time SDS was upgraded. |
| 315 |
type: str |
| 316 |
links: |
| 317 |
description: SDS links. |
| 318 |
type: list |
| 319 |
contains: |
| 320 |
href: |
| 321 |
description: SDS instance URL. |
| 322 |
type: str |
| 323 |
rel: |
| 324 |
description: SDS's relationship with different entities. |
| 325 |
type: str |
| 326 |
maintenanceState: |
| 327 |
description: Maintenance state. |
| 328 |
type: str |
| 329 |
maintenanceType: |
| 330 |
description: Maintenance type. |
| 331 |
type: str |
| 332 |
mdmConnectionState: |
| 333 |
description: MDM connection state. |
| 334 |
type: str |
| 335 |
membershipState: |
| 336 |
description: Membership state. |
| 337 |
type: str |
| 338 |
name: |
| 339 |
description: Name of the SDS. |
| 340 |
type: str |
| 341 |
numOfIoBuffers: |
| 342 |
description: Number of IO buffers. |
| 343 |
type: int |
| 344 |
numRestarts: |
| 345 |
description: Number of restarts. |
| 346 |
type: int |
| 347 |
onVmWare: |
| 348 |
description: Presence on VMware. |
| 349 |
type: bool |
| 350 |
perfProfile: |
| 351 |
description: Performance profile. |
| 352 |
type: str |
| 353 |
port: |
| 354 |
description: SDS port. |
| 355 |
type: int |
| 356 |
protectionDomainId: |
| 357 |
description: Protection Domain ID. |
| 358 |
type: str |
| 359 |
protectionDomainName: |
| 360 |
description: Protection Domain Name. |
| 361 |
type: str |
| 362 |
raidControllers: |
| 363 |
description: Number of RAID controllers. |
| 364 |
type: int |
| 365 |
rfcacheEnabled: |
| 366 |
description: Whether RF cache is enabled or not. |
| 367 |
type: bool |
| 368 |
rfcacheErrorApiVersionMismatch: |
| 369 |
description: RF cache error for API version mismatch. |
| 370 |
type: bool |
| 371 |
rfcacheErrorDeviceDoesNotExist: |
| 372 |
description: RF cache error for device does not exist. |
| 373 |
type: bool |
| 374 |
rfcacheErrorInconsistentCacheConfiguration: |
| 375 |
description: RF cache error for inconsistent cache configuration. |
| 376 |
type: bool |
| 377 |
rfcacheErrorInconsistentSourceConfiguration: |
| 378 |
description: RF cache error for inconsistent source configuration. |
| 379 |
type: bool |
| 380 |
rfcacheErrorInvalidDriverPath: |
| 381 |
description: RF cache error for invalid driver path. |
| 382 |
type: bool |
| 383 |
rfcacheErrorLowResources: |
| 384 |
description: RF cache error for low resources. |
| 385 |
type: bool |
| 386 |
rmcacheEnabled: |
| 387 |
description: Whether Read RAM cache is enabled or not. |
| 388 |
type: bool |
| 389 |
rmcacheFrozen: |
| 390 |
description: RM cache frozen. |
| 391 |
type: bool |
| 392 |
rmcacheMemoryAllocationState: |
| 393 |
description: RM cache memory allocation state. |
| 394 |
type: bool |
| 395 |
rmcacheSizeInKb: |
| 396 |
description: RM cache size in KB. |
| 397 |
type: int |
| 398 |
rmcacheSizeInMb: |
| 399 |
description: RM cache size in MB. |
| 400 |
type: int |
| 401 |
sdsConfigurationFailure: |
| 402 |
description: SDS configuration failure. |
| 403 |
type: str |
| 404 |
sdsDecoupled: |
| 405 |
description: SDS decoupled. |
| 406 |
type: str |
| 407 |
sdsReceiveBufferAllocationFailures: |
| 408 |
description: SDS receive buffer allocation failures. |
| 409 |
type: str |
| 410 |
sdsState: |
| 411 |
description: SDS state. |
| 412 |
type: str |
| 413 |
softwareVersionInfo: |
| 414 |
description: SDS software version information. |
| 415 |
type: str |
| 416 |
sample: { |
| 417 |
"authenticationError": "None", |
| 418 |
"certificateInfo": null, |
| 419 |
"configuredDrlMode": "Volatile", |
| 420 |
"drlMode": "Volatile", |
| 421 |
"faultSetId": null, |
| 422 |
"fglMetadataCacheSize": 0, |
| 423 |
"fglMetadataCacheState": "Disabled", |
| 424 |
"fglNumConcurrentWrites": 1000, |
| 425 |
"id": "8f3bb0cc00000002", |
| 426 |
"ipList": [ |
| 427 |
{ |
| 428 |
"ip": "10.47.xxx.xxx", |
| 429 |
"role": "all" |
| 430 |
} |
| 431 |
], |
| 432 |
"lastUpgradeTime": 0, |
| 433 |
"links": [ |
| 434 |
{ |
| 435 |
"href": "/api/instances/Sds::8f3bb0cc00000002", |
| 436 |
"rel": "self" |
| 437 |
}, |
| 438 |
{ |
| 439 |
"href": "/api/instances/Sds::8f3bb0cc00000002/relationships |
| 440 |
/Statistics", |
| 441 |
"rel": "/api/Sds/relationship/Statistics" |
| 442 |
}, |
| 443 |
{ |
| 444 |
"href": "/api/instances/Sds::8f3bb0cc00000002/relationships |
| 445 |
/SpSds", |
| 446 |
"rel": "/api/Sds/relationship/SpSds" |
| 447 |
}, |
| 448 |
{ |
| 449 |
"href": "/api/instances/Sds::8f3bb0cc00000002/relationships |
| 450 |
/Device", |
| 451 |
"rel": "/api/Sds/relationship/Device" |
| 452 |
}, |
| 453 |
{ |
| 454 |
"href": "/api/instances/ProtectionDomain::9300c1f900000000", |
| 455 |
"rel": "/api/parent/relationship/protectionDomainId" |
| 456 |
} |
| 457 |
], |
| 458 |
"maintenanceState": "NoMaintenance", |
| 459 |
"maintenanceType": "NoMaintenance", |
| 460 |
"mdmConnectionState": "Connected", |
| 461 |
"membershipState": "Joined", |
| 462 |
"name": "node0", |
| 463 |
"numOfIoBuffers": null, |
| 464 |
"numRestarts": 2, |
| 465 |
"onVmWare": true, |
| 466 |
"perfProfile": "HighPerformance", |
| 467 |
"port": 7072, |
| 468 |
"protectionDomainId": "9300c1f900000000", |
| 469 |
"protectionDomainName": "domain1", |
| 470 |
"raidControllers": null, |
| 471 |
"rfcacheEnabled": true, |
| 472 |
"rfcacheErrorApiVersionMismatch": false, |
| 473 |
"rfcacheErrorDeviceDoesNotExist": false, |
| 474 |
"rfcacheErrorInconsistentCacheConfiguration": false, |
| 475 |
"rfcacheErrorInconsistentSourceConfiguration": false, |
| 476 |
"rfcacheErrorInvalidDriverPath": false, |
| 477 |
"rfcacheErrorLowResources": false, |
| 478 |
"rmcacheEnabled": true, |
| 479 |
"rmcacheFrozen": false, |
| 480 |
"rmcacheMemoryAllocationState": "AllocationPending", |
| 481 |
"rmcacheSizeInKb": 131072, |
| 482 |
"rmcacheSizeInMb": 128, |
| 483 |
"sdsConfigurationFailure": null, |
| 484 |
"sdsDecoupled": null, |
| 485 |
"sdsReceiveBufferAllocationFailures": null, |
| 486 |
"sdsState": "Normal", |
| 487 |
"softwareVersionInfo": "R3_6.0.0" |
| 488 |
} |
| 489 |
''' |
| 490 |
|
| 491 |
from ansible.module_utils.basic import AnsibleModule |
| 492 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell\ |
| 493 |
import utils |
| 494 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.libraries.powerflex_base \ |
| 495 |
import powerflex_compatibility |
| 496 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.libraries.powerflex_base \ |
| 497 |
import PowerFlexBase |
| 498 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.libraries.configuration \ |
| 499 |
import Configuration |
| 500 |
import copy |
| 501 |
|
| 502 |
LOG = utils.get_logger('sds') |
| 503 |
|
| 504 |
|
| 505 |
@powerflex_compatibility(min_ver='3.6', max_ver='5.0') |
| 506 |
class PowerFlexSDS(PowerFlexBase): |
| 507 |
"""Class with SDS operations""" |
| 508 |
|
| 509 |
def __init__(self): |
| 510 |
""" Define all parameters required by this module""" |
| 511 |
self.module_params = utils.get_powerflex_gateway_host_parameters() |
| 512 |
self.module_params.update(get_powerflex_sds_parameters()) |
| 513 |
|
| 514 |
mut_ex_args = [['sds_name', 'sds_id'], |
| 515 |
['protection_domain_name', 'protection_domain_id'], |
| 516 |
['fault_set_name', 'fault_set_id']] |
| 517 |
|
| 518 |
required_together_args = [['sds_ip_list', 'sds_ip_state']] |
| 519 |
|
| 520 |
required_one_of_args = [['sds_name', 'sds_id']] |
| 521 |
|
| 522 |
|
| 523 |
ansible_module_params = { |
| 524 |
'argument_spec': get_powerflex_sds_parameters(), |
| 525 |
'supports_check_mode': True, |
| 526 |
'mutually_exclusive': mut_ex_args, |
| 527 |
'required_one_of': required_one_of_args, |
| 528 |
'required_together': required_together_args |
| 529 |
} |
| 530 |
super().__init__(AnsibleModule, ansible_module_params) |
| 531 |
super().check_module_compatibility() |
| 532 |
|
| 533 |
self.result = dict( |
| 534 |
changed=False, |
| 535 |
sds_details={} |
| 536 |
) |
| 537 |
|
| 538 |
def validate_rmcache_size_parameter(self, rmcache_enabled, rmcache_size): |
| 539 |
"""Validate the input parameters""" |
| 540 |
|
| 541 |
|
| 542 |
if rmcache_size is not None and rmcache_enabled is False: |
| 543 |
error_msg = "RM cache size can be set only when RM cache " \ |
| 544 |
"is enabled, please enable it along with RM " \ |
| 545 |
"cache size." |
| 546 |
LOG.error(error_msg) |
| 547 |
self.module.fail_json(msg=error_msg) |
| 548 |
|
| 549 |
def validate_ip_parameter(self, sds_ip_list): |
| 550 |
"""Validate the input parameters""" |
| 551 |
|
| 552 |
if sds_ip_list is None or len(sds_ip_list) == 0: |
| 553 |
error_msg = "Provide valid values for " \ |
| 554 |
"sds_ip_list as 'ip' and 'role' for Create/Modify " \ |
| 555 |
"operations." |
| 556 |
LOG.error(error_msg) |
| 557 |
self.module.fail_json(msg=error_msg) |
| 558 |
|
| 559 |
def get_sds_details(self, sds_name=None, sds_id=None): |
| 560 |
"""Get SDS details |
| 561 |
:param sds_name: Name of the SDS |
| 562 |
:type sds_name: str |
| 563 |
:param sds_id: ID of the SDS |
| 564 |
:type sds_id: str |
| 565 |
:return: Details of SDS if it exist |
| 566 |
:rtype: dict |
| 567 |
""" |
| 568 |
|
| 569 |
id_or_name = sds_id if sds_id else sds_name |
| 570 |
|
| 571 |
try: |
| 572 |
if sds_name: |
| 573 |
sds_details = self.powerflex_conn.sds.get( |
| 574 |
filter_fields={'name': sds_name}) |
| 575 |
else: |
| 576 |
sds_details = self.powerflex_conn.sds.get( |
| 577 |
filter_fields={'id': sds_id}) |
| 578 |
|
| 579 |
if len(sds_details) == 0: |
| 580 |
msg = "SDS with identifier '%s' not found" % id_or_name |
| 581 |
LOG.info(msg) |
| 582 |
return None |
| 583 |
|
| 584 |
return sds_details[0] |
| 585 |
|
| 586 |
except Exception as e: |
| 587 |
error_msg = "Failed to get the SDS '%s' with error '%s'" \ |
| 588 |
% (id_or_name, str(e)) |
| 589 |
LOG.error(error_msg) |
| 590 |
self.module.fail_json(msg=error_msg) |
| 591 |
|
| 592 |
def get_protection_domain( |
| 593 |
self, protection_domain_name=None, protection_domain_id=None |
| 594 |
): |
| 595 |
"""Get the details of a protection domain in a given PowerFlex storage |
| 596 |
system""" |
| 597 |
return Configuration(self.powerflex_conn, self.module).get_protection_domain( |
| 598 |
protection_domain_name=protection_domain_name, protection_domain_id=protection_domain_id) |
| 599 |
|
| 600 |
def get_fault_set(self, fault_set_name=None, fault_set_id=None, protection_domain_id=None): |
| 601 |
"""Get fault set details |
| 602 |
:param fault_set_name: Name of the fault set |
| 603 |
:param fault_set_id: Id of the fault set |
| 604 |
:param protection_domain_id: ID of the protection domain |
| 605 |
:return: Fault set details |
| 606 |
:rtype: dict |
| 607 |
""" |
| 608 |
return Configuration(self.powerflex_conn, self.module).get_fault_set( |
| 609 |
fault_set_name=fault_set_name, fault_set_id=fault_set_id, protection_domain_id=protection_domain_id) |
| 610 |
|
| 611 |
def restructure_ip_role_dict(self, sds_ip_list): |
| 612 |
"""Restructure IP role dict |
| 613 |
:param sds_ip_list: List of one or more IP addresses and |
| 614 |
their roles |
| 615 |
:type sds_ip_list: list[dict] |
| 616 |
:return: List of one or more IP addresses and their roles |
| 617 |
:rtype: list[dict] |
| 618 |
""" |
| 619 |
new_sds_ip_list = [] |
| 620 |
for item in sds_ip_list: |
| 621 |
new_sds_ip_list.append({"SdsIp": item}) |
| 622 |
return new_sds_ip_list |
| 623 |
|
| 624 |
def validate_create(self, protection_domain_id, sds_ip_list, sds_ip_state, sds_name, |
| 625 |
sds_id, sds_new_name, rmcache_enabled=None, rmcache_size=None, |
| 626 |
fault_set_id=None): |
| 627 |
|
| 628 |
if sds_name is None or len(sds_name.strip()) == 0: |
| 629 |
error_msg = "Please provide valid sds_name value for " \ |
| 630 |
"creation of SDS." |
| 631 |
LOG.error(error_msg) |
| 632 |
self.module.fail_json(msg=error_msg) |
| 633 |
|
| 634 |
if protection_domain_id is None: |
| 635 |
error_msg = "Protection Domain is a mandatory parameter " \ |
| 636 |
"for creating an SDS. Please enter a valid value." |
| 637 |
LOG.error(error_msg) |
| 638 |
self.module.fail_json(msg=error_msg) |
| 639 |
|
| 640 |
if sds_ip_list is None or len(sds_ip_list) == 0: |
| 641 |
error_msg = "Please provide valid sds_ip_list values for " \ |
| 642 |
"creation of SDS." |
| 643 |
LOG.error(error_msg) |
| 644 |
self.module.fail_json(msg=error_msg) |
| 645 |
|
| 646 |
if sds_ip_state is not None and sds_ip_state != "present-in-sds": |
| 647 |
error_msg = "Incorrect IP state given for creation of SDS." |
| 648 |
LOG.error(error_msg) |
| 649 |
self.module.fail_json(msg=error_msg) |
| 650 |
|
| 651 |
if sds_id: |
| 652 |
error_msg = "Creation of SDS is allowed using sds_name " \ |
| 653 |
"only, sds_id given." |
| 654 |
LOG.info(error_msg) |
| 655 |
self.module.fail_json(msg=error_msg) |
| 656 |
|
| 657 |
def create_sds(self, protection_domain_id, sds_ip_list, sds_ip_state, sds_name, |
| 658 |
sds_id, sds_new_name, rmcache_enabled=None, rmcache_size=None, fault_set_id=None): |
| 659 |
"""Create SDS |
| 660 |
:param protection_domain_id: ID of the Protection Domain |
| 661 |
:type protection_domain_id: str |
| 662 |
:param sds_ip_list: List of one or more IP addresses associated |
| 663 |
with the SDS over which the data will be |
| 664 |
transferred. |
| 665 |
:type sds_ip_list: list[dict] |
| 666 |
:param sds_ip_state: SDS IP state |
| 667 |
:type sds_ip_state: str |
| 668 |
:param sds_name: SDS name |
| 669 |
:type sds_name: str |
| 670 |
:param rmcache_enabled: Whether to enable the Read RAM cache |
| 671 |
:type rmcache_enabled: bool |
| 672 |
:param rmcache_size: Read RAM cache size (in MB) |
| 673 |
:type rmcache_size: int |
| 674 |
:param fault_set_id: ID of the Fault Set |
| 675 |
:type fault_set_id: str |
| 676 |
:return: Boolean indicating if create operation is successful |
| 677 |
""" |
| 678 |
try: |
| 679 |
|
| 680 |
|
| 681 |
self.validate_create(protection_domain_id=protection_domain_id, |
| 682 |
sds_ip_list=sds_ip_list, sds_ip_state=sds_ip_state, |
| 683 |
sds_name=sds_name, sds_id=sds_id, sds_new_name=sds_new_name, |
| 684 |
rmcache_enabled=rmcache_enabled, rmcache_size=rmcache_size, |
| 685 |
fault_set_id=fault_set_id) |
| 686 |
|
| 687 |
self.validate_ip_parameter(sds_ip_list) |
| 688 |
|
| 689 |
if not self.module.check_mode: |
| 690 |
if sds_ip_list and sds_ip_state == "present-in-sds": |
| 691 |
sds_ip_list = self.restructure_ip_role_dict(sds_ip_list) |
| 692 |
|
| 693 |
if rmcache_size is not None: |
| 694 |
self.validate_rmcache_size_parameter(rmcache_enabled=rmcache_enabled, |
| 695 |
rmcache_size=rmcache_size) |
| 696 |
|
| 697 |
rmcache_size = rmcache_size * 1024 |
| 698 |
|
| 699 |
create_params = ("protection_domain_id: %s," |
| 700 |
" sds_ip_list: %s," |
| 701 |
" sds_name: %s," |
| 702 |
" rmcache_enabled: %s, " |
| 703 |
" rmcache_size_KB: %s, " |
| 704 |
" fault_set_id: %s" |
| 705 |
% (protection_domain_id, sds_ip_list, |
| 706 |
sds_name, rmcache_enabled, rmcache_size, |
| 707 |
fault_set_id)) |
| 708 |
LOG.info("Creating SDS with params: %s", create_params) |
| 709 |
|
| 710 |
self.powerflex_conn.sds.create( |
| 711 |
protection_domain_id=protection_domain_id, |
| 712 |
sds_ips=sds_ip_list, |
| 713 |
name=sds_name, |
| 714 |
rmcache_enabled=rmcache_enabled, |
| 715 |
rmcache_size_in_kb=rmcache_size, |
| 716 |
fault_set_id=fault_set_id) |
| 717 |
return self.get_sds_details(sds_name=sds_name) |
| 718 |
|
| 719 |
except Exception as e: |
| 720 |
error_msg = f"Create SDS {sds_name} operation failed with error {str(e)}" |
| 721 |
LOG.error(error_msg) |
| 722 |
self.module.fail_json(msg=error_msg) |
| 723 |
|
| 724 |
def to_modify(self, sds_details, sds_new_name, rfcache_enabled, |
| 725 |
rmcache_enabled, rmcache_size, performance_profile): |
| 726 |
""" |
| 727 |
:param sds_details: Details of the SDS |
| 728 |
:type sds_details: dict |
| 729 |
:param sds_new_name: New name of SDS |
| 730 |
:type sds_new_name: str |
| 731 |
:param rfcache_enabled: Whether to enable the Read Flash cache |
| 732 |
:type rfcache_enabled: bool |
| 733 |
:param rmcache_enabled: Whether to enable the Read RAM cache |
| 734 |
:type rmcache_enabled: bool |
| 735 |
:param rmcache_size: Read RAM cache size (in MB) |
| 736 |
:type rmcache_size: int |
| 737 |
:param performance_profile: Performance profile to apply to the SDS |
| 738 |
:type performance_profile: str |
| 739 |
:return: Dictionary containing the attributes of SDS which are to be |
| 740 |
updated |
| 741 |
:rtype: dict |
| 742 |
""" |
| 743 |
modify_dict = {} |
| 744 |
|
| 745 |
if sds_new_name is not None and \ |
| 746 |
sds_new_name != sds_details['name']: |
| 747 |
modify_dict['name'] = sds_new_name |
| 748 |
|
| 749 |
param_input = dict() |
| 750 |
param_input['rfcacheEnabled'] = rfcache_enabled |
| 751 |
param_input['rmcacheEnabled'] = rmcache_enabled |
| 752 |
param_input['perfProfile'] = performance_profile |
| 753 |
|
| 754 |
param_list = ['rfcacheEnabled', 'rmcacheEnabled', 'perfProfile'] |
| 755 |
for param in param_list: |
| 756 |
if param_input[param] is not None and \ |
| 757 |
sds_details[param] != param_input[param]: |
| 758 |
modify_dict[param] = param_input[param] |
| 759 |
|
| 760 |
if rmcache_size is not None: |
| 761 |
self.validate_rmcache_size_parameter(rmcache_enabled, |
| 762 |
rmcache_size) |
| 763 |
exisitng_size_mb = sds_details['rmcacheSizeInKb'] / 1024 |
| 764 |
if rmcache_size != exisitng_size_mb: |
| 765 |
if sds_details['rmcacheEnabled']: |
| 766 |
modify_dict['rmcacheSizeInMB'] = rmcache_size |
| 767 |
else: |
| 768 |
error_msg = "Failed to update RM cache size for the " \ |
| 769 |
"SDS '%s' as RM cache is disabled " \ |
| 770 |
"previously, please enable it before " \ |
| 771 |
"setting the size." \ |
| 772 |
% sds_details['name'] |
| 773 |
LOG.error(error_msg) |
| 774 |
self.module.fail_json(msg=error_msg) |
| 775 |
|
| 776 |
return modify_dict |
| 777 |
|
| 778 |
def modify_sds_attributes(self, sds_id, modify_dict, |
| 779 |
create_flag=False): |
| 780 |
"""Modify SDS attributes |
| 781 |
:param sds_id: SDS ID |
| 782 |
:type sds_id: str |
| 783 |
:param modify_dict: Dictionary containing the attributes of SDS |
| 784 |
which are to be updated |
| 785 |
:type modify_dict: dict |
| 786 |
:param create_flag: Flag to indicate whether modify operation is |
| 787 |
followed by create operation or not |
| 788 |
:type create_flag: bool |
| 789 |
:return: Boolean indicating if the operation is successful |
| 790 |
""" |
| 791 |
try: |
| 792 |
msg = "Dictionary containing attributes which are to be" \ |
| 793 |
" updated is '%s'." % (str(modify_dict)) |
| 794 |
LOG.info(msg) |
| 795 |
|
| 796 |
if not self.module.check_mode: |
| 797 |
if 'name' in modify_dict: |
| 798 |
self.powerflex_conn.sds.rename(sds_id, modify_dict['name']) |
| 799 |
msg = "The name of the SDS is updated to '%s' successfully." \ |
| 800 |
% modify_dict['name'] |
| 801 |
LOG.info(msg) |
| 802 |
|
| 803 |
if 'rfcacheEnabled' in modify_dict: |
| 804 |
self.powerflex_conn.sds.set_rfcache_enabled( |
| 805 |
sds_id, modify_dict['rfcacheEnabled']) |
| 806 |
msg = "The use RFcache is updated to '%s' successfully." \ |
| 807 |
% modify_dict['rfcacheEnabled'] |
| 808 |
LOG.info(msg) |
| 809 |
|
| 810 |
if 'rmcacheEnabled' in modify_dict: |
| 811 |
self.powerflex_conn.sds.set_rmcache_enabled( |
| 812 |
sds_id, modify_dict['rmcacheEnabled']) |
| 813 |
msg = "The use RMcache is updated to '%s' successfully." \ |
| 814 |
% modify_dict['rmcacheEnabled'] |
| 815 |
LOG.info(msg) |
| 816 |
|
| 817 |
if 'rmcacheSizeInMB' in modify_dict: |
| 818 |
self.powerflex_conn.sds.set_rmcache_size( |
| 819 |
sds_id, modify_dict['rmcacheSizeInMB']) |
| 820 |
msg = "The size of RMcache is updated to '%s' successfully." \ |
| 821 |
% modify_dict['rmcacheSizeInMB'] |
| 822 |
LOG.info(msg) |
| 823 |
|
| 824 |
if 'perfProfile' in modify_dict: |
| 825 |
self.powerflex_conn.sds.set_performance_parameters( |
| 826 |
sds_id, modify_dict['perfProfile']) |
| 827 |
msg = "The performance profile is updated to '%s'" \ |
| 828 |
% modify_dict['perfProfile'] |
| 829 |
LOG.info(msg) |
| 830 |
|
| 831 |
return self.get_sds_details(sds_id=sds_id) |
| 832 |
except Exception as e: |
| 833 |
if create_flag: |
| 834 |
error_msg = "Create SDS is successful, but failed to update" \ |
| 835 |
" the SDS '%s' with error '%s'"\ |
| 836 |
% (sds_id, str(e)) |
| 837 |
else: |
| 838 |
error_msg = "Failed to update the SDS '%s' with error '%s'" \ |
| 839 |
% (sds_id, str(e)) |
| 840 |
LOG.error(error_msg) |
| 841 |
self.module.fail_json(msg=error_msg) |
| 842 |
|
| 843 |
def identify_ip_role_add(self, sds_ip_list, sds_details, sds_ip_state): |
| 844 |
|
| 845 |
|
| 846 |
existing_ip_role_list = sds_details['ipList'] |
| 847 |
update_role = [] |
| 848 |
ips_to_add = [] |
| 849 |
|
| 850 |
|
| 851 |
existing_ip_list = [] |
| 852 |
if existing_ip_role_list: |
| 853 |
for ip in existing_ip_role_list: |
| 854 |
existing_ip_list.append(ip['ip']) |
| 855 |
for given_ip in sds_ip_list: |
| 856 |
ip = given_ip['ip'] |
| 857 |
if ip not in existing_ip_list: |
| 858 |
ips_to_add.append(given_ip) |
| 859 |
LOG.info("IP(s) to be added: %s", ips_to_add) |
| 860 |
|
| 861 |
if len(ips_to_add) != 0: |
| 862 |
for ip in ips_to_add: |
| 863 |
sds_ip_list.remove(ip) |
| 864 |
|
| 865 |
|
| 866 |
update_role = [ip for ip in sds_ip_list |
| 867 |
if ip not in existing_ip_role_list] |
| 868 |
LOG.info("Role update needed for: %s", update_role) |
| 869 |
return ips_to_add, update_role |
| 870 |
|
| 871 |
def identify_ip_role_remove(self, sds_ip_list, sds_details, sds_ip_state): |
| 872 |
|
| 873 |
|
| 874 |
existing_ip_role_list = sds_details['ipList'] |
| 875 |
if sds_ip_state == "absent-in-sds": |
| 876 |
ips_to_remove = [ip for ip in existing_ip_role_list |
| 877 |
if ip in sds_ip_list] |
| 878 |
if len(ips_to_remove) != 0: |
| 879 |
LOG.info("IP(s) to remove: %s", ips_to_remove) |
| 880 |
return ips_to_remove |
| 881 |
else: |
| 882 |
LOG.info("IP(s) do not exists.") |
| 883 |
return [] |
| 884 |
|
| 885 |
def add_ip(self, sds_id, sds_ip_list): |
| 886 |
"""Add IP to SDS |
| 887 |
:param sds_id: SDS ID |
| 888 |
:type sds_id: str |
| 889 |
:param sds_ip_list: List of one or more IP addresses and |
| 890 |
their roles |
| 891 |
:type sds_ip_list: list[dict] |
| 892 |
:return: Boolean indicating if add IP operation is successful |
| 893 |
""" |
| 894 |
try: |
| 895 |
if not self.module.check_mode: |
| 896 |
for ip in sds_ip_list: |
| 897 |
LOG.info("IP to add: %s", ip) |
| 898 |
self.powerflex_conn.sds.add_ip(sds_id=sds_id, sds_ip=ip) |
| 899 |
LOG.info("IP added successfully.") |
| 900 |
return True |
| 901 |
except Exception as e: |
| 902 |
error_msg = "Add IP to SDS '%s' operation failed with " \ |
| 903 |
"error '%s'" % (sds_id, str(e)) |
| 904 |
LOG.error(error_msg) |
| 905 |
self.module.fail_json(msg=error_msg) |
| 906 |
|
| 907 |
def update_role(self, sds_id, sds_ip_list): |
| 908 |
"""Update IP's role for an SDS |
| 909 |
:param sds_id: SDS ID |
| 910 |
:type sds_id: str |
| 911 |
:param sds_ip_list: List of one or more IP addresses and |
| 912 |
their roles |
| 913 |
:type sds_ip_list: list[dict] |
| 914 |
:return: Boolean indicating if add IP operation is successful |
| 915 |
""" |
| 916 |
try: |
| 917 |
if not self.module.check_mode: |
| 918 |
LOG.info("Role updates for: %s", sds_ip_list) |
| 919 |
if len(sds_ip_list) != 0: |
| 920 |
for ip in sds_ip_list: |
| 921 |
LOG.info("ip-role: %s", ip) |
| 922 |
self.powerflex_conn.sds.set_ip_role(sds_id, ip['ip'], |
| 923 |
ip['role']) |
| 924 |
msg = "The role '%s' for IP '%s' is updated " \ |
| 925 |
"successfully." % (ip['role'], ip['ip']) |
| 926 |
LOG.info(msg) |
| 927 |
return True |
| 928 |
except Exception as e: |
| 929 |
error_msg = "Update role of IP for SDS '%s' operation failed " \ |
| 930 |
"with error '%s'" % (sds_id, str(e)) |
| 931 |
LOG.error(error_msg) |
| 932 |
self.module.fail_json(msg=error_msg) |
| 933 |
|
| 934 |
def remove_ip(self, sds_id, sds_ip_list): |
| 935 |
"""Remove IP from SDS |
| 936 |
:param sds_id: SDS ID |
| 937 |
:type sds_id: str |
| 938 |
:param sds_ip_list: List of one or more IP addresses and |
| 939 |
their roles. |
| 940 |
:type sds_ip_list: list[dict] |
| 941 |
:return: Boolean indicating if remove IP operation is successful |
| 942 |
""" |
| 943 |
try: |
| 944 |
if not self.module.check_mode: |
| 945 |
for ip in sds_ip_list: |
| 946 |
LOG.info("IP to remove: %s", ip) |
| 947 |
self.powerflex_conn.sds.remove_ip(sds_id=sds_id, ip=ip['ip']) |
| 948 |
LOG.info("IP removed successfully.") |
| 949 |
return True |
| 950 |
except Exception as e: |
| 951 |
error_msg = "Remove IP from SDS '%s' operation failed with " \ |
| 952 |
"error '%s'" % (sds_id, str(e)) |
| 953 |
LOG.error(error_msg) |
| 954 |
self.module.fail_json(msg=error_msg) |
| 955 |
|
| 956 |
def delete_sds(self, sds_id): |
| 957 |
"""Delete SDS |
| 958 |
:param sds_id: SDS ID |
| 959 |
:type sds_id: str |
| 960 |
:return: Boolean indicating if delete operation is successful |
| 961 |
""" |
| 962 |
try: |
| 963 |
if not self.module.check_mode: |
| 964 |
self.powerflex_conn.sds.delete(sds_id) |
| 965 |
return None |
| 966 |
return self.get_sds_details(sds_id=sds_id) |
| 967 |
except Exception as e: |
| 968 |
error_msg = "Delete SDS '%s' operation failed with error '%s'" \ |
| 969 |
% (sds_id, str(e)) |
| 970 |
LOG.error(error_msg) |
| 971 |
self.module.fail_json(msg=error_msg) |
| 972 |
|
| 973 |
def show_output(self, sds_id): |
| 974 |
"""Show SDS details |
| 975 |
:param sds_id: ID of the SDS |
| 976 |
:type sds_id: str |
| 977 |
:return: Details of SDS |
| 978 |
:rtype: dict |
| 979 |
""" |
| 980 |
|
| 981 |
try: |
| 982 |
sds_details = self.powerflex_conn.sds.get( |
| 983 |
filter_fields={'id': sds_id}) |
| 984 |
|
| 985 |
if len(sds_details) == 0: |
| 986 |
msg = "SDS with identifier '%s' not found" % sds_id |
| 987 |
LOG.error(msg) |
| 988 |
return None |
| 989 |
|
| 990 |
|
| 991 |
if 'protectionDomainId' in sds_details[0] \ |
| 992 |
and sds_details[0]['protectionDomainId']: |
| 993 |
pd_details = self.get_protection_domain( |
| 994 |
protection_domain_id=sds_details[0]['protectionDomainId']) |
| 995 |
sds_details[0]['protectionDomainName'] = pd_details['name'] |
| 996 |
|
| 997 |
|
| 998 |
if 'rmcacheSizeInKb' in sds_details[0] \ |
| 999 |
and sds_details[0]['rmcacheSizeInKb']: |
| 1000 |
rmcache_size_mb = sds_details[0]['rmcacheSizeInKb'] / 1024 |
| 1001 |
sds_details[0]['rmcacheSizeInMb'] = int(rmcache_size_mb) |
| 1002 |
|
| 1003 |
|
| 1004 |
if 'faultSetId' in sds_details[0] \ |
| 1005 |
and sds_details[0]['faultSetId']: |
| 1006 |
fs_details = self.get_fault_set( |
| 1007 |
fault_set_id=sds_details[0]['faultSetId'], |
| 1008 |
protection_domain_id=sds_details[0]['protectionDomainId']) |
| 1009 |
sds_details[0]['faultSetName'] = fs_details['name'] |
| 1010 |
|
| 1011 |
return sds_details[0] |
| 1012 |
|
| 1013 |
except Exception as e: |
| 1014 |
error_msg = "Failed to get the SDS '%s' with error '%s'"\ |
| 1015 |
% (sds_id, str(e)) |
| 1016 |
LOG.error(error_msg) |
| 1017 |
self.module.fail_json(msg=error_msg) |
| 1018 |
|
| 1019 |
def validate_parameters(self, sds_params): |
| 1020 |
params = [sds_params['sds_name'], sds_params['sds_new_name']] |
| 1021 |
for param in params: |
| 1022 |
if param is not None and len(param.strip()) == 0: |
| 1023 |
error_msg = "Provide valid value for name for the " \ |
| 1024 |
"creation/modification of the SDS." |
| 1025 |
LOG.error(error_msg) |
| 1026 |
self.module.fail_json(msg=error_msg) |
| 1027 |
|
| 1028 |
|
| 1029 |
def get_powerflex_sds_parameters(): |
| 1030 |
"""This method provide parameter required for the SDS module on |
| 1031 |
PowerFlex""" |
| 1032 |
return dict( |
| 1033 |
sds_name=dict(), |
| 1034 |
sds_id=dict(), |
| 1035 |
sds_new_name=dict(), |
| 1036 |
protection_domain_name=dict(), |
| 1037 |
protection_domain_id=dict(), |
| 1038 |
sds_ip_list=dict( |
| 1039 |
type='list', elements='dict', options=dict( |
| 1040 |
ip=dict(required=True), |
| 1041 |
role=dict(required=True, choices=['all', 'sdsOnly', |
| 1042 |
'sdcOnly']) |
| 1043 |
) |
| 1044 |
), |
| 1045 |
sds_ip_state=dict(choices=['present-in-sds', 'absent-in-sds']), |
| 1046 |
rfcache_enabled=dict(type='bool'), |
| 1047 |
rmcache_enabled=dict(type='bool'), |
| 1048 |
rmcache_size=dict(type='int'), |
| 1049 |
performance_profile=dict(choices=['Compact', 'HighPerformance']), |
| 1050 |
fault_set_name=dict(), |
| 1051 |
fault_set_id=dict(), |
| 1052 |
state=dict(required=True, type='str', choices=['present', 'absent']) |
| 1053 |
) |
| 1054 |
|
| 1055 |
|
| 1056 |
class SDSExitHandler(): |
| 1057 |
def handle(self, sds_obj, sds_details): |
| 1058 |
if sds_details: |
| 1059 |
sds_obj.result["sds_details"] = sds_obj.show_output(sds_id=sds_details['id']) |
| 1060 |
else: |
| 1061 |
sds_obj.result["sds_details"] = None |
| 1062 |
sds_obj.module.exit_json(**sds_obj.result) |
| 1063 |
|
| 1064 |
|
| 1065 |
class SDSDeleteHandler(): |
| 1066 |
def handle(self, sds_obj, sds_params, sds_details): |
| 1067 |
if sds_params['state'] == 'absent' and sds_details: |
| 1068 |
sds_details = sds_obj.delete_sds(sds_details['id']) |
| 1069 |
sds_obj.result['changed'] = True |
| 1070 |
|
| 1071 |
SDSExitHandler().handle(sds_obj, sds_details) |
| 1072 |
|
| 1073 |
|
| 1074 |
class SDSRemoveIPHandler(): |
| 1075 |
def handle(self, sds_obj, sds_params, sds_details, sds_ip_list): |
| 1076 |
if sds_params['state'] == 'present' and sds_details: |
| 1077 |
|
| 1078 |
remove_ip_changed = False |
| 1079 |
if sds_params['sds_ip_state'] == "absent-in-sds": |
| 1080 |
sds_obj.validate_ip_parameter(sds_ip_list) |
| 1081 |
ips_to_remove = sds_obj.identify_ip_role_remove(sds_ip_list, sds_details, |
| 1082 |
sds_params['sds_ip_state']) |
| 1083 |
if ips_to_remove: |
| 1084 |
remove_ip_changed = sds_obj.remove_ip(sds_details['id'], ips_to_remove) |
| 1085 |
|
| 1086 |
if remove_ip_changed: |
| 1087 |
sds_obj.result['changed'] = True |
| 1088 |
|
| 1089 |
SDSDeleteHandler().handle(sds_obj, sds_params, sds_details) |
| 1090 |
|
| 1091 |
|
| 1092 |
class SDSAddIPHandler(): |
| 1093 |
def handle(self, sds_obj, sds_params, sds_details, sds_ip_list): |
| 1094 |
if sds_params['state'] == 'present' and sds_details: |
| 1095 |
|
| 1096 |
|
| 1097 |
add_ip_changed = False |
| 1098 |
update_role_changed = False |
| 1099 |
if sds_params['sds_ip_state'] == "present-in-sds": |
| 1100 |
sds_obj.validate_ip_parameter(sds_ip_list) |
| 1101 |
ips_to_add, roles_to_update = sds_obj.identify_ip_role_add( |
| 1102 |
sds_ip_list, sds_details, sds_params['sds_ip_state']) |
| 1103 |
if ips_to_add: |
| 1104 |
add_ip_changed = sds_obj.add_ip(sds_details['id'], ips_to_add) |
| 1105 |
if roles_to_update: |
| 1106 |
update_role_changed = sds_obj.update_role(sds_details['id'], |
| 1107 |
roles_to_update) |
| 1108 |
|
| 1109 |
if add_ip_changed or update_role_changed: |
| 1110 |
sds_obj.result['changed'] = True |
| 1111 |
|
| 1112 |
SDSRemoveIPHandler().handle(sds_obj, sds_params, sds_details, sds_ip_list) |
| 1113 |
|
| 1114 |
|
| 1115 |
class SDSModifyHandler(): |
| 1116 |
def handle(self, sds_obj, sds_params, sds_details, create_flag, sds_ip_list): |
| 1117 |
if sds_params['state'] == 'present' and sds_details: |
| 1118 |
modify_dict = sds_obj.to_modify(sds_details=sds_details, |
| 1119 |
sds_new_name=sds_params['sds_new_name'], |
| 1120 |
rfcache_enabled=sds_params['rfcache_enabled'], |
| 1121 |
rmcache_enabled=sds_params['rmcache_enabled'], |
| 1122 |
rmcache_size=sds_params['rmcache_size'], |
| 1123 |
performance_profile=sds_params['performance_profile']) |
| 1124 |
if modify_dict: |
| 1125 |
sds_details = sds_obj.modify_sds_attributes(sds_id=sds_details['id'], |
| 1126 |
modify_dict=modify_dict, |
| 1127 |
create_flag=create_flag) |
| 1128 |
sds_obj.result['changed'] = True |
| 1129 |
|
| 1130 |
SDSAddIPHandler().handle(sds_obj, sds_params, sds_details, sds_ip_list) |
| 1131 |
|
| 1132 |
|
| 1133 |
class SDSCreateHandler(): |
| 1134 |
def handle(self, sds_obj, sds_params, sds_details, protection_domain_id, fault_set_id): |
| 1135 |
create_flag = False |
| 1136 |
sds_ip_list = copy.deepcopy(sds_params['sds_ip_list']) |
| 1137 |
if sds_params['state'] == 'present' and not sds_details: |
| 1138 |
sds_details = sds_obj.create_sds(sds_name=sds_params['sds_name'], |
| 1139 |
sds_id=sds_params['sds_id'], |
| 1140 |
sds_new_name=sds_params['sds_new_name'], |
| 1141 |
protection_domain_id=protection_domain_id, |
| 1142 |
sds_ip_list=sds_ip_list, |
| 1143 |
sds_ip_state=sds_params['sds_ip_state'], |
| 1144 |
rmcache_enabled=sds_params['rmcache_enabled'], |
| 1145 |
rmcache_size=sds_params['rmcache_size'], |
| 1146 |
fault_set_id=fault_set_id) |
| 1147 |
sds_obj.result['changed'] = True |
| 1148 |
create_flag = True |
| 1149 |
|
| 1150 |
SDSModifyHandler().handle(sds_obj, sds_params, sds_details, create_flag, sds_ip_list) |
| 1151 |
|
| 1152 |
|
| 1153 |
class SDSHandler(): |
| 1154 |
def handle(self, sds_obj, sds_params): |
| 1155 |
sds_details = sds_obj.get_sds_details(sds_params['sds_name'], sds_params['sds_id']) |
| 1156 |
sds_obj.validate_parameters(sds_params=sds_params) |
| 1157 |
protection_domain_id = None |
| 1158 |
if sds_params['protection_domain_id'] or sds_params['protection_domain_name']: |
| 1159 |
protection_domain_id = sds_obj.get_protection_domain( |
| 1160 |
protection_domain_id=sds_params['protection_domain_id'], |
| 1161 |
protection_domain_name=sds_params['protection_domain_name'])['id'] |
| 1162 |
fault_set_id = None |
| 1163 |
if sds_params['fault_set_name'] or sds_params['fault_set_id']: |
| 1164 |
fault_set_details = sds_obj.get_fault_set(fault_set_name=sds_params['fault_set_name'], |
| 1165 |
fault_set_id=sds_params['fault_set_id'], |
| 1166 |
protection_domain_id=protection_domain_id) |
| 1167 |
if fault_set_details is None: |
| 1168 |
error_msg = "The specified Fault set is not in the specified Protection Domain." |
| 1169 |
LOG.error(error_msg) |
| 1170 |
sds_obj.module.fail_json(msg=error_msg) |
| 1171 |
else: |
| 1172 |
fault_set_id = fault_set_details['id'] |
| 1173 |
SDSCreateHandler().handle(sds_obj, sds_params, sds_details, protection_domain_id, fault_set_id) |
| 1174 |
|
| 1175 |
|
| 1176 |
def main(): |
| 1177 |
""" Create PowerFlex SDS object and perform action on it |
| 1178 |
based on user input from playbook.""" |
| 1179 |
obj = PowerFlexSDS() |
| 1180 |
SDSHandler().handle(obj, obj.module.params) |
| 1181 |
|
| 1182 |
|
| 1183 |
if __name__ == '__main__': |
| 1184 |
main() |