| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
""" Ansible module for managing device 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: device |
| 14 |
version_added: '1.1.0' |
| 15 |
short_description: Manage device on Dell PowerFlex |
| 16 |
description: |
| 17 |
- Managing device on PowerFlex storage system includes |
| 18 |
adding new device, getting details of device, and removing a device. |
| 19 |
author: |
| 20 |
- Rajshree Khare (@khareRajshree) <[email protected]> |
| 21 |
extends_documentation_fragment: |
| 22 |
- dellemc.powerflex.powerflex |
| 23 |
options: |
| 24 |
current_pathname: |
| 25 |
description: |
| 26 |
- Full path of the device to be added. |
| 27 |
- Required while adding a device. |
| 28 |
type: str |
| 29 |
device_name: |
| 30 |
description: |
| 31 |
- Device name. |
| 32 |
- Mutually exclusive with I(device_id). |
| 33 |
type: str |
| 34 |
device_id: |
| 35 |
description: |
| 36 |
- Device ID. |
| 37 |
- Mutually exclusive with I(device_name). |
| 38 |
type: str |
| 39 |
sds_name: |
| 40 |
description: |
| 41 |
- The name of the SDS. |
| 42 |
- Required while adding a device. |
| 43 |
- Mutually exclusive with I(sds_id). |
| 44 |
type: str |
| 45 |
sds_id: |
| 46 |
description: |
| 47 |
- The ID of the SDS. |
| 48 |
- Required while adding a device. |
| 49 |
- Mutually exclusive with I(sds_name). |
| 50 |
type: str |
| 51 |
storage_pool_name: |
| 52 |
description: |
| 53 |
- Storage Pool name. |
| 54 |
- Used while adding a storage device. |
| 55 |
- Mutually exclusive with I(storage_pool_id), I(acceleration_pool_id) and |
| 56 |
I(acceleration_pool_name). |
| 57 |
type: str |
| 58 |
storage_pool_id: |
| 59 |
description: |
| 60 |
- Storage Pool ID. |
| 61 |
- Used while adding a storage device. |
| 62 |
- Media type supported are C(SSD) and C(HDD). |
| 63 |
- Mutually exclusive with I(storage_pool_name), I(acceleration_pool_id) and |
| 64 |
I(acceleration_pool_name). |
| 65 |
type: str |
| 66 |
acceleration_pool_name: |
| 67 |
description: |
| 68 |
- Acceleration Pool Name. |
| 69 |
- Used while adding an acceleration device. |
| 70 |
- Media type supported are C(SSD) and C(NVDIMM). |
| 71 |
- Mutually exclusive with I(storage_pool_id), I(storage_pool_name) and |
| 72 |
I(acceleration_pool_name). |
| 73 |
type: str |
| 74 |
acceleration_pool_id: |
| 75 |
description: |
| 76 |
- Acceleration Pool ID. |
| 77 |
- Used while adding an acceleration device. |
| 78 |
- Media type supported are C(SSD) and C(NVDIMM). |
| 79 |
- Mutually exclusive with I(acceleration_pool_name), I(storage_pool_name) and |
| 80 |
I(storage_pool_id). |
| 81 |
type: str |
| 82 |
protection_domain_name: |
| 83 |
description: |
| 84 |
- Protection domain name. |
| 85 |
- Used while identifying a storage pool along with I(storage_pool_name). |
| 86 |
- Mutually exclusive with I(protection_domain_id). |
| 87 |
type: str |
| 88 |
protection_domain_id: |
| 89 |
description: |
| 90 |
- Protection domain ID. |
| 91 |
- Used while identifying a storage pool along with I(storage_pool_name). |
| 92 |
- Mutually exclusive with I(protection_domain_name). |
| 93 |
type: str |
| 94 |
external_acceleration_type: |
| 95 |
description: |
| 96 |
- Device external acceleration types. |
| 97 |
- Used while adding a device. |
| 98 |
type: str |
| 99 |
choices: ['Invalid', 'None', 'Read', 'Write', 'ReadAndWrite'] |
| 100 |
media_type: |
| 101 |
description: |
| 102 |
- Device media types. |
| 103 |
- Required while adding a device. |
| 104 |
type: str |
| 105 |
choices: ['HDD', 'SSD', 'NVDIMM'] |
| 106 |
state: |
| 107 |
description: |
| 108 |
- State of the device. |
| 109 |
choices: ['present', 'absent'] |
| 110 |
required: true |
| 111 |
type: str |
| 112 |
force: |
| 113 |
description: |
| 114 |
- Using the Force flag to add a device. |
| 115 |
- Use this flag, to overwrite existing data on the device. |
| 116 |
- Use this flag with caution, because all data on the device will be |
| 117 |
destroyed. |
| 118 |
type: bool |
| 119 |
default: false |
| 120 |
notes: |
| 121 |
- The value for device_id is generated only after successful addition of the |
| 122 |
device. |
| 123 |
- To uniquely identify a device, either I(device_id) can be passed or one of |
| 124 |
I(current_pathname) or I(device_name) must be passed with I(sds_id) or I(sds_name). |
| 125 |
- It is recommended to install Rfcache driver for SSD device on SDS in |
| 126 |
order to add it to an acceleration pool. |
| 127 |
- The I(check_mode) is not supported. |
| 128 |
''' |
| 129 |
|
| 130 |
EXAMPLES = r''' |
| 131 |
- name: Add a device |
| 132 |
dellemc.powerflex.device: |
| 133 |
hostname: "{{hostname}}" |
| 134 |
username: "{{username}}" |
| 135 |
password: "{{password}}" |
| 136 |
validate_certs: "{{validate_certs}}" |
| 137 |
port: "{{port}}" |
| 138 |
current_pathname: "/dev/sdb" |
| 139 |
sds_name: "node1" |
| 140 |
media_type: "HDD" |
| 141 |
device_name: "device2" |
| 142 |
storage_pool_name: "pool1" |
| 143 |
protection_domain_name: "domain1" |
| 144 |
external_acceleration_type: "ReadAndWrite" |
| 145 |
state: "present" |
| 146 |
- name: Add a device with force flag |
| 147 |
dellemc.powerflex.device: |
| 148 |
hostname: "{{hostname}}" |
| 149 |
username: "{{username}}" |
| 150 |
password: "{{password}}" |
| 151 |
validate_certs: "{{validate_certs}}" |
| 152 |
port: "{{port}}" |
| 153 |
current_pathname: "/dev/sdb" |
| 154 |
sds_name: "node1" |
| 155 |
media_type: "HDD" |
| 156 |
device_name: "device2" |
| 157 |
storage_pool_name: "pool1" |
| 158 |
protection_domain_name: "domain1" |
| 159 |
external_acceleration_type: "ReadAndWrite" |
| 160 |
force: true |
| 161 |
state: "present" |
| 162 |
- name: Get device details using device_id |
| 163 |
dellemc.powerflex.device: |
| 164 |
hostname: "{{hostname}}" |
| 165 |
username: "{{username}}" |
| 166 |
password: "{{password}}" |
| 167 |
validate_certs: "{{validate_certs}}" |
| 168 |
port: "{{port}}" |
| 169 |
device_id: "d7fe088900000000" |
| 170 |
state: "present" |
| 171 |
- name: Get device details using (current_pathname, sds_name) |
| 172 |
dellemc.powerflex.device: |
| 173 |
hostname: "{{hostname}}" |
| 174 |
username: "{{username}}" |
| 175 |
password: "{{password}}" |
| 176 |
validate_certs: "{{validate_certs}}" |
| 177 |
port: "{{port}}" |
| 178 |
current_pathname: "/dev/sdb" |
| 179 |
sds_name: "node0" |
| 180 |
state: "present" |
| 181 |
- name: Get device details using (current_pathname, sds_id) |
| 182 |
dellemc.powerflex.device: |
| 183 |
hostname: "{{hostname}}" |
| 184 |
username: "{{username}}" |
| 185 |
password: "{{password}}" |
| 186 |
validate_certs: "{{validate_certs}}" |
| 187 |
port: "{{port}}" |
| 188 |
current_pathname: "/dev/sdb" |
| 189 |
sds_id: "5717d71800000000" |
| 190 |
state: "present" |
| 191 |
- name: Remove a device using device_id |
| 192 |
dellemc.powerflex.device: |
| 193 |
hostname: "{{hostname}}" |
| 194 |
username: "{{username}}" |
| 195 |
password: "{{password}}" |
| 196 |
validate_certs: "{{validate_certs}}" |
| 197 |
port: "{{port}}" |
| 198 |
device_id: "76eb7e2f00010000" |
| 199 |
state: "absent" |
| 200 |
- name: Remove a device using (current_pathname, sds_id) |
| 201 |
dellemc.powerflex.device: |
| 202 |
hostname: "{{hostname}}" |
| 203 |
username: "{{username}}" |
| 204 |
password: "{{password}}" |
| 205 |
validate_certs: "{{validate_certs}}" |
| 206 |
port: "{{port}}" |
| 207 |
current_pathname: "/dev/sdb" |
| 208 |
sds_name: "node1" |
| 209 |
state: "absent" |
| 210 |
''' |
| 211 |
|
| 212 |
RETURN = r''' |
| 213 |
changed: |
| 214 |
description: Whether or not the resource has changed. |
| 215 |
returned: always |
| 216 |
type: bool |
| 217 |
sample: 'false' |
| 218 |
device_details: |
| 219 |
description: Details of the device. |
| 220 |
returned: When device exists |
| 221 |
type: dict |
| 222 |
contains: |
| 223 |
accelerationPoolId: |
| 224 |
description: Acceleration pool ID. |
| 225 |
type: str |
| 226 |
accelerationPoolName: |
| 227 |
description: Acceleration pool name. |
| 228 |
type: str |
| 229 |
accelerationProps: |
| 230 |
description: Indicates acceleration props. |
| 231 |
type: str |
| 232 |
aggregatedState: |
| 233 |
description: Indicates aggregated state. |
| 234 |
type: str |
| 235 |
ataSecurityActive: |
| 236 |
description: Indicates ATA security active state. |
| 237 |
type: bool |
| 238 |
autoDetectMediaType: |
| 239 |
description: Indicates auto detection of media type. |
| 240 |
type: str |
| 241 |
cacheLookAheadActive: |
| 242 |
description: Indicates cache look ahead active state. |
| 243 |
type: bool |
| 244 |
capacity: |
| 245 |
description: Device capacity. |
| 246 |
type: int |
| 247 |
capacityLimitInKb: |
| 248 |
description: Device capacity limit in KB. |
| 249 |
type: int |
| 250 |
deviceCurrentPathName: |
| 251 |
description: Device current path name. |
| 252 |
type: str |
| 253 |
deviceOriginalPathName: |
| 254 |
description: Device original path name. |
| 255 |
type: str |
| 256 |
deviceState: |
| 257 |
description: Indicates device state. |
| 258 |
type: str |
| 259 |
deviceType: |
| 260 |
description: Indicates device type. |
| 261 |
type: str |
| 262 |
errorState: |
| 263 |
description: Indicates error state. |
| 264 |
type: str |
| 265 |
externalAccelerationType: |
| 266 |
description: Indicates external acceleration type. |
| 267 |
type: str |
| 268 |
fglNvdimmMetadataAmortizationX100: |
| 269 |
description: Indicates FGL NVDIMM meta data amortization value. |
| 270 |
type: int |
| 271 |
fglNvdimmWriteCacheSize: |
| 272 |
description: Indicates FGL NVDIMM write cache size. |
| 273 |
type: int |
| 274 |
firmwareVersion: |
| 275 |
description: Indicates firmware version. |
| 276 |
type: str |
| 277 |
id: |
| 278 |
description: Device ID. |
| 279 |
type: str |
| 280 |
ledSetting: |
| 281 |
description: Indicates LED setting. |
| 282 |
type: str |
| 283 |
links: |
| 284 |
description: Device links. |
| 285 |
type: list |
| 286 |
contains: |
| 287 |
href: |
| 288 |
description: Device instance URL. |
| 289 |
type: str |
| 290 |
rel: |
| 291 |
description: Relationship of device with different |
| 292 |
entities. |
| 293 |
type: str |
| 294 |
logicalSectorSizeInBytes: |
| 295 |
description: Logical sector size in bytes. |
| 296 |
type: int |
| 297 |
longSuccessfulIos: |
| 298 |
description: Indicates long successful IOs. |
| 299 |
type: list |
| 300 |
maxCapacityInKb: |
| 301 |
description: Maximum device capacity limit in KB. |
| 302 |
type: int |
| 303 |
mediaFailing: |
| 304 |
description: Indicates media failing. |
| 305 |
type: bool |
| 306 |
mediaType: |
| 307 |
description: Indicates media type. |
| 308 |
type: str |
| 309 |
modelName: |
| 310 |
description: Indicates model name. |
| 311 |
type: str |
| 312 |
name: |
| 313 |
description: Device name. |
| 314 |
type: str |
| 315 |
persistentChecksumState: |
| 316 |
description: Indicates persistent checksum state. |
| 317 |
type: str |
| 318 |
physicalSectorSizeInBytes: |
| 319 |
description: Physical sector size in bytes. |
| 320 |
type: int |
| 321 |
protectionDomainId: |
| 322 |
description: Protection domain ID. |
| 323 |
type: str |
| 324 |
protectionDomainName: |
| 325 |
description: Protection domain name. |
| 326 |
type: str |
| 327 |
raidControllerSerialNumber: |
| 328 |
description: RAID controller serial number. |
| 329 |
type: str |
| 330 |
rfcacheErrorDeviceDoesNotExist: |
| 331 |
description: Indicates RF cache error device does not exist. |
| 332 |
type: bool |
| 333 |
rfcacheProps: |
| 334 |
description: RF cache props. |
| 335 |
type: str |
| 336 |
sdsId: |
| 337 |
description: SDS ID. |
| 338 |
type: str |
| 339 |
sdsName: |
| 340 |
description: SDS name. |
| 341 |
type: str |
| 342 |
serialNumber: |
| 343 |
description: Indicates Serial number. |
| 344 |
type: str |
| 345 |
spSdsId: |
| 346 |
description: Indicates SPs SDS ID. |
| 347 |
type: str |
| 348 |
ssdEndOfLifeState: |
| 349 |
description: Indicates SSD end of life state. |
| 350 |
type: str |
| 351 |
storagePoolId: |
| 352 |
description: Storage Pool ID. |
| 353 |
type: str |
| 354 |
storagePoolName: |
| 355 |
description: Storage Pool name. |
| 356 |
type: str |
| 357 |
storageProps: |
| 358 |
description: Storage props. |
| 359 |
type: list |
| 360 |
temperatureState: |
| 361 |
description: Indicates temperature state. |
| 362 |
type: str |
| 363 |
vendorName: |
| 364 |
description: Indicates vendor name. |
| 365 |
type: str |
| 366 |
writeCacheActive: |
| 367 |
description: Indicates write cache active. |
| 368 |
type: bool |
| 369 |
sample: { |
| 370 |
"accelerationPoolId": null, |
| 371 |
"accelerationProps": null, |
| 372 |
"aggregatedState": "NeverFailed", |
| 373 |
"ataSecurityActive": false, |
| 374 |
"autoDetectMediaType": "SSD", |
| 375 |
"cacheLookAheadActive": false, |
| 376 |
"capacity": 0, |
| 377 |
"capacityLimitInKb": 365772800, |
| 378 |
"deviceCurrentPathName": "/dev/sdb", |
| 379 |
"deviceOriginalPathName": "/dev/sdb", |
| 380 |
"deviceState": "Normal", |
| 381 |
"deviceType": "Unknown", |
| 382 |
"errorState": "None", |
| 383 |
"externalAccelerationType": "None", |
| 384 |
"fglNvdimmMetadataAmortizationX100": 150, |
| 385 |
"fglNvdimmWriteCacheSize": 16, |
| 386 |
"firmwareVersion": null, |
| 387 |
"id": "b6efa59900000000", |
| 388 |
"ledSetting": "Off", |
| 389 |
"links": [ |
| 390 |
{ |
| 391 |
"href": "/api/instances/Device::b6efa59900000000", |
| 392 |
"rel": "self" |
| 393 |
}, |
| 394 |
{ |
| 395 |
"href": "/api/instances/Device::b6efa59900000000/relationships |
| 396 |
/Statistics", |
| 397 |
"rel": "/api/Device/relationship/Statistics" |
| 398 |
}, |
| 399 |
{ |
| 400 |
"href": "/api/instances/Sds::8f3bb0ce00000000", |
| 401 |
"rel": "/api/parent/relationship/sdsId" |
| 402 |
}, |
| 403 |
{ |
| 404 |
"href": "/api/instances/StoragePool::e0d8f6c900000000", |
| 405 |
"rel": "/api/parent/relationship/storagePoolId" |
| 406 |
}, |
| 407 |
{ |
| 408 |
"href": "/api/instances/SpSds::fedf6f2000000000", |
| 409 |
"rel": "/api/parent/relationship/spSdsId" |
| 410 |
} |
| 411 |
], |
| 412 |
"logicalSectorSizeInBytes": 0, |
| 413 |
"longSuccessfulIos": { |
| 414 |
"longWindow": null, |
| 415 |
"mediumWindow": null, |
| 416 |
"shortWindow": null |
| 417 |
}, |
| 418 |
"maxCapacityInKb": 365772800, |
| 419 |
"mediaFailing": false, |
| 420 |
"mediaType": "HDD", |
| 421 |
"modelName": null, |
| 422 |
"name": "device230", |
| 423 |
"persistentChecksumState": "Protected", |
| 424 |
"physicalSectorSizeInBytes": 0, |
| 425 |
"protectionDomainId": "9300c1f900000000", |
| 426 |
"protectionDomainName": "domain1", |
| 427 |
"raidControllerSerialNumber": null, |
| 428 |
"rfcacheErrorDeviceDoesNotExist": false, |
| 429 |
"rfcacheProps": null, |
| 430 |
"sdsId": "8f3bb0ce00000000", |
| 431 |
"sdsName": "node1", |
| 432 |
"serialNumber": null, |
| 433 |
"slotNumber": null, |
| 434 |
"spSdsId": "fedf6f2000000000", |
| 435 |
"ssdEndOfLifeState": "NeverFailed", |
| 436 |
"storagePoolId": "e0d8f6c900000000", |
| 437 |
"storagePoolName": "pool1", |
| 438 |
"storageProps": { |
| 439 |
"destFglAccDeviceId": null, |
| 440 |
"destFglNvdimmSizeMb": 0, |
| 441 |
"fglAccDeviceId": null, |
| 442 |
"fglNvdimmSizeMb": 0 |
| 443 |
}, |
| 444 |
"temperatureState": "NeverFailed", |
| 445 |
"vendorName": null, |
| 446 |
"writeCacheActive": false |
| 447 |
} |
| 448 |
''' |
| 449 |
|
| 450 |
from ansible.module_utils.basic import AnsibleModule |
| 451 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell\ |
| 452 |
import utils |
| 453 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.libraries.powerflex_base \ |
| 454 |
import powerflex_compatibility |
| 455 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.libraries.powerflex_base \ |
| 456 |
import PowerFlexBase |
| 457 |
|
| 458 |
LOG = utils.get_logger('device') |
| 459 |
|
| 460 |
|
| 461 |
@powerflex_compatibility(min_ver='3.6', max_ver='5.0', successor='device_v2') |
| 462 |
class PowerFlexDevice(PowerFlexBase): |
| 463 |
"""Class with device operations""" |
| 464 |
|
| 465 |
def __init__(self): |
| 466 |
""" Define all parameters required by this module""" |
| 467 |
argument_spec = get_powerflex_device_parameters() |
| 468 |
|
| 469 |
mut_ex_args = [['sds_name', 'sds_id'], |
| 470 |
['device_name', 'device_id'], |
| 471 |
['protection_domain_name', |
| 472 |
'protection_domain_id'], |
| 473 |
['storage_pool_name', 'storage_pool_id'], |
| 474 |
['acceleration_pool_name', 'acceleration_pool_id'], |
| 475 |
['acceleration_pool_id', 'storage_pool_id'], |
| 476 |
['acceleration_pool_name', 'storage_pool_name'], |
| 477 |
['device_id', 'sds_name'], |
| 478 |
['device_id', 'sds_id'], |
| 479 |
['device_id', 'current_pathname']] |
| 480 |
|
| 481 |
module_params = { |
| 482 |
'argument_spec': argument_spec, |
| 483 |
'supports_check_mode': False, |
| 484 |
'mutually_exclusive': mut_ex_args |
| 485 |
} |
| 486 |
|
| 487 |
super().__init__(AnsibleModule, module_params) |
| 488 |
super().check_module_compatibility() |
| 489 |
|
| 490 |
def get_device_details(self, current_pathname=None, sds_id=None, |
| 491 |
device_name=None, device_id=None): |
| 492 |
"""Get device details |
| 493 |
:param current_pathname: Device path name |
| 494 |
:type current_pathname: str |
| 495 |
:param sds_id: ID of the SDS |
| 496 |
:type sds_id: str |
| 497 |
:param device_name: Name of the device |
| 498 |
:type device_name: str |
| 499 |
:param device_id: ID of the device |
| 500 |
:type device_id: str |
| 501 |
:return: Details of device if it exist |
| 502 |
:rtype: dict |
| 503 |
""" |
| 504 |
|
| 505 |
try: |
| 506 |
if current_pathname and sds_id: |
| 507 |
device_details = self.powerflex_conn.device.get( |
| 508 |
filter_fields={'deviceCurrentPathName': current_pathname, |
| 509 |
'sdsId': sds_id}) |
| 510 |
elif device_name and sds_id: |
| 511 |
device_details = self.powerflex_conn.device.get( |
| 512 |
filter_fields={'name': device_name, |
| 513 |
'sdsId': sds_id}) |
| 514 |
else: |
| 515 |
device_details = self.powerflex_conn.device.get( |
| 516 |
filter_fields={'id': device_id}) |
| 517 |
|
| 518 |
if len(device_details) == 0: |
| 519 |
msg = "Device not found" |
| 520 |
LOG.info(msg) |
| 521 |
return None |
| 522 |
|
| 523 |
return device_details[0] |
| 524 |
|
| 525 |
except Exception as e: |
| 526 |
error_msg = "Failed to get the device with error '%s'" % str(e) |
| 527 |
LOG.error(error_msg) |
| 528 |
self.module.fail_json(msg=error_msg) |
| 529 |
|
| 530 |
def get_sds(self, sds_name=None, sds_id=None): |
| 531 |
"""Get SDS details |
| 532 |
:param sds_name: Name of the SDS |
| 533 |
:param sds_id: ID of the SDS |
| 534 |
:return: SDS details |
| 535 |
:rtype: dict |
| 536 |
""" |
| 537 |
name_or_id = sds_id if sds_id else sds_name |
| 538 |
try: |
| 539 |
sds_details = None |
| 540 |
if sds_id: |
| 541 |
sds_details = self.powerflex_conn.sds.get( |
| 542 |
filter_fields={'id': sds_id}) |
| 543 |
|
| 544 |
if sds_name: |
| 545 |
sds_details = self.powerflex_conn.sds.get( |
| 546 |
filter_fields={'name': sds_name}) |
| 547 |
|
| 548 |
if not sds_details: |
| 549 |
error_msg = "Unable to find the SDS with '%s'. Please " \ |
| 550 |
"enter a valid SDS name/id." % name_or_id |
| 551 |
LOG.error(error_msg) |
| 552 |
self.module.fail_json(msg=error_msg) |
| 553 |
|
| 554 |
return sds_details[0] |
| 555 |
|
| 556 |
except Exception as e: |
| 557 |
error_msg = "Failed to get the SDS '%s' with error '%s'" \ |
| 558 |
% (name_or_id, str(e)) |
| 559 |
LOG.error(error_msg) |
| 560 |
self.module.fail_json(msg=error_msg) |
| 561 |
|
| 562 |
def get_protection_domain(self, protection_domain_name=None, |
| 563 |
protection_domain_id=None): |
| 564 |
"""Get protection domain details |
| 565 |
:param protection_domain_name: Name of the protection domain |
| 566 |
:param protection_domain_id: ID of the protection domain |
| 567 |
:return: Protection domain details |
| 568 |
:rtype: dict |
| 569 |
""" |
| 570 |
name_or_id = protection_domain_id if protection_domain_id \ |
| 571 |
else protection_domain_name |
| 572 |
try: |
| 573 |
pd_details = None |
| 574 |
if protection_domain_id: |
| 575 |
pd_details = self.powerflex_conn.protection_domain.get( |
| 576 |
filter_fields={'id': protection_domain_id}) |
| 577 |
|
| 578 |
if protection_domain_name: |
| 579 |
pd_details = self.powerflex_conn.protection_domain.get( |
| 580 |
filter_fields={'name': protection_domain_name}) |
| 581 |
|
| 582 |
if not pd_details: |
| 583 |
error_msg = "Unable to find the protection domain with " \ |
| 584 |
"'%s'. Please enter a valid protection domain " \ |
| 585 |
"name/id." % name_or_id |
| 586 |
LOG.error(error_msg) |
| 587 |
self.module.fail_json(msg=error_msg) |
| 588 |
|
| 589 |
return pd_details[0] |
| 590 |
|
| 591 |
except Exception as e: |
| 592 |
error_msg = "Failed to get the protection domain '%s' with " \ |
| 593 |
"error '%s'" % (name_or_id, str(e)) |
| 594 |
LOG.error(error_msg) |
| 595 |
self.module.fail_json(msg=error_msg) |
| 596 |
|
| 597 |
def get_storage_pool(self, storage_pool_name=None, |
| 598 |
storage_pool_id=None, |
| 599 |
protection_domain_id=None): |
| 600 |
"""Get storage pool details |
| 601 |
:param storage_pool_name: Name of the storage pool |
| 602 |
:param storage_pool_id: ID of the storage pool |
| 603 |
:param protection_domain_id: ID of the protection domain |
| 604 |
:return: Storage pool details |
| 605 |
:rtype: dict |
| 606 |
""" |
| 607 |
name_or_id = storage_pool_id if storage_pool_id else storage_pool_name |
| 608 |
try: |
| 609 |
storage_pool_details = None |
| 610 |
if storage_pool_id: |
| 611 |
storage_pool_details = self.powerflex_conn.storage_pool.get( |
| 612 |
filter_fields={'id': storage_pool_id}) |
| 613 |
|
| 614 |
if storage_pool_name: |
| 615 |
storage_pool_details = self.powerflex_conn.storage_pool.get( |
| 616 |
filter_fields={'name': storage_pool_name, |
| 617 |
'protectionDomainId': protection_domain_id} |
| 618 |
) |
| 619 |
|
| 620 |
if not storage_pool_details: |
| 621 |
error_msg = "Unable to find the storage pool with " \ |
| 622 |
"'%s'. Please enter a valid storage pool " \ |
| 623 |
"name/id." % name_or_id |
| 624 |
LOG.error(error_msg) |
| 625 |
self.module.fail_json(msg=error_msg) |
| 626 |
|
| 627 |
return storage_pool_details[0] |
| 628 |
|
| 629 |
except Exception as e: |
| 630 |
error_msg = "Failed to get the storage_pool '%s' with " \ |
| 631 |
"error '%s'" % (name_or_id, str(e)) |
| 632 |
LOG.error(error_msg) |
| 633 |
self.module.fail_json(msg=error_msg) |
| 634 |
|
| 635 |
def get_acceleration_pool(self, acceleration_pool_name=None, |
| 636 |
acceleration_pool_id=None, |
| 637 |
protection_domain_id=None): |
| 638 |
"""Get acceleration pool details |
| 639 |
:param acceleration_pool_name: Name of the acceleration pool |
| 640 |
:param acceleration_pool_id: ID of the acceleration pool |
| 641 |
:param protection_domain_id: ID of the protection domain |
| 642 |
:return: Acceleration pool details |
| 643 |
:rtype: dict |
| 644 |
""" |
| 645 |
name_or_id = acceleration_pool_id \ |
| 646 |
if acceleration_pool_id else acceleration_pool_name |
| 647 |
try: |
| 648 |
acceleration_pool_details = None |
| 649 |
if acceleration_pool_id: |
| 650 |
acceleration_pool_details = self.powerflex_conn.\ |
| 651 |
acceleration_pool.get(filter_fields={ |
| 652 |
'id': acceleration_pool_id}) |
| 653 |
|
| 654 |
if acceleration_pool_name: |
| 655 |
acceleration_pool_details = self.powerflex_conn.\ |
| 656 |
acceleration_pool.get(filter_fields={ |
| 657 |
'name': acceleration_pool_name, |
| 658 |
'protectionDomainId': protection_domain_id}) |
| 659 |
|
| 660 |
if not acceleration_pool_details: |
| 661 |
error_msg = "Unable to find the acceleration pool with " \ |
| 662 |
"'%s'. Please enter a valid acceleration pool " \ |
| 663 |
"name/id." % name_or_id |
| 664 |
LOG.error(error_msg) |
| 665 |
self.module.fail_json(msg=error_msg) |
| 666 |
|
| 667 |
return acceleration_pool_details[0] |
| 668 |
|
| 669 |
except Exception as e: |
| 670 |
error_msg = "Failed to get the acceleration pool '%s' with " \ |
| 671 |
"error '%s'" % (name_or_id, str(e)) |
| 672 |
LOG.error(error_msg) |
| 673 |
self.module.fail_json(msg=error_msg) |
| 674 |
|
| 675 |
def add_device(self, device_name, current_pathname, sds_id, |
| 676 |
storage_pool_id, media_type, acceleration_pool_id, |
| 677 |
external_acceleration_type): |
| 678 |
"""Add device |
| 679 |
:param device_name: Device name |
| 680 |
:type device_name: str |
| 681 |
:param current_pathname: Current pathname of device |
| 682 |
:type current_pathname: str |
| 683 |
:param sds_id: SDS ID |
| 684 |
:type sds_id: str |
| 685 |
:param storage_pool_id: Storage Pool ID |
| 686 |
:type storage_pool_id: str |
| 687 |
:param media_type: Media type of device |
| 688 |
:type media_type: str |
| 689 |
:param acceleration_pool_id: Acceleration pool ID |
| 690 |
:type acceleration_pool_id: str |
| 691 |
:param external_acceleration_type: External acceleration type |
| 692 |
:type external_acceleration_type: str |
| 693 |
return: Boolean indicating if add device operation is successful |
| 694 |
""" |
| 695 |
try: |
| 696 |
if device_name is None or len(device_name.strip()) == 0: |
| 697 |
error_msg = "Please provide valid device_name value for " \ |
| 698 |
"adding a device." |
| 699 |
LOG.error(error_msg) |
| 700 |
self.module.fail_json(msg=error_msg) |
| 701 |
|
| 702 |
if current_pathname is None or len(current_pathname.strip()) == 0: |
| 703 |
error_msg = "Current pathname of device is a mandatory " \ |
| 704 |
"parameter for adding a device. Please enter a " \ |
| 705 |
"valid value." |
| 706 |
LOG.error(error_msg) |
| 707 |
self.module.fail_json(msg=error_msg) |
| 708 |
|
| 709 |
if sds_id is None or len(sds_id.strip()) == 0: |
| 710 |
error_msg = "Please provide valid sds_id value " \ |
| 711 |
"for adding a device." |
| 712 |
LOG.error(error_msg) |
| 713 |
self.module.fail_json(msg=error_msg) |
| 714 |
|
| 715 |
if storage_pool_id is None and acceleration_pool_id is None: |
| 716 |
error_msg = "Please provide either storage pool name/ID " \ |
| 717 |
"or acceleration pool name/ID for adding a " \ |
| 718 |
"device." |
| 719 |
LOG.error(error_msg) |
| 720 |
self.module.fail_json(msg=error_msg) |
| 721 |
|
| 722 |
add_params = ("current_pathname: %s, " |
| 723 |
"sds_id: %s, " |
| 724 |
"acceleration_pool_id: %s," |
| 725 |
"external_acceleration_type: %s," |
| 726 |
"media_type: %s," |
| 727 |
"device_name: %s," |
| 728 |
"storage_pool_id: %s," |
| 729 |
% (current_pathname, sds_id, |
| 730 |
acceleration_pool_id, |
| 731 |
external_acceleration_type, |
| 732 |
media_type, |
| 733 |
device_name, |
| 734 |
storage_pool_id)) |
| 735 |
LOG.info("Adding device with params: %s", add_params) |
| 736 |
|
| 737 |
self.powerflex_conn.device.create( |
| 738 |
current_pathname=current_pathname, |
| 739 |
sds_id=sds_id, acceleration_pool_id=acceleration_pool_id, |
| 740 |
external_acceleration_type=external_acceleration_type, |
| 741 |
media_type=media_type, name=device_name, |
| 742 |
storage_pool_id=storage_pool_id, |
| 743 |
force=self.module.params['force']) |
| 744 |
return True |
| 745 |
except Exception as e: |
| 746 |
error_msg = "Adding device %s operation failed with " \ |
| 747 |
"error '%s'" % (device_name, str(e)) |
| 748 |
LOG.error(error_msg) |
| 749 |
self.module.fail_json(msg=error_msg) |
| 750 |
|
| 751 |
def remove_device(self, device_id): |
| 752 |
"""Remove device |
| 753 |
:param device_id: Device ID |
| 754 |
:type device_id: str |
| 755 |
return: Boolean indicating if remove device operation is |
| 756 |
successful |
| 757 |
""" |
| 758 |
try: |
| 759 |
LOG.info("Device to be removed: %s", device_id) |
| 760 |
self.powerflex_conn.device.delete(device_id=device_id) |
| 761 |
return True |
| 762 |
except Exception as e: |
| 763 |
error_msg = "Remove device '%s' operation failed with " \ |
| 764 |
"error '%s'" % (device_id, str(e)) |
| 765 |
LOG.error(error_msg) |
| 766 |
self.module.fail_json(msg=error_msg) |
| 767 |
|
| 768 |
def validate_input_parameters(self, device_name=None, device_id=None, |
| 769 |
current_pathname=None, sds_name=None, |
| 770 |
sds_id=None): |
| 771 |
"""Validate the input parameters""" |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
self.validate_current_pathname(current_pathname, sds_name, sds_id) |
| 781 |
|
| 782 |
self.validate_device_name(device_name, sds_name, sds_id) |
| 783 |
|
| 784 |
self.validate_sds_name(device_name, current_pathname, sds_name) |
| 785 |
|
| 786 |
self.validate_sds_id(device_name, current_pathname, sds_id) |
| 787 |
|
| 788 |
if device_id is not None and len(device_id.strip()) == 0: |
| 789 |
error_msg = "Please provide valid device_id value to identify " \ |
| 790 |
"a device." |
| 791 |
LOG.error(error_msg) |
| 792 |
self.module.fail_json(msg=error_msg) |
| 793 |
|
| 794 |
if current_pathname is None and device_name is None \ |
| 795 |
and device_id is None: |
| 796 |
error_msg = "Please specify a valid parameter combination to " \ |
| 797 |
"identify a device." |
| 798 |
LOG.error(error_msg) |
| 799 |
self.module.fail_json(msg=error_msg) |
| 800 |
|
| 801 |
def validate_sds_id(self, device_name, current_pathname, sds_id): |
| 802 |
if sds_id: |
| 803 |
if (current_pathname is None |
| 804 |
or len(current_pathname.strip()) == 0) \ |
| 805 |
and (device_name is None |
| 806 |
or len(device_name.strip()) == 0): |
| 807 |
error_msg = "current_pathname or device_name is mandatory " \ |
| 808 |
"along with sds_id. Please enter a valid value." |
| 809 |
LOG.error(error_msg) |
| 810 |
self.module.fail_json(msg=error_msg) |
| 811 |
elif sds_id is not None and len(sds_id.strip()) == 0: |
| 812 |
error_msg = "Please enter a valid value for sds_id." |
| 813 |
LOG.error(error_msg) |
| 814 |
self.module.fail_json(msg=error_msg) |
| 815 |
|
| 816 |
def validate_sds_name(self, device_name, current_pathname, sds_name): |
| 817 |
if sds_name: |
| 818 |
if (current_pathname is None |
| 819 |
or len(current_pathname.strip()) == 0) \ |
| 820 |
and (device_name is None |
| 821 |
or len(device_name.strip()) == 0): |
| 822 |
error_msg = "current_pathname or device_name is mandatory " \ |
| 823 |
"along with sds_name. Please enter a valid value." |
| 824 |
LOG.error(error_msg) |
| 825 |
self.module.fail_json(msg=error_msg) |
| 826 |
elif sds_name is not None and len(sds_name.strip()) == 0: |
| 827 |
error_msg = "Please enter a valid value for sds_name." |
| 828 |
LOG.error(error_msg) |
| 829 |
self.module.fail_json(msg=error_msg) |
| 830 |
|
| 831 |
def validate_device_name(self, device_name, sds_name, sds_id): |
| 832 |
if device_name: |
| 833 |
if (sds_name is None or len(sds_name.strip()) == 0) \ |
| 834 |
and (sds_id is None or len(sds_id.strip()) == 0): |
| 835 |
error_msg = "sds_name or sds_id is mandatory along with " \ |
| 836 |
"device_name. Please enter a valid value." |
| 837 |
LOG.error(error_msg) |
| 838 |
self.module.fail_json(msg=error_msg) |
| 839 |
elif device_name is not None and len(device_name.strip()) == 0: |
| 840 |
error_msg = "Please enter a valid value for device_name." |
| 841 |
LOG.error(error_msg) |
| 842 |
self.module.fail_json(msg=error_msg) |
| 843 |
|
| 844 |
def validate_current_pathname(self, current_pathname, sds_name, sds_id): |
| 845 |
if current_pathname: |
| 846 |
if (sds_name is None or len(sds_name.strip()) == 0) \ |
| 847 |
and (sds_id is None or len(sds_id.strip()) == 0): |
| 848 |
error_msg = "sds_name or sds_id is mandatory along with " \ |
| 849 |
"current_pathname. Please enter a valid value." |
| 850 |
LOG.error(error_msg) |
| 851 |
self.module.fail_json(msg=error_msg) |
| 852 |
elif current_pathname is not None \ |
| 853 |
and len(current_pathname.strip()) == 0: |
| 854 |
error_msg = "Please enter a valid value for current_pathname." |
| 855 |
LOG.error(error_msg) |
| 856 |
self.module.fail_json(msg=error_msg) |
| 857 |
|
| 858 |
def validate_add_parameters(self, device_id=None, |
| 859 |
external_acceleration_type=None, |
| 860 |
storage_pool_id=None, |
| 861 |
storage_pool_name=None, |
| 862 |
acceleration_pool_id=None, |
| 863 |
acceleration_pool_name=None): |
| 864 |
"""Validate the add device parameters""" |
| 865 |
|
| 866 |
if device_id: |
| 867 |
error_msg = "Addition of device is allowed using " \ |
| 868 |
"device_name only, device_id given." |
| 869 |
LOG.info(error_msg) |
| 870 |
self.module.fail_json(msg=error_msg) |
| 871 |
if external_acceleration_type and storage_pool_id is None \ |
| 872 |
and storage_pool_name is None \ |
| 873 |
and acceleration_pool_id is None \ |
| 874 |
and acceleration_pool_name is None: |
| 875 |
error_msg = "Storage Pool ID/name or Acceleration Pool " \ |
| 876 |
"ID/name is mandatory along with " \ |
| 877 |
"external_acceleration_type." |
| 878 |
LOG.error(error_msg) |
| 879 |
self.module.fail_json(msg=error_msg) |
| 880 |
|
| 881 |
def perform_module_operation(self): |
| 882 |
""" |
| 883 |
Perform different actions on device based on parameters passed in |
| 884 |
the playbook |
| 885 |
""" |
| 886 |
current_pathname = self.module.params['current_pathname'] |
| 887 |
device_name = self.module.params['device_name'] |
| 888 |
device_id = self.module.params['device_id'] |
| 889 |
sds_name = self.module.params['sds_name'] |
| 890 |
sds_id = self.module.params['sds_id'] |
| 891 |
storage_pool_name = self.module.params['storage_pool_name'] |
| 892 |
storage_pool_id = self.module.params['storage_pool_id'] |
| 893 |
acceleration_pool_id = self.module.params['acceleration_pool_id'] |
| 894 |
acceleration_pool_name = self.module.params['acceleration_pool_name'] |
| 895 |
protection_domain_name = self.module.params['protection_domain_name'] |
| 896 |
protection_domain_id = self.module.params['protection_domain_id'] |
| 897 |
external_acceleration_type = self.module.params[ |
| 898 |
'external_acceleration_type'] |
| 899 |
media_type = self.module.params['media_type'] |
| 900 |
state = self.module.params['state'] |
| 901 |
|
| 902 |
|
| 903 |
result = dict( |
| 904 |
changed=False, |
| 905 |
device_details={} |
| 906 |
) |
| 907 |
|
| 908 |
|
| 909 |
self.validate_input_parameters(device_name, device_id, |
| 910 |
current_pathname, sds_name, sds_id) |
| 911 |
|
| 912 |
|
| 913 |
if sds_name: |
| 914 |
sds_id = self.get_sds_id(sds_name) |
| 915 |
|
| 916 |
|
| 917 |
device_details = self.get_device_details(current_pathname, |
| 918 |
sds_id, device_name, |
| 919 |
device_id) |
| 920 |
|
| 921 |
if device_details: |
| 922 |
device_id = device_details['id'] |
| 923 |
msg = "Fetched the device details %s" % (str(device_details)) |
| 924 |
LOG.info(msg) |
| 925 |
|
| 926 |
|
| 927 |
add_changed = False |
| 928 |
if state == 'present': |
| 929 |
if device_details: |
| 930 |
|
| 931 |
modify_dict = to_modify(device_details, media_type, |
| 932 |
external_acceleration_type) |
| 933 |
self.can_modify(modify_dict) |
| 934 |
else: |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
device_id, add_changed = self.create_device( |
| 939 |
current_pathname, device_name, device_id, sds_id, |
| 940 |
storage_pool_id, storage_pool_name, acceleration_pool_id, |
| 941 |
acceleration_pool_name, protection_domain_id, |
| 942 |
protection_domain_name, external_acceleration_type, |
| 943 |
media_type) |
| 944 |
|
| 945 |
device_details = self.show_output(device_id) |
| 946 |
result['device_details'] = device_details |
| 947 |
|
| 948 |
|
| 949 |
remove_changed = False |
| 950 |
if state == 'absent' and device_details: |
| 951 |
remove_changed = self.remove_device(device_id) |
| 952 |
|
| 953 |
|
| 954 |
result['changed'] = add_changed or remove_changed |
| 955 |
self.module.exit_json(**result) |
| 956 |
|
| 957 |
def create_device(self, current_pathname, device_name, device_id, sds_id, |
| 958 |
storage_pool_id, storage_pool_name, acceleration_pool_id, |
| 959 |
acceleration_pool_name, protection_domain_id, |
| 960 |
protection_domain_name, external_acceleration_type, |
| 961 |
media_type): |
| 962 |
if protection_domain_name \ |
| 963 |
and (storage_pool_name or acceleration_pool_name): |
| 964 |
protection_domain_id = self.get_protection_domain_id( |
| 965 |
protection_domain_name) |
| 966 |
|
| 967 |
|
| 968 |
if storage_pool_name: |
| 969 |
storage_pool_id = self.get_storage_pool_id( |
| 970 |
storage_pool_name, protection_domain_id) |
| 971 |
|
| 972 |
|
| 973 |
if acceleration_pool_name: |
| 974 |
acceleration_pool_id = self.get_acceleration_pool_id( |
| 975 |
acceleration_pool_name, protection_domain_id) |
| 976 |
|
| 977 |
|
| 978 |
self.validate_add_parameters(device_id, |
| 979 |
external_acceleration_type, |
| 980 |
storage_pool_id, |
| 981 |
storage_pool_name, |
| 982 |
acceleration_pool_id, |
| 983 |
acceleration_pool_name) |
| 984 |
add_changed = self.add_device(device_name, current_pathname, |
| 985 |
sds_id, storage_pool_id, media_type, |
| 986 |
acceleration_pool_id, |
| 987 |
external_acceleration_type) |
| 988 |
if add_changed: |
| 989 |
device_details = self.get_device_details( |
| 990 |
device_name=device_name, sds_id=sds_id) |
| 991 |
device_id = device_details['id'] |
| 992 |
msg = "Device created successfully, fetched device details " \ |
| 993 |
"%s" % (str(device_details)) |
| 994 |
LOG.info(msg) |
| 995 |
return device_id, add_changed |
| 996 |
|
| 997 |
def can_modify(self, modify_dict): |
| 998 |
if modify_dict: |
| 999 |
error_msg = "Modification of device attributes is " \ |
| 1000 |
"currently not supported by Ansible modules." |
| 1001 |
LOG.info(error_msg) |
| 1002 |
self.module.fail_json(msg=error_msg) |
| 1003 |
|
| 1004 |
def get_acceleration_pool_id(self, acceleration_pool_name, protection_domain_id): |
| 1005 |
if protection_domain_id: |
| 1006 |
acceleration_pool_details = self.get_acceleration_pool( |
| 1007 |
acceleration_pool_name=acceleration_pool_name, |
| 1008 |
protection_domain_id=protection_domain_id) |
| 1009 |
if acceleration_pool_details: |
| 1010 |
acceleration_pool_id = acceleration_pool_details['id'] |
| 1011 |
msg = "Fetched the acceleration pool details with id " \ |
| 1012 |
"'%s', name '%s'" % (acceleration_pool_id, |
| 1013 |
acceleration_pool_name) |
| 1014 |
LOG.info(msg) |
| 1015 |
else: |
| 1016 |
error_msg = "Protection domain name/id is required to " \ |
| 1017 |
"uniquely identify a acceleration pool, " \ |
| 1018 |
"only acceleration_pool_name is given." |
| 1019 |
LOG.info(error_msg) |
| 1020 |
self.module.fail_json(msg=error_msg) |
| 1021 |
return acceleration_pool_id |
| 1022 |
|
| 1023 |
def get_storage_pool_id(self, storage_pool_name, protection_domain_id): |
| 1024 |
if protection_domain_id: |
| 1025 |
storage_pool_details = self.get_storage_pool( |
| 1026 |
storage_pool_name=storage_pool_name, |
| 1027 |
protection_domain_id=protection_domain_id) |
| 1028 |
if storage_pool_details: |
| 1029 |
storage_pool_id = storage_pool_details['id'] |
| 1030 |
msg = "Fetched the storage pool details with id '%s', " \ |
| 1031 |
"name '%s'" % (storage_pool_id, storage_pool_name) |
| 1032 |
LOG.info(msg) |
| 1033 |
else: |
| 1034 |
error_msg = "Protection domain name/id is required to " \ |
| 1035 |
"uniquely identify a storage pool, only " \ |
| 1036 |
"storage_pool_name is given." |
| 1037 |
LOG.info(error_msg) |
| 1038 |
self.module.fail_json(msg=error_msg) |
| 1039 |
return storage_pool_id |
| 1040 |
|
| 1041 |
def get_protection_domain_id(self, protection_domain_name): |
| 1042 |
pd_details = self.get_protection_domain( |
| 1043 |
protection_domain_name) |
| 1044 |
if pd_details: |
| 1045 |
protection_domain_id = pd_details['id'] |
| 1046 |
msg = "Fetched the protection domain details with id " \ |
| 1047 |
"'%s', name '%s'" % (protection_domain_id, |
| 1048 |
protection_domain_name) |
| 1049 |
LOG.info(msg) |
| 1050 |
return protection_domain_id |
| 1051 |
|
| 1052 |
def get_sds_id(self, sds_name): |
| 1053 |
sds_details = self.get_sds(sds_name) |
| 1054 |
if sds_details: |
| 1055 |
sds_id = sds_details['id'] |
| 1056 |
msg = "Fetched the SDS details with id '%s', name '%s'" \ |
| 1057 |
% (sds_id, sds_name) |
| 1058 |
LOG.info(msg) |
| 1059 |
return sds_id |
| 1060 |
|
| 1061 |
def show_output(self, device_id): |
| 1062 |
"""Show device details |
| 1063 |
:param device_id: ID of the device |
| 1064 |
:type device_id: str |
| 1065 |
:return: Details of device |
| 1066 |
:rtype: dict |
| 1067 |
""" |
| 1068 |
|
| 1069 |
try: |
| 1070 |
device_details = self.powerflex_conn.device.get( |
| 1071 |
filter_fields={'id': device_id}) |
| 1072 |
|
| 1073 |
if len(device_details) == 0: |
| 1074 |
msg = "Device with identifier '%s' not found" % device_id |
| 1075 |
LOG.error(msg) |
| 1076 |
return None |
| 1077 |
|
| 1078 |
|
| 1079 |
if 'sdsId' in device_details[0] and device_details[0]['sdsId']: |
| 1080 |
sds_details = self.get_sds(sds_id=device_details[0]['sdsId']) |
| 1081 |
device_details[0]['sdsName'] = sds_details['name'] |
| 1082 |
|
| 1083 |
|
| 1084 |
if 'storagePoolId' in device_details[0] \ |
| 1085 |
and device_details[0]['storagePoolId']: |
| 1086 |
sp_details = self.get_storage_pool( |
| 1087 |
storage_pool_id=device_details[0]['storagePoolId']) |
| 1088 |
device_details[0]['storagePoolName'] = sp_details['name'] |
| 1089 |
pd_id = sp_details['protectionDomainId'] |
| 1090 |
device_details[0]['protectionDomainId'] = pd_id |
| 1091 |
pd_details = self.get_protection_domain( |
| 1092 |
protection_domain_id=pd_id) |
| 1093 |
device_details[0]['protectionDomainName'] = pd_details['name'] |
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
if 'accelerationPoolId' in device_details[0] \ |
| 1098 |
and device_details[0]['accelerationPoolId']: |
| 1099 |
ap_details = self.get_acceleration_pool( |
| 1100 |
acceleration_pool_id=device_details[0][ |
| 1101 |
'accelerationPoolId']) |
| 1102 |
device_details[0]['accelerationPoolName'] = ap_details['name'] |
| 1103 |
pd_id = ap_details['protectionDomainId'] |
| 1104 |
device_details[0]['protectionDomainId'] = pd_id |
| 1105 |
pd_details = self.get_protection_domain( |
| 1106 |
protection_domain_id=pd_id) |
| 1107 |
device_details[0]['protectionDomainName'] = pd_details['name'] |
| 1108 |
|
| 1109 |
return device_details[0] |
| 1110 |
|
| 1111 |
except Exception as e: |
| 1112 |
error_msg = "Failed to get the device '%s' with error '%s'"\ |
| 1113 |
% (device_id, str(e)) |
| 1114 |
LOG.error(error_msg) |
| 1115 |
self.module.fail_json(msg=error_msg) |
| 1116 |
|
| 1117 |
|
| 1118 |
def to_modify(device_details, media_type, external_acceleration_type): |
| 1119 |
"""Identify device attributes to be modified""" |
| 1120 |
|
| 1121 |
modify_dict = {} |
| 1122 |
|
| 1123 |
if media_type is not None and \ |
| 1124 |
device_details['mediaType'] != media_type: |
| 1125 |
modify_dict['mediaType'] = media_type |
| 1126 |
|
| 1127 |
if external_acceleration_type is not None and \ |
| 1128 |
device_details['externalAccelerationType'] \ |
| 1129 |
!= external_acceleration_type: |
| 1130 |
modify_dict['externalAccelerationType'] \ |
| 1131 |
= external_acceleration_type |
| 1132 |
|
| 1133 |
if len(modify_dict) != 0: |
| 1134 |
LOG.info("Attributes to be modified: %s", modify_dict) |
| 1135 |
return modify_dict |
| 1136 |
|
| 1137 |
|
| 1138 |
def get_powerflex_device_parameters(): |
| 1139 |
"""This method provide parameter required for the device module on |
| 1140 |
PowerFlex""" |
| 1141 |
return dict( |
| 1142 |
current_pathname=dict(), device_name=dict(), device_id=dict(), |
| 1143 |
sds_name=dict(), sds_id=dict(), storage_pool_name=dict(), |
| 1144 |
storage_pool_id=dict(), acceleration_pool_id=dict(), |
| 1145 |
acceleration_pool_name=dict(), protection_domain_name=dict(), |
| 1146 |
protection_domain_id=dict(), external_acceleration_type=dict( |
| 1147 |
choices=['Invalid', 'None', 'Read', 'Write', 'ReadAndWrite']), |
| 1148 |
media_type=dict(choices=['HDD', 'SSD', 'NVDIMM']), |
| 1149 |
state=dict(required=True, type='str', choices=['present', 'absent']), |
| 1150 |
force=dict(type='bool', default=False) |
| 1151 |
) |
| 1152 |
|
| 1153 |
|
| 1154 |
def main(): |
| 1155 |
""" Create PowerFlex device object and perform actions on it |
| 1156 |
based on user input from playbook""" |
| 1157 |
obj = PowerFlexDevice() |
| 1158 |
obj.perform_module_operation() |
| 1159 |
|
| 1160 |
|
| 1161 |
if __name__ == '__main__': |
| 1162 |
main() |