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