| 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_aws |
| 8 |
''' |
| 9 |
|
| 10 |
from __future__ import absolute_import, division, print_function |
| 11 |
__metaclass__ = type |
| 12 |
|
| 13 |
DOCUMENTATION = ''' |
| 14 |
|
| 15 |
module: na_cloudmanager_cvo_aws |
| 16 |
short_description: NetApp Cloud Manager CVO for AWS |
| 17 |
extends_documentation_fragment: |
| 18 |
- netapp.cloudmanager.netapp.cloudmanager |
| 19 |
version_added: '21.3.0' |
| 20 |
author: NetApp Ansible Team (@carchi8py) <[email protected]> |
| 21 |
|
| 22 |
description: |
| 23 |
- Create, delete, or manage Cloud Manager CVO for AWS. |
| 24 |
|
| 25 |
options: |
| 26 |
|
| 27 |
state: |
| 28 |
description: |
| 29 |
- Whether the specified Cloud Manager CVO for AWS should exist or not. |
| 30 |
choices: ['present', 'absent'] |
| 31 |
default: 'present' |
| 32 |
type: str |
| 33 |
|
| 34 |
name: |
| 35 |
required: true |
| 36 |
description: |
| 37 |
- The name of the Cloud Manager CVO for AWS to manage. |
| 38 |
type: str |
| 39 |
|
| 40 |
instance_type: |
| 41 |
description: |
| 42 |
- The instance type to use, which depends on the license type. |
| 43 |
- Explore ['m5.xlarge']. |
| 44 |
- Standard ['m5.2xlarge','r5.xlarge']. |
| 45 |
- Premium ['m5.4xlarge','r5.2xlarge','c4.8xlarge']. |
| 46 |
- For more supported instance types, refer to Cloud Volumes ONTAP Release Notes. |
| 47 |
type: str |
| 48 |
default: m5.2xlarge |
| 49 |
|
| 50 |
license_type: |
| 51 |
description: |
| 52 |
- The type of license to use. |
| 53 |
- For single node by Capacity ['capacity-paygo'] |
| 54 |
- For single node by Node paygo ['cot-explore-paygo', 'cot-standard-paygo', 'cot-premium-paygo']. |
| 55 |
- For single node by Node boyl ['cot-premium-byol']. |
| 56 |
- For HA by Capacity ['ha-capacity-paygo'] |
| 57 |
- For HA by Node paygo ['ha-cot-explore-paygo','ha-cot-standard-paygo','ha-cot-premium-paygo']. |
| 58 |
- For HA by Node boyl ['ha-cot-premium-byol']. |
| 59 |
choices: ['capacity-paygo', 'cot-standard-paygo', 'cot-premium-paygo', 'cot-explore-paygo', 'cot-premium-byol', \ |
| 60 |
'ha-cot-standard-paygo', 'ha-cot-premium-paygo', 'ha-cot-premium-byol', 'ha-cot-explore-paygo', \ |
| 61 |
'ha-capacity-paygo'] |
| 62 |
default: capacity-paygo |
| 63 |
type: str |
| 64 |
|
| 65 |
provided_license: |
| 66 |
description: |
| 67 |
- Using a NLF license file for BYOL deployment. |
| 68 |
type: str |
| 69 |
|
| 70 |
capacity_package_name: |
| 71 |
description: |
| 72 |
- Capacity package name is required when selecting a capacity based license. |
| 73 |
- Essential only available with Bring Your Own License Capacity-Based. |
| 74 |
- Professional available as an annual contract from AWS marketplace or Bring Your Own License Capacity-Based. |
| 75 |
choices: ['Professional', 'Essential', 'Freemium'] |
| 76 |
default: 'Essential' |
| 77 |
type: str |
| 78 |
version_added: 21.12.0 |
| 79 |
|
| 80 |
workspace_id: |
| 81 |
description: |
| 82 |
- The ID of the Cloud Manager workspace where you want to deploy Cloud Volumes ONTAP. |
| 83 |
- If not provided, Cloud Manager uses the first workspace. |
| 84 |
- You can find the ID from the Workspace tab on U(https://cloudmanager.netapp.com). |
| 85 |
type: str |
| 86 |
|
| 87 |
subnet_id: |
| 88 |
description: |
| 89 |
- The subnet id where the working environment will be created. Required when single node only. |
| 90 |
type: str |
| 91 |
|
| 92 |
vpc_id: |
| 93 |
description: |
| 94 |
- The VPC ID where the working environment will be created. |
| 95 |
- If this argument is not provided, the VPC will be calculated by using the provided subnet ID. |
| 96 |
type: str |
| 97 |
|
| 98 |
region: |
| 99 |
required: true |
| 100 |
description: |
| 101 |
- The region where the working environment will be created. |
| 102 |
type: str |
| 103 |
|
| 104 |
data_encryption_type: |
| 105 |
description: |
| 106 |
- The type of encryption to use for the working environment. |
| 107 |
choices: ['AWS', 'NONE'] |
| 108 |
default: 'AWS' |
| 109 |
type: str |
| 110 |
|
| 111 |
client_id: |
| 112 |
required: true |
| 113 |
description: |
| 114 |
- The connector ID of the Cloud Manager Connector. |
| 115 |
- You can find the ID from the Connector tab on U(https://cloudmanager.netapp.com). |
| 116 |
type: str |
| 117 |
|
| 118 |
ebs_volume_size: |
| 119 |
description: |
| 120 |
- EBS volume size for the first data aggregate. |
| 121 |
- For GB, the value can be [100 or 500]. |
| 122 |
- For TB, the value can be [1,2,4,8,16]. |
| 123 |
default: 1 |
| 124 |
type: int |
| 125 |
|
| 126 |
ebs_volume_size_unit: |
| 127 |
description: |
| 128 |
- The unit for ebs volume size. |
| 129 |
choices: ['GB', 'TB'] |
| 130 |
default: 'TB' |
| 131 |
type: str |
| 132 |
|
| 133 |
ebs_volume_type: |
| 134 |
description: |
| 135 |
- The EBS volume type for the first data aggregate. |
| 136 |
choices: ['gp3', 'gp2', 'io1', 'sc1', 'st1'] |
| 137 |
default: 'gp2' |
| 138 |
type: str |
| 139 |
|
| 140 |
security_group_id: |
| 141 |
description: |
| 142 |
- The ID of the security group for the working environment. If not provided, Cloud Manager creates the security group. |
| 143 |
type: str |
| 144 |
|
| 145 |
instance_profile_name: |
| 146 |
description: |
| 147 |
- The instance profile name for the working environment. If not provided, Cloud Manager creates the instance profile. |
| 148 |
type: str |
| 149 |
|
| 150 |
svm_password: |
| 151 |
required: true |
| 152 |
description: |
| 153 |
- The admin password for Cloud Volumes ONTAP. |
| 154 |
- It will be updated on each run. |
| 155 |
type: str |
| 156 |
|
| 157 |
svm_name: |
| 158 |
description: |
| 159 |
- The name of the SVM. |
| 160 |
type: str |
| 161 |
version_added: 21.22.0 |
| 162 |
|
| 163 |
ontap_version: |
| 164 |
description: |
| 165 |
- The required ONTAP version. Ignored if 'use_latest_version' is set to true. |
| 166 |
type: str |
| 167 |
default: 'latest' |
| 168 |
|
| 169 |
use_latest_version: |
| 170 |
description: |
| 171 |
- Indicates whether to use the latest available ONTAP version. |
| 172 |
type: bool |
| 173 |
default: true |
| 174 |
|
| 175 |
platform_serial_number: |
| 176 |
description: |
| 177 |
- The serial number for the cluster. This is required when using 'cot-premium-byol'. |
| 178 |
type: str |
| 179 |
|
| 180 |
tier_level: |
| 181 |
description: |
| 182 |
- The tiering level when 'capacity_tier' is set to 'S3'. |
| 183 |
choices: ['normal', 'ia', 'ia-single', 'intelligent'] |
| 184 |
default: 'normal' |
| 185 |
type: str |
| 186 |
|
| 187 |
cluster_key_pair_name: |
| 188 |
description: |
| 189 |
- SSH authentication key pair name |
| 190 |
type: str |
| 191 |
version_added: 21.20.0 |
| 192 |
|
| 193 |
nss_account: |
| 194 |
description: |
| 195 |
- The NetApp Support Site account ID to use with this Cloud Volumes ONTAP system. |
| 196 |
- If the license type is BYOL and an NSS account is not provided, Cloud Manager tries to use the first existing NSS account. |
| 197 |
type: str |
| 198 |
|
| 199 |
writing_speed_state: |
| 200 |
description: |
| 201 |
- The write speed setting for Cloud Volumes ONTAP ['NORMAL','HIGH']. |
| 202 |
- This argument is not relevant for HA pairs. |
| 203 |
type: str |
| 204 |
|
| 205 |
iops: |
| 206 |
description: |
| 207 |
- Provisioned IOPS. Required only when provider_volume_type is 'io1' or 'gp3'. |
| 208 |
type: int |
| 209 |
|
| 210 |
throughput: |
| 211 |
description: |
| 212 |
- Unit is Mb/s. Valid range 125-1000. |
| 213 |
- Required only when provider_volume_type is 'gp3'. |
| 214 |
type: int |
| 215 |
|
| 216 |
capacity_tier: |
| 217 |
description: |
| 218 |
- Whether to enable data tiering for the first data aggregate. |
| 219 |
choices: ['S3', 'NONE'] |
| 220 |
default: 'S3' |
| 221 |
type: str |
| 222 |
|
| 223 |
instance_tenancy: |
| 224 |
description: |
| 225 |
- The EC2 instance tenancy. |
| 226 |
choices: ['default', 'dedicated'] |
| 227 |
default: 'default' |
| 228 |
type: str |
| 229 |
|
| 230 |
cloud_provider_account: |
| 231 |
description: |
| 232 |
- The cloud provider credentials id to use when deploying the Cloud Volumes ONTAP system. |
| 233 |
- You can find the ID in Cloud Manager from the Settings > Credentials page. |
| 234 |
- If not specified, Cloud Manager uses the instance profile of the Connector. |
| 235 |
type: str |
| 236 |
|
| 237 |
backup_volumes_to_cbs: |
| 238 |
description: |
| 239 |
- Automatically enable back up of all volumes to S3. |
| 240 |
default: false |
| 241 |
type: bool |
| 242 |
|
| 243 |
enable_compliance: |
| 244 |
description: |
| 245 |
- Enable the Cloud Compliance service on the working environment. |
| 246 |
default: false |
| 247 |
type: bool |
| 248 |
|
| 249 |
enable_monitoring: |
| 250 |
description: |
| 251 |
- Enable the Monitoring service on the working environment. |
| 252 |
default: false |
| 253 |
type: bool |
| 254 |
|
| 255 |
optimized_network_utilization: |
| 256 |
description: |
| 257 |
- Use optimized network utilization. |
| 258 |
default: true |
| 259 |
type: bool |
| 260 |
|
| 261 |
kms_key_id: |
| 262 |
description: |
| 263 |
- Aws Encryption parameters. It is required if using aws encryption. Only one of KMS key id or KMS arn should be specified. |
| 264 |
type: str |
| 265 |
|
| 266 |
kms_key_arn: |
| 267 |
description: |
| 268 |
- AWS encryption parameters. It is required if using aws encryption. Only one of KMS key id or KMS arn should be specified. |
| 269 |
type: str |
| 270 |
version_added: 21.10.0 |
| 271 |
|
| 272 |
aws_tag: |
| 273 |
description: |
| 274 |
- Additional tags for the AWS CVO working environment. |
| 275 |
type: list |
| 276 |
elements: dict |
| 277 |
suboptions: |
| 278 |
tag_key: |
| 279 |
description: The key of the tag. |
| 280 |
type: str |
| 281 |
tag_value: |
| 282 |
description: The tag value. |
| 283 |
type: str |
| 284 |
|
| 285 |
is_ha: |
| 286 |
description: |
| 287 |
- Indicate whether the working environment is an HA pair or not. |
| 288 |
type: bool |
| 289 |
default: false |
| 290 |
|
| 291 |
platform_serial_number_node1: |
| 292 |
description: |
| 293 |
- For HA BYOL, the serial number for the first node. This is required when using 'ha-cot-premium-byol'. |
| 294 |
type: str |
| 295 |
|
| 296 |
platform_serial_number_node2: |
| 297 |
description: |
| 298 |
- For HA BYOL, the serial number for the second node. This is required when using 'ha-cot-premium-byol'. |
| 299 |
type: str |
| 300 |
|
| 301 |
node1_subnet_id: |
| 302 |
description: |
| 303 |
- For HA, the subnet ID of the first node. |
| 304 |
type: str |
| 305 |
|
| 306 |
node2_subnet_id: |
| 307 |
description: |
| 308 |
- For HA, the subnet ID of the second node. |
| 309 |
type: str |
| 310 |
|
| 311 |
mediator_subnet_id: |
| 312 |
description: |
| 313 |
- For HA, the subnet ID of the mediator. |
| 314 |
type: str |
| 315 |
|
| 316 |
failover_mode: |
| 317 |
description: |
| 318 |
- For HA, the failover mode for the HA pair. 'PrivateIP' is for a single availability zone and 'FloatingIP' is for multiple availability zones. |
| 319 |
type: str |
| 320 |
choices: ['PrivateIP', 'FloatingIP'] |
| 321 |
|
| 322 |
mediator_assign_public_ip: |
| 323 |
description: |
| 324 |
- Boolean option to assign public IP. |
| 325 |
type: bool |
| 326 |
default: true |
| 327 |
|
| 328 |
mediator_key_pair_name: |
| 329 |
description: |
| 330 |
- For HA, the key pair name for the mediator instance. |
| 331 |
type: str |
| 332 |
|
| 333 |
cluster_floating_ip: |
| 334 |
description: |
| 335 |
- For HA FloatingIP, the cluster management floating IP address. |
| 336 |
type: str |
| 337 |
|
| 338 |
data_floating_ip: |
| 339 |
description: |
| 340 |
- For HA FloatingIP, the data floating IP address. |
| 341 |
type: str |
| 342 |
|
| 343 |
data_floating_ip2: |
| 344 |
description: |
| 345 |
- For HA FloatingIP, the data floating IP address. |
| 346 |
type: str |
| 347 |
|
| 348 |
svm_floating_ip: |
| 349 |
description: |
| 350 |
- For HA FloatingIP, the SVM management floating IP address. |
| 351 |
type: str |
| 352 |
|
| 353 |
route_table_ids: |
| 354 |
description: |
| 355 |
- For HA FloatingIP, the list of route table IDs that will be updated with the floating IPs. |
| 356 |
type: list |
| 357 |
elements: str |
| 358 |
|
| 359 |
upgrade_ontap_version: |
| 360 |
description: |
| 361 |
- Indicates whether to upgrade ONTAP image on the CVO. |
| 362 |
- If the current version already matches the desired version, no action is taken. |
| 363 |
type: bool |
| 364 |
default: false |
| 365 |
version_added: 21.13.0 |
| 366 |
|
| 367 |
update_svm_password: |
| 368 |
description: |
| 369 |
- Indicates whether to update svm_password on the CVO. |
| 370 |
- When set to true, the module is not idempotent, as we cannot read the current password. |
| 371 |
type: bool |
| 372 |
default: false |
| 373 |
version_added: 21.13.0 |
| 374 |
|
| 375 |
notes: |
| 376 |
- Support check_mode. |
| 377 |
''' |
| 378 |
|
| 379 |
EXAMPLES = """ |
| 380 |
- name: Create NetApp Cloud Manager CVO for AWS single |
| 381 |
netapp.cloudmanager.na_cloudmanager_cvo_aws: |
| 382 |
state: present |
| 383 |
refresh_token: "{{ xxxxxxxxxxxxxxx }}" |
| 384 |
name: AnsibleCVO |
| 385 |
region: us-west-1 |
| 386 |
subnet_id: subnet-xxxxxxx |
| 387 |
vpc_id: vpc-xxxxxxxx |
| 388 |
svm_password: P@assword! |
| 389 |
client_id: "{{ xxxxxxxxxxxxxxx }}" |
| 390 |
writing_speed_state: NORMAL |
| 391 |
aws_tag: [ |
| 392 |
{tag_key: abc, |
| 393 |
tag_value: a123}] |
| 394 |
|
| 395 |
- name: Create NetApp Cloud Manager CVO for AWS HA |
| 396 |
netapp.cloudmanager.na_cloudmanager_cvo_aws: |
| 397 |
state: present |
| 398 |
refresh_token: "{{ xxxxxxxxxxxxxxx }}" |
| 399 |
name: AnsibleCVO |
| 400 |
region: us-west-1 |
| 401 |
subnet_id: subnet-xxxxxxx |
| 402 |
vpc_id: vpc-xxxxxxxx |
| 403 |
svm_password: P@assword! |
| 404 |
client_id: "{{ xxxxxxxxxxxxxxx }}" |
| 405 |
writing_speed_state: NORMAL |
| 406 |
aws_tag: [ |
| 407 |
{tag_key: abc, |
| 408 |
tag_value: a123}] |
| 409 |
is_ha: true |
| 410 |
failover_mode: FloatingIP |
| 411 |
node1_subnet_id: subnet-1 |
| 412 |
node2_subnet_id: subnet-1 |
| 413 |
mediator_subnet_id: subnet-1 |
| 414 |
mediator_key_pair_name: key1 |
| 415 |
cluster_floating_ip: 2.1.1.1 |
| 416 |
data_floating_ip: 2.1.1.2 |
| 417 |
data_floating_ip2: 2.1.1.3 |
| 418 |
svm_floating_ip: 2.1.1.4 |
| 419 |
route_table_ids: [rt-1,rt-2] |
| 420 |
|
| 421 |
- name: Delete NetApp Cloud Manager cvo for AWS |
| 422 |
netapp.cloudmanager.na_cloudmanager_cvo_aws: |
| 423 |
state: absent |
| 424 |
name: ansible |
| 425 |
region: us-west-1 |
| 426 |
refresh_token: "{{ xxxxxxxxxxxxxxx }}" |
| 427 |
subnet_id: subnet-xxxxxxx |
| 428 |
vpc_id: vpc-xxxxxxxx |
| 429 |
svm_password: P@assword! |
| 430 |
client_id: "{{ xxxxxxxxxxxxxxx }}" |
| 431 |
""" |
| 432 |
|
| 433 |
RETURN = ''' |
| 434 |
working_environment_id: |
| 435 |
description: Newly created AWS CVO working_environment_id. |
| 436 |
type: str |
| 437 |
returned: success |
| 438 |
''' |
| 439 |
|
| 440 |
import traceback |
| 441 |
|
| 442 |
from ansible.module_utils.basic import AnsibleModule |
| 443 |
from ansible.module_utils._text import to_native |
| 444 |
import ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp as netapp_utils |
| 445 |
from ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp_module import NetAppModule |
| 446 |
from ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp import CloudManagerRestAPI |
| 447 |
IMPORT_EXCEPTION = None |
| 448 |
|
| 449 |
try: |
| 450 |
import boto3 |
| 451 |
from botocore.exceptions import ClientError |
| 452 |
HAS_AWS_LIB = True |
| 453 |
except ImportError as exc: |
| 454 |
HAS_AWS_LIB = False |
| 455 |
IMPORT_EXCEPTION = exc |
| 456 |
|
| 457 |
AWS_License_Types = ['cot-standard-paygo', 'cot-premium-paygo', 'cot-explore-paygo', 'cot-premium-byol', 'ha-cot-standard-paygo', |
| 458 |
'ha-cot-premium-paygo', 'ha-cot-premium-byol', 'ha-cot-explore-paygo', 'capacity-paygo', 'ha-capacity-paygo'] |
| 459 |
|
| 460 |
|
| 461 |
class NetAppCloudManagerCVOAWS: |
| 462 |
''' object initialize and class methods ''' |
| 463 |
|
| 464 |
def __init__(self): |
| 465 |
self.use_rest = False |
| 466 |
self.argument_spec = netapp_utils.cloudmanager_host_argument_spec() |
| 467 |
self.argument_spec.update(dict( |
| 468 |
name=dict(required=True, type='str'), |
| 469 |
state=dict(required=False, choices=['present', 'absent'], default='present'), |
| 470 |
instance_type=dict(required=False, type='str', default='m5.2xlarge'), |
| 471 |
license_type=dict(required=False, type='str', choices=AWS_License_Types, default='capacity-paygo'), |
| 472 |
workspace_id=dict(required=False, type='str'), |
| 473 |
subnet_id=dict(required=False, type='str'), |
| 474 |
vpc_id=dict(required=False, type='str'), |
| 475 |
region=dict(required=True, type='str'), |
| 476 |
data_encryption_type=dict(required=False, type='str', choices=['AWS', 'NONE'], default='AWS'), |
| 477 |
ebs_volume_size=dict(required=False, type='int', default='1'), |
| 478 |
ebs_volume_size_unit=dict(required=False, type='str', choices=['GB', 'TB'], default='TB'), |
| 479 |
ebs_volume_type=dict(required=False, type='str', choices=['gp3', 'gp2', 'io1', 'sc1', 'st1'], default='gp2'), |
| 480 |
svm_password=dict(required=True, type='str', no_log=True), |
| 481 |
svm_name=dict(required=False, type='str'), |
| 482 |
ontap_version=dict(required=False, type='str', default='latest'), |
| 483 |
use_latest_version=dict(required=False, type='bool', default=True), |
| 484 |
platform_serial_number=dict(required=False, type='str'), |
| 485 |
capacity_package_name=dict(required=False, type='str', choices=['Professional', 'Essential', 'Freemium'], default='Essential'), |
| 486 |
provided_license=dict(required=False, type='str'), |
| 487 |
tier_level=dict(required=False, type='str', choices=['normal', 'ia', 'ia-single', 'intelligent'], default='normal'), |
| 488 |
cluster_key_pair_name=dict(required=False, type='str'), |
| 489 |
nss_account=dict(required=False, type='str'), |
| 490 |
writing_speed_state=dict(required=False, type='str'), |
| 491 |
iops=dict(required=False, type='int'), |
| 492 |
throughput=dict(required=False, type='int'), |
| 493 |
capacity_tier=dict(required=False, type='str', choices=['S3', 'NONE'], default='S3'), |
| 494 |
instance_tenancy=dict(required=False, type='str', choices=['default', 'dedicated'], default='default'), |
| 495 |
instance_profile_name=dict(required=False, type='str'), |
| 496 |
security_group_id=dict(required=False, type='str'), |
| 497 |
cloud_provider_account=dict(required=False, type='str'), |
| 498 |
backup_volumes_to_cbs=dict(required=False, type='bool', default=False), |
| 499 |
enable_compliance=dict(required=False, type='bool', default=False), |
| 500 |
enable_monitoring=dict(required=False, type='bool', default=False), |
| 501 |
optimized_network_utilization=dict(required=False, type='bool', default=True), |
| 502 |
kms_key_id=dict(required=False, type='str', no_log=True), |
| 503 |
kms_key_arn=dict(required=False, type='str', no_log=True), |
| 504 |
client_id=dict(required=True, type='str'), |
| 505 |
aws_tag=dict(required=False, type='list', elements='dict', options=dict( |
| 506 |
tag_key=dict(type='str', no_log=False), |
| 507 |
tag_value=dict(type='str') |
| 508 |
)), |
| 509 |
is_ha=dict(required=False, type='bool', default=False), |
| 510 |
platform_serial_number_node1=dict(required=False, type='str'), |
| 511 |
platform_serial_number_node2=dict(required=False, type='str'), |
| 512 |
failover_mode=dict(required=False, type='str', choices=['PrivateIP', 'FloatingIP']), |
| 513 |
mediator_assign_public_ip=dict(required=False, type='bool', default=True), |
| 514 |
node1_subnet_id=dict(required=False, type='str'), |
| 515 |
node2_subnet_id=dict(required=False, type='str'), |
| 516 |
mediator_subnet_id=dict(required=False, type='str'), |
| 517 |
mediator_key_pair_name=dict(required=False, type='str'), |
| 518 |
cluster_floating_ip=dict(required=False, type='str'), |
| 519 |
data_floating_ip=dict(required=False, type='str'), |
| 520 |
data_floating_ip2=dict(required=False, type='str'), |
| 521 |
svm_floating_ip=dict(required=False, type='str'), |
| 522 |
route_table_ids=dict(required=False, type='list', elements='str'), |
| 523 |
upgrade_ontap_version=dict(required=False, type='bool', default=False), |
| 524 |
update_svm_password=dict(required=False, type='bool', default=False), |
| 525 |
)) |
| 526 |
|
| 527 |
self.module = AnsibleModule( |
| 528 |
argument_spec=self.argument_spec, |
| 529 |
required_if=[ |
| 530 |
['ebs_volume_type', 'gp3', ['iops', 'throughput']], |
| 531 |
['ebs_volume_type', 'io1', ['iops']], |
| 532 |
['license_type', 'cot-premium-byol', ['platform_serial_number']], |
| 533 |
['license_type', 'ha-cot-premium-byol', ['platform_serial_number_node1', 'platform_serial_number_node2']], |
| 534 |
['license_type', 'capacity-paygo', ['capacity_package_name']], |
| 535 |
['license_type', 'ha-capacity-paygo', ['capacity_package_name']], |
| 536 |
], |
| 537 |
required_one_of=[['refresh_token', 'sa_client_id']], |
| 538 |
mutually_exclusive=[['kms_key_id', 'kms_key_arn']], |
| 539 |
required_together=[['sa_client_id', 'sa_secret_key']], |
| 540 |
supports_check_mode=True, |
| 541 |
) |
| 542 |
|
| 543 |
if HAS_AWS_LIB is False: |
| 544 |
self.module.fail_json(msg="the python AWS library boto3 and botocore is required. Command is pip install boto3." |
| 545 |
"Import error: %s" % str(IMPORT_EXCEPTION)) |
| 546 |
|
| 547 |
self.na_helper = NetAppModule() |
| 548 |
self.parameters = self.na_helper.set_parameters(self.module.params) |
| 549 |
self.changeable_params = ['aws_tag', 'svm_password', 'svm_name', 'tier_level', 'ontap_version', 'instance_type', 'license_type', 'writing_speed_state'] |
| 550 |
self.rest_api = CloudManagerRestAPI(self.module) |
| 551 |
self.rest_api.url += self.rest_api.environment_data['CLOUD_MANAGER_HOST'] |
| 552 |
self.rest_api.api_root_path = '/occm/api/%s' % ('aws/ha' if self.parameters['is_ha'] else 'vsa') |
| 553 |
self.headers = { |
| 554 |
'X-Agent-Id': self.rest_api.format_client_id(self.parameters['client_id']) |
| 555 |
} |
| 556 |
|
| 557 |
def get_vpc(self): |
| 558 |
""" |
| 559 |
Get vpc |
| 560 |
:return: vpc ID |
| 561 |
""" |
| 562 |
vpc_result = None |
| 563 |
ec2 = boto3.client('ec2', region_name=self.parameters['region']) |
| 564 |
|
| 565 |
vpc_input = {'SubnetIds': [self.parameters['subnet_id']]} |
| 566 |
|
| 567 |
try: |
| 568 |
vpc_result = ec2.describe_subnets(**vpc_input) |
| 569 |
except ClientError as error: |
| 570 |
self.module.fail_json(msg=to_native(error), exception=traceback.format_exc()) |
| 571 |
|
| 572 |
return vpc_result['Subnets'][0]['VpcId'] |
| 573 |
|
| 574 |
def create_cvo_aws(self): |
| 575 |
""" Create AWS CVO """ |
| 576 |
if self.parameters.get('workspace_id') is None: |
| 577 |
response, msg = self.na_helper.get_tenant(self.rest_api, self.headers) |
| 578 |
if response is None: |
| 579 |
self.module.fail_json(msg) |
| 580 |
self.parameters['workspace_id'] = response |
| 581 |
|
| 582 |
if self.parameters.get('vpc_id') is None and self.parameters['is_ha'] is False: |
| 583 |
self.parameters['vpc_id'] = self.get_vpc() |
| 584 |
|
| 585 |
if self.parameters.get('nss_account') is None: |
| 586 |
if self.parameters.get('platform_serial_number') is not None: |
| 587 |
if not self.parameters['platform_serial_number'].startswith('Eval-') and self.parameters['license_type'] == 'cot-premium-byol': |
| 588 |
response, msg = self.na_helper.get_nss(self.rest_api, self.headers) |
| 589 |
if response is None: |
| 590 |
self.module.fail_json(msg) |
| 591 |
self.parameters['nss_account'] = response |
| 592 |
elif self.parameters.get('platform_serial_number_node1') is not None and self.parameters.get('platform_serial_number_node2') is not None: |
| 593 |
if not self.parameters['platform_serial_number_node1'].startswith('Eval-')\ |
| 594 |
and not self.parameters['platform_serial_number_node2'].startswith('Eval-')\ |
| 595 |
and self.parameters['license_type'] == 'ha-cot-premium-byol': |
| 596 |
response, msg = self.na_helper.get_nss(self.rest_api, self.headers) |
| 597 |
if response is None: |
| 598 |
self.module.fail_json(msg) |
| 599 |
self.parameters['nss_account'] = response |
| 600 |
|
| 601 |
json = {"name": self.parameters['name'], |
| 602 |
"region": self.parameters['region'], |
| 603 |
"tenantId": self.parameters['workspace_id'], |
| 604 |
"vpcId": self.parameters['vpc_id'], |
| 605 |
"dataEncryptionType": self.parameters['data_encryption_type'], |
| 606 |
"ebsVolumeSize": { |
| 607 |
"size": self.parameters['ebs_volume_size'], |
| 608 |
"unit": self.parameters['ebs_volume_size_unit']}, |
| 609 |
"ebsVolumeType": self.parameters['ebs_volume_type'], |
| 610 |
"svmPassword": self.parameters['svm_password'], |
| 611 |
"backupVolumesToCbs": self.parameters['backup_volumes_to_cbs'], |
| 612 |
"enableCompliance": self.parameters['enable_compliance'], |
| 613 |
"enableMonitoring": self.parameters['enable_monitoring'], |
| 614 |
"optimizedNetworkUtilization": self.parameters['optimized_network_utilization'], |
| 615 |
"vsaMetadata": { |
| 616 |
"ontapVersion": self.parameters['ontap_version'], |
| 617 |
"licenseType": self.parameters['license_type'], |
| 618 |
"useLatestVersion": self.parameters['use_latest_version'], |
| 619 |
"instanceType": self.parameters['instance_type']}, |
| 620 |
} |
| 621 |
|
| 622 |
if self.parameters['capacity_tier'] == "S3": |
| 623 |
json.update({"capacityTier": self.parameters['capacity_tier'], |
| 624 |
"tierLevel": self.parameters['tier_level']}) |
| 625 |
|
| 626 |
# clean default value if it is not by Capacity license |
| 627 |
if not self.parameters['license_type'].endswith('capacity-paygo'): |
| 628 |
json['vsaMetadata'].update({"capacityPackageName": ''}) |
| 629 |
|
| 630 |
if self.parameters.get('platform_serial_number') is not None: |
| 631 |
json['vsaMetadata'].update({"platformSerialNumber": self.parameters['platform_serial_number']}) |
| 632 |
|
| 633 |
if self.parameters.get('provided_license') is not None: |
| 634 |
json['vsaMetadata'].update({"providedLicense": self.parameters['provided_license']}) |
| 635 |
|
| 636 |
if self.parameters.get('capacity_package_name') is not None: |
| 637 |
json['vsaMetadata'].update({"capacityPackageName": self.parameters['capacity_package_name']}) |
| 638 |
|
| 639 |
if self.parameters.get('writing_speed_state') is not None: |
| 640 |
json.update({"writingSpeedState": self.parameters['writing_speed_state'].upper()}) |
| 641 |
|
| 642 |
if self.parameters.get('iops') is not None: |
| 643 |
json.update({"iops": self.parameters['iops']}) |
| 644 |
|
| 645 |
if self.parameters.get('throughput') is not None: |
| 646 |
json.update({"throughput": self.parameters['throughput']}) |
| 647 |
|
| 648 |
if self.parameters.get('cluster_key_pair_name') is not None: |
| 649 |
json.update({"clusterKeyPairName": self.parameters['cluster_key_pair_name']}) |
| 650 |
|
| 651 |
if self.parameters.get('instance_tenancy') is not None: |
| 652 |
json.update({"instanceTenancy": self.parameters['instance_tenancy']}) |
| 653 |
|
| 654 |
if self.parameters.get('instance_profile_name') is not None: |
| 655 |
json.update({"instanceProfileName": self.parameters['instance_profile_name']}) |
| 656 |
|
| 657 |
if self.parameters.get('security_group_id') is not None: |
| 658 |
json.update({"securityGroupId": self.parameters['security_group_id']}) |
| 659 |
|
| 660 |
if self.parameters.get('cloud_provider_account') is not None: |
| 661 |
json.update({"cloudProviderAccount": self.parameters['cloud_provider_account']}) |
| 662 |
|
| 663 |
if self.parameters.get('backup_volumes_to_cbs') is not None: |
| 664 |
json.update({"backupVolumesToCbs": self.parameters['backup_volumes_to_cbs']}) |
| 665 |
|
| 666 |
if self.parameters.get('svm_name') is not None: |
| 667 |
json.update({"svmName": self.parameters['svm_name']}) |
| 668 |
|
| 669 |
if self.parameters['data_encryption_type'] == "AWS": |
| 670 |
if self.parameters.get('kms_key_id') is not None: |
| 671 |
json.update({"awsEncryptionParameters": {"kmsKeyId": self.parameters['kms_key_id']}}) |
| 672 |
if self.parameters.get('kms_key_arn') is not None: |
| 673 |
json.update({"awsEncryptionParameters": {"kmsKeyArn": self.parameters['kms_key_arn']}}) |
| 674 |
|
| 675 |
if self.parameters.get('aws_tag') is not None: |
| 676 |
tags = [] |
| 677 |
for each_tag in self.parameters['aws_tag']: |
| 678 |
tag = { |
| 679 |
'tagKey': each_tag['tag_key'], |
| 680 |
'tagValue': each_tag['tag_value'] |
| 681 |
} |
| 682 |
|
| 683 |
tags.append(tag) |
| 684 |
json.update({"awsTags": tags}) |
| 685 |
|
| 686 |
if self.parameters['is_ha'] is True: |
| 687 |
ha_params = dict({ |
| 688 |
"mediatorAssignPublicIP": self.parameters['mediator_assign_public_ip'] |
| 689 |
}) |
| 690 |
|
| 691 |
if self.parameters.get('failover_mode'): |
| 692 |
ha_params["failoverMode"] = self.parameters['failover_mode'] |
| 693 |
|
| 694 |
if self.parameters.get('node1_subnet_id'): |
| 695 |
ha_params["node1SubnetId"] = self.parameters['node1_subnet_id'] |
| 696 |
|
| 697 |
if self.parameters.get('node2_subnet_id'): |
| 698 |
ha_params["node2SubnetId"] = self.parameters['node2_subnet_id'] |
| 699 |
|
| 700 |
if self.parameters.get('mediator_subnet_id'): |
| 701 |
ha_params["mediatorSubnetId"] = self.parameters['mediator_subnet_id'] |
| 702 |
|
| 703 |
if self.parameters.get('mediator_key_pair_name'): |
| 704 |
ha_params["mediatorKeyPairName"] = self.parameters['mediator_key_pair_name'] |
| 705 |
|
| 706 |
if self.parameters.get('cluster_floating_ip'): |
| 707 |
ha_params["clusterFloatingIP"] = self.parameters['cluster_floating_ip'] |
| 708 |
|
| 709 |
if self.parameters.get('data_floating_ip'): |
| 710 |
ha_params["dataFloatingIP"] = self.parameters['data_floating_ip'] |
| 711 |
|
| 712 |
if self.parameters.get('data_floating_ip2'): |
| 713 |
ha_params["dataFloatingIP2"] = self.parameters['data_floating_ip2'] |
| 714 |
|
| 715 |
if self.parameters.get('svm_floating_ip'): |
| 716 |
ha_params["svmFloatingIP"] = self.parameters['svm_floating_ip'] |
| 717 |
|
| 718 |
if self.parameters.get('route_table_ids'): |
| 719 |
ha_params["routeTableIds"] = self.parameters['route_table_ids'] |
| 720 |
|
| 721 |
if self.parameters.get('platform_serial_number_node1'): |
| 722 |
ha_params["platformSerialNumberNode1"] = self.parameters['platform_serial_number_node1'] |
| 723 |
|
| 724 |
if self.parameters.get('platform_serial_number_node2'): |
| 725 |
ha_params["platformSerialNumberNode2"] = self.parameters['platform_serial_number_node2'] |
| 726 |
|
| 727 |
json["haParams"] = ha_params |
| 728 |
|
| 729 |
else: |
| 730 |
json["subnetId"] = self.parameters['subnet_id'] |
| 731 |
|
| 732 |
api_url = '%s/working-environments' % self.rest_api.api_root_path |
| 733 |
response, error, on_cloud_request_id = self.rest_api.post(api_url, json, header=self.headers) |
| 734 |
if error is not None: |
| 735 |
self.module.fail_json( |
| 736 |
msg="Error: unexpected response on creating cvo aws: %s, %s" % (str(error), str(response))) |
| 737 |
working_environment_id = response['publicId'] |
| 738 |
wait_on_completion_api_url = '/occm/api/audit/activeTask/%s' % str(on_cloud_request_id) |
| 739 |
|
| 740 |
err = self.rest_api.wait_on_completion(wait_on_completion_api_url, "CVO", "create", 60, 90) |
| 741 |
|
| 742 |
if err is not None: |
| 743 |
self.module.fail_json(msg="Error: unexpected response wait_on_completion for creating CVO AWS: %s" % str(err)) |
| 744 |
|
| 745 |
return working_environment_id |
| 746 |
|
| 747 |
def update_cvo_aws(self, working_environment_id, modify): |
| 748 |
base_url = '%s/working-environments/%s/' % (self.rest_api.api_root_path, working_environment_id) |
| 749 |
for item in modify: |
| 750 |
if item == 'svm_password': |
| 751 |
response, error = self.na_helper.update_svm_password(base_url, self.rest_api, self.headers, self.parameters['svm_password']) |
| 752 |
if error is not None: |
| 753 |
self.module.fail_json(changed=False, msg=error) |
| 754 |
if item == 'svm_name': |
| 755 |
response, error = self.na_helper.update_svm_name(base_url, self.rest_api, self.headers, self.parameters['svm_name']) |
| 756 |
if error is not None: |
| 757 |
self.module.fail_json(changed=False, msg=error) |
| 758 |
if item == 'aws_tag': |
| 759 |
tag_list = None |
| 760 |
if 'aws_tag' in self.parameters: |
| 761 |
tag_list = self.parameters['aws_tag'] |
| 762 |
response, error = self.na_helper.update_cvo_tags(base_url, self.rest_api, self.headers, 'aws_tag', tag_list) |
| 763 |
if error is not None: |
| 764 |
self.module.fail_json(changed=False, msg=error) |
| 765 |
if item == 'tier_level': |
| 766 |
response, error = self.na_helper.update_tier_level(base_url, self.rest_api, self.headers, self.parameters['tier_level']) |
| 767 |
if error is not None: |
| 768 |
self.module.fail_json(changed=False, msg=error) |
| 769 |
if item == 'writing_speed_state': |
| 770 |
response, error = self.na_helper.update_writing_speed_state(base_url, self.rest_api, self.headers, self.parameters['writing_speed_state']) |
| 771 |
if error is not None: |
| 772 |
self.module.fail_json(changed=False, msg=error) |
| 773 |
if item == 'ontap_version': |
| 774 |
response, error = self.na_helper.upgrade_ontap_image(self.rest_api, self.headers, self.parameters['ontap_version']) |
| 775 |
if error is not None: |
| 776 |
self.module.fail_json(changed=False, msg=error) |
| 777 |
if item == 'instance_type' or item == 'license_type': |
| 778 |
response, error = self.na_helper.update_instance_license_type(base_url, self.rest_api, self.headers, |
| 779 |
self.parameters['instance_type'], |
| 780 |
self.parameters['license_type']) |
| 781 |
if error is not None: |
| 782 |
self.module.fail_json(changed=False, msg=error) |
| 783 |
|
| 784 |
def delete_cvo_aws(self, we_id): |
| 785 |
""" |
| 786 |
Delete AWS CVO |
| 787 |
""" |
| 788 |
api_url = '%s/working-environments/%s' % (self.rest_api.api_root_path, we_id) |
| 789 |
response, error, on_cloud_request_id = self.rest_api.delete(api_url, None, header=self.headers) |
| 790 |
if error is not None: |
| 791 |
self.module.fail_json(msg="Error: unexpected response on deleting cvo aws: %s, %s" % (str(error), str(response))) |
| 792 |
|
| 793 |
wait_on_completion_api_url = '/occm/api/audit/activeTask/%s' % str(on_cloud_request_id) |
| 794 |
err = self.rest_api.wait_on_completion(wait_on_completion_api_url, "CVO", "delete", 40, 60) |
| 795 |
|
| 796 |
if err is not None: |
| 797 |
self.module.fail_json(msg="Error: unexpected response wait_on_completion for deleting CVO AWS: %s" % str(err)) |
| 798 |
|
| 799 |
def validate_cvo_params(self): |
| 800 |
if self.parameters['use_latest_version'] is True and self.parameters['ontap_version'] != "latest": |
| 801 |
self.module.fail_json(msg="ontap_version parameter not required when having use_latest_version as true") |
| 802 |
|
| 803 |
if self.parameters['is_ha'] is True and self.parameters['license_type'] == "ha-cot-premium-byol": |
| 804 |
if self.parameters.get('platform_serial_number_node1') is None or self.parameters.get('platform_serial_number_node2') is None: |
| 805 |
self.module.fail_json(msg="both platform_serial_number_node1 and platform_serial_number_node2 parameters are required" |
| 806 |
"when having ha type as true and license_type as ha-cot-premium-byol") |
| 807 |
|
| 808 |
if self.parameters['is_ha'] is True and self.parameters['license_type'] == 'capacity-paygo': |
| 809 |
self.parameters['license_type'] = 'ha-capacity-paygo' |
| 810 |
|
| 811 |
def apply(self): |
| 812 |
""" |
| 813 |
Apply action to the Cloud Manager CVO for AWS |
| 814 |
:return: None |
| 815 |
""" |
| 816 |
working_environment_id = None |
| 817 |
modify = None |
| 818 |
current, dummy = self.na_helper.get_working_environment_details_by_name(self.rest_api, self.headers, |
| 819 |
self.parameters['name'], "aws") |
| 820 |
if current: |
| 821 |
self.parameters['working_environment_id'] = current['publicId'] |
| 822 |
# check the action |
| 823 |
cd_action = self.na_helper.get_cd_action(current, self.parameters) |
| 824 |
|
| 825 |
if current and self.parameters['state'] != 'absent': |
| 826 |
# Check mandatory parameters |
| 827 |
self.validate_cvo_params() |
| 828 |
working_environment_id = current['publicId'] |
| 829 |
modify, error = self.na_helper.is_cvo_update_needed(self.rest_api, self.headers, self.parameters, self.changeable_params, 'aws') |
| 830 |
if error is not None: |
| 831 |
self.module.fail_json(changed=False, msg=error) |
| 832 |
|
| 833 |
if self.na_helper.changed and not self.module.check_mode: |
| 834 |
if cd_action == "create": |
| 835 |
self.validate_cvo_params() |
| 836 |
working_environment_id = self.create_cvo_aws() |
| 837 |
elif cd_action == "delete": |
| 838 |
self.delete_cvo_aws(current['publicId']) |
| 839 |
else: |
| 840 |
self.update_cvo_aws(current['publicId'], modify) |
| 841 |
|
| 842 |
self.module.exit_json(changed=self.na_helper.changed, working_environment_id=working_environment_id) |
| 843 |
|
| 844 |
|
| 845 |
def main(): |
| 846 |
""" |
| 847 |
Create Cloud Manager CVO for AWS class instance and invoke apply |
| 848 |
:return: None |
| 849 |
""" |
| 850 |
obj_store = NetAppCloudManagerCVOAWS() |
| 851 |
obj_store.apply() |
| 852 |
|
| 853 |
|
| 854 |
if __name__ == '__main__': |
| 855 |
main() |