| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: azure_rm_openshiftmanagedcluster |
| 14 |
version_added: '1.2.0' |
| 15 |
short_description: Manage Azure Red Hat OpenShift Managed Cluster instance |
| 16 |
description: |
| 17 |
- Create, update and delete instance of Azure Red Hat OpenShift Managed Cluster instance. |
| 18 |
options: |
| 19 |
resource_group: |
| 20 |
description: |
| 21 |
- The name of the resource group. |
| 22 |
required: true |
| 23 |
type: str |
| 24 |
name: |
| 25 |
description: |
| 26 |
- Resource name. |
| 27 |
required: true |
| 28 |
type: str |
| 29 |
location: |
| 30 |
description: |
| 31 |
- Resource location. |
| 32 |
required: true |
| 33 |
type: str |
| 34 |
cluster_profile: |
| 35 |
description: |
| 36 |
- Configuration for OpenShift cluster. |
| 37 |
type: dict |
| 38 |
default: {} |
| 39 |
suboptions: |
| 40 |
pull_secret: |
| 41 |
description: |
| 42 |
- Pull secret for the cluster (immutable). |
| 43 |
type: str |
| 44 |
domain: |
| 45 |
description: |
| 46 |
- The domain for the cluster (immutable). |
| 47 |
type: str |
| 48 |
cluster_resource_group_id: |
| 49 |
description: |
| 50 |
- The ID of the cluster resource group (immutable). |
| 51 |
type: str |
| 52 |
version: |
| 53 |
description: |
| 54 |
- The Openshift version (immutable). |
| 55 |
type: str |
| 56 |
fips_validated_modules: |
| 57 |
description: |
| 58 |
- If FIPS validated crypto modules are used |
| 59 |
type: str |
| 60 |
choices: |
| 61 |
- Disabled |
| 62 |
- Enabled |
| 63 |
default: Enabled |
| 64 |
service_principal_profile: |
| 65 |
description: |
| 66 |
- service principal. |
| 67 |
type: dict |
| 68 |
suboptions: |
| 69 |
client_id: |
| 70 |
description: |
| 71 |
- Client ID of the service principal (immutable). |
| 72 |
required: true |
| 73 |
type: str |
| 74 |
client_secret: |
| 75 |
description: |
| 76 |
- Client secret of the service principal (immutable). |
| 77 |
required: true |
| 78 |
type: str |
| 79 |
network_profile: |
| 80 |
description: |
| 81 |
- Configuration for OpenShift networking (immutable). |
| 82 |
type: dict |
| 83 |
default: {'pod_cidr' : '10.128.0.0/14', 'service_cidr' : '172.30.0.0/16'} |
| 84 |
suboptions: |
| 85 |
pod_cidr: |
| 86 |
description: |
| 87 |
- CIDR for the OpenShift Pods (immutable). |
| 88 |
type: str |
| 89 |
service_cidr: |
| 90 |
description: |
| 91 |
- CIDR for OpenShift Services (immutable). |
| 92 |
type: str |
| 93 |
outbound_type: |
| 94 |
description: |
| 95 |
- The OutboundType used for egress traffic. |
| 96 |
type: str |
| 97 |
choices: |
| 98 |
- Loadbalancer |
| 99 |
- UserDefinedRouting |
| 100 |
preconfigured_nsg: |
| 101 |
description: |
| 102 |
- Specifies whether subnets are pre-attached with an NSG |
| 103 |
type: str |
| 104 |
choices: |
| 105 |
- Disabled |
| 106 |
- Enabled |
| 107 |
default: Disabled |
| 108 |
master_profile: |
| 109 |
description: |
| 110 |
- Configuration for OpenShift master VMs. |
| 111 |
type: dict |
| 112 |
suboptions: |
| 113 |
vm_size: |
| 114 |
description: |
| 115 |
- Size of agent VMs (immutable). |
| 116 |
type: str |
| 117 |
subnet_id: |
| 118 |
description: |
| 119 |
- The Azure resource ID of the master subnet (immutable). |
| 120 |
required: true |
| 121 |
type: str |
| 122 |
encryption_at_host: |
| 123 |
description: |
| 124 |
- Whether master virtual machines are encrypted at host. |
| 125 |
type: str |
| 126 |
choices: |
| 127 |
- Disabled |
| 128 |
- Enabled |
| 129 |
default: Disabled |
| 130 |
disk_encryption_set_id: |
| 131 |
description: |
| 132 |
- The resource ID of an associated DiskEncryptionSet, if applicable. |
| 133 |
type: str |
| 134 |
worker_profiles: |
| 135 |
description: |
| 136 |
- Configuration for OpenShift worker Vms. |
| 137 |
type: list |
| 138 |
elements: dict |
| 139 |
suboptions: |
| 140 |
name: |
| 141 |
description: name of the worker profile (immutable). |
| 142 |
type: str |
| 143 |
required: true |
| 144 |
choices: |
| 145 |
- worker |
| 146 |
vm_size: |
| 147 |
description: |
| 148 |
- The size of the worker Vms (immutable). |
| 149 |
type: str |
| 150 |
disk_size: |
| 151 |
description: |
| 152 |
- The disk size of the worker VMs in GB. Must be 128 or greater (immutable). |
| 153 |
type: int |
| 154 |
subnet_id: |
| 155 |
description: |
| 156 |
- The Azure resource ID of the worker subnet (immutable). |
| 157 |
type: str |
| 158 |
required: true |
| 159 |
count: |
| 160 |
description: |
| 161 |
- The number of worker VMs. Must be between 3 and 20 (immutable). |
| 162 |
type: int |
| 163 |
encryption_at_host: |
| 164 |
description: |
| 165 |
- Whether worker virtual machines are encrypted at host. |
| 166 |
type: str |
| 167 |
choices: |
| 168 |
- Disabled |
| 169 |
- Enabled |
| 170 |
default: Disabled |
| 171 |
disk_encryption_set_id: |
| 172 |
description: |
| 173 |
- The resource ID of an associated DiskEncryptionSet, if applicable. |
| 174 |
type: str |
| 175 |
api_server_profile: |
| 176 |
description: |
| 177 |
- API server configuration. |
| 178 |
type: dict |
| 179 |
suboptions: |
| 180 |
visibility: |
| 181 |
description: |
| 182 |
- API server visibility. |
| 183 |
type: str |
| 184 |
default: Public |
| 185 |
choices: |
| 186 |
- Public |
| 187 |
- Private |
| 188 |
ip: |
| 189 |
description: |
| 190 |
- IP address of api server (immutable), only appears in response. |
| 191 |
type: str |
| 192 |
url: |
| 193 |
description: |
| 194 |
- Url of api server (immutable), only appears in response. |
| 195 |
type: str |
| 196 |
ingress_profiles: |
| 197 |
description: |
| 198 |
- Ingress profiles configuration. only one profile is supported at the current API version. |
| 199 |
type: list |
| 200 |
elements: dict |
| 201 |
suboptions: |
| 202 |
visibility: |
| 203 |
description: |
| 204 |
- Ingress visibility. |
| 205 |
type: str |
| 206 |
default: Public |
| 207 |
choices: |
| 208 |
- Public |
| 209 |
- Private |
| 210 |
name: |
| 211 |
description: |
| 212 |
- Name of the ingress (immutable). |
| 213 |
type: str |
| 214 |
default: default |
| 215 |
choices: |
| 216 |
- default |
| 217 |
ip: |
| 218 |
description: |
| 219 |
- IP of the ingress (immutable), only appears in response. |
| 220 |
type: str |
| 221 |
provisioning_state: |
| 222 |
description: |
| 223 |
- The current deployment or provisioning state, which only appears in the response. |
| 224 |
type: str |
| 225 |
state: |
| 226 |
description: |
| 227 |
- Assert the state of the OpenShiftManagedCluster. |
| 228 |
- Use C(present) to create or update an OpenShiftManagedCluster and C(absent) to delete it. |
| 229 |
default: present |
| 230 |
type: str |
| 231 |
choices: |
| 232 |
- absent |
| 233 |
- present |
| 234 |
extends_documentation_fragment: |
| 235 |
- azure.azcollection.azure |
| 236 |
- azure.azcollection.azure_tags |
| 237 |
author: |
| 238 |
- Haiyuan Zhang (@haiyuazhang) |
| 239 |
''' |
| 240 |
|
| 241 |
EXAMPLES = ''' |
| 242 |
- name: Create openshift cluster |
| 243 |
azure_rm_openshiftmanagedcluster: |
| 244 |
resource_group: "myResourceGroup" |
| 245 |
name: "myCluster" |
| 246 |
location: "eastus" |
| 247 |
cluster_profile: |
| 248 |
cluster_resource_group_id: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/clusterResourceGroup" |
| 249 |
domain: "mydomain" |
| 250 |
service_principal_profile: |
| 251 |
client_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" |
| 252 |
client_secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
| 253 |
network_profile: |
| 254 |
pod_cidr: "10.128.0.0/14" |
| 255 |
service_cidr: "172.30.0.0/16" |
| 256 |
worker_profiles: |
| 257 |
- name: worker |
| 258 |
vm_size: "Standard_D4s_v3" |
| 259 |
subnet_id: "/subscriptions/xx-xx-xx-xx-xx/resourceGroups/myResourceGroup/Microsoft.Network/virtualNetworks/myVnet/subnets/worker" |
| 260 |
disk_size: 128 |
| 261 |
count: 3 |
| 262 |
master_profile: |
| 263 |
vm_size: "Standard_D8s_v3" |
| 264 |
subnet_id: "/subscriptions/xx-xx-xx-xx-xx/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/master" |
| 265 |
- name: Create openshift cluster with multi parameters |
| 266 |
azure_rm_openshiftmanagedcluster: |
| 267 |
resource_group: "myResourceGroup" |
| 268 |
name: "myCluster" |
| 269 |
location: "eastus" |
| 270 |
cluster_profile: |
| 271 |
cluster_resource_group_id: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/clusterResourceGroup" |
| 272 |
domain: "mydomain" |
| 273 |
fips_validated_modules: Enabled |
| 274 |
service_principal_profile: |
| 275 |
client_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" |
| 276 |
client_secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
| 277 |
network_profile: |
| 278 |
pod_cidr: "10.128.0.0/14" |
| 279 |
service_cidr: "172.30.0.0/16" |
| 280 |
outbound_type: Loadbalancer |
| 281 |
preconfigured_nsg: Disabled |
| 282 |
worker_profiles: |
| 283 |
- name: worker |
| 284 |
vm_size: "Standard_D4s_v3" |
| 285 |
subnet_id: "/subscriptions/xx-xx-xx-xx-xx/resourceGroups/myResourceGroup/Microsoft.Network/virtualNetworks/myVnet/subnets/worker" |
| 286 |
disk_size: 128 |
| 287 |
count: 3 |
| 288 |
encryption_at_host: Disabled |
| 289 |
master_profile: |
| 290 |
vm_size: "Standard_D8s_v3" |
| 291 |
subnet_id: "/subscriptions/xx-xx-xx-xx-xx/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/master" |
| 292 |
encryption_at_host: Disabled |
| 293 |
- name: Delete OpenShift Managed Cluster |
| 294 |
azure_rm_openshiftmanagedcluster: |
| 295 |
resource_group: myResourceGroup |
| 296 |
name: myCluster |
| 297 |
location: eastus |
| 298 |
state: absent |
| 299 |
''' |
| 300 |
|
| 301 |
RETURN = ''' |
| 302 |
id: |
| 303 |
description: |
| 304 |
- Resource ID. |
| 305 |
returned: always |
| 306 |
type: str |
| 307 |
sample: /subscriptions/xx-xx-xx-xx/resourceGroups/mycluster-eastus/providers/Microsoft.RedHatOpenShift/openShiftClusters/mycluster |
| 308 |
name: |
| 309 |
description: |
| 310 |
- Resource name. |
| 311 |
returned: always |
| 312 |
type: str |
| 313 |
sample: mycluster |
| 314 |
type: |
| 315 |
description: |
| 316 |
- Resource type. |
| 317 |
returned: always |
| 318 |
type: str |
| 319 |
sample: Microsoft.RedHatOpenShift/openShiftClusters |
| 320 |
location: |
| 321 |
description: |
| 322 |
- Resource location. |
| 323 |
returned: always |
| 324 |
type: str |
| 325 |
sample: eatus |
| 326 |
properties: |
| 327 |
description: |
| 328 |
- Properties of a OpenShift managed cluster. |
| 329 |
returned: always |
| 330 |
type: complex |
| 331 |
sample: null |
| 332 |
contains: |
| 333 |
provisioningState: |
| 334 |
description: |
| 335 |
- The current deployment or provisioning state, which only appears in the response. |
| 336 |
returned: always |
| 337 |
type: str |
| 338 |
sample: Creating |
| 339 |
clusterProfile: |
| 340 |
description: |
| 341 |
- Configuration for Openshift cluster. |
| 342 |
returned: always |
| 343 |
type: complex |
| 344 |
contains: |
| 345 |
domain: |
| 346 |
description: |
| 347 |
- Domain for the cluster. |
| 348 |
returned: always |
| 349 |
type: str |
| 350 |
sample: mycluster |
| 351 |
version: |
| 352 |
description: |
| 353 |
- Openshift version. |
| 354 |
returned: always |
| 355 |
type: str |
| 356 |
sample: 4.4.17 |
| 357 |
resourceGroupId: |
| 358 |
description: |
| 359 |
- The ID of the cluster resource group. |
| 360 |
returned: always |
| 361 |
type: str |
| 362 |
sample: /subscriptions/xx-xx-xx-xx/resourceGroups/mycluster-eastus-cluster |
| 363 |
fipsValidatedModules: |
| 364 |
description: |
| 365 |
- If FIPS validated crypto modules are used |
| 366 |
type: str |
| 367 |
returned: always |
| 368 |
sample: Enabled |
| 369 |
servicePrincipalProfile: |
| 370 |
description: |
| 371 |
- Service principal. |
| 372 |
type: complex |
| 373 |
returned: always |
| 374 |
contains: |
| 375 |
clientId: |
| 376 |
description: Client ID of the service principal. |
| 377 |
returned: always |
| 378 |
type: str |
| 379 |
sample: xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 380 |
networkProfile: |
| 381 |
description: |
| 382 |
- Configuration for OpenShift networking. |
| 383 |
returned: always |
| 384 |
type: complex |
| 385 |
contains: |
| 386 |
podCidr: |
| 387 |
description: |
| 388 |
- CIDR for the OpenShift Pods. |
| 389 |
returned: always |
| 390 |
type: str |
| 391 |
sample: 10.128.0.0/14 |
| 392 |
serviceCidr: |
| 393 |
description: |
| 394 |
- CIDR for OpenShift Services. |
| 395 |
type: str |
| 396 |
returned: always |
| 397 |
sample: 172.30.0.0/16 |
| 398 |
outboundType: |
| 399 |
description: |
| 400 |
- The OutboundType used for egress traffic. |
| 401 |
type: str |
| 402 |
returned: always |
| 403 |
sample: Loadbalancer |
| 404 |
preconfiguredNSG: |
| 405 |
description: |
| 406 |
- Specifies whether subnets are pre-attached with an NSG |
| 407 |
type: str |
| 408 |
returned: always |
| 409 |
sample: Disabled |
| 410 |
masterProfile: |
| 411 |
description: |
| 412 |
- Configuration for OpenShift master VMs. |
| 413 |
returned: always |
| 414 |
type: complex |
| 415 |
contains: |
| 416 |
vmSize: |
| 417 |
description: |
| 418 |
- Size of agent VMs (immutable). |
| 419 |
type: str |
| 420 |
returned: always |
| 421 |
sample: Standard_D8s_v3 |
| 422 |
subnetId: |
| 423 |
description: |
| 424 |
- The Azure resource ID of the master subnet (immutable). |
| 425 |
type: str |
| 426 |
returned: always |
| 427 |
sample: /subscriptions/xx-xx-xx-xx/resourceGroups/mycluster-eastus/providers/Microsoft.Network/ |
| 428 |
virtualNetworks/mycluster-vnet/subnets/mycluster-worker |
| 429 |
encryptionAtHost: |
| 430 |
description: |
| 431 |
- Whether master virtual machines are encrypted at host. |
| 432 |
type: str |
| 433 |
returned: always |
| 434 |
sample: Disabled |
| 435 |
disk_encryption_set_id: |
| 436 |
description: |
| 437 |
- The resource ID of an associated DiskEncryptionSet, if applicable. |
| 438 |
type: str |
| 439 |
returned: successd |
| 440 |
sample: null |
| 441 |
workerProfiles: |
| 442 |
description: |
| 443 |
- Configuration of OpenShift cluster VMs. |
| 444 |
returned: always |
| 445 |
type: complex |
| 446 |
contains: |
| 447 |
name: |
| 448 |
description: |
| 449 |
- Unique name of the pool profile in the context of the subscription and resource group. |
| 450 |
returned: always |
| 451 |
type: str |
| 452 |
sample: worker |
| 453 |
count: |
| 454 |
description: |
| 455 |
- Number of agents (VMs) to host docker containers. |
| 456 |
returned: always |
| 457 |
type: int |
| 458 |
sample: 3 |
| 459 |
vmSize: |
| 460 |
description: |
| 461 |
- Size of agent VMs. |
| 462 |
returned: always |
| 463 |
type: str |
| 464 |
sample: Standard_D4s_v3 |
| 465 |
diskSizeGB: |
| 466 |
description: |
| 467 |
- disk size in GB. |
| 468 |
returned: always |
| 469 |
type: int |
| 470 |
sample: 128 |
| 471 |
subnetId: |
| 472 |
description: |
| 473 |
- Subnet ID for worker pool. |
| 474 |
returned: always |
| 475 |
type: str |
| 476 |
sample: /subscriptions/xx-xx-xx-xx/resourceGroups/mycluster-eastus/providers/Microsoft.Network/ |
| 477 |
virtualNetworks/mycluster-vnet/subnets/mycluster-worker |
| 478 |
encryptionAtHost: |
| 479 |
description: |
| 480 |
- Whether worker virtual machines are encrypted at host. |
| 481 |
type: str |
| 482 |
returned: always |
| 483 |
sample: Disabled |
| 484 |
ingressProfiles: |
| 485 |
description: |
| 486 |
- Ingress configruation. |
| 487 |
returned: always |
| 488 |
type: list |
| 489 |
sample: [{"name": "default", "visibility": "Public"}, ] |
| 490 |
apiserverProfile: |
| 491 |
description: |
| 492 |
- API server configuration. |
| 493 |
returned: always |
| 494 |
type: complex |
| 495 |
contains: |
| 496 |
visibility: |
| 497 |
description: |
| 498 |
- api server visibility. |
| 499 |
returned: always |
| 500 |
type: str |
| 501 |
sample: Public |
| 502 |
''' |
| 503 |
|
| 504 |
import time |
| 505 |
import json |
| 506 |
import random |
| 507 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBaseExt |
| 508 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_rest import GenericRestClient |
| 509 |
|
| 510 |
|
| 511 |
class Actions: |
| 512 |
NoAction, Create, Update, Delete = range(4) |
| 513 |
|
| 514 |
|
| 515 |
class AzureRMOpenShiftManagedClusters(AzureRMModuleBaseExt): |
| 516 |
def __init__(self): |
| 517 |
self.module_arg_spec = dict( |
| 518 |
resource_group=dict( |
| 519 |
type='str', |
| 520 |
required=True |
| 521 |
), |
| 522 |
name=dict( |
| 523 |
type='str', |
| 524 |
required=True |
| 525 |
), |
| 526 |
location=dict( |
| 527 |
type='str', |
| 528 |
required=True |
| 529 |
), |
| 530 |
cluster_profile=dict( |
| 531 |
type='dict', |
| 532 |
default=dict(), |
| 533 |
options=dict( |
| 534 |
pull_secret=dict( |
| 535 |
type='str', |
| 536 |
no_log=True, |
| 537 |
), |
| 538 |
cluster_resource_group_id=dict( |
| 539 |
type='str', |
| 540 |
), |
| 541 |
domain=dict( |
| 542 |
type='str', |
| 543 |
), |
| 544 |
version=dict( |
| 545 |
type='str', |
| 546 |
), |
| 547 |
fips_validated_modules=dict( |
| 548 |
type='str', |
| 549 |
choices=['Enabled', 'Disabled'], |
| 550 |
default='Enabled' |
| 551 |
), |
| 552 |
), |
| 553 |
), |
| 554 |
service_principal_profile=dict( |
| 555 |
type='dict', |
| 556 |
options=dict( |
| 557 |
client_id=dict( |
| 558 |
type='str', |
| 559 |
required=True |
| 560 |
), |
| 561 |
client_secret=dict( |
| 562 |
type='str', |
| 563 |
no_log=True, |
| 564 |
required=True |
| 565 |
) |
| 566 |
) |
| 567 |
), |
| 568 |
network_profile=dict( |
| 569 |
type='dict', |
| 570 |
options=dict( |
| 571 |
pod_cidr=dict( |
| 572 |
type='str', |
| 573 |
), |
| 574 |
service_cidr=dict( |
| 575 |
type='str', |
| 576 |
), |
| 577 |
outbound_type=dict( |
| 578 |
type='str', |
| 579 |
choices=['Loadbalancer', 'UserDefinedRouting'] |
| 580 |
), |
| 581 |
preconfigured_nsg=dict( |
| 582 |
type='str', |
| 583 |
choices=['Disabled', 'Enabled'], |
| 584 |
default='Disabled' |
| 585 |
) |
| 586 |
), |
| 587 |
default=dict( |
| 588 |
pod_cidr="10.128.0.0/14", |
| 589 |
service_cidr="172.30.0.0/16" |
| 590 |
) |
| 591 |
), |
| 592 |
master_profile=dict( |
| 593 |
type='dict', |
| 594 |
options=dict( |
| 595 |
vm_size=dict( |
| 596 |
type='str' |
| 597 |
), |
| 598 |
subnet_id=dict( |
| 599 |
type='str', |
| 600 |
required=True |
| 601 |
), |
| 602 |
encryption_at_host=dict( |
| 603 |
type='str', |
| 604 |
choices=['Disabled', 'Enabled'], |
| 605 |
default='Disabled' |
| 606 |
), |
| 607 |
disk_encryption_set_id=dict( |
| 608 |
type='str' |
| 609 |
) |
| 610 |
) |
| 611 |
), |
| 612 |
worker_profiles=dict( |
| 613 |
type='list', |
| 614 |
elements='dict', |
| 615 |
options=dict( |
| 616 |
name=dict( |
| 617 |
type='str', |
| 618 |
required=True, |
| 619 |
choices=['worker'] |
| 620 |
), |
| 621 |
count=dict( |
| 622 |
type='int', |
| 623 |
), |
| 624 |
vm_size=dict( |
| 625 |
type='str' |
| 626 |
), |
| 627 |
subnet_id=dict( |
| 628 |
type='str', |
| 629 |
required=True |
| 630 |
), |
| 631 |
disk_size=dict( |
| 632 |
type='int', |
| 633 |
), |
| 634 |
encryption_at_host=dict( |
| 635 |
type='str', |
| 636 |
choices=['Disabled', 'Enabled'], |
| 637 |
default='Disabled' |
| 638 |
), |
| 639 |
disk_encryption_set_id=dict( |
| 640 |
type='str' |
| 641 |
) |
| 642 |
) |
| 643 |
), |
| 644 |
api_server_profile=dict( |
| 645 |
type='dict', |
| 646 |
options=dict( |
| 647 |
visibility=dict( |
| 648 |
type='str', |
| 649 |
choices=['Public', 'Private'], |
| 650 |
default='Public' |
| 651 |
), |
| 652 |
url=dict( |
| 653 |
type='str', |
| 654 |
), |
| 655 |
ip=dict( |
| 656 |
type='str', |
| 657 |
) |
| 658 |
) |
| 659 |
), |
| 660 |
ingress_profiles=dict( |
| 661 |
type='list', |
| 662 |
elements='dict', |
| 663 |
options=dict( |
| 664 |
name=dict( |
| 665 |
type='str', |
| 666 |
choices=['default'], |
| 667 |
default='default' |
| 668 |
), |
| 669 |
visibility=dict( |
| 670 |
type='str', |
| 671 |
choices=['Public', 'Private'], |
| 672 |
default='Public' |
| 673 |
), |
| 674 |
ip=dict( |
| 675 |
type='str', |
| 676 |
) |
| 677 |
) |
| 678 |
), |
| 679 |
provisioning_state=dict( |
| 680 |
type='str', |
| 681 |
), |
| 682 |
state=dict( |
| 683 |
type='str', |
| 684 |
default='present', |
| 685 |
choices=['present', 'absent'] |
| 686 |
) |
| 687 |
) |
| 688 |
|
| 689 |
self.resource_group = None |
| 690 |
self.name = None |
| 691 |
|
| 692 |
self.results = dict(changed=False) |
| 693 |
self.mgmt_client = None |
| 694 |
self.state = None |
| 695 |
self.url = None |
| 696 |
self.status_code = [200, 201, 202] |
| 697 |
self.to_do = Actions.NoAction |
| 698 |
|
| 699 |
self.body = {} |
| 700 |
self.body['properties'] = {} |
| 701 |
self.query_parameters = {} |
| 702 |
self.header_parameters = {} |
| 703 |
|
| 704 |
self.query_parameters['api-version'] = '2023-09-04' |
| 705 |
self.header_parameters['Content-Type'] = 'application/json; charset=utf-8' |
| 706 |
|
| 707 |
super(AzureRMOpenShiftManagedClusters, self).__init__(derived_arg_spec=self.module_arg_spec, |
| 708 |
supports_check_mode=True, |
| 709 |
supports_tags=True) |
| 710 |
|
| 711 |
def exec_module(self, **kwargs): |
| 712 |
for key in list(self.module_arg_spec.keys()) + ['tags']: |
| 713 |
if hasattr(self, key): |
| 714 |
setattr(self, key, kwargs[key]) |
| 715 |
elif kwargs[key] is not None: |
| 716 |
if key == 'cluster_profile': |
| 717 |
self.body['properties']['clusterProfile'] = {} |
| 718 |
for item in ['pull_secret', 'cluster_resource_group_id', 'domain', 'version', 'fips_validated_modules']: |
| 719 |
if not kwargs[key].get(item): |
| 720 |
continue |
| 721 |
if item == 'pull_secret': |
| 722 |
self.body['properties']['clusterProfile']['pullSecret'] = kwargs[key].get(item) |
| 723 |
elif item == 'cluster_resource_group_id': |
| 724 |
self.body['properties']['clusterProfile']['resourceGroupId'] = kwargs[key].get(item) |
| 725 |
elif item == 'domain': |
| 726 |
self.body['properties']['clusterProfile']['domain'] = kwargs[key].get(item) |
| 727 |
elif item == 'version': |
| 728 |
self.body['properties']['clusterProfile']['version'] = kwargs[key].get(item) |
| 729 |
elif item == 'fips_validated_modules': |
| 730 |
self.body['properties']['clusterProfile']['fipsValidatedModules'] = kwargs[key].get(item) |
| 731 |
elif key == 'service_principal_profile': |
| 732 |
self.body['properties']['servicePrincipalProfile'] = {} |
| 733 |
self.body['properties']['servicePrincipalProfile']['ClientId'] = kwargs[key].get('client_id') |
| 734 |
self.body['properties']['servicePrincipalProfile']['clientSecret'] = kwargs[key].get('client_secret') |
| 735 |
elif key == 'network_profile': |
| 736 |
self.body['properties']['networkProfile'] = {} |
| 737 |
for item in kwargs[key].keys(): |
| 738 |
if item == 'pod_cidr': |
| 739 |
self.body['properties']['networkProfile']['podCidr'] = kwargs[key].get(item) |
| 740 |
elif item == 'service_cidr': |
| 741 |
self.body['properties']['networkProfile']['serviceCidr'] = kwargs[key].get(item) |
| 742 |
elif item == 'outbound_type': |
| 743 |
self.body['properties']['networkProfile']['outboundType'] = kwargs[key].get(item) |
| 744 |
elif item == 'preconfigured_nsg': |
| 745 |
self.body['properties']['networkProfile']['preconfiguredNSG'] = kwargs[key].get(item) |
| 746 |
elif key == 'master_profile': |
| 747 |
self.body['properties']['masterProfile'] = {} |
| 748 |
if 'subnet_id' in kwargs[key].keys(): |
| 749 |
self.body['properties']['masterProfile']['subnetId'] = kwargs[key].get('subnet_id') |
| 750 |
if 'disk_encryption_set_id' in kwargs[key].keys(): |
| 751 |
self.body['properties']['masterProfile']['encryptionAtHost'] = kwargs[key].get('disk_encryption_set_id') |
| 752 |
if 'encryption_at_host' in kwargs[key].keys(): |
| 753 |
self.body['properties']['masterProfile']['encryptionAtHost'] = kwargs[key].get('encryption_at_host') |
| 754 |
self.body['properties']['masterProfile']['vmSize'] = kwargs[key].get('vm_size') |
| 755 |
elif key == 'worker_profiles': |
| 756 |
self.body['properties']['workerProfiles'] = [] |
| 757 |
for item in kwargs[key]: |
| 758 |
worker_profile = {} |
| 759 |
if item.get('name') is not None: |
| 760 |
worker_profile['name'] = item['name'] |
| 761 |
if item.get('subnet_id') is not None: |
| 762 |
worker_profile['subnetId'] = item['subnet_id'] |
| 763 |
worker_profile['count'] = item.get('count') |
| 764 |
worker_profile['vmSize'] = item.get('vm_size') |
| 765 |
worker_profile['diskSizeGB'] = item.get('disk_size') |
| 766 |
worker_profile['encryptionAtHost'] = item.get('encryption_at_host') |
| 767 |
worker_profile['DiskEncryptionSetId'] = item.get('disk_encryption_set_id') |
| 768 |
|
| 769 |
self.body['properties']['workerProfiles'].append(worker_profile) |
| 770 |
elif key == 'api_server_profile': |
| 771 |
self.body['properties']['apiserverProfile'] = kwargs[key] |
| 772 |
elif key == 'ingress_profiles': |
| 773 |
self.body['properties']['ingressProfiles'] = kwargs[key] |
| 774 |
elif key == 'provisioning_state': |
| 775 |
self.body['properties']['provisioningState'] = kwargs[key] |
| 776 |
else: |
| 777 |
self.body[key] = kwargs[key] |
| 778 |
|
| 779 |
response = None |
| 780 |
|
| 781 |
self.mgmt_client = self.get_mgmt_svc_client(GenericRestClient, |
| 782 |
base_url=self._cloud_environment.endpoints.resource_manager) |
| 783 |
|
| 784 |
self.url = ('/subscriptions' + |
| 785 |
'/{{ subscription_id }}' + |
| 786 |
'/resourceGroups' + |
| 787 |
'/{{ resource_group }}' + |
| 788 |
'/providers' + |
| 789 |
'/Microsoft.RedHatOpenShift' + |
| 790 |
'/openShiftClusters' + |
| 791 |
'/{{ open_shift_managed_cluster_name }}') |
| 792 |
self.url = self.url.replace('{{ subscription_id }}', self.subscription_id) |
| 793 |
self.url = self.url.replace('{{ resource_group }}', self.resource_group) |
| 794 |
self.url = self.url.replace('{{ open_shift_managed_cluster_name }}', self.name) |
| 795 |
|
| 796 |
old_response = self.get_resource() |
| 797 |
|
| 798 |
if not old_response: |
| 799 |
self.log("OpenShiftManagedCluster instance doesn't exist") |
| 800 |
|
| 801 |
if self.state == 'absent': |
| 802 |
self.log("Old instance didn't exist") |
| 803 |
else: |
| 804 |
self.to_do = Actions.Create |
| 805 |
else: |
| 806 |
self.log('OpenShiftManagedCluster instance already exists') |
| 807 |
|
| 808 |
if self.state == 'absent': |
| 809 |
self.to_do = Actions.Delete |
| 810 |
else: |
| 811 |
modifiers = {} |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
self.fail("module doesn't support cluster update yet") |
| 820 |
|
| 821 |
if (self.to_do == Actions.Create) or (self.to_do == Actions.Update): |
| 822 |
self.log('Need to Create / Update the OpenShiftManagedCluster instance') |
| 823 |
|
| 824 |
if self.check_mode: |
| 825 |
self.results['changed'] = True |
| 826 |
return self.results |
| 827 |
|
| 828 |
response = self.create_update_resource() |
| 829 |
|
| 830 |
self.results['changed'] = True |
| 831 |
self.log('Creation / Update done') |
| 832 |
elif self.to_do == Actions.Delete: |
| 833 |
self.log('OpenShiftManagedCluster instance deleted') |
| 834 |
self.results['changed'] = True |
| 835 |
|
| 836 |
if self.check_mode: |
| 837 |
return self.results |
| 838 |
|
| 839 |
self.delete_resource() |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
while self.get_resource(): |
| 844 |
time.sleep(20) |
| 845 |
else: |
| 846 |
self.log('OpenShiftManagedCluster instance unchanged') |
| 847 |
self.results['changed'] = False |
| 848 |
response = old_response |
| 849 |
|
| 850 |
if response: |
| 851 |
self.results["id"] = response["id"] |
| 852 |
self.results["name"] = response["name"] |
| 853 |
self.results["type"] = response["type"] |
| 854 |
self.results["location"] = response["location"] |
| 855 |
self.results["properties"] = response["properties"] |
| 856 |
|
| 857 |
return self.results |
| 858 |
|
| 859 |
def create_update_resource(self): |
| 860 |
|
| 861 |
if self.to_do == Actions.Create: |
| 862 |
required_profile_for_creation = ["workerProfiles", "clusterProfile", "servicePrincipalProfile", "masterProfile"] |
| 863 |
|
| 864 |
if 'properties' not in self.body: |
| 865 |
self.fail('{0} are required for creating a openshift cluster'.format( |
| 866 |
'[worker_profile, cluster_profile, service_principal_profile, master_profile]')) |
| 867 |
for profile in required_profile_for_creation: |
| 868 |
if profile not in self.body['properties']: |
| 869 |
self.fail('{0} is required for creating a openshift cluster'.format(profile)) |
| 870 |
|
| 871 |
self.set_default() |
| 872 |
|
| 873 |
try: |
| 874 |
response = self.mgmt_client.query(self.url, |
| 875 |
'PUT', |
| 876 |
self.query_parameters, |
| 877 |
self.header_parameters, |
| 878 |
self.body, |
| 879 |
self.status_code, |
| 880 |
600, |
| 881 |
30) |
| 882 |
except Exception as exc: |
| 883 |
self.log('Error attempting to create the OpenShiftManagedCluster instance.') |
| 884 |
self.fail('Error creating the OpenShiftManagedCluster instance: {0}' |
| 885 |
'\n{1}'.format(str(self.body), str(exc))) |
| 886 |
if hasattr(response, 'body'): |
| 887 |
response = json.loads(response.body()) |
| 888 |
elif hasattr(response, 'context'): |
| 889 |
response = response.context['deserialized_data'] |
| 890 |
else: |
| 891 |
self.fail("Create or Updating fail, no match message return, return info as {0}".format(response)) |
| 892 |
|
| 893 |
return response |
| 894 |
|
| 895 |
def delete_resource(self): |
| 896 |
|
| 897 |
try: |
| 898 |
response = self.mgmt_client.query(self.url, |
| 899 |
'DELETE', |
| 900 |
self.query_parameters, |
| 901 |
self.header_parameters, |
| 902 |
None, |
| 903 |
self.status_code, |
| 904 |
600, |
| 905 |
30) |
| 906 |
except Exception as e: |
| 907 |
self.log('Error attempting to delete the OpenShiftManagedCluster instance.') |
| 908 |
self.fail('Error deleting the OpenShiftManagedCluster instance: {0}'.format(str(e))) |
| 909 |
|
| 910 |
return True |
| 911 |
|
| 912 |
def get_resource(self): |
| 913 |
|
| 914 |
found = False |
| 915 |
try: |
| 916 |
response = self.mgmt_client.query(self.url, |
| 917 |
'GET', |
| 918 |
self.query_parameters, |
| 919 |
self.header_parameters, |
| 920 |
None, |
| 921 |
self.status_code, |
| 922 |
600, |
| 923 |
30) |
| 924 |
found = True |
| 925 |
response = json.loads(response.body()) |
| 926 |
found = True |
| 927 |
self.log("Response : {0}".format(response)) |
| 928 |
|
| 929 |
except Exception as e: |
| 930 |
self.log('Did not find the OpenShiftManagedCluster instance.') |
| 931 |
if found is True: |
| 932 |
return response |
| 933 |
|
| 934 |
return False |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
def random_id(self): |
| 942 |
random_id = (''.join(random.choice('abcdefghijklmnopqrstuvwxyz')) + |
| 943 |
''.join(random.choice('abcdefghijklmnopqrstuvwxyz1234567890') |
| 944 |
for key in range(7))) |
| 945 |
return random_id |
| 946 |
|
| 947 |
|
| 948 |
def set_default(self): |
| 949 |
if 'apiserverProfile' not in self.body['properties']: |
| 950 |
api_profile = dict(visibility="Public") |
| 951 |
self.body['properties']['apiserverProfile'] = api_profile |
| 952 |
if 'ingressProfiles' not in self.body['properties']: |
| 953 |
ingress_profile = dict(visibility="Public", name="default") |
| 954 |
self.body['properties']['ingressProfiles'] = [ingress_profile] |
| 955 |
else: |
| 956 |
|
| 957 |
for profile in self.body['properties']['ingressProfiles']: |
| 958 |
profile['name'] = "default" |
| 959 |
if 'name' not in self.body['properties']['workerProfiles'][0]: |
| 960 |
self.body['properties']['workerProfiles'][0]['name'] = 'worker' |
| 961 |
if 'vmSize' not in self.body['properties']['workerProfiles'][0]: |
| 962 |
self.body['properties']['workerProfiles'][0]['vmSize'] = "Standard_D4s_v3" |
| 963 |
if 'diskSizeGB' not in self.body['properties']['workerProfiles'][0]: |
| 964 |
self.body['properties']['workerProfiles'][0]['diskSizeGB'] = 128 |
| 965 |
if 'vmSize' not in self.body['properties']['masterProfile']: |
| 966 |
self.body['properties']['masterProfile']['vmSize'] = "Standard_D8s_v3" |
| 967 |
if 'pullSecret' not in self.body['properties']['clusterProfile']: |
| 968 |
self.body['properties']['clusterProfile']['pullSecret'] = '' |
| 969 |
if 'resourceGroupId' not in self.body['properties']['clusterProfile']: |
| 970 |
resourcegroup_id = "/subscriptions/" + self.subscription_id + "/resourceGroups/" + self.name + "-cluster" |
| 971 |
self.body['properties']['clusterProfile']['resourceGroupId'] = resourcegroup_id |
| 972 |
|
| 973 |
if 'domain' not in self.body['properties']['clusterProfile'] or not self.body['properties']['clusterProfile']['domain']: |
| 974 |
self.body['properties']['clusterProfile']['domain'] = self.random_id() |
| 975 |
|
| 976 |
|
| 977 |
def main(): |
| 978 |
AzureRMOpenShiftManagedClusters() |
| 979 |
|
| 980 |
|
| 981 |
if __name__ == '__main__': |
| 982 |
main() |