| 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_azure |
| 8 |
''' |
| 9 |
|
| 10 |
from __future__ import absolute_import, division, print_function |
| 11 |
__metaclass__ = type |
| 12 |
|
| 13 |
DOCUMENTATION = ''' |
| 14 |
|
| 15 |
module: na_cloudmanager_cvo_azure |
| 16 |
short_description: NetApp Cloud Manager CVO/working environment in single or HA mode for Azure. |
| 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/working environment in single or HA mode for Azure. |
| 24 |
|
| 25 |
options: |
| 26 |
|
| 27 |
state: |
| 28 |
description: |
| 29 |
- Whether the specified Cloud Manager CVO for AZURE 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 AZURE to manage. |
| 38 |
type: str |
| 39 |
|
| 40 |
subscription_id: |
| 41 |
required: true |
| 42 |
description: |
| 43 |
- The ID of the Azure subscription. |
| 44 |
type: str |
| 45 |
|
| 46 |
instance_type: |
| 47 |
description: |
| 48 |
- The type of instance to use, which depends on the license type you chose. |
| 49 |
- Explore ['Standard_DS3_v2']. |
| 50 |
- Standard ['Standard_DS4_v2, Standard_DS13_v2, Standard_L8s_v2']. |
| 51 |
- Premium ['Standard_DS5_v2', 'Standard_DS14_v2']. |
| 52 |
- For more supported instance types, refer to Cloud Volumes ONTAP Release Notes. |
| 53 |
type: str |
| 54 |
default: Standard_DS4_v2 |
| 55 |
|
| 56 |
license_type: |
| 57 |
description: |
| 58 |
- The type of license to use. |
| 59 |
- For single node by Capacity ['capacity-paygo']. |
| 60 |
- For single node by Node paygo ['azure-cot-explore-paygo', 'azure-cot-standard-paygo', 'azure-cot-premium-paygo']. |
| 61 |
- For single node by Node byol ['azure-cot-premium-byol']. |
| 62 |
- For HA by Capacity ['ha-capacity-paygo']. |
| 63 |
- For HA by Node paygo ['azure-ha-cot-standard-paygo', 'azure-ha-cot-premium-paygo']. |
| 64 |
- For HA by Node byol ['azure-ha-cot-premium-byol']. |
| 65 |
choices: ['azure-cot-standard-paygo', 'azure-cot-premium-paygo', 'azure-cot-premium-byol', \ |
| 66 |
'azure-cot-explore-paygo', 'azure-ha-cot-standard-paygo', 'azure-ha-cot-premium-paygo', \ |
| 67 |
'azure-ha-cot-premium-byol', 'capacity-paygo', 'ha-capacity-paygo'] |
| 68 |
default: 'capacity-paygo' |
| 69 |
type: str |
| 70 |
|
| 71 |
provided_license: |
| 72 |
description: |
| 73 |
- Using a NLF license file for BYOL deployment. |
| 74 |
type: str |
| 75 |
|
| 76 |
capacity_package_name: |
| 77 |
description: |
| 78 |
- Capacity package name is required when selecting a capacity based license. |
| 79 |
- Essential only available with Bring Your Own License Capacity-Based. |
| 80 |
- Professional available as an annual contract from a cloud provider or Bring Your Own License Capacity-Based. |
| 81 |
choices: ['Professional', 'Essential', 'Freemium'] |
| 82 |
default: 'Essential' |
| 83 |
type: str |
| 84 |
version_added: 21.12.0 |
| 85 |
|
| 86 |
workspace_id: |
| 87 |
description: |
| 88 |
- The ID of the Cloud Manager workspace where you want to deploy Cloud Volumes ONTAP. |
| 89 |
- If not provided, Cloud Manager uses the first workspace. |
| 90 |
- You can find the ID from the Workspace tab on [https://cloudmanager.netapp.com]. |
| 91 |
type: str |
| 92 |
|
| 93 |
subnet_id: |
| 94 |
required: true |
| 95 |
description: |
| 96 |
- The name of the subnet for the Cloud Volumes ONTAP system. |
| 97 |
type: str |
| 98 |
|
| 99 |
vnet_id: |
| 100 |
required: true |
| 101 |
description: |
| 102 |
- The name of the virtual network. |
| 103 |
type: str |
| 104 |
|
| 105 |
vnet_resource_group: |
| 106 |
description: |
| 107 |
- The resource group in Azure associated to the virtual network. |
| 108 |
type: str |
| 109 |
|
| 110 |
resource_group: |
| 111 |
description: |
| 112 |
- The resource_group where Cloud Volumes ONTAP will be created. |
| 113 |
- If not provided, Cloud Manager generates the resource group name (name of the working environment/CVO with suffix '-rg'). |
| 114 |
- If the resource group does not exist, it is created. |
| 115 |
type: str |
| 116 |
|
| 117 |
allow_deploy_in_existing_rg: |
| 118 |
description: |
| 119 |
- Indicates if to allow creation in existing resource group. |
| 120 |
type: bool |
| 121 |
default: false |
| 122 |
|
| 123 |
cidr: |
| 124 |
required: true |
| 125 |
description: |
| 126 |
- The CIDR of the VNET. If not provided, resource needs az login to authorize and fetch the cidr details from Azure. |
| 127 |
type: str |
| 128 |
|
| 129 |
location: |
| 130 |
required: true |
| 131 |
description: |
| 132 |
- The location where the working environment will be created. |
| 133 |
type: str |
| 134 |
|
| 135 |
data_encryption_type: |
| 136 |
description: |
| 137 |
- The type of encryption to use for the working environment. |
| 138 |
choices: ['AZURE', 'NONE'] |
| 139 |
default: 'AZURE' |
| 140 |
type: str |
| 141 |
|
| 142 |
azure_encryption_parameters: |
| 143 |
description: |
| 144 |
- AZURE encryption parameters. It is required if using AZURE encryption. |
| 145 |
type: str |
| 146 |
version_added: 21.10.0 |
| 147 |
|
| 148 |
storage_type: |
| 149 |
description: |
| 150 |
- The type of storage for the first data aggregate. |
| 151 |
choices: ['Premium_LRS', 'Standard_LRS', 'StandardSSD_LRS', 'Premium_ZRS'] |
| 152 |
default: 'Premium_LRS' |
| 153 |
type: str |
| 154 |
|
| 155 |
client_id: |
| 156 |
required: true |
| 157 |
description: |
| 158 |
- The connector ID of the Cloud Manager Connector. |
| 159 |
- You can find the ID from the Connector tab on [https://cloudmanager.netapp.com]. |
| 160 |
type: str |
| 161 |
|
| 162 |
disk_size: |
| 163 |
description: |
| 164 |
- Azure volume size for the first data aggregate. |
| 165 |
- For GB, the value can be [100, 500]. |
| 166 |
- For TB, the value can be [1,2,4,8,16]. |
| 167 |
default: 1 |
| 168 |
type: int |
| 169 |
|
| 170 |
disk_size_unit: |
| 171 |
description: |
| 172 |
- The unit for disk size. |
| 173 |
choices: ['GB', 'TB'] |
| 174 |
default: 'TB' |
| 175 |
type: str |
| 176 |
|
| 177 |
security_group_id: |
| 178 |
description: |
| 179 |
- The ID of the security group for the working environment. If not provided, Cloud Manager creates the security group. |
| 180 |
type: str |
| 181 |
|
| 182 |
svm_password: |
| 183 |
required: true |
| 184 |
description: |
| 185 |
- The admin password for Cloud Volumes ONTAP. |
| 186 |
- It will be updated on each run. |
| 187 |
type: str |
| 188 |
|
| 189 |
svm_name: |
| 190 |
description: |
| 191 |
- The name of the SVM. |
| 192 |
type: str |
| 193 |
version_added: 21.22.0 |
| 194 |
|
| 195 |
ontap_version: |
| 196 |
description: |
| 197 |
- The required ONTAP version. Ignored if 'use_latest_version' is set to true. |
| 198 |
type: str |
| 199 |
default: 'latest' |
| 200 |
|
| 201 |
use_latest_version: |
| 202 |
description: |
| 203 |
- Indicates whether to use the latest available ONTAP version. |
| 204 |
type: bool |
| 205 |
default: true |
| 206 |
|
| 207 |
serial_number: |
| 208 |
description: |
| 209 |
- The serial number for the cluster. |
| 210 |
- Required when using one of these, 'azure-cot-premium-byol' or 'azure-ha-cot-premium-byol'. |
| 211 |
type: str |
| 212 |
|
| 213 |
tier_level: |
| 214 |
description: |
| 215 |
- If capacity_tier is Blob, this argument indicates the tiering level. |
| 216 |
choices: ['normal', 'cool'] |
| 217 |
default: 'normal' |
| 218 |
type: str |
| 219 |
|
| 220 |
nss_account: |
| 221 |
description: |
| 222 |
- The NetApp Support Site account ID to use with this Cloud Volumes ONTAP system. |
| 223 |
- If the license type is BYOL and an NSS account isn't provided, Cloud Manager tries to use the first existing NSS account. |
| 224 |
type: str |
| 225 |
|
| 226 |
writing_speed_state: |
| 227 |
description: |
| 228 |
- The write speed setting for Cloud Volumes ONTAP ['NORMAL','HIGH']. |
| 229 |
- This argument is not relevant for HA pairs. |
| 230 |
type: str |
| 231 |
|
| 232 |
capacity_tier: |
| 233 |
description: |
| 234 |
- Whether to enable data tiering for the first data aggregate. |
| 235 |
choices: ['Blob', 'NONE'] |
| 236 |
default: 'Blob' |
| 237 |
type: str |
| 238 |
|
| 239 |
cloud_provider_account: |
| 240 |
description: |
| 241 |
- The cloud provider credentials id to use when deploying the Cloud Volumes ONTAP system. |
| 242 |
- You can find the ID in Cloud Manager from the Settings > Credentials page. |
| 243 |
- If not specified, Cloud Manager uses the instance profile of the Connector. |
| 244 |
type: str |
| 245 |
|
| 246 |
backup_volumes_to_cbs: |
| 247 |
description: |
| 248 |
- Automatically enable back up of all volumes to S3. |
| 249 |
default: false |
| 250 |
type: bool |
| 251 |
|
| 252 |
enable_compliance: |
| 253 |
description: |
| 254 |
- Enable the Cloud Compliance service on the working environment. |
| 255 |
default: false |
| 256 |
type: bool |
| 257 |
|
| 258 |
enable_monitoring: |
| 259 |
description: |
| 260 |
- Enable the Monitoring service on the working environment. |
| 261 |
default: false |
| 262 |
type: bool |
| 263 |
|
| 264 |
azure_tag: |
| 265 |
description: |
| 266 |
- Additional tags for the AZURE CVO working environment. |
| 267 |
type: list |
| 268 |
elements: dict |
| 269 |
suboptions: |
| 270 |
tag_key: |
| 271 |
description: The key of the tag. |
| 272 |
type: str |
| 273 |
tag_value: |
| 274 |
description: The tag value. |
| 275 |
type: str |
| 276 |
is_ha: |
| 277 |
description: |
| 278 |
- Indicate whether the working environment is an HA pair or not. |
| 279 |
type: bool |
| 280 |
default: false |
| 281 |
|
| 282 |
platform_serial_number_node1: |
| 283 |
description: |
| 284 |
- For HA BYOL, the serial number for the first node. |
| 285 |
type: str |
| 286 |
|
| 287 |
platform_serial_number_node2: |
| 288 |
description: |
| 289 |
- For HA BYOL, the serial number for the second node. |
| 290 |
type: str |
| 291 |
|
| 292 |
ha_enable_https: |
| 293 |
description: |
| 294 |
- For HA, enable the HTTPS connection from CVO to storage accounts. This can impact write performance. The default is false. |
| 295 |
type: bool |
| 296 |
version_added: 21.10.0 |
| 297 |
|
| 298 |
upgrade_ontap_version: |
| 299 |
description: |
| 300 |
- Indicates whether to upgrade ONTAP image on the CVO. |
| 301 |
- If the current version already matches the desired version, no action is taken. |
| 302 |
type: bool |
| 303 |
default: false |
| 304 |
version_added: 21.13.0 |
| 305 |
|
| 306 |
update_svm_password: |
| 307 |
description: |
| 308 |
- Indicates whether to update svm_password on the CVO. |
| 309 |
- When set to true, the module is not idempotent, as we cannot read the current password. |
| 310 |
type: bool |
| 311 |
default: false |
| 312 |
version_added: 21.13.0 |
| 313 |
|
| 314 |
availability_zone: |
| 315 |
description: |
| 316 |
- The availability zone on the location configuration. |
| 317 |
type: int |
| 318 |
version_added: 21.20.0 |
| 319 |
|
| 320 |
availability_zone_node1: |
| 321 |
description: |
| 322 |
- The node1 availability zone on the location configuration for HA. |
| 323 |
type: int |
| 324 |
version_added: 21.21.0 |
| 325 |
|
| 326 |
availability_zone_node2: |
| 327 |
description: |
| 328 |
- The node2 availability zone on the location configuration for HA. |
| 329 |
type: int |
| 330 |
version_added: 21.21.0 |
| 331 |
''' |
| 332 |
|
| 333 |
EXAMPLES = """ |
| 334 |
- name: create NetApp Cloud Manager CVO for Azure single |
| 335 |
netapp.cloudmanager.na_cloudmanager_cvo_azure: |
| 336 |
state: present |
| 337 |
refresh_token: "{{ xxxxxxxxxxxxxxx }}" |
| 338 |
name: AnsibleCVO |
| 339 |
location: westus |
| 340 |
subnet_id: subnet-xxxxxxx |
| 341 |
vnet_id: vnetxxxxxxxx |
| 342 |
svm_password: P@assword! |
| 343 |
client_id: "{{ xxxxxxxxxxxxxxx }}" |
| 344 |
writing_speed_state: NORMAL |
| 345 |
azure_tag: [ |
| 346 |
{tag_key: abc, |
| 347 |
tag_value: a123}] |
| 348 |
|
| 349 |
- name: create NetApp Cloud Manager CVO for Azure HA |
| 350 |
netapp.cloudmanager.na_cloudmanager_cvo_azure: |
| 351 |
state: present |
| 352 |
refresh_token: "{{ xxxxxxxxxxxxxxx }}" |
| 353 |
name: AnsibleCVO |
| 354 |
location: westus |
| 355 |
subnet_id: subnet-xxxxxxx |
| 356 |
vnet_id: vnetxxxxxxxx |
| 357 |
svm_password: P@assword! |
| 358 |
client_id: "{{ xxxxxxxxxxxxxxx }}" |
| 359 |
writing_speed_state: NORMAL |
| 360 |
azure_tag: [ |
| 361 |
{tag_key: abc, |
| 362 |
tag_value: a123}] |
| 363 |
is_ha: true |
| 364 |
|
| 365 |
- name: delete NetApp Cloud Manager cvo for Azure |
| 366 |
netapp.cloudmanager.na_cloudmanager_cvo_azure: |
| 367 |
state: absent |
| 368 |
name: ansible |
| 369 |
refresh_token: "{{ xxxxxxxxxxxxxxx }}" |
| 370 |
location: westus |
| 371 |
subnet_id: subnet-xxxxxxx |
| 372 |
vnet_id: vnetxxxxxxxx |
| 373 |
svm_password: P@assword! |
| 374 |
client_id: "{{ xxxxxxxxxxxxxxx }}" |
| 375 |
""" |
| 376 |
|
| 377 |
RETURN = ''' |
| 378 |
working_environment_id: |
| 379 |
description: Newly created AZURE CVO working_environment_id. |
| 380 |
type: str |
| 381 |
returned: success |
| 382 |
''' |
| 383 |
|
| 384 |
from ansible.module_utils.basic import AnsibleModule |
| 385 |
import ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp as netapp_utils |
| 386 |
from ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp_module import NetAppModule |
| 387 |
from ansible_collections.netapp.cloudmanager.plugins.module_utils.netapp import CloudManagerRestAPI |
| 388 |
|
| 389 |
|
| 390 |
AZURE_License_Types = ['azure-cot-standard-paygo', 'azure-cot-premium-paygo', 'azure-cot-premium-byol', 'azure-cot-explore-paygo', |
| 391 |
'azure-ha-cot-standard-paygo', 'azure-ha-cot-premium-paygo', 'azure-ha-cot-premium-byol', 'capacity-paygo', 'ha-capacity-paygo'] |
| 392 |
|
| 393 |
|
| 394 |
class NetAppCloudManagerCVOAZURE: |
| 395 |
""" object initialize and class methods """ |
| 396 |
|
| 397 |
def __init__(self): |
| 398 |
self.use_rest = False |
| 399 |
self.argument_spec = netapp_utils.cloudmanager_host_argument_spec() |
| 400 |
self.argument_spec.update(dict( |
| 401 |
name=dict(required=True, type='str'), |
| 402 |
state=dict(required=False, choices=['present', 'absent'], default='present'), |
| 403 |
instance_type=dict(required=False, type='str', default='Standard_DS4_v2'), |
| 404 |
license_type=dict(required=False, type='str', choices=AZURE_License_Types, default='capacity-paygo'), |
| 405 |
workspace_id=dict(required=False, type='str'), |
| 406 |
capacity_package_name=dict(required=False, type='str', choices=['Professional', 'Essential', 'Freemium'], default='Essential'), |
| 407 |
provided_license=dict(required=False, type='str'), |
| 408 |
subnet_id=dict(required=True, type='str'), |
| 409 |
vnet_id=dict(required=True, type='str'), |
| 410 |
vnet_resource_group=dict(required=False, type='str'), |
| 411 |
resource_group=dict(required=False, type='str'), |
| 412 |
cidr=dict(required=True, type='str'), |
| 413 |
location=dict(required=True, type='str'), |
| 414 |
subscription_id=dict(required=True, type='str'), |
| 415 |
data_encryption_type=dict(required=False, type='str', choices=['AZURE', 'NONE'], default='AZURE'), |
| 416 |
azure_encryption_parameters=dict(required=False, type='str', no_log=True), |
| 417 |
storage_type=dict(required=False, type='str', choices=['Premium_LRS', 'Standard_LRS', 'StandardSSD_LRS', 'Premium_ZRS'], default='Premium_LRS'), |
| 418 |
disk_size=dict(required=False, type='int', default=1), |
| 419 |
disk_size_unit=dict(required=False, type='str', choices=['GB', 'TB'], default='TB'), |
| 420 |
svm_password=dict(required=True, type='str', no_log=True), |
| 421 |
svm_name=dict(required=False, type='str'), |
| 422 |
ontap_version=dict(required=False, type='str', default='latest'), |
| 423 |
use_latest_version=dict(required=False, type='bool', default=True), |
| 424 |
tier_level=dict(required=False, type='str', choices=['normal', 'cool'], default='normal'), |
| 425 |
nss_account=dict(required=False, type='str'), |
| 426 |
writing_speed_state=dict(required=False, type='str'), |
| 427 |
capacity_tier=dict(required=False, type='str', choices=['Blob', 'NONE'], default='Blob'), |
| 428 |
security_group_id=dict(required=False, type='str'), |
| 429 |
cloud_provider_account=dict(required=False, type='str'), |
| 430 |
backup_volumes_to_cbs=dict(required=False, type='bool', default=False), |
| 431 |
enable_compliance=dict(required=False, type='bool', default=False), |
| 432 |
enable_monitoring=dict(required=False, type='bool', default=False), |
| 433 |
allow_deploy_in_existing_rg=dict(required=False, type='bool', default=False), |
| 434 |
client_id=dict(required=True, type='str'), |
| 435 |
azure_tag=dict(required=False, type='list', elements='dict', options=dict( |
| 436 |
tag_key=dict(type='str', no_log=False), |
| 437 |
tag_value=dict(type='str') |
| 438 |
)), |
| 439 |
serial_number=dict(required=False, type='str'), |
| 440 |
is_ha=dict(required=False, type='bool', default=False), |
| 441 |
platform_serial_number_node1=dict(required=False, type='str'), |
| 442 |
platform_serial_number_node2=dict(required=False, type='str'), |
| 443 |
ha_enable_https=dict(required=False, type='bool'), |
| 444 |
upgrade_ontap_version=dict(required=False, type='bool', default=False), |
| 445 |
update_svm_password=dict(required=False, type='bool', default=False), |
| 446 |
availability_zone=dict(required=False, type='int'), |
| 447 |
availability_zone_node1=dict(required=False, type='int'), |
| 448 |
availability_zone_node2=dict(required=False, type='int'), |
| 449 |
)) |
| 450 |
|
| 451 |
self.module = AnsibleModule( |
| 452 |
argument_spec=self.argument_spec, |
| 453 |
required_one_of=[['refresh_token', 'sa_client_id']], |
| 454 |
required_together=[['sa_client_id', 'sa_secret_key']], |
| 455 |
required_if=[ |
| 456 |
['license_type', 'capacity-paygo', ['capacity_package_name']], |
| 457 |
['license_type', 'ha-capacity-paygo', ['capacity_package_name']], |
| 458 |
['license_type', 'azure-cot-premium-byol', ['serial_number']], |
| 459 |
['license_type', 'azure-ha-cot-premium-byol', ['platform_serial_number_node1', 'platform_serial_number_node2']], |
| 460 |
], |
| 461 |
supports_check_mode=True |
| 462 |
) |
| 463 |
|
| 464 |
self.na_helper = NetAppModule() |
| 465 |
self.parameters = self.na_helper.set_parameters(self.module.params) |
| 466 |
self.changeable_params = ['svm_password', 'svm_name', 'azure_tag', 'tier_level', 'ontap_version', |
| 467 |
'instance_type', 'license_type', 'writing_speed_state'] |
| 468 |
self.rest_api = CloudManagerRestAPI(self.module) |
| 469 |
self.rest_api.url += self.rest_api.environment_data['CLOUD_MANAGER_HOST'] |
| 470 |
self.rest_api.api_root_path = '/occm/api/azure/%s' % ('ha' if self.parameters['is_ha'] else 'vsa') |
| 471 |
self.headers = { |
| 472 |
'X-Agent-Id': self.rest_api.format_client_id(self.parameters['client_id']) |
| 473 |
} |
| 474 |
|
| 475 |
def create_cvo_azure(self): |
| 476 |
""" |
| 477 |
Create AZURE CVO |
| 478 |
""" |
| 479 |
if self.parameters.get('workspace_id') is None: |
| 480 |
response, msg = self.na_helper.get_tenant(self.rest_api, self.headers) |
| 481 |
if response is None: |
| 482 |
self.module.fail_json(msg) |
| 483 |
self.parameters['workspace_id'] = response |
| 484 |
|
| 485 |
if self.parameters.get('nss_account') is None: |
| 486 |
if self.parameters.get('serial_number') is not None: |
| 487 |
if not self.parameters['serial_number'].startswith('Eval-') and self.parameters['license_type'] == 'azure-cot-premium-byol': |
| 488 |
response, msg = self.na_helper.get_nss(self.rest_api, self.headers) |
| 489 |
if response is None: |
| 490 |
self.module.fail_json(msg) |
| 491 |
self.parameters['nss_account'] = response |
| 492 |
elif self.parameters.get('platform_serial_number_node1') is not None and self.parameters.get('platform_serial_number_node2') is not None: |
| 493 |
if not self.parameters['platform_serial_number_node1'].startswith('Eval-')\ |
| 494 |
and not self.parameters['platform_serial_number_node2'].startswith('Eval-')\ |
| 495 |
and self.parameters['license_type'] == 'azure-ha-cot-premium-byol': |
| 496 |
response, msg = self.na_helper.get_nss(self.rest_api, self.headers) |
| 497 |
if response is None: |
| 498 |
self.module.fail_json(msg) |
| 499 |
self.parameters['nss_account'] = response |
| 500 |
|
| 501 |
json = {"name": self.parameters['name'], |
| 502 |
"region": self.parameters['location'], |
| 503 |
"subscriptionId": self.parameters['subscription_id'], |
| 504 |
"tenantId": self.parameters['workspace_id'], |
| 505 |
"storageType": self.parameters['storage_type'], |
| 506 |
"dataEncryptionType": self.parameters['data_encryption_type'], |
| 507 |
"optimizedNetworkUtilization": True, |
| 508 |
"diskSize": { |
| 509 |
"size": self.parameters['disk_size'], |
| 510 |
"unit": self.parameters['disk_size_unit']}, |
| 511 |
"svmPassword": self.parameters['svm_password'], |
| 512 |
"backupVolumesToCbs": self.parameters['backup_volumes_to_cbs'], |
| 513 |
"enableCompliance": self.parameters['enable_compliance'], |
| 514 |
"enableMonitoring": self.parameters['enable_monitoring'], |
| 515 |
"vsaMetadata": { |
| 516 |
"ontapVersion": self.parameters['ontap_version'], |
| 517 |
"licenseType": self.parameters['license_type'], |
| 518 |
"useLatestVersion": self.parameters['use_latest_version'], |
| 519 |
"instanceType": self.parameters['instance_type']} |
| 520 |
} |
| 521 |
|
| 522 |
if self.parameters['capacity_tier'] == "Blob": |
| 523 |
json.update({"capacityTier": self.parameters['capacity_tier'], |
| 524 |
"tierLevel": self.parameters['tier_level']}) |
| 525 |
|
| 526 |
if self.parameters.get('provided_license') is not None: |
| 527 |
json['vsaMetadata'].update({"providedLicense": self.parameters['provided_license']}) |
| 528 |
|
| 529 |
# clean default value if it is not by Capacity license |
| 530 |
if not self.parameters['license_type'].endswith('capacity-paygo'): |
| 531 |
json['vsaMetadata'].update({"capacityPackageName": ''}) |
| 532 |
|
| 533 |
if self.parameters.get('capacity_package_name') is not None: |
| 534 |
json['vsaMetadata'].update({"capacityPackageName": self.parameters['capacity_package_name']}) |
| 535 |
|
| 536 |
if self.parameters.get('cidr') is not None: |
| 537 |
json.update({"cidr": self.parameters['cidr']}) |
| 538 |
|
| 539 |
if self.parameters.get('writing_speed_state') is not None: |
| 540 |
json.update({"writingSpeedState": self.parameters['writing_speed_state'].upper()}) |
| 541 |
|
| 542 |
if self.parameters.get('resource_group') is not None: |
| 543 |
json.update({"resourceGroup": self.parameters['resource_group'], |
| 544 |
"allowDeployInExistingRg": self.parameters['allow_deploy_in_existing_rg']}) |
| 545 |
else: |
| 546 |
json.update({"resourceGroup": (self.parameters['name'] + '-rg')}) |
| 547 |
|
| 548 |
if self.parameters.get('serial_number') is not None: |
| 549 |
json.update({"serialNumber": self.parameters['serial_number']}) |
| 550 |
|
| 551 |
if self.parameters.get('security_group_id') is not None: |
| 552 |
json.update({"securityGroupId": self.parameters['security_group_id']}) |
| 553 |
|
| 554 |
if self.parameters.get('cloud_provider_account') is not None: |
| 555 |
json.update({"cloudProviderAccount": self.parameters['cloud_provider_account']}) |
| 556 |
|
| 557 |
if self.parameters.get('backup_volumes_to_cbs') is not None: |
| 558 |
json.update({"backupVolumesToCbs": self.parameters['backup_volumes_to_cbs']}) |
| 559 |
|
| 560 |
if self.parameters.get('nss_account') is not None: |
| 561 |
json.update({"nssAccount": self.parameters['nss_account']}) |
| 562 |
|
| 563 |
if self.parameters.get('availability_zone') is not None: |
| 564 |
json.update({"availabilityZone": self.parameters['availability_zone']}) |
| 565 |
|
| 566 |
if self.parameters['data_encryption_type'] == "AZURE": |
| 567 |
if self.parameters.get('azure_encryption_parameters') is not None: |
| 568 |
json.update({"azureEncryptionParameters": {"key": self.parameters['azure_encryption_parameters']}}) |
| 569 |
|
| 570 |
if self.parameters.get('svm_name') is not None: |
| 571 |
json.update({"svmName": self.parameters['svm_name']}) |
| 572 |
|
| 573 |
if self.parameters.get('azure_tag') is not None: |
| 574 |
tags = [] |
| 575 |
for each_tag in self.parameters['azure_tag']: |
| 576 |
tag = { |
| 577 |
'tagKey': each_tag['tag_key'], |
| 578 |
'tagValue': each_tag['tag_value'] |
| 579 |
} |
| 580 |
|
| 581 |
tags.append(tag) |
| 582 |
json.update({"azureTags": tags}) |
| 583 |
|
| 584 |
if self.parameters['is_ha']: |
| 585 |
ha_params = dict() |
| 586 |
|
| 587 |
if self.parameters.get('platform_serial_number_node1'): |
| 588 |
ha_params["platformSerialNumberNode1"] = self.parameters['platform_serial_number_node1'] |
| 589 |
|
| 590 |
if self.parameters.get('platform_serial_number_node2'): |
| 591 |
ha_params["platformSerialNumberNode2"] = self.parameters['platform_serial_number_node2'] |
| 592 |
|
| 593 |
if self.parameters.get('availability_zone_node1'): |
| 594 |
ha_params["availabilityZoneNode1"] = self.parameters['availability_zone_node1'] |
| 595 |
|
| 596 |
if self.parameters.get('availability_zone_node2'): |
| 597 |
ha_params["availabilityZoneNode2"] = self.parameters['availability_zone_node2'] |
| 598 |
|
| 599 |
if self.parameters.get('ha_enable_https') is not None: |
| 600 |
ha_params['enableHttps'] = self.parameters['ha_enable_https'] |
| 601 |
|
| 602 |
json["haParams"] = ha_params |
| 603 |
|
| 604 |
resource_group = self.parameters['vnet_resource_group'] if self.parameters.get( |
| 605 |
'vnet_resource_group') is not None else self.parameters['resource_group'] |
| 606 |
|
| 607 |
resource_group_path = 'subscriptions/%s/resourceGroups/%s' % (self.parameters['subscription_id'], resource_group) |
| 608 |
vnet_format = '%s/%s' if self.rest_api.simulator else '/%s/providers/Microsoft.Network/virtualNetworks/%s' |
| 609 |
vnet = vnet_format % (resource_group_path, self.parameters['vnet_id']) |
| 610 |
json.update({"vnetId": vnet}) |
| 611 |
json.update({"subnetId": '%s/subnets/%s' % (vnet, self.parameters['subnet_id'])}) |
| 612 |
|
| 613 |
api_url = '%s/working-environments' % self.rest_api.api_root_path |
| 614 |
response, error, on_cloud_request_id = self.rest_api.post(api_url, json, header=self.headers) |
| 615 |
if error is not None: |
| 616 |
self.module.fail_json( |
| 617 |
msg="Error: unexpected response on creating cvo azure: %s, %s" % (str(error), str(response))) |
| 618 |
working_environment_id = response['publicId'] |
| 619 |
wait_on_completion_api_url = '/occm/api/audit/activeTask/%s' % str(on_cloud_request_id) |
| 620 |
err = self.rest_api.wait_on_completion(wait_on_completion_api_url, "CVO", "create", 60, 90) |
| 621 |
|
| 622 |
if err is not None: |
| 623 |
self.module.fail_json(msg="Error: unexpected response wait_on_completion for creating CVO AZURE: %s" % str(err)) |
| 624 |
|
| 625 |
return working_environment_id |
| 626 |
|
| 627 |
def get_extra_azure_tags(self, rest_api, headers): |
| 628 |
# Get extra azure tag from current working environment |
| 629 |
# It is created automatically not from the user input |
| 630 |
we, err = self.na_helper.get_working_environment_details(rest_api, headers) |
| 631 |
if err is not None: |
| 632 |
self.module.fail_json(msg="Error: unexpected response to get CVO AZURE details: %s" % str(err)) |
| 633 |
return [{'tag_key': 'DeployedByOccm', 'tag_value': we['userTags']['DeployedByOccm']}] if 'DeployedByOccm' in \ |
| 634 |
we['userTags'] else [] |
| 635 |
|
| 636 |
def update_cvo_azure(self, working_environment_id, modify): |
| 637 |
base_url = '%s/working-environments/%s/' % (self.rest_api.api_root_path, working_environment_id) |
| 638 |
for item in modify: |
| 639 |
if item == 'svm_password': |
| 640 |
response, error = self.na_helper.update_svm_password(base_url, self.rest_api, self.headers, self.parameters['svm_password']) |
| 641 |
if error is not None: |
| 642 |
self.module.fail_json(changed=False, msg=error) |
| 643 |
if item == 'svm_name': |
| 644 |
response, error = self.na_helper.update_svm_name(base_url, self.rest_api, self.headers, self.parameters['svm_name']) |
| 645 |
if error is not None: |
| 646 |
self.module.fail_json(changed=False, msg=error) |
| 647 |
if item == 'azure_tag': |
| 648 |
# default azure tag |
| 649 |
tag_list = self.get_extra_azure_tags(self.rest_api, self.headers) |
| 650 |
if 'azure_tag' in self.parameters: |
| 651 |
tag_list.extend(self.parameters['azure_tag']) |
| 652 |
response, error = self.na_helper.update_cvo_tags(base_url, self.rest_api, self.headers, 'azure_tag', tag_list) |
| 653 |
if error is not None: |
| 654 |
self.module.fail_json(changed=False, msg=error) |
| 655 |
if item == 'tier_level': |
| 656 |
response, error = self.na_helper.update_tier_level(base_url, self.rest_api, self.headers, self.parameters['tier_level']) |
| 657 |
if error is not None: |
| 658 |
self.module.fail_json(changed=False, msg=error) |
| 659 |
if item == 'writing_speed_state': |
| 660 |
response, error = self.na_helper.update_writing_speed_state(base_url, self.rest_api, self.headers, self.parameters['writing_speed_state']) |
| 661 |
if error is not None: |
| 662 |
self.module.fail_json(changed=False, msg=error) |
| 663 |
if item == 'ontap_version': |
| 664 |
response, error = self.na_helper.upgrade_ontap_image(self.rest_api, self.headers, self.parameters['ontap_version']) |
| 665 |
if error is not None: |
| 666 |
self.module.fail_json(changed=False, msg=error) |
| 667 |
if item == 'instance_type' or item == 'license_type': |
| 668 |
response, error = self.na_helper.update_instance_license_type(base_url, self.rest_api, self.headers, |
| 669 |
self.parameters['instance_type'], |
| 670 |
self.parameters['license_type']) |
| 671 |
if error is not None: |
| 672 |
self.module.fail_json(changed=False, msg=error) |
| 673 |
|
| 674 |
def delete_cvo_azure(self, we_id): |
| 675 |
""" |
| 676 |
Delete AZURE CVO |
| 677 |
""" |
| 678 |
|
| 679 |
api_url = '%s/working-environments/%s' % (self.rest_api.api_root_path, we_id) |
| 680 |
response, error, on_cloud_request_id = self.rest_api.delete(api_url, None, header=self.headers) |
| 681 |
if error is not None: |
| 682 |
self.module.fail_json(msg="Error: unexpected response on deleting cvo azure: %s, %s" % (str(error), str(response))) |
| 683 |
|
| 684 |
wait_on_completion_api_url = '/occm/api/audit/activeTask/%s' % str(on_cloud_request_id) |
| 685 |
err = self.rest_api.wait_on_completion(wait_on_completion_api_url, "CVO", "delete", 40, 60) |
| 686 |
|
| 687 |
if err is not None: |
| 688 |
self.module.fail_json(msg="Error: unexpected response wait_on_completion for deleting CVO AZURE: %s" % str(err)) |
| 689 |
|
| 690 |
def validate_cvo_params(self): |
| 691 |
if self.parameters['use_latest_version'] is True and self.parameters['ontap_version'] != "latest": |
| 692 |
self.module.fail_json(msg="ontap_version parameter not required when having use_latest_version as true") |
| 693 |
|
| 694 |
if self.parameters.get('serial_number') is None and self.parameters['license_type'] == "azure-cot-premium-byol": |
| 695 |
self.module.fail_json(msg="serial_number parameter required when having license_type as azure-cot-premium-byol") |
| 696 |
|
| 697 |
if self.parameters['is_ha'] and self.parameters['license_type'] == "azure-ha-cot-premium-byol": |
| 698 |
if self.parameters.get('platform_serial_number_node1') is None or self.parameters.get('platform_serial_number_node2') is None: |
| 699 |
self.module.fail_json(msg="both platform_serial_number_node1 and platform_serial_number_node2 parameters are required" |
| 700 |
"when having ha type as true and license_type as azure-ha-cot-premium-byol") |
| 701 |
if self.parameters['is_ha'] is True and self.parameters['license_type'] == 'capacity-paygo': |
| 702 |
self.parameters['license_type'] == 'ha-capacity-paygo' |
| 703 |
|
| 704 |
def apply(self): |
| 705 |
""" |
| 706 |
Apply action to the Cloud Manager CVO for AZURE |
| 707 |
:return: None |
| 708 |
""" |
| 709 |
working_environment_id = None |
| 710 |
modify = None |
| 711 |
current, dummy = self.na_helper.get_working_environment_details_by_name(self.rest_api, self.headers, |
| 712 |
self.parameters['name'], "azure") |
| 713 |
if current: |
| 714 |
self.parameters['working_environment_id'] = current['publicId'] |
| 715 |
# check the action whether to create, delete, or not |
| 716 |
cd_action = self.na_helper.get_cd_action(current, self.parameters) |
| 717 |
|
| 718 |
if current and self.parameters['state'] != 'absent': |
| 719 |
working_environment_id = current['publicId'] |
| 720 |
modify, error = self.na_helper.is_cvo_update_needed(self.rest_api, self.headers, self.parameters, self.changeable_params, 'azure') |
| 721 |
if error is not None: |
| 722 |
self.module.fail_json(changed=False, msg=error) |
| 723 |
|
| 724 |
if self.na_helper.changed and not self.module.check_mode: |
| 725 |
if cd_action == "create": |
| 726 |
self.validate_cvo_params() |
| 727 |
working_environment_id = self.create_cvo_azure() |
| 728 |
elif cd_action == "delete": |
| 729 |
self.delete_cvo_azure(current['publicId']) |
| 730 |
else: |
| 731 |
self.update_cvo_azure(current['publicId'], modify) |
| 732 |
|
| 733 |
self.module.exit_json(changed=self.na_helper.changed, working_environment_id=working_environment_id) |
| 734 |
|
| 735 |
|
| 736 |
def main(): |
| 737 |
""" |
| 738 |
Create Cloud Manager CVO for AZURE class instance and invoke apply |
| 739 |
:return: None |
| 740 |
""" |
| 741 |
obj_store = NetAppCloudManagerCVOAZURE() |
| 742 |
obj_store.apply() |
| 743 |
|
| 744 |
|
| 745 |
if __name__ == '__main__': |
| 746 |
main() |