Debian Codegraph @

ansible_collections/netapp/cloudmanager/plugins/modules/na_cloudmanager_cvo_gcp.py

raw
1 #!/usr/bin/python
2
3 # (c) 2022, 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_cvo_gcp
8 '''
9
10 from __future__ import absolute_import, division, print_function
11 __metaclass__ = type
12
13 DOCUMENTATION = '''
14
15 module: na_cloudmanager_cvo_gcp
16 short_description: NetApp Cloud Manager CVO for GCP
17 extends_documentation_fragment:
18 - netapp.cloudmanager.netapp.cloudmanager
19 version_added: '21.4.0'
20 author: NetApp Ansible Team (@carchi8py) <[email protected]>
21
22 description:
23 - Create, delete, or manage Cloud Manager CVO for GCP.
24
25 options:
26
27 backup_volumes_to_cbs:
28 description:
29 - Automatically backup all volumes to cloud.
30 default: false
31 type: bool
32
33 capacity_tier:
34 description:
35 - Whether to enable data tiering for the first data aggregate.
36 choices: ['cloudStorage']
37 type: str
38
39 client_id:
40 required: true
41 description:
42 - The connector ID of the Cloud Manager Connector.
43 - You can find the ID from the Connector tab on U(https://cloudmanager.netapp.com).
44 type: str
45
46 data_encryption_type:
47 description:
48 - Type of encryption to use for this working environment.
49 choices: ['GCP']
50 type: str
51
52 gcp_encryption_parameters:
53 description:
54 - The GCP encryption parameters.
55 type: str
56 version_added: 21.10.0
57
58 enable_compliance:
59 description:
60 - Enable the Cloud Compliance service on the working environment.
61 default: false
62 type: bool
63
64 firewall_rule:
65 description:
66 - Firewall name for a single node cluster.
67 type: str
68
69 gcp_labels:
70 description:
71 - Optionally provide up to four key-value pairs with which to all GCP entities created by Cloud Manager.
72 type: list
73 elements: dict
74 suboptions:
75 label_key:
76 description: The key of the label.
77 type: str
78 label_value:
79 description: The label value.
80 type: str
81
82 gcp_service_account:
83 description:
84 - The gcp_service_account email in order to enable tiering of cold data to Google Cloud Storage.
85 required: true
86 type: str
87
88 gcp_volume_size:
89 description:
90 - GCP volume size.
91 type: int
92
93 gcp_volume_size_unit:
94 description:
95 - GCP volume size unit.
96 choices: ['GB', 'TB']
97 type: str
98
99 gcp_volume_type:
100 description:
101 - GCP volume type.
102 choices: ['pd-balanced', 'pd-standard', 'pd-ssd']
103 type: str
104
105 instance_type:
106 description:
107 - The type of instance to use, which depends on the license type you choose.
108 - Explore ['custom-4-16384'].
109 - Standard ['n1-standard-8'].
110 - Premium ['n1-standard-32'].
111 - BYOL all instance types defined for PayGo.
112 - For more supported instance types, refer to Cloud Volumes ONTAP Release Notes.
113 default: 'n1-standard-8'
114 type: str
115
116 is_ha:
117 description:
118 - Indicate whether the working environment is an HA pair or not.
119 type: bool
120 default: false
121
122 license_type:
123 description:
124 - The type of license to use.
125 - For single node by Capacity ['capacity-paygo'].
126 - For single node by Node paygo ['gcp-cot-explore-paygo', 'gcp-cot-standard-paygo', 'gcp-cot-premium-paygo'].
127 - For single node by Node byol ['gcp-cot-premium-byol'].
128 - For HA by Capacity ['ha-capacity-paygo'].
129 - For HA by Node paygo ['gcp-ha-cot-explore-paygo', 'gcp-ha-cot-standard-paygo', 'gcp-ha-cot-premium-paygo'].
130 - For HA by Node byol ['gcp-cot-premium-byol'].
131 choices: ['gcp-cot-standard-paygo', 'gcp-cot-explore-paygo', 'gcp-cot-premium-paygo', 'gcp-cot-premium-byol', \
132 'gcp-ha-cot-standard-paygo', 'gcp-ha-cot-premium-paygo', 'gcp-ha-cot-explore-paygo', 'gcp-ha-cot-premium-byol', \
133 'capacity-paygo', 'ha-capacity-paygo']
134 type: str
135 default: 'capacity-paygo'
136
137 provided_license:
138 description:
139 - Using a NLF license file for BYOL deployment
140 type: str
141
142 capacity_package_name:
143 description:
144 - Capacity package name is required when selecting a capacity based license.
145 choices: ['Professional', 'Essential', 'Freemium']
146 default: 'Essential'
147 type: str
148 version_added: 21.12.0
149
150 mediator_zone:
151 description:
152 - The zone for mediator.
153 - Option for HA pair only.
154 type: str
155
156 name:
157 description:
158 - The name of the Cloud Manager CVO for GCP to manage.
159 required: true
160 type: str
161
162 network_project_id:
163 description:
164 - The project id in GCP associated with the Subnet.
165 - If not provided, it is assumed that the Subnet is within the previously specified project id.
166 type: str
167
168 node1_zone:
169 description:
170 - Zone for node 1.
171 - Option for HA pair only.
172 type: str
173
174 node2_zone:
175 description:
176 - Zone for node 2.
177 - Option for HA pair only.
178 type: str
179
180 nss_account:
181 description:
182 - The NetApp Support Site account ID to use with this Cloud Volumes ONTAP system.
183 - If the license type is BYOL and an NSS account isn't provided, Cloud Manager tries to use the first existing NSS account.
184 type: str
185
186 ontap_version:
187 description:
188 - The required ONTAP version. Ignored if 'use_latest_version' is set to true.
189 type: str
190 default: 'latest'
191
192 platform_serial_number_node1:
193 description:
194 - For HA BYOL, the serial number for the first node.
195 - Option for HA pair only.
196 type: str
197
198 platform_serial_number_node2:
199 description:
200 - For HA BYOL, the serial number for the second node.
201 - Option for HA pair only.
202 type: str
203
204 project_id:
205 description:
206 - The ID of the GCP project.
207 required: true
208 type: str
209
210 platform_serial_number:
211 description:
212 - The serial number for the system. Required when using 'gcp-cot-premium-byol'.
213 type: str
214
215 state:
216 description:
217 - Whether the specified Cloud Manager CVO for GCP should exist or not.
218 choices: ['present', 'absent']
219 default: 'present'
220 type: str
221
222 subnet_id:
223 description:
224 - The name of the subnet for Cloud Volumes ONTAP.
225 type: str
226
227 subnet0_node_and_data_connectivity:
228 description:
229 - Subnet path for nic1, required for node and data connectivity.
230 - If using shared VPC, network_project_id must be provided.
231 - Option for HA pair only.
232 type: str
233
234 subnet1_cluster_connectivity:
235 description:
236 - Subnet path for nic2, required for cluster connectivity.
237 - Option for HA pair only.
238 type: str
239
240 subnet2_ha_connectivity:
241 description:
242 - Subnet path for nic3, required for HA connectivity.
243 - Option for HA pair only.
244 type: str
245
246 subnet3_data_replication:
247 description:
248 - Subnet path for nic4, required for HA connectivity.
249 - Option for HA pair only.
250 type: str
251
252 svm_password:
253 description:
254 - The admin password for Cloud Volumes ONTAP.
255 - It will be updated on each run.
256 type: str
257
258 svm_name:
259 description:
260 - The name of the SVM.
261 type: str
262 version_added: 21.22.0
263
264 tier_level:
265 description:
266 - The tiering level when 'capacity_tier' is set to 'cloudStorage'.
267 choices: ['standard', 'nearline', 'coldline']
268 default: 'standard'
269 type: str
270
271 use_latest_version:
272 description:
273 - Indicates whether to use the latest available ONTAP version.
274 type: bool
275 default: true
276
277 vpc_id:
278 required: true
279 description:
280 - The name of the VPC.
281 type: str
282
283 vpc0_firewall_rule_name:
284 description:
285 - Firewall rule name for vpc1.
286 - Option for HA pair only.
287 type: str
288
289 vpc0_node_and_data_connectivity:
290 description:
291 - VPC path for nic1, required for node and data connectivity.
292 - If using shared VPC, network_project_id must be provided.
293 - Option for HA pair only.
294 type: str
295
296 vpc1_cluster_connectivity:
297 description:
298 - VPC path for nic2, required for cluster connectivity.
299 - Option for HA pair only.
300 type: str
301
302 vpc1_firewall_rule_name:
303 description:
304 - Firewall rule name for vpc2.
305 - Option for HA pair only.
306 type: str
307
308 vpc2_ha_connectivity:
309 description:
310 - VPC path for nic3, required for HA connectivity.
311 - Option for HA pair only.
312 type: str
313
314 vpc2_firewall_rule_name:
315 description:
316 - Firewall rule name for vpc3.
317 - Option for HA pair only.
318 type: str
319
320 vpc3_data_replication:
321 description:
322 - VPC path for nic4, required for data replication.
323 - Option for HA pair only.
324 type: str
325
326 vpc3_firewall_rule_name:
327 description:
328 - Firewall rule name for vpc4.
329 - Option for HA pair only.
330 type: str
331
332 workspace_id:
333 description:
334 - The ID of the Cloud Manager workspace where you want to deploy Cloud Volumes ONTAP.
335 - If not provided, Cloud Manager uses the first workspace.
336 - You can find the ID from the Workspace tab on [https://cloudmanager.netapp.com].
337 type: str
338
339 writing_speed_state:
340 description:
341 - The write speed setting for Cloud Volumes ONTAP ['NORMAL','HIGH'].
342 - Default value is 'NORMAL' for non-HA GCP CVO
343 - This argument is not relevant for HA pairs.
344 type: str
345
346 zone:
347 description:
348 - The zone of the region where the working environment will be created.
349 required: true
350 type: str
351
352 upgrade_ontap_version:
353 description:
354 - Indicates whether to upgrade ONTAP image on the CVO.
355 - If the current version already matches the desired version, no action is taken.
356 type: bool
357 default: false
358 version_added: 21.13.0
359
360 update_svm_password:
361 description:
362 - Indicates whether to update svm_password on the CVO.
363 - When set to true, the module is not idempotent, as we cannot read the current password.
364 type: bool
365 default: false
366 version_added: 21.13.0
367
368 subnet_path:
369 description:
370 - Subnet path for a single node cluster.
371 type: str
372 version_added: 21.20.0
373
374 notes:
375 - Support check_mode.
376 '''
377
378 EXAMPLES = """
379
380 - name: Create NetApp Cloud Manager cvo for GCP
381 netapp.cloudmanager.na_cloudmanager_cvo_gcp:
382 state: present
383 name: ansiblecvogcp
384 project_id: default-project
385 zone: us-east4-b
386 subnet_path: projects/<project>/regions/<region>/subnetworks/<subnetwork>
387 subnet_id: projects/<project>/regions/<region>/subnetworks/<subnetwork>
388 gcp_volume_type: pd-ssd
389 gcp_volume_size: 500
390 gcp_volume_size_unit: GB
391 gcp_service_account: "{{ xxxxxxxxxxxxxxx }}"
392 data_encryption_type: GCP
393 svm_password: "{{ xxxxxxxxxxxxxxx }}"
394 ontap_version: latest
395 use_latest_version: true
396 license_type: capacity-paygo
397 instance_type: n1-standard-8
398 client_id: "{{ xxxxxxxxxxxxxxx }}"
399 workspace_id: "{{ xxxxxxxxxxxxxxx }}"
400 capacity_tier: cloudStorage
401 writing_speed_state: NORMAL
402 refresh_token: "{{ xxxxxxxxxxxxxxx }}"
403 vpc_id: default
404 gcp_labels:
405 - label_key: key1
406 label_value: value1
407 - label_key: key2
408 label_value: value2
409
410 - name: Create NetApp Cloud Manager cvo ha for GCP
411 netapp.cloudmanager.na_cloudmanager_cvo_gcp:
412 state: present
413 name: ansiblecvogcpha
414 project_id: "default-project"
415 zone: us-east1-b
416 gcp_volume_type: pd-ssd
417 gcp_volume_size: 500
418 gcp_volume_size_unit: GB
419 gcp_service_account: "{{ xxxxxxxxxxxxxxx }}"
420 data_encryption_type: GCP
421 svm_password: "{{ xxxxxxxxxxxxxxx }}"
422 ontap_version: ONTAP-9.9.0.T1.gcpha
423 use_latest_version: false
424 license_type: ha-capacity-paygo
425 instance_type: custom-4-16384
426 client_id: "{{ xxxxxxxxxxxxxxx }}"
427 workspace_id: "{{ xxxxxxxxxxxxxxx }}"
428 capacity_tier: cloudStorage
429 writing_speed_state: NORMAL
430 refresh_token: "{{ xxxxxxxxxxxxxxx }}"
431 is_ha: true
432 mediator_zone: us-east1-b
433 node1_zone: us-east1-b
434 node2_zone: us-east1-b
435 subnet0_node_and_data_connectivity: default
436 subnet1_cluster_connectivity: subnet2
437 subnet2_ha_connectivity: subnet3
438 subnet3_data_replication: subnet1
439 vpc0_node_and_data_connectivity: default
440 vpc1_cluster_connectivity: vpc2
441 vpc2_ha_connectivity: vpc3
442 vpc3_data_replication: vpc1
443 vpc_id: default
444 subnet_id: default
445
446 """
447
448 RETURN = '''
449 working_environment_id:
450 description: Newly created GCP CVO working_environment_id.
451 type: str
452 returned: success
453 '''
454
455 from ansible.module_utils.basic import AnsibleModule
456 import ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp as netapp_utils
457 from ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp_module import NetAppModule
458 from ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp import CloudManagerRestAPI
459
460
461 GCP_LICENSE_TYPES = ["gcp-cot-standard-paygo", "gcp-cot-explore-paygo", "gcp-cot-premium-paygo", "gcp-cot-premium-byol",
462 "gcp-ha-cot-standard-paygo", "gcp-ha-cot-premium-paygo", "gcp-ha-cot-explore-paygo",
463 "gcp-ha-cot-premium-byol", "capacity-paygo", "ha-capacity-paygo"]
464 GOOGLE_API_URL = "https://www.googleapis.com/compute/v1/projects"
465
466
467 class NetAppCloudManagerCVOGCP:
468 ''' object initialize and class methods '''
469
470 def __init__(self):
471 self.use_rest = False
472 self.argument_spec = netapp_utils.cloudmanager_host_argument_spec()
473 self.argument_spec.update(dict(
474 backup_volumes_to_cbs=dict(required=False, type='bool', default=False),
475 capacity_tier=dict(required=False, type='str', choices=['cloudStorage']),
476 client_id=dict(required=True, type='str'),
477 data_encryption_type=dict(required=False, choices=['GCP'], type='str'),
478 gcp_encryption_parameters=dict(required=False, type='str', no_log=True),
479 enable_compliance=dict(required=False, type='bool', default=False),
480 firewall_rule=dict(required=False, type='str'),
481 gcp_labels=dict(required=False, type='list', elements='dict', options=dict(
482 label_key=dict(type='str', no_log=False),
483 label_value=dict(type='str')
484 )),
485 gcp_service_account=dict(required=True, type='str'),
486 gcp_volume_size=dict(required=False, type='int'),
487 gcp_volume_size_unit=dict(required=False, choices=['GB', 'TB'], type='str'),
488 gcp_volume_type=dict(required=False, choices=['pd-balanced', 'pd-standard', 'pd-ssd'], type='str'),
489 instance_type=dict(required=False, type='str', default='n1-standard-8'),
490 is_ha=dict(required=False, type='bool', default=False),
491 license_type=dict(required=False, type='str', choices=GCP_LICENSE_TYPES, default='capacity-paygo'),
492 mediator_zone=dict(required=False, type='str'),
493 name=dict(required=True, type='str'),
494 network_project_id=dict(required=False, type='str'),
495 node1_zone=dict(required=False, type='str'),
496 node2_zone=dict(required=False, type='str'),
497 nss_account=dict(required=False, type='str'),
498 ontap_version=dict(required=False, type='str', default='latest'),
499 platform_serial_number=dict(required=False, type='str'),
500 platform_serial_number_node1=dict(required=False, type='str'),
501 platform_serial_number_node2=dict(required=False, type='str'),
502 project_id=dict(required=True, type='str'),
503 state=dict(required=False, choices=['present', 'absent'], default='present'),
504 subnet_id=dict(required=False, type='str'),
505 subnet0_node_and_data_connectivity=dict(required=False, type='str'),
506 subnet1_cluster_connectivity=dict(required=False, type='str'),
507 subnet2_ha_connectivity=dict(required=False, type='str'),
508 subnet3_data_replication=dict(required=False, type='str'),
509 svm_password=dict(required=False, type='str', no_log=True),
510 svm_name=dict(required=False, type='str'),
511 tier_level=dict(required=False, type='str', choices=['standard', 'nearline', 'coldline'],
512 default='standard'),
513 use_latest_version=dict(required=False, type='bool', default=True),
514 capacity_package_name=dict(required=False, type='str', choices=['Professional', 'Essential', 'Freemium'], default='Essential'),
515 provided_license=dict(required=False, type='str'),
516 vpc_id=dict(required=True, type='str'),
517 vpc0_firewall_rule_name=dict(required=False, type='str'),
518 vpc0_node_and_data_connectivity=dict(required=False, type='str'),
519 vpc1_cluster_connectivity=dict(required=False, type='str'),
520 vpc1_firewall_rule_name=dict(required=False, type='str'),
521 vpc2_firewall_rule_name=dict(required=False, type='str'),
522 vpc2_ha_connectivity=dict(required=False, type='str'),
523 vpc3_data_replication=dict(required=False, type='str'),
524 vpc3_firewall_rule_name=dict(required=False, type='str'),
525 workspace_id=dict(required=False, type='str'),
526 writing_speed_state=dict(required=False, type='str'),
527 zone=dict(required=True, type='str'),
528 upgrade_ontap_version=dict(required=False, type='bool', default=False),
529 update_svm_password=dict(required=False, type='bool', default=False),
530 subnet_path=dict(required=False, type='str'),
531 ))
532
533 self.module = AnsibleModule(
534 argument_spec=self.argument_spec,
535 required_one_of=[['refresh_token', 'sa_client_id']],
536 required_together=[['sa_client_id', 'sa_secret_key']],
537 required_if=[
538 ['license_type', 'capacity-paygo', ['capacity_package_name']],
539 ['license_type', 'ha-capacity-paygo', ['capacity_package_name']],
540 ['license_type', 'gcp-cot-premium-byol', ['platform_serial_number']],
541 ['license_type', 'gcp-ha-cot-premium-byol', ['platform_serial_number_node1', 'platform_serial_number_node2']],
542 ],
543 supports_check_mode=True
544 )
545 self.na_helper = NetAppModule()
546 self.parameters = self.na_helper.set_parameters(self.module.params)
547 self.changeable_params = ['svm_password', 'svm_name', 'tier_level', 'gcp_labels', 'ontap_version',
548 'instance_type', 'license_type', 'writing_speed_state']
549 self.rest_api = CloudManagerRestAPI(self.module)
550 self.rest_api.url += self.rest_api.environment_data['CLOUD_MANAGER_HOST']
551 self.rest_api.api_root_path = '/occm/api/gcp/%s' % ('ha' if self.parameters['is_ha'] else 'vsa')
552 self.headers = {
553 'X-Agent-Id': self.rest_api.format_client_id(self.parameters['client_id'])
554 }
555
556 @staticmethod
557 def has_self_link(param):
558 return param.startswith(("https://www.googleapis.com/compute/", "projects/"))
559
560 def create_cvo_gcp(self):
561
562 if self.parameters.get('workspace_id') is None:
563 response, msg = self.na_helper.get_tenant(self.rest_api, self.headers)
564 if response is None:
565 self.module.fail_json(msg)
566 self.parameters['workspace_id'] = response
567
568 if self.parameters.get('nss_account') is None:
569 if self.parameters.get('platform_serial_number') is not None:
570 if not self.parameters['platform_serial_number'].startswith('Eval-'):
571 if self.parameters['license_type'] == 'gcp-cot-premium-byol' or self.parameters['license_type'] == 'gcp-ha-cot-premium-byol':
572 response, msg = self.na_helper.get_nss(self.rest_api, self.headers)
573 if response is None:
574 self.module.fail_json(msg)
575 self.parameters['nss_account'] = response
576
577 if self.parameters['is_ha'] is True and self.parameters['license_type'] == 'capacity-paygo':
578 self.parameters['license_type'] == 'ha-capacity-paygo'
579
580 json = {"name": self.parameters['name'],
581 "region": self.parameters['zone'],
582 "tenantId": self.parameters['workspace_id'],
583 "vpcId": self.parameters['vpc_id'],
584 "gcpServiceAccount": self.parameters['gcp_service_account'],
585 "gcpVolumeSize": {
586 "size": self.parameters['gcp_volume_size'],
587 "unit": self.parameters['gcp_volume_size_unit']},
588 "gcpVolumeType": self.parameters['gcp_volume_type'],
589 "svmPassword": self.parameters['svm_password'],
590 "backupVolumesToCbs": self.parameters['backup_volumes_to_cbs'],
591 "enableCompliance": self.parameters['enable_compliance'],
592 "vsaMetadata": {
593 "ontapVersion": self.parameters['ontap_version'],
594 "licenseType": self.parameters['license_type'],
595 "useLatestVersion": self.parameters['use_latest_version'],
596 "instanceType": self.parameters['instance_type']}
597 }
598
599 if self.parameters['is_ha'] is False:
600 if self.parameters.get('writing_speed_state') is None:
601 self.parameters['writing_speed_state'] = 'NORMAL'
602 json.update({'writingSpeedState': self.parameters['writing_speed_state'].upper()})
603
604 if self.parameters.get('data_encryption_type') is not None and self.parameters['data_encryption_type'] == "GCP":
605 json.update({'dataEncryptionType': self.parameters['data_encryption_type']})
606 if self.parameters.get('gcp_encryption_parameters') is not None:
607 json.update({"gcpEncryptionParameters": {"key": self.parameters['gcp_encryption_parameters']}})
608
609 if self.parameters.get('provided_license') is not None:
610 json['vsaMetadata'].update({"providedLicense": self.parameters['provided_license']})
611
612 # clean default value if it is not by Capacity license
613 if not self.parameters['license_type'].endswith('capacity-paygo'):
614 json['vsaMetadata'].update({"capacityPackageName": ''})
615
616 if self.parameters.get('capacity_package_name') is not None:
617 json['vsaMetadata'].update({"capacityPackageName": self.parameters['capacity_package_name']})
618
619 if self.parameters.get('project_id'):
620 json.update({'project': self.parameters['project_id']})
621
622 if self.parameters.get('nss_account'):
623 json.update({'nssAccount': self.parameters['nss_account']})
624
625 if self.parameters.get('subnet_id'):
626 json.update({'subnetId': self.parameters['subnet_id']})
627
628 if self.parameters.get('subnet_path'):
629 json.update({'subnetPath': self.parameters['subnet_path']})
630
631 if self.parameters.get('platform_serial_number') is not None:
632 json.update({"serialNumber": self.parameters['platform_serial_number']})
633
634 if self.parameters.get('capacity_tier') is not None and self.parameters['capacity_tier'] == "cloudStorage":
635 json.update({"capacityTier": self.parameters['capacity_tier'],
636 "tierLevel": self.parameters['tier_level']})
637
638 if self.parameters.get('svm_name') is not None:
639 json.update({"svmName": self.parameters['svm_name']})
640
641 if self.parameters.get('gcp_labels') is not None:
642 labels = []
643 for each_label in self.parameters['gcp_labels']:
644 label = {
645 'labelKey': each_label['label_key'],
646 'labelValue': each_label['label_value']
647 }
648
649 labels.append(label)
650 json.update({"gcpLabels": labels})
651
652 if self.parameters.get('firewall_rule'):
653 json.update({'firewallRule': self.parameters['firewall_rule']})
654
655 if self.parameters['is_ha'] is True:
656 ha_params = dict()
657
658 if self.parameters.get('network_project_id') is not None:
659 network_project_id = self.parameters.get('network_project_id')
660 else:
661 network_project_id = self.parameters['project_id']
662
663 if not self.has_self_link(self.parameters['subnet_id']):
664 json.update({'subnetId': 'projects/%s/regions/%s/subnetworks/%s' % (network_project_id,
665 self.parameters['zone'][:-2],
666 self.parameters['subnet_id'])})
667
668 if self.parameters.get('platform_serial_number_node1'):
669 ha_params["platformSerialNumberNode1"] = self.parameters['platform_serial_number_node1']
670
671 if self.parameters.get('platform_serial_number_node2'):
672 ha_params["platformSerialNumberNode2"] = self.parameters['platform_serial_number_node2']
673
674 if self.parameters.get('node1_zone'):
675 ha_params["node1Zone"] = self.parameters['node1_zone']
676
677 if self.parameters.get('node2_zone'):
678 ha_params["node2Zone"] = self.parameters['node2_zone']
679
680 if self.parameters.get('mediator_zone'):
681 ha_params["mediatorZone"] = self.parameters['mediator_zone']
682
683 if self.parameters.get('vpc0_node_and_data_connectivity'):
684 if self.has_self_link(self.parameters['vpc0_node_and_data_connectivity']):
685 ha_params["vpc0NodeAndDataConnectivity"] = self.parameters['vpc0_node_and_data_connectivity']
686 else:
687 ha_params["vpc0NodeAndDataConnectivity"] = GOOGLE_API_URL + "/{0}/global/networks/{1}".format(
688 network_project_id, self.parameters['vpc0_node_and_data_connectivity'])
689
690 if self.parameters.get('vpc1_cluster_connectivity'):
691 if self.has_self_link(self.parameters['vpc1_cluster_connectivity']):
692 ha_params["vpc1ClusterConnectivity"] = self.parameters['vpc1_cluster_connectivity']
693 else:
694 ha_params["vpc1ClusterConnectivity"] = GOOGLE_API_URL + "/{0}/global/networks/{1}".format(
695 network_project_id, self.parameters['vpc1_cluster_connectivity'])
696
697 if self.parameters.get('vpc2_ha_connectivity'):
698 if self.has_self_link(self.parameters['vpc2_ha_connectivity']):
699 ha_params["vpc2HAConnectivity"] = self.parameters['vpc2_ha_connectivity']
700 else:
701 ha_params["vpc2HAConnectivity"] = "https://www.googleapis.com/compute/v1/projects/{0}/global/networks" \
702 "/{1}".format(network_project_id, self.parameters['vpc2_ha_connectivity'])
703
704 if self.parameters.get('vpc3_data_replication'):
705 if self.has_self_link(self.parameters['vpc3_data_replication']):
706 ha_params["vpc3DataReplication"] = self.parameters['vpc3_data_replication']
707 else:
708 ha_params["vpc3DataReplication"] = GOOGLE_API_URL + "/{0}/global/networks/{1}".format(
709 network_project_id, self.parameters['vpc3_data_replication'])
710
711 if self.parameters.get('subnet0_node_and_data_connectivity'):
712 if self.has_self_link(self.parameters['subnet0_node_and_data_connectivity']):
713 ha_params["subnet0NodeAndDataConnectivity"] = self.parameters['subnet0_node_and_data_connectivity']
714 else:
715 ha_params["subnet0NodeAndDataConnectivity"] = GOOGLE_API_URL + "/{0}/regions/{1}/subnetworks/{2}".\
716 format(network_project_id, self.parameters['zone'][:-2], self.parameters['subnet0_node_and_data_connectivity'])
717
718 if self.parameters.get('subnet1_cluster_connectivity'):
719 if self.has_self_link(self.parameters['subnet1_cluster_connectivity']):
720 ha_params["subnet1ClusterConnectivity"] = self.parameters['subnet1_cluster_connectivity']
721 else:
722 ha_params["subnet1ClusterConnectivity"] = GOOGLE_API_URL + "/{0}/regions/{1}/subnetworks/{2}".format(
723 network_project_id, self.parameters['zone'][:-2],
724 self.parameters['subnet1_cluster_connectivity'])
725
726 if self.parameters.get('subnet2_ha_connectivity'):
727 if self.has_self_link(self.parameters['subnet2_ha_connectivity']):
728 ha_params["subnet2HAConnectivity"] = self.parameters['subnet2_ha_connectivity']
729 else:
730 ha_params["subnet2HAConnectivity"] = GOOGLE_API_URL + "/{0}/regions/{1}/subnetworks/{2}".format(
731 network_project_id, self.parameters['zone'][:-2],
732 self.parameters['subnet2_ha_connectivity'])
733
734 if self.parameters.get('subnet3_data_replication'):
735 if self.has_self_link(self.parameters['subnet3_data_replication']):
736 ha_params["subnet3DataReplication"] = self.parameters['subnet3_data_replication']
737 else:
738 ha_params["subnet3DataReplication"] = GOOGLE_API_URL + "/{0}/regions/{1}/subnetworks/{2}". \
739 format(network_project_id, self.parameters['zone'][:-2],
740 self.parameters['subnet3_data_replication'])
741
742 if self.parameters.get('vpc0_firewall_rule_name'):
743 ha_params["vpc0FirewallRuleName"] = self.parameters['vpc0_firewall_ruleName']
744
745 if self.parameters.get('vpc1_firewall_rule_name'):
746 ha_params["vpc1FirewallRuleName"] = self.parameters['vpc1_firewall_rule_name']
747
748 if self.parameters.get('vpc2_firewall_rule_name'):
749 ha_params["vpc2FirewallRuleName"] = self.parameters['vpc2_firewall_rule_name']
750
751 if self.parameters.get('vpc3_firewall_rule_name'):
752 ha_params["vpc3FirewallRuleName"] = self.parameters['vpc3_firewall_rule_name']
753
754 json["haParams"] = ha_params
755
756 api_url = '%s/working-environments' % self.rest_api.api_root_path
757 response, error, on_cloud_request_id = self.rest_api.post(api_url, json, header=self.headers)
758 if error is not None:
759 self.module.fail_json(
760 msg="Error: unexpected response on creating cvo gcp: %s, %s" % (str(error), str(response)))
761 working_environment_id = response['publicId']
762 wait_on_completion_api_url = '/occm/api/audit/activeTask/%s' % str(on_cloud_request_id)
763 err = self.rest_api.wait_on_completion(wait_on_completion_api_url, "CVO", "create", 60, 90)
764
765 if err is not None:
766 self.module.fail_json(msg="Error: unexpected response wait_on_completion for creating CVO GCP: %s" % str(err))
767 return working_environment_id
768
769 def update_cvo_gcp(self, working_environment_id, modify):
770 base_url = '%s/working-environments/%s/' % (self.rest_api.api_root_path, working_environment_id)
771 for item in modify:
772 if item == 'svm_password':
773 response, error = self.na_helper.update_svm_password(base_url, self.rest_api, self.headers, self.parameters['svm_password'])
774 if error is not None:
775 self.module.fail_json(changed=False, msg=error)
776 if item == 'svm_name':
777 response, error = self.na_helper.update_svm_name(base_url, self.rest_api, self.headers, self.parameters['svm_name'])
778 if error is not None:
779 self.module.fail_json(changed=False, msg=error)
780 if item == 'gcp_labels':
781 tag_list = None
782 if 'gcp_labels' in self.parameters:
783 tag_list = self.parameters['gcp_labels']
784 response, error = self.na_helper.update_cvo_tags(base_url, self.rest_api, self.headers, 'gcp_labels', tag_list)
785 if error is not None:
786 self.module.fail_json(changed=False, msg=error)
787 if item == 'tier_level':
788 response, error = self.na_helper.update_tier_level(base_url, self.rest_api, self.headers, self.parameters['tier_level'])
789 if error is not None:
790 self.module.fail_json(changed=False, msg=error)
791 if item == 'writing_speed_state':
792 response, error = self.na_helper.update_writing_speed_state(base_url, self.rest_api, self.headers, self.parameters['writing_speed_state'])
793 if error is not None:
794 self.module.fail_json(changed=False, msg=error)
795 if item == 'ontap_version':
796 response, error = self.na_helper.upgrade_ontap_image(self.rest_api, self.headers, self.parameters['ontap_version'])
797 if error is not None:
798 self.module.fail_json(changed=False, msg=error)
799 if item == 'instance_type' or item == 'license_type':
800 response, error = self.na_helper.update_instance_license_type(base_url, self.rest_api, self.headers,
801 self.parameters['instance_type'],
802 self.parameters['license_type'])
803 if error is not None:
804 self.module.fail_json(changed=False, msg=error)
805
806 def delete_cvo_gcp(self, we_id):
807 """
808 Delete GCP CVO
809 """
810 api_url = '%s/working-environments/%s' % (self.rest_api.api_root_path, we_id)
811 response, error, on_cloud_request_id = self.rest_api.delete(api_url, None, header=self.headers)
812 if error is not None:
813 self.module.fail_json(msg="Error: unexpected response on deleting cvo gcp: %s, %s" % (str(error), str(response)))
814
815 wait_on_completion_api_url = '/occm/api/audit/activeTask/%s' % str(on_cloud_request_id)
816 err = self.rest_api.wait_on_completion(wait_on_completion_api_url, "CVO", "delete", 40, 60)
817 if err is not None:
818 self.module.fail_json(msg="Error: unexpected response wait_on_completion for deleting cvo gcp: %s" % str(err))
819
820 def apply(self):
821 working_environment_id = None
822 modify = None
823
824 current, dummy = self.na_helper.get_working_environment_details_by_name(self.rest_api, self.headers,
825 self.parameters['name'], "gcp")
826 if current:
827 self.parameters['working_environment_id'] = current['publicId']
828 # check the action
829 cd_action = self.na_helper.get_cd_action(current, self.parameters)
830
831 if current and self.parameters['state'] != 'absent':
832 working_environment_id = current['publicId']
833 modify, error = self.na_helper.is_cvo_update_needed(self.rest_api, self.headers, self.parameters, self.changeable_params, 'gcp')
834 if error is not None:
835 self.module.fail_json(changed=False, msg=error)
836
837 if self.na_helper.changed and not self.module.check_mode:
838 if cd_action == "create":
839 working_environment_id = self.create_cvo_gcp()
840 elif cd_action == "delete":
841 self.delete_cvo_gcp(current['publicId'])
842 else:
843 self.update_cvo_gcp(current['publicId'], modify)
844
845 self.module.exit_json(changed=self.na_helper.changed, working_environment_id=working_environment_id)
846
847
848 def main():
849 """
850 Create Cloud Manager CVO for GCP class instance and invoke apply
851 :return: None
852 """
853 obj_store = NetAppCloudManagerCVOGCP()
854 obj_store.apply()
855
856
857 if __name__ == '__main__':
858 main()