| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: ibm_svc_mdiskgrp |
| 14 |
short_description: This module manages pools on IBM Storage Virtualize family systems |
| 15 |
description: |
| 16 |
- Ansible interface to manage 'mkmdiskgrp' and 'rmmdiskgrp' pool commands. |
| 17 |
version_added: "1.0.0" |
| 18 |
options: |
| 19 |
name: |
| 20 |
description: |
| 21 |
- Specifies the name to assign to the new pool. |
| 22 |
required: true |
| 23 |
type: str |
| 24 |
state: |
| 25 |
description: |
| 26 |
- Creates (C(present)) or removes (C(absent)) an MDisk group. |
| 27 |
choices: [ absent, present ] |
| 28 |
required: true |
| 29 |
type: str |
| 30 |
clustername: |
| 31 |
description: |
| 32 |
- The hostname or management IP of the Storage Virtualize system. |
| 33 |
type: str |
| 34 |
required: true |
| 35 |
domain: |
| 36 |
description: |
| 37 |
- Domain for the Storage Virtualize system. |
| 38 |
- Valid when hostname is used for the parameter I(clustername). |
| 39 |
type: str |
| 40 |
username: |
| 41 |
description: |
| 42 |
- REST API username for the Storage Virtualize system. |
| 43 |
- The parameters I(username) and I(password) are required if not using I(token) to authenticate a user. |
| 44 |
type: str |
| 45 |
password: |
| 46 |
description: |
| 47 |
- REST API password for the Storage Virtualize system. |
| 48 |
- The parameters I(username) and I(password) are required if not using I(token) to authenticate a user. |
| 49 |
type: str |
| 50 |
token: |
| 51 |
description: |
| 52 |
- The authentication token to verify a user on the Storage Virtualize system. |
| 53 |
- To generate a token, use the M(ibm.storage_virtualize.ibm_svc_auth) module. |
| 54 |
type: str |
| 55 |
version_added: '1.5.0' |
| 56 |
datareduction: |
| 57 |
description: |
| 58 |
- Defines use of data reduction pools (DRPs) on the MDisk group. |
| 59 |
- Applies when I(state=present), to create a pool. |
| 60 |
type: str |
| 61 |
default: 'no' |
| 62 |
choices: ['yes', 'no'] |
| 63 |
easytier: |
| 64 |
description: |
| 65 |
- Defines use of easytier with the MDisk group. |
| 66 |
- Applies when I(state=present), to create a pool. |
| 67 |
type: str |
| 68 |
default: 'off' |
| 69 |
choices: ['on', 'off', 'auto'] |
| 70 |
encrypt: |
| 71 |
description: |
| 72 |
- Defines use of encryption with the MDisk group. |
| 73 |
- Applies when I(state=present), to create a pool. |
| 74 |
type: str |
| 75 |
default: 'no' |
| 76 |
choices: ['yes', 'no'] |
| 77 |
ext: |
| 78 |
description: |
| 79 |
- Specifies the size of the extents for this group in MB. |
| 80 |
- Applies when I(state=present), to create a pool. |
| 81 |
type: int |
| 82 |
log_path: |
| 83 |
description: |
| 84 |
- Path of debug log file. |
| 85 |
type: str |
| 86 |
validate_certs: |
| 87 |
description: |
| 88 |
- Validates certification. |
| 89 |
default: false |
| 90 |
type: bool |
| 91 |
parentmdiskgrp: |
| 92 |
description: |
| 93 |
- Parentmdiskgrp for subpool. |
| 94 |
- Applies when I(state=present), to create a pool. |
| 95 |
type: str |
| 96 |
safeguarded: |
| 97 |
description: |
| 98 |
- Specify to create a safeguarded child pool. |
| 99 |
- Applicable only during child pool creation. |
| 100 |
type: bool |
| 101 |
version_added: 1.8.0 |
| 102 |
noquota: |
| 103 |
description: |
| 104 |
- Specify to create a data reduction child pool. |
| 105 |
- I(noquota) and I(size) parameters are mutually exclusive. |
| 106 |
- I(noquota) parameter must be used with I(datareduction) set to yes to create a data reduction child pool. |
| 107 |
- I(noquota) parameter must be used with I(parentmdiskgrp) in a parent data reduction storage pool. |
| 108 |
type: bool |
| 109 |
version_added: 1.8.0 |
| 110 |
unit: |
| 111 |
description: |
| 112 |
- Unit for subpool. |
| 113 |
- Applies when I(state=present), to create a pool. |
| 114 |
type: str |
| 115 |
provisioningpolicy: |
| 116 |
description: |
| 117 |
- Specify the name of the provisioning policy to map it with the pool. |
| 118 |
- Applies, when I(state=present). |
| 119 |
type: str |
| 120 |
version_added: 1.10.0 |
| 121 |
noprovisioningpolicy: |
| 122 |
description: |
| 123 |
- Specify to unmap provisioning policy from the pool. |
| 124 |
- Applies, when I(state=present) to modify an existing pool. |
| 125 |
type: bool |
| 126 |
version_added: 1.10.0 |
| 127 |
replicationpoollinkuid: |
| 128 |
description: |
| 129 |
- Specifies the replication pool unique identifier which should be same as the pool that present in the replication server. |
| 130 |
- Applies, when I(state=present). |
| 131 |
- Supported in SV build 8.5.2.1 or later. |
| 132 |
type: str |
| 133 |
version_added: 1.10.0 |
| 134 |
resetreplicationpoollinkuid: |
| 135 |
description: |
| 136 |
- If set, any links between this pool on local system and pools on remote systems will be removed. |
| 137 |
- Applies, when I(state=present) to modify an existing pool. |
| 138 |
- Supported in SV build 8.5.2.1 or later. |
| 139 |
type: bool |
| 140 |
version_added: 1.10.0 |
| 141 |
replication_partner_clusterid: |
| 142 |
description: |
| 143 |
- Specifies the id or name of the partner cluster for setting replication pool linked systems mask. |
| 144 |
- Applies, when I(state=present). |
| 145 |
- Supported in SV build 8.5.2.1 or later. |
| 146 |
type: str |
| 147 |
version_added: 1.10.0 |
| 148 |
size: |
| 149 |
description: |
| 150 |
- Specifies the child pool capacity. The value must be |
| 151 |
a numeric value (and an integer multiple of the extent size). |
| 152 |
- Applies when I(state=present), to create a pool. |
| 153 |
type: int |
| 154 |
warning: |
| 155 |
description: |
| 156 |
- If specified, generates a warning when the used disk capacity in the storage pool first exceeds the specified threshold. |
| 157 |
- The default value is 80. To disable it, specify the value as 0. |
| 158 |
- Applies when I(state=present) while creating the pool. |
| 159 |
type: int |
| 160 |
version_added: '1.12.0' |
| 161 |
ownershipgroup: |
| 162 |
description: |
| 163 |
- Specifies the name of the ownershipgroup to map it with the pool. |
| 164 |
- Applies when I(state=present). |
| 165 |
type: str |
| 166 |
version_added: '1.12.0' |
| 167 |
noownershipgroup: |
| 168 |
description: |
| 169 |
- Specifies to unmap ownershipgroup from the pool. |
| 170 |
- Applies when I(state=present) to modify an existing pool. |
| 171 |
type: bool |
| 172 |
version_added: '1.12.0' |
| 173 |
vdiskprotectionenabled: |
| 174 |
description: |
| 175 |
- Specifies whether volume protection is enabled for this storage pool. The default value is 'yes'. |
| 176 |
- Applies when I(state=present). |
| 177 |
type: str |
| 178 |
choices: ['yes', 'no'] |
| 179 |
version_added: '1.12.0' |
| 180 |
etfcmoverallocationmax: |
| 181 |
description: |
| 182 |
- Specifies the maximum over allocation which Easy Tier can migrate onto FlashCore Module arrays, when the array is used as the top |
| 183 |
tier in a multitier pool. The value acts as a multiplier of the physically available space. |
| 184 |
- The allowed values are a percentage in the range of 100% (default) to 400% or off. Setting the value to off disables this feature. |
| 185 |
- Applies when I(state=present). |
| 186 |
type: str |
| 187 |
version_added: '1.12.0' |
| 188 |
old_name: |
| 189 |
description: |
| 190 |
- Specifies the old name of an existing pool. |
| 191 |
- Applies when I(state=present), to rename the existing pool. |
| 192 |
type: str |
| 193 |
version_added: '1.12.0' |
| 194 |
|
| 195 |
author: |
| 196 |
- Peng Wang(@wangpww) |
| 197 |
- Sanjaikumaar M (@sanjaikumaar) |
| 198 |
- Lavanya C R(@lavanya) |
| 199 |
- Sandip Gulab Rajbanshi (@Sandip-Rajbanshi) |
| 200 |
notes: |
| 201 |
- This module supports C(check_mode). |
| 202 |
''' |
| 203 |
EXAMPLES = ''' |
| 204 |
- name: Create mdisk group |
| 205 |
ibm.storage_virtualize.ibm_svc_mdiskgrp: |
| 206 |
clustername: "{{ clustername }}" |
| 207 |
domain: "{{ domain }}" |
| 208 |
username: "{{ username }}" |
| 209 |
password: "{{ password }}" |
| 210 |
name: pool1 |
| 211 |
provisioningpolicy: pp0 |
| 212 |
replicationpoollinkuid: '000000000000000' |
| 213 |
etfcmoverallocationmax: 120 |
| 214 |
state: present |
| 215 |
datareduction: 'no' |
| 216 |
easytier: auto |
| 217 |
encrypt: 'no' |
| 218 |
ext: 1024 |
| 219 |
- name: Create childpool with ownershipgroup |
| 220 |
ibm.storage_virtualize.ibm_svc_mdiskgrp: |
| 221 |
clustername: "{{ clustername }}" |
| 222 |
domain: "{{ domain }}" |
| 223 |
username: "{{ username }}" |
| 224 |
password: "{{ password }}" |
| 225 |
name: childpool0 |
| 226 |
ownershipgroup: owner0 |
| 227 |
parentmdiskgrp: pool1 |
| 228 |
state: present |
| 229 |
datareduction: 'no' |
| 230 |
easytier: auto |
| 231 |
encrypt: 'no' |
| 232 |
ext: 1024 |
| 233 |
- name: Create a safeguarded backup location |
| 234 |
ibm.storage_virtualize.ibm_svc_mdiskgrp: |
| 235 |
clustername: "{{ clustername }}" |
| 236 |
token: "{{ results.token }}" |
| 237 |
log_path: "{{ log_path }}" |
| 238 |
parentmdiskgrp: Pool1 |
| 239 |
name: Pool1child1 |
| 240 |
datareduction: 'yes' |
| 241 |
safeguarded: 'True' |
| 242 |
ext: 1024 |
| 243 |
noquota: 'True' |
| 244 |
state: present |
| 245 |
- name: Delete mdisk group |
| 246 |
ibm.storage_virtualize.ibm_svc_mdiskgrp: |
| 247 |
clustername: "{{ clustername }}" |
| 248 |
domain: "{{ domain }}" |
| 249 |
username: "{{ username }}" |
| 250 |
password: "{{ password }}" |
| 251 |
name: pool1 |
| 252 |
state: absent |
| 253 |
- name: Delete a safeguarded backup location |
| 254 |
ibm.storage_virtualize.ibm_svc_mdiskgrp: |
| 255 |
clustername: "{{ clustername }}" |
| 256 |
token: "{{ results.token }}" |
| 257 |
log_path: "{{ log_path }}" |
| 258 |
parentmdiskgrp: Pool1 |
| 259 |
name: Pool1child1 |
| 260 |
state: absent |
| 261 |
''' |
| 262 |
|
| 263 |
RETURN = '''#''' |
| 264 |
|
| 265 |
from traceback import format_exc |
| 266 |
from ansible.module_utils.basic import AnsibleModule |
| 267 |
from ansible.module_utils._text import to_native |
| 268 |
from ansible_collections.ibm.storage_virtualize.plugins.module_utils.ibm_svc_utils import IBMSVCRestApi, svc_argument_spec, get_logger |
| 269 |
|
| 270 |
|
| 271 |
class IBMSVCmdiskgrp(object): |
| 272 |
def __init__(self): |
| 273 |
argument_spec = svc_argument_spec() |
| 274 |
|
| 275 |
argument_spec.update( |
| 276 |
dict( |
| 277 |
name=dict(type='str', required=True), |
| 278 |
state=dict(type='str', required=True, choices=['absent', |
| 279 |
'present']), |
| 280 |
datareduction=dict(type='str', default='no', choices=['yes', |
| 281 |
'no']), |
| 282 |
easytier=dict(type='str', default='off', choices=['on', 'off', |
| 283 |
'auto']), |
| 284 |
encrypt=dict(type='str', default='no', choices=['yes', 'no']), |
| 285 |
ext=dict(type='int'), |
| 286 |
parentmdiskgrp=dict(type='str'), |
| 287 |
safeguarded=dict(type='bool'), |
| 288 |
noquota=dict(type='bool'), |
| 289 |
size=dict(type='int'), |
| 290 |
unit=dict(type='str'), |
| 291 |
provisioningpolicy=dict(type='str'), |
| 292 |
noprovisioningpolicy=dict(type='bool'), |
| 293 |
replicationpoollinkuid=dict(type='str'), |
| 294 |
resetreplicationpoollinkuid=dict(type='bool'), |
| 295 |
replication_partner_clusterid=dict(type='str'), |
| 296 |
warning=dict(type='int'), |
| 297 |
vdiskprotectionenabled=dict(type='str', choices=['yes', 'no']), |
| 298 |
ownershipgroup=dict(type='str'), |
| 299 |
noownershipgroup=dict(type='bool'), |
| 300 |
etfcmoverallocationmax=dict(type='str'), |
| 301 |
old_name=dict(type='str') |
| 302 |
) |
| 303 |
) |
| 304 |
|
| 305 |
mutually_exclusive = [] |
| 306 |
self.module = AnsibleModule(argument_spec=argument_spec, |
| 307 |
mutually_exclusive=mutually_exclusive, |
| 308 |
supports_check_mode=True) |
| 309 |
|
| 310 |
|
| 311 |
log_path = self.module.params['log_path'] |
| 312 |
log = get_logger(self.__class__.__name__, log_path) |
| 313 |
self.log = log.info |
| 314 |
|
| 315 |
|
| 316 |
self.name = self.module.params['name'] |
| 317 |
self.state = self.module.params['state'] |
| 318 |
|
| 319 |
|
| 320 |
self.datareduction = self.module.params.get('datareduction', None) |
| 321 |
self.easytier = self.module.params.get('easytier', None) |
| 322 |
self.encrypt = self.module.params.get('encrypt', None) |
| 323 |
self.ext = self.module.params.get('ext', None) |
| 324 |
self.safeguarded = self.module.params.get('safeguarded', False) |
| 325 |
self.noquota = self.module.params.get('noquota', False) |
| 326 |
self.provisioningpolicy = self.module.params.get('provisioningpolicy', '') |
| 327 |
self.noprovisioningpolicy = self.module.params.get('noprovisioningpolicy', False) |
| 328 |
self.replicationpoollinkuid = self.module.params.get('replicationpoollinkuid', '') |
| 329 |
self.resetreplicationpoollinkuid = self.module.params.get('resetreplicationpoollinkuid', False) |
| 330 |
self.replication_partner_clusterid = self.module.params.get('replication_partner_clusterid', '') |
| 331 |
self.warning = self.module.params.get('warning', None) |
| 332 |
self.ownershipgroup = self.module.params.get('ownershipgroup', '') |
| 333 |
self.noownershipgroup = self.module.params.get('noownershipgroup', False) |
| 334 |
self.vdiskprotectionenabled = self.module.params.get('vdiskprotectionenabled', None) |
| 335 |
self.etfcmoverallocationmax = self.module.params.get('etfcmoverallocationmax', '') |
| 336 |
self.old_name = self.module.params.get('old_name', '') |
| 337 |
|
| 338 |
self.parentmdiskgrp = self.module.params.get('parentmdiskgrp', None) |
| 339 |
self.size = self.module.params.get('size', None) |
| 340 |
self.unit = self.module.params.get('unit', None) |
| 341 |
|
| 342 |
|
| 343 |
self.changed = False |
| 344 |
|
| 345 |
|
| 346 |
self.partnership_index = None |
| 347 |
|
| 348 |
self.basic_checks() |
| 349 |
|
| 350 |
self.restapi = IBMSVCRestApi( |
| 351 |
module=self.module, |
| 352 |
clustername=self.module.params['clustername'], |
| 353 |
domain=self.module.params['domain'], |
| 354 |
username=self.module.params['username'], |
| 355 |
password=self.module.params['password'], |
| 356 |
validate_certs=self.module.params['validate_certs'], |
| 357 |
log_path=log_path, |
| 358 |
token=self.module.params['token'] |
| 359 |
) |
| 360 |
|
| 361 |
def basic_checks(self): |
| 362 |
if not self.name: |
| 363 |
self.module.fail_json(msg='Missing mandatory parameter: name') |
| 364 |
|
| 365 |
if self.state == 'present': |
| 366 |
if self.replicationpoollinkuid and self.resetreplicationpoollinkuid: |
| 367 |
self.module.fail_json( |
| 368 |
msg='Mutually exclusive parameters: replicationpoollinkuid, resetreplicationpoollinkuid' |
| 369 |
) |
| 370 |
|
| 371 |
elif self.state == 'absent': |
| 372 |
invalids = ('datareduction', 'easytier', 'encrypt', 'ext', 'parentmdiskgrp', |
| 373 |
'safeguarded', 'noquota', 'unit', 'provisioningpolicy', 'noprovisioningpolicy', |
| 374 |
'replicationpoollinkuid', 'resetreplicationpoollinkuid', 'replication_partner_clusterid', 'size', 'warning', |
| 375 |
'ownershipgroup', 'noownershipgroup', 'vdiskprotectionenabled', 'etfcmoverallocationmax', 'old_name') |
| 376 |
invalid_exists = ', '.join((var for var in invalids if getattr(self, var) not in {'', None, 'no', 'off'})) |
| 377 |
|
| 378 |
if invalid_exists: |
| 379 |
self.module.fail_json( |
| 380 |
msg='state=absent but following parameters have been passed: {0}'.format(invalid_exists)) |
| 381 |
|
| 382 |
def create_validation(self): |
| 383 |
invalids = ('noownershipgroup', 'old_name') |
| 384 |
invalid_exists = ', '.join((var for var in invalids if getattr(self, var) not in {'', None})) |
| 385 |
|
| 386 |
if invalid_exists: |
| 387 |
self.module.fail_json( |
| 388 |
msg='Following parameters not supported during creation: {0}'.format(invalid_exists) |
| 389 |
) |
| 390 |
|
| 391 |
def mdiskgrp_rename(self, mdiskgrp_data): |
| 392 |
msg = None |
| 393 |
old_mdiskgrp_data = self.mdiskgrp_exists(self.old_name) |
| 394 |
if not old_mdiskgrp_data and not mdiskgrp_data: |
| 395 |
self.module.fail_json(msg="mdiskgrp [{0}] does not exists.".format(self.old_name)) |
| 396 |
elif old_mdiskgrp_data and mdiskgrp_data: |
| 397 |
self.module.fail_json(msg="mdiskgrp with name [{0}] already exists.".format(self.name)) |
| 398 |
elif not old_mdiskgrp_data and mdiskgrp_data: |
| 399 |
msg = "mdiskgrp [{0}] already renamed.".format(self.name) |
| 400 |
elif old_mdiskgrp_data and not mdiskgrp_data: |
| 401 |
if (self.old_name == self.parentmdiskgrp): |
| 402 |
self.module.fail_json("Old name shouldn't be same as parentmdiskgrp while renaming childmdiskgrp") |
| 403 |
|
| 404 |
if self.module.check_mode: |
| 405 |
self.changed = True |
| 406 |
return |
| 407 |
self.restapi.svc_run_command('chmdiskgrp', {'name': self.name}, [self.old_name]) |
| 408 |
self.changed = True |
| 409 |
msg = "mdiskgrp [{0}] has been successfully rename to [{1}].".format(self.old_name, self.name) |
| 410 |
return msg |
| 411 |
|
| 412 |
def mdiskgrp_exists(self, name): |
| 413 |
merged_result = {} |
| 414 |
data = self.restapi.svc_obj_info( |
| 415 |
cmd='lsmdiskgrp', |
| 416 |
cmdopts=None, |
| 417 |
cmdargs=['-gui', name] |
| 418 |
) |
| 419 |
|
| 420 |
if isinstance(data, list): |
| 421 |
for d in data: |
| 422 |
merged_result.update(d) |
| 423 |
else: |
| 424 |
merged_result = data |
| 425 |
|
| 426 |
return merged_result |
| 427 |
|
| 428 |
def mdiskgrp_create(self): |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
self.create_validation() |
| 435 |
|
| 436 |
self.log("creating mdisk group '%s'", self.name) |
| 437 |
|
| 438 |
|
| 439 |
cmd = 'mkmdiskgrp' |
| 440 |
cmdopts = {} |
| 441 |
|
| 442 |
if not self.ext: |
| 443 |
self.module.fail_json(msg="You must pass the ext to the module.") |
| 444 |
|
| 445 |
if self.noquota or self.safeguarded: |
| 446 |
if not self.parentmdiskgrp: |
| 447 |
self.module.fail_json(msg='Required parameter missing: parentmdiskgrp') |
| 448 |
|
| 449 |
if self.module.check_mode: |
| 450 |
self.changed = True |
| 451 |
return |
| 452 |
|
| 453 |
if self.parentmdiskgrp: |
| 454 |
cmdopts['parentmdiskgrp'] = self.parentmdiskgrp |
| 455 |
if self.size: |
| 456 |
cmdopts['size'] = self.size |
| 457 |
if self.unit: |
| 458 |
cmdopts['unit'] = self.unit |
| 459 |
if self.safeguarded: |
| 460 |
cmdopts['safeguarded'] = self.safeguarded |
| 461 |
if self.noquota: |
| 462 |
cmdopts['noquota'] = self.noquota |
| 463 |
else: |
| 464 |
if self.easytier: |
| 465 |
cmdopts['easytier'] = self.easytier |
| 466 |
if self.encrypt: |
| 467 |
cmdopts['encrypt'] = self.encrypt |
| 468 |
if self.ext: |
| 469 |
cmdopts['ext'] = str(self.ext) |
| 470 |
if self.provisioningpolicy: |
| 471 |
cmdopts['provisioningpolicy'] = self.provisioningpolicy |
| 472 |
if self.datareduction: |
| 473 |
cmdopts['datareduction'] = self.datareduction |
| 474 |
if self.replicationpoollinkuid: |
| 475 |
cmdopts['replicationpoollinkuid'] = self.replicationpoollinkuid |
| 476 |
if self.ownershipgroup: |
| 477 |
cmdopts['ownershipgroup'] = self.ownershipgroup |
| 478 |
if self.vdiskprotectionenabled: |
| 479 |
cmdopts['vdiskprotectionenabled'] = self.vdiskprotectionenabled |
| 480 |
if self.etfcmoverallocationmax: |
| 481 |
if "%" not in self.etfcmoverallocationmax and self.etfcmoverallocationmax != "off": |
| 482 |
cmdopts['etfcmoverallocationmax'] = self.etfcmoverallocationmax + "%" |
| 483 |
else: |
| 484 |
cmdopts['etfcmoverallocationmax'] = self.etfcmoverallocationmax |
| 485 |
|
| 486 |
if self.warning: |
| 487 |
cmdopts['warning'] = str(self.warning) + "%" |
| 488 |
cmdopts['name'] = self.name |
| 489 |
self.log("creating mdisk group command %s opts %s", cmd, cmdopts) |
| 490 |
|
| 491 |
|
| 492 |
self.restapi.svc_run_command(cmd, cmdopts, cmdargs=None) |
| 493 |
|
| 494 |
if self.replication_partner_clusterid: |
| 495 |
self.check_partnership() |
| 496 |
self.set_bit_mask() |
| 497 |
|
| 498 |
def check_partnership(self): |
| 499 |
if self.replication_partner_clusterid: |
| 500 |
merged_result = {} |
| 501 |
result = self.restapi.svc_obj_info( |
| 502 |
cmd='lspartnership', |
| 503 |
cmdopts=None, |
| 504 |
cmdargs=['-gui', self.replication_partner_clusterid] |
| 505 |
) |
| 506 |
|
| 507 |
if isinstance(result, list): |
| 508 |
for res in result: |
| 509 |
merged_result = res |
| 510 |
else: |
| 511 |
merged_result = result |
| 512 |
|
| 513 |
if merged_result: |
| 514 |
self.partnership_index = merged_result.get('partnership_index') |
| 515 |
else: |
| 516 |
self.module.fail_json( |
| 517 |
msg='Partnership does not exist for the given cluster ({0}).'.format(self.replication_partner_clusterid) |
| 518 |
) |
| 519 |
|
| 520 |
def set_bit_mask(self, systemmask=None): |
| 521 |
cmd = 'chmdiskgrp' |
| 522 |
bit_mask = '1'.ljust(int(self.partnership_index) + 1, '0') if not systemmask else systemmask |
| 523 |
cmdopts = {'replicationpoollinkedsystemsmask': bit_mask} |
| 524 |
self.restapi.svc_run_command(cmd, cmdopts, cmdargs=[self.name]) |
| 525 |
|
| 526 |
def mdiskgrp_delete(self): |
| 527 |
if self.module.check_mode: |
| 528 |
self.changed = True |
| 529 |
return |
| 530 |
|
| 531 |
self.log("deleting mdiskgrp '%s'", self.name) |
| 532 |
|
| 533 |
cmd = 'rmmdiskgrp' |
| 534 |
cmdopts = None |
| 535 |
cmdargs = [self.name] |
| 536 |
|
| 537 |
self.restapi.svc_run_command(cmd, cmdopts, cmdargs) |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
def mdiskgrp_update(self, modify): |
| 543 |
|
| 544 |
self.log("updating mdiskgrp '%s'", self.name) |
| 545 |
|
| 546 |
systemmask = None |
| 547 |
cmd = 'chmdiskgrp' |
| 548 |
|
| 549 |
if 'replicationpoollinkedsystemsmask' in modify: |
| 550 |
systemmask = modify.pop('replicationpoollinkedsystemsmask') |
| 551 |
|
| 552 |
if modify: |
| 553 |
cmdopts = modify |
| 554 |
self.restapi.svc_run_command(cmd, cmdopts, cmdargs=[self.name]) |
| 555 |
|
| 556 |
if systemmask in modify: |
| 557 |
self.set_bit_mask(systemmask) |
| 558 |
|
| 559 |
self.changed = True |
| 560 |
|
| 561 |
def mdiskgrp_probe(self, data): |
| 562 |
props = {} |
| 563 |
|
| 564 |
field_mappings = ( |
| 565 |
('noprovisioningpolicy', not bool(data.get('provisioning_policy_name', ''))), |
| 566 |
('provisioningpolicy', data.get('provisioning_policy_name', '')), |
| 567 |
('noownershipgroup', not bool(data.get('owner_name', ''))), |
| 568 |
('ownershipgroup', data.get('owner_name', '')), |
| 569 |
('vdiskprotectionenabled', data.get('vdisk_protection_enabled', '')), |
| 570 |
('replicationpoollinkuid', data.get('replication_pool_link_uid', '')), |
| 571 |
) |
| 572 |
|
| 573 |
for field, existing_value in field_mappings: |
| 574 |
new_value = getattr(self, field, None) |
| 575 |
if new_value is not None and new_value != existing_value: |
| 576 |
props[field] = getattr(self, field, None) |
| 577 |
|
| 578 |
if self.resetreplicationpoollinkuid: |
| 579 |
props['resetreplicationpoollinkuid'] = self.resetreplicationpoollinkuid |
| 580 |
if self.warning and self.warning != data.get('warning', ''): |
| 581 |
props['warning'] = str(self.warning) + "%" |
| 582 |
if self.etfcmoverallocationmax: |
| 583 |
if "%" not in self.etfcmoverallocationmax and self.etfcmoverallocationmax != "off": |
| 584 |
self.etfcmoverallocationmax += "%" |
| 585 |
if self.etfcmoverallocationmax != data.get('easy_tier_fcm_over_allocation_max', ''): |
| 586 |
props['etfcmoverallocationmax'] = self.etfcmoverallocationmax |
| 587 |
if self.replication_partner_clusterid: |
| 588 |
self.check_partnership() |
| 589 |
bit_mask = '1'.ljust(int(self.partnership_index) + 1, '0') |
| 590 |
if bit_mask.zfill(64) != data.get('replication_pool_linked_systems_mask', ''): |
| 591 |
props['replicationpoollinkedsystemsmask'] = bit_mask |
| 592 |
|
| 593 |
self.log("mdiskgrp_probe props='%s'", props) |
| 594 |
return props |
| 595 |
|
| 596 |
def apply(self): |
| 597 |
changed = False |
| 598 |
msg = None |
| 599 |
modify = [] |
| 600 |
|
| 601 |
mdiskgrp_data = self.mdiskgrp_exists(self.name) |
| 602 |
if self.state == 'present' and self.old_name: |
| 603 |
msg = self.mdiskgrp_rename(mdiskgrp_data) |
| 604 |
elif self.state == 'absent' and self.old_name: |
| 605 |
self.module.fail_json(msg="Rename functionality is not supported when 'state' is absent.") |
| 606 |
|
| 607 |
else: |
| 608 |
if mdiskgrp_data: |
| 609 |
if self.state == 'absent': |
| 610 |
self.log("CHANGED: mdisk group exists, " |
| 611 |
"but requested state is 'absent'") |
| 612 |
changed = True |
| 613 |
elif self.state == 'present': |
| 614 |
|
| 615 |
modify = self.mdiskgrp_probe(mdiskgrp_data) |
| 616 |
if modify: |
| 617 |
changed = True |
| 618 |
else: |
| 619 |
if self.state == 'present': |
| 620 |
self.log("CHANGED: mdisk group does not exist, " |
| 621 |
"but requested state is 'present'") |
| 622 |
changed = True |
| 623 |
if changed: |
| 624 |
if self.state == 'present': |
| 625 |
if not mdiskgrp_data: |
| 626 |
self.mdiskgrp_create() |
| 627 |
self.changed = True |
| 628 |
msg = "Mdisk group [%s] has been created." % self.name |
| 629 |
else: |
| 630 |
|
| 631 |
self.mdiskgrp_update(modify) |
| 632 |
msg = "Mdisk group [%s] has been modified." % self.name |
| 633 |
|
| 634 |
elif self.state == 'absent': |
| 635 |
self.mdiskgrp_delete() |
| 636 |
self.changed = True |
| 637 |
msg = "mdiskgrp [%s] has been deleted." % self.name |
| 638 |
|
| 639 |
else: |
| 640 |
self.log("exiting with no changes") |
| 641 |
if self.state == 'absent': |
| 642 |
msg = "Mdisk group [%s] did not exist." % self.name |
| 643 |
else: |
| 644 |
msg = "Mdisk group [%s] already exists. No modifications done" % self.name |
| 645 |
|
| 646 |
if self.module.check_mode: |
| 647 |
msg = 'skipping changes due to check mode' |
| 648 |
|
| 649 |
self.module.exit_json(msg=msg, changed=self.changed) |
| 650 |
|
| 651 |
|
| 652 |
def main(): |
| 653 |
v = IBMSVCmdiskgrp() |
| 654 |
try: |
| 655 |
v.apply() |
| 656 |
except Exception as e: |
| 657 |
v.log("Exception in apply(): \n%s", format_exc()) |
| 658 |
v.module.fail_json(msg="Module failed. Error [%s]." % to_native(e)) |
| 659 |
|
| 660 |
|
| 661 |
if __name__ == '__main__': |
| 662 |
main() |