| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
# (c) 2021, NetApp, Inc |
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
|
| 6 |
''' |
| 7 |
na_cloudmanager_snapmirror |
| 8 |
''' |
| 9 |
|
| 10 |
from __future__ import absolute_import, division, print_function |
| 11 |
__metaclass__ = type |
| 12 |
|
| 13 |
DOCUMENTATION = ''' |
| 14 |
|
| 15 |
module: na_cloudmanager_snapmirror |
| 16 |
short_description: NetApp Cloud Manager SnapMirror |
| 17 |
extends_documentation_fragment: |
| 18 |
- netapp.cloudmanager.netapp.cloudmanager |
| 19 |
version_added: '21.6.0' |
| 20 |
author: NetApp Ansible Team (@carchi8py) <[email protected]> |
| 21 |
|
| 22 |
description: |
| 23 |
- Create or Delete SnapMirror relationship on Cloud Manager. |
| 24 |
|
| 25 |
options: |
| 26 |
|
| 27 |
state: |
| 28 |
description: |
| 29 |
- Whether the specified snapmirror relationship should exist or not. |
| 30 |
choices: ['present', 'absent'] |
| 31 |
default: 'present' |
| 32 |
type: str |
| 33 |
|
| 34 |
source_working_environment_name: |
| 35 |
description: |
| 36 |
- The working environment name of the source volume. |
| 37 |
type: str |
| 38 |
|
| 39 |
destination_working_environment_name: |
| 40 |
description: |
| 41 |
- The working environment name of the destination volume. |
| 42 |
type: str |
| 43 |
|
| 44 |
source_working_environment_id: |
| 45 |
description: |
| 46 |
- The public ID of the working environment of the source volume. |
| 47 |
type: str |
| 48 |
|
| 49 |
destination_working_environment_id: |
| 50 |
description: |
| 51 |
- The public ID of the working environment of the destination volume. |
| 52 |
type: str |
| 53 |
|
| 54 |
destination_aggregate_name: |
| 55 |
description: |
| 56 |
- The aggregate in which the volume will be created. |
| 57 |
- If not provided, Cloud Manager chooses the best aggregate for you. |
| 58 |
type: str |
| 59 |
|
| 60 |
policy: |
| 61 |
description: |
| 62 |
- The SnapMirror policy name. |
| 63 |
type: str |
| 64 |
default: 'MirrorAllSnapshots' |
| 65 |
|
| 66 |
max_transfer_rate: |
| 67 |
description: |
| 68 |
- Maximum transfer rate limit KB/s. |
| 69 |
- Use 0 for no limit, otherwise use number between 1024 and 2,147,482,624. |
| 70 |
type: int |
| 71 |
default: 100000 |
| 72 |
|
| 73 |
source_svm_name: |
| 74 |
description: |
| 75 |
- The name of the source SVM. |
| 76 |
- The default SVM name is used, if a name is not provided. |
| 77 |
type: str |
| 78 |
|
| 79 |
destination_svm_name: |
| 80 |
description: |
| 81 |
- The name of the destination SVM. |
| 82 |
- The default SVM name is used, if a name is not provided. |
| 83 |
type: str |
| 84 |
|
| 85 |
source_volume_name: |
| 86 |
description: |
| 87 |
- The name of the source volume. |
| 88 |
required: true |
| 89 |
type: str |
| 90 |
|
| 91 |
destination_volume_name: |
| 92 |
description: |
| 93 |
- The name of the destination volume to be created for snapmirror relationship. |
| 94 |
required: true |
| 95 |
type: str |
| 96 |
|
| 97 |
schedule: |
| 98 |
description: |
| 99 |
- The name of the Schedule. |
| 100 |
type: str |
| 101 |
default: '1hour' |
| 102 |
|
| 103 |
provider_volume_type: |
| 104 |
description: |
| 105 |
- The underlying cloud provider volume type. |
| 106 |
- For AWS ['gp3', 'gp2', 'io1', 'st1', 'sc1']. |
| 107 |
- For Azure ['Premium_LRS','Standard_LRS','StandardSSD_LRS']. |
| 108 |
- For GCP ['pd-balanced','pd-ssd','pd-standard']. |
| 109 |
type: str |
| 110 |
|
| 111 |
capacity_tier: |
| 112 |
description: |
| 113 |
- The volume capacity tier for tiering cold data to object storage. |
| 114 |
- The default values for each cloud provider are as follows, Amazon 'S3', Azure 'Blob', GCP 'cloudStorage'. |
| 115 |
- If NONE, the capacity tier will not be set on volume creation. |
| 116 |
type: str |
| 117 |
choices: ['S3', 'Blob', 'cloudStorage', 'NONE'] |
| 118 |
|
| 119 |
tenant_id: |
| 120 |
description: |
| 121 |
- The NetApp account ID that the Connector will be associated with. To be used only when using FSx. |
| 122 |
type: str |
| 123 |
version_added: 21.14.0 |
| 124 |
|
| 125 |
client_id: |
| 126 |
description: |
| 127 |
- The connector ID of the Cloud Manager Connector. |
| 128 |
required: true |
| 129 |
type: str |
| 130 |
|
| 131 |
notes: |
| 132 |
- Support check_mode. |
| 133 |
''' |
| 134 |
|
| 135 |
EXAMPLES = ''' |
| 136 |
- name: Create snapmirror with working_environment_name |
| 137 |
netapp.cloudmanager.na_cloudmanager_snapmirror: |
| 138 |
state: present |
| 139 |
source_working_environment_name: source |
| 140 |
destination_working_environment_name: dest |
| 141 |
source_volume_name: source |
| 142 |
destination_volume_name: source_copy |
| 143 |
policy: MirrorAllSnapshots |
| 144 |
schedule: 5min |
| 145 |
max_transfer_rate: 102400 |
| 146 |
client_id: client_id |
| 147 |
refresh_token: refresh_token |
| 148 |
|
| 149 |
- name: Delete snapmirror |
| 150 |
netapp.cloudmanager.na_cloudmanager_snapmirror: |
| 151 |
state: absent |
| 152 |
source_working_environment_name: source |
| 153 |
destination_working_environment_name: dest |
| 154 |
source_volume_name: source |
| 155 |
destination_volume_name: source_copy |
| 156 |
client_id: client_id |
| 157 |
refresh_token: refresh_token |
| 158 |
''' |
| 159 |
|
| 160 |
RETURN = r''' # ''' |
| 161 |
|
| 162 |
|
| 163 |
from ansible.module_utils.basic import AnsibleModule |
| 164 |
import ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp as netapp_utils |
| 165 |
from ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp_module import NetAppModule |
| 166 |
from ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp import CloudManagerRestAPI |
| 167 |
|
| 168 |
|
| 169 |
PROVIDER_TO_CAPACITY_TIER = {'amazon': 'S3', 'azure': 'Blob', 'gcp': 'cloudStorage'} |
| 170 |
|
| 171 |
|
| 172 |
class NetAppCloudmanagerSnapmirror: |
| 173 |
|
| 174 |
def __init__(self): |
| 175 |
""" |
| 176 |
Parse arguments, setup state variables, |
| 177 |
check parameters and ensure request module is installed |
| 178 |
""" |
| 179 |
self.argument_spec = netapp_utils.cloudmanager_host_argument_spec() |
| 180 |
self.argument_spec.update(dict( |
| 181 |
state=dict(required=False, choices=['present', 'absent'], default='present'), |
| 182 |
source_working_environment_id=dict(required=False, type='str'), |
| 183 |
destination_working_environment_id=dict(required=False, type='str'), |
| 184 |
source_working_environment_name=dict(required=False, type='str'), |
| 185 |
destination_working_environment_name=dict(required=False, type='str'), |
| 186 |
destination_aggregate_name=dict(required=False, type='str'), |
| 187 |
policy=dict(required=False, type='str', default='MirrorAllSnapshots'), |
| 188 |
max_transfer_rate=dict(required=False, type='int', default='100000'), |
| 189 |
schedule=dict(required=False, type='str', default='1hour'), |
| 190 |
source_svm_name=dict(required=False, type='str'), |
| 191 |
destination_svm_name=dict(required=False, type='str'), |
| 192 |
source_volume_name=dict(required=True, type='str'), |
| 193 |
destination_volume_name=dict(required=True, type='str'), |
| 194 |
capacity_tier=dict(required=False, type='str', choices=['NONE', 'S3', 'Blob', 'cloudStorage']), |
| 195 |
provider_volume_type=dict(required=False, type='str'), |
| 196 |
tenant_id=dict(required=False, type='str'), |
| 197 |
client_id=dict(required=True, type='str'), |
| 198 |
)) |
| 199 |
self.module = AnsibleModule( |
| 200 |
argument_spec=self.argument_spec, |
| 201 |
required_one_of=[ |
| 202 |
['source_working_environment_id', 'source_working_environment_name'], |
| 203 |
['refresh_token', 'sa_client_id'], |
| 204 |
], |
| 205 |
required_together=(['source_working_environment_id', 'destination_working_environment_id'], |
| 206 |
['source_working_environment_name', 'destination_working_environment_name'], |
| 207 |
['sa_client_id', 'sa_secret_key'], |
| 208 |
), |
| 209 |
supports_check_mode=True |
| 210 |
) |
| 211 |
|
| 212 |
self.na_helper = NetAppModule() |
| 213 |
# set up state variables |
| 214 |
self.parameters = self.na_helper.set_parameters(self.module.params) |
| 215 |
|
| 216 |
self.rest_api = CloudManagerRestAPI(self.module) |
| 217 |
self.rest_api.url += self.rest_api.environment_data['CLOUD_MANAGER_HOST'] |
| 218 |
self.rest_api.api_root_path = None |
| 219 |
self.headers = { |
| 220 |
'X-Agent-Id': self.rest_api.format_client_id(self.parameters['client_id']) |
| 221 |
} |
| 222 |
if self.rest_api.simulator: |
| 223 |
self.headers.update({'x-simulator': 'true'}) |
| 224 |
|
| 225 |
def get_snapmirror(self): |
| 226 |
source_we_info, dest_we_info, err = self.na_helper.get_working_environment_detail_for_snapmirror(self.rest_api, self.headers) |
| 227 |
if err is not None: |
| 228 |
self.module.fail_json(changed=False, msg=err) |
| 229 |
|
| 230 |
get_url = '/occm/api/replication/status/%s' % source_we_info['publicId'] |
| 231 |
snapmirror_info, err, dummy = self.rest_api.send_request("GET", get_url, None, header=self.headers) |
| 232 |
if err is not None: |
| 233 |
self.module.fail_json(changed=False, msg='Error getting snapmirror relationship %s: %s.' % (err, snapmirror_info)) |
| 234 |
sm_found = False |
| 235 |
snapmirror = None |
| 236 |
for sm in snapmirror_info: |
| 237 |
if sm['destination']['volumeName'] == self.parameters['destination_volume_name']: |
| 238 |
sm_found = True |
| 239 |
snapmirror = sm |
| 240 |
break |
| 241 |
|
| 242 |
if not sm_found: |
| 243 |
return None |
| 244 |
result = { |
| 245 |
'source_working_environment_id': source_we_info['publicId'], |
| 246 |
'destination_svm_name': snapmirror['destination']['svmName'], |
| 247 |
'destination_working_environment_id': dest_we_info['publicId'], |
| 248 |
} |
| 249 |
if not dest_we_info['publicId'].startswith('fs-'): |
| 250 |
result['cloud_provider_name'] = dest_we_info['cloudProviderName'] |
| 251 |
return result |
| 252 |
|
| 253 |
def create_snapmirror(self): |
| 254 |
snapmirror_build_data = {} |
| 255 |
replication_request = {} |
| 256 |
replication_volume = {} |
| 257 |
source_we_info, dest_we_info, err = self.na_helper.get_working_environment_detail_for_snapmirror(self.rest_api, self.headers) |
| 258 |
if err is not None: |
| 259 |
self.module.fail_json(changed=False, msg=err) |
| 260 |
if self.parameters.get('capacity_tier') is not None: |
| 261 |
if self.parameters['capacity_tier'] == 'NONE': |
| 262 |
self.parameters.pop('capacity_tier') |
| 263 |
else: |
| 264 |
if dest_we_info.get('cloudProviderName'): |
| 265 |
self.parameters['capacity_tier'] = PROVIDER_TO_CAPACITY_TIER[dest_we_info['cloudProviderName'].lower()] |
| 266 |
|
| 267 |
interclusterlifs_info = self.get_interclusterlifs(source_we_info['publicId'], dest_we_info['publicId']) |
| 268 |
|
| 269 |
if source_we_info['workingEnvironmentType'] != 'ON_PREM': |
| 270 |
source_volumes = self.get_volumes(source_we_info, self.parameters['source_volume_name']) |
| 271 |
else: |
| 272 |
source_volumes = self.get_volumes_on_prem(source_we_info, self.parameters['source_volume_name']) |
| 273 |
|
| 274 |
if len(source_volumes) == 0: |
| 275 |
self.module.fail_json(changed=False, msg='source volume not found') |
| 276 |
|
| 277 |
vol_found = False |
| 278 |
vol_dest_quote = {} |
| 279 |
source_volume_resp = {} |
| 280 |
for vol in source_volumes: |
| 281 |
if vol['name'] == self.parameters['source_volume_name']: |
| 282 |
vol_found = True |
| 283 |
vol_dest_quote = vol |
| 284 |
source_volume_resp = vol |
| 285 |
if self.parameters.get('source_svm_name') is not None and vol['svmName'] != self.parameters['source_svm_name']: |
| 286 |
vol_found = False |
| 287 |
if vol_found: |
| 288 |
break |
| 289 |
|
| 290 |
if not vol_found: |
| 291 |
self.module.fail_json(changed=False, msg='source volume not found') |
| 292 |
|
| 293 |
if self.parameters.get('source_svm_name') is None: |
| 294 |
self.parameters['source_svm_name'] = source_volume_resp['svmName'] |
| 295 |
|
| 296 |
if self.parameters.get('destination_svm_name') is None: |
| 297 |
if dest_we_info.get('svmName') is not None: |
| 298 |
self.parameters['destination_svm_name'] = dest_we_info['svmName'] |
| 299 |
else: |
| 300 |
self.parameters['destination_working_environment_name'] = dest_we_info['name'] |
| 301 |
dest_working_env_detail, err = self.na_helper.get_working_environment_details_by_name(self.rest_api, |
| 302 |
self.headers, |
| 303 |
self.parameters['destination_working_environment_name']) |
| 304 |
if err: |
| 305 |
self.module.fail_json(changed=False, msg='Error getting destination info %s: %s.' % (err, dest_working_env_detail)) |
| 306 |
self.parameters['destination_svm_name'] = dest_working_env_detail['svmName'] |
| 307 |
|
| 308 |
if dest_we_info.get('workingEnvironmentType') and dest_we_info['workingEnvironmentType'] != 'ON_PREM'\ |
| 309 |
and not dest_we_info['publicId'].startswith('fs-'): |
| 310 |
quote = self.build_quote_request(source_we_info, dest_we_info, vol_dest_quote) |
| 311 |
quote_response = self.quote_volume(quote) |
| 312 |
replication_volume['numOfDisksApprovedToAdd'] = int(quote_response['numOfDisks']) |
| 313 |
if 'iops' in quote: |
| 314 |
replication_volume['iops'] = quote['iops'] |
| 315 |
if 'throughput' in quote: |
| 316 |
replication_volume['throughput'] = quote['throughput'] |
| 317 |
if self.parameters.get('destination_aggregate_name') is not None: |
| 318 |
replication_volume['advancedMode'] = True |
| 319 |
else: |
| 320 |
replication_volume['advancedMode'] = False |
| 321 |
replication_volume['destinationAggregateName'] = quote_response['aggregateName'] |
| 322 |
if self.parameters.get('provider_volume_type') is None: |
| 323 |
replication_volume['destinationProviderVolumeType'] = source_volume_resp['providerVolumeType'] |
| 324 |
|
| 325 |
if self.parameters.get('capacity_tier') is not None: |
| 326 |
replication_volume['destinationCapacityTier'] = self.parameters['capacity_tier'] |
| 327 |
replication_request['sourceWorkingEnvironmentId'] = source_we_info['publicId'] |
| 328 |
if dest_we_info['publicId'].startswith('fs-'): |
| 329 |
replication_request['destinationFsxId'] = dest_we_info['publicId'] |
| 330 |
else: |
| 331 |
replication_request['destinationWorkingEnvironmentId'] = dest_we_info['publicId'] |
| 332 |
replication_volume['sourceVolumeName'] = self.parameters['source_volume_name'] |
| 333 |
replication_volume['destinationVolumeName'] = self.parameters['destination_volume_name'] |
| 334 |
replication_request['policyName'] = self.parameters['policy'] |
| 335 |
replication_request['scheduleName'] = self.parameters['schedule'] |
| 336 |
replication_request['maxTransferRate'] = self.parameters['max_transfer_rate'] |
| 337 |
replication_volume['sourceSvmName'] = source_volume_resp['svmName'] |
| 338 |
replication_volume['destinationSvmName'] = self.parameters['destination_svm_name'] |
| 339 |
replication_request['sourceInterclusterLifIps'] = [interclusterlifs_info['interClusterLifs'][0]['address']] |
| 340 |
replication_request['destinationInterclusterLifIps'] = [interclusterlifs_info['peerInterClusterLifs'][0]['address']] |
| 341 |
|
| 342 |
snapmirror_build_data['replicationRequest'] = replication_request |
| 343 |
snapmirror_build_data['replicationVolume'] = replication_volume |
| 344 |
|
| 345 |
if dest_we_info['publicId'].startswith('fs-'): |
| 346 |
api = '/occm/api/replication/fsx' |
| 347 |
elif dest_we_info['workingEnvironmentType'] != 'ON_PREM': |
| 348 |
api = '/occm/api/replication/vsa' |
| 349 |
else: |
| 350 |
api = '/occm/api/replication/onprem' |
| 351 |
|
| 352 |
response, err, on_cloud_request_id = self.rest_api.send_request("POST", api, None, snapmirror_build_data, header=self.headers) |
| 353 |
if err is not None: |
| 354 |
self.module.fail_json(changed=False, msg='Error creating snapmirror relationship %s: %s.' % (err, response)) |
| 355 |
wait_on_completion_api_url = '/occm/api/audit/activeTask/%s' % (str(on_cloud_request_id)) |
| 356 |
err = self.rest_api.wait_on_completion(wait_on_completion_api_url, "snapmirror", "create", 20, 5) |
| 357 |
if err is not None: |
| 358 |
self.module.fail_json(changed=False, msg=err) |
| 359 |
|
| 360 |
def get_volumes(self, working_environment_detail, name): |
| 361 |
self.na_helper.set_api_root_path(working_environment_detail, self.rest_api) |
| 362 |
response, err, dummy = self.rest_api.send_request("GET", "%s/volumes?workingEnvironmentId=%s&name=%s" % ( |
| 363 |
self.rest_api.api_root_path, working_environment_detail['publicId'], name), None, header=self.headers) |
| 364 |
if err is not None: |
| 365 |
self.module.fail_json(changed=False, msg='Error getting volume %s: %s.' % (err, response)) |
| 366 |
return response |
| 367 |
|
| 368 |
def quote_volume(self, quote): |
| 369 |
response, err, on_cloud_request_id = self.rest_api.send_request("POST", '%s/volumes/quote' % |
| 370 |
self.rest_api.api_root_path, None, quote, header=self.headers) |
| 371 |
if err is not None: |
| 372 |
self.module.fail_json(changed=False, msg='Error quoting destination volume %s: %s.' % (err, response)) |
| 373 |
wait_on_completion_api_url = '/occm/api/audit/activeTask/%s' % (str(on_cloud_request_id)) |
| 374 |
err = self.rest_api.wait_on_completion(wait_on_completion_api_url, "volume", "quote", 20, 5) |
| 375 |
if err is not None: |
| 376 |
self.module.fail_json(changed=False, msg=err) |
| 377 |
return response |
| 378 |
|
| 379 |
def get_volumes_on_prem(self, working_environment_detail, name): |
| 380 |
response, err, dummy = self.rest_api.send_request("GET", "/occm/api/onprem/volumes?workingEnvironmentId=%s&name=%s" % |
| 381 |
(working_environment_detail['publicId'], name), None, header=self.headers) |
| 382 |
if err is not None: |
| 383 |
self.module.fail_json(changed=False, msg='Error getting volume on prem %s: %s.' % (err, response)) |
| 384 |
return response |
| 385 |
|
| 386 |
def get_aggregate_detail(self, working_environment_detail, aggregate_name): |
| 387 |
if working_environment_detail['workingEnvironmentType'] == 'ON_PREM': |
| 388 |
api = "/occm/api/onprem/aggregates?workingEnvironmentId=%s" % working_environment_detail['publicId'] |
| 389 |
else: |
| 390 |
self.na_helper.set_api_root_path(working_environment_detail, self.rest_api) |
| 391 |
api_root_path = self.rest_api.api_root_path |
| 392 |
if working_environment_detail['cloudProviderName'] != "Amazon": |
| 393 |
api = '%s/aggregates/%s' |
| 394 |
else: |
| 395 |
api = '%s/aggregates?workingEnvironmentId=%s' |
| 396 |
api = api % (api_root_path, working_environment_detail['publicId']) |
| 397 |
response, error, dummy = self.rest_api.get(api, header=self.headers) |
| 398 |
if error: |
| 399 |
self.module.fail_json(msg="Error: Failed to get aggregate list: %s" % str(error)) |
| 400 |
for aggr in response: |
| 401 |
if aggr['name'] == aggregate_name: |
| 402 |
return aggr |
| 403 |
return None |
| 404 |
|
| 405 |
def build_quote_request(self, source_we_info, dest_we_info, vol_dest_quote): |
| 406 |
quote = dict() |
| 407 |
quote['size'] = {'size': vol_dest_quote['size']['size'], 'unit': vol_dest_quote['size']['unit']} |
| 408 |
quote['name'] = self.parameters['destination_volume_name'] |
| 409 |
quote['snapshotPolicyName'] = vol_dest_quote['snapshotPolicy'] |
| 410 |
quote['enableDeduplication'] = vol_dest_quote['deduplication'] |
| 411 |
quote['enableThinProvisioning'] = vol_dest_quote['thinProvisioning'] |
| 412 |
quote['enableCompression'] = vol_dest_quote['compression'] |
| 413 |
quote['verifyNameUniqueness'] = True |
| 414 |
quote['replicationFlow'] = True |
| 415 |
|
| 416 |
# Use source working environment to get physical properties info of volumes |
| 417 |
aggregate = self.get_aggregate_detail(source_we_info, vol_dest_quote['aggregateName']) |
| 418 |
if aggregate is None: |
| 419 |
self.module.fail_json(changed=False, msg='Error getting aggregate on source volume') |
| 420 |
# All the volumes in one aggregate have the same physical properties |
| 421 |
if source_we_info['workingEnvironmentType'] != 'ON_PREM': |
| 422 |
if aggregate['providerVolumes'][0]['diskType'] == 'gp3' or aggregate['providerVolumes'][0]['diskType'] == 'io1'\ |
| 423 |
or aggregate['providerVolumes'][0]['diskType'] == 'io2': |
| 424 |
quote['iops'] = aggregate['providerVolumes'][0]['iops'] |
| 425 |
if aggregate['providerVolumes'][0]['diskType'] == 'gp3': |
| 426 |
quote['throughput'] = aggregate['providerVolumes'][0]['throughput'] |
| 427 |
quote['workingEnvironmentId'] = dest_we_info['publicId'] |
| 428 |
quote['svmName'] = self.parameters['destination_svm_name'] |
| 429 |
if self.parameters.get('capacity_tier') is not None: |
| 430 |
quote['capacityTier'] = self.parameters['capacity_tier'] |
| 431 |
|
| 432 |
if self.parameters.get('provider_volume_type') is None: |
| 433 |
quote['providerVolumeType'] = vol_dest_quote['providerVolumeType'] |
| 434 |
else: |
| 435 |
quote['providerVolumeType'] = self.parameters['provider_volume_type'] |
| 436 |
|
| 437 |
return quote |
| 438 |
|
| 439 |
def delete_snapmirror(self, sm_detail): |
| 440 |
api_delete = '/occm/api/replication/%s/%s/%s' %\ |
| 441 |
(sm_detail['destination_working_environment_id'], sm_detail['destination_svm_name'], self.parameters['destination_volume_name']) |
| 442 |
dummy, err, dummy_second = self.rest_api.send_request("DELETE", api_delete, None, None, header=self.headers) |
| 443 |
if err is not None: |
| 444 |
self.module.fail_json(changed=False, msg='Error deleting snapmirror relationship %s: %s.' % (err, dummy)) |
| 445 |
|
| 446 |
def get_interclusterlifs(self, source_we_id, dest_we_id): |
| 447 |
api_get = '/occm/api/replication/intercluster-lifs?peerWorkingEnvironmentId=%s&workingEnvironmentId=%s' % (dest_we_id, source_we_id) |
| 448 |
response, err, dummy_second = self.rest_api.send_request("GET", api_get, None, header=self.headers) |
| 449 |
if err is not None: |
| 450 |
self.module.fail_json(changed=False, msg='Error getting interclusterlifs %s: %s.' % (err, response)) |
| 451 |
return response |
| 452 |
|
| 453 |
def apply(self): |
| 454 |
current = self.get_snapmirror() |
| 455 |
cd_action = self.na_helper.get_cd_action(current, self.parameters) |
| 456 |
if self.na_helper.changed and not self.module.check_mode: |
| 457 |
if cd_action == 'create': |
| 458 |
self.create_snapmirror() |
| 459 |
elif cd_action == 'delete': |
| 460 |
self.delete_snapmirror(current) |
| 461 |
self.module.exit_json(changed=self.na_helper.changed) |
| 462 |
|
| 463 |
|
| 464 |
def main(): |
| 465 |
'''Main Function''' |
| 466 |
volume = NetAppCloudmanagerSnapmirror() |
| 467 |
volume.apply() |
| 468 |
|
| 469 |
|
| 470 |
if __name__ == '__main__': |
| 471 |
main() |