| 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_info |
| 14 |
version_added: '1.11.0' |
| 15 |
short_description: Get Info onf Azure Red Hat OpenShift Managed Cluster |
| 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: false |
| 23 |
type: str |
| 24 |
name: |
| 25 |
description: |
| 26 |
- Resource name. |
| 27 |
required: false |
| 28 |
type: str |
| 29 |
extends_documentation_fragment: |
| 30 |
- azure.azcollection.azure |
| 31 |
author: |
| 32 |
- Paul Czarkowski (@paulczar) |
| 33 |
''' |
| 34 |
|
| 35 |
EXAMPLES = ''' |
| 36 |
- name: List all Azure Red Hat OpenShift Managed Clusters for a given subscription |
| 37 |
azure_rm_openshiftmanagedcluster_info: |
| 38 |
- name: List all Azure Red Hat OpenShift Managed Clusters for a given resource group |
| 39 |
azure_rm_openshiftmanagedcluster_info: |
| 40 |
resource_group: myResourceGroup |
| 41 |
- name: Get Azure Red Hat OpenShift Managed Clusters |
| 42 |
azure_rm_openshiftmanagedcluster_info: |
| 43 |
resource_group: myResourceGroup |
| 44 |
name: myAzureFirewall |
| 45 |
''' |
| 46 |
|
| 47 |
RETURN = ''' |
| 48 |
id: |
| 49 |
description: |
| 50 |
- Resource ID. |
| 51 |
returned: always |
| 52 |
type: str |
| 53 |
sample: /subscriptions/xx-xx-xx-xx/resourceGroups/mycluster-eastus/providers/Microsoft.RedHatOpenShift/openShiftClusters/mycluster |
| 54 |
name: |
| 55 |
description: |
| 56 |
- Resource name. |
| 57 |
returned: always |
| 58 |
type: str |
| 59 |
sample: mycluster |
| 60 |
type: |
| 61 |
description: |
| 62 |
- Resource type. |
| 63 |
returned: always |
| 64 |
type: str |
| 65 |
sample: Microsoft.RedHatOpenShift/openShiftClusters |
| 66 |
location: |
| 67 |
description: |
| 68 |
- Resource location. |
| 69 |
returned: always |
| 70 |
type: str |
| 71 |
sample: eatus |
| 72 |
properties: |
| 73 |
description: |
| 74 |
- Properties of a OpenShift managed cluster. |
| 75 |
returned: always |
| 76 |
type: complex |
| 77 |
sample: null |
| 78 |
contains: |
| 79 |
provisioningState: |
| 80 |
description: |
| 81 |
- The current deployment or provisioning state, which only appears in the response. |
| 82 |
returned: always |
| 83 |
type: str |
| 84 |
sample: Creating |
| 85 |
clusterProfile: |
| 86 |
description: |
| 87 |
- Configuration for Openshift cluster. |
| 88 |
returned: always |
| 89 |
type: complex |
| 90 |
contains: |
| 91 |
domain: |
| 92 |
description: |
| 93 |
- Domain for the cluster. |
| 94 |
returned: always |
| 95 |
type: str |
| 96 |
sample: mycluster |
| 97 |
version: |
| 98 |
description: |
| 99 |
- Openshift version. |
| 100 |
returned: always |
| 101 |
type: str |
| 102 |
sample: 4.4.17 |
| 103 |
resourceGroupId: |
| 104 |
description: |
| 105 |
- The ID of the cluster resource group. |
| 106 |
returned: always |
| 107 |
type: str |
| 108 |
sample: /subscriptions/xx-xx-xx-xx/resourceGroups/mycluster-eastus-cluster |
| 109 |
fipsValidatedModules: |
| 110 |
description: |
| 111 |
- If FIPS validated crypto modules are used |
| 112 |
type: str |
| 113 |
returned: always |
| 114 |
sample: Enabled |
| 115 |
servicePrincipalProfile: |
| 116 |
description: |
| 117 |
- Service principal. |
| 118 |
type: complex |
| 119 |
returned: always |
| 120 |
contains: |
| 121 |
clientId: |
| 122 |
description: Client ID of the service principal. |
| 123 |
returned: always |
| 124 |
type: str |
| 125 |
sample: xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 126 |
networkProfile: |
| 127 |
description: |
| 128 |
- Configuration for OpenShift networking. |
| 129 |
returned: always |
| 130 |
type: complex |
| 131 |
contains: |
| 132 |
podCidr: |
| 133 |
description: |
| 134 |
- CIDR for the OpenShift Pods. |
| 135 |
returned: always |
| 136 |
type: str |
| 137 |
sample: 10.128.0.0/14 |
| 138 |
serviceCidr: |
| 139 |
description: |
| 140 |
- CIDR for OpenShift Services. |
| 141 |
type: str |
| 142 |
returned: always |
| 143 |
sample: 172.30.0.0/16 |
| 144 |
outboundType: |
| 145 |
description: |
| 146 |
- The OutboundType used for egress traffic. |
| 147 |
type: str |
| 148 |
returned: always |
| 149 |
sample: Loadbalancer |
| 150 |
preconfiguredNSG: |
| 151 |
description: |
| 152 |
- Specifies whether subnets are pre-attached with an NSG |
| 153 |
type: str |
| 154 |
returned: always |
| 155 |
sample: Disabled |
| 156 |
masterProfile: |
| 157 |
description: |
| 158 |
- Configuration for OpenShift master VMs. |
| 159 |
returned: always |
| 160 |
type: complex |
| 161 |
contains: |
| 162 |
vmSize: |
| 163 |
description: |
| 164 |
- Size of agent VMs (immutable). |
| 165 |
type: str |
| 166 |
returned: always |
| 167 |
sample: Standard_D8s_v3 |
| 168 |
subnetId: |
| 169 |
description: |
| 170 |
- The Azure resource ID of the master subnet (immutable). |
| 171 |
type: str |
| 172 |
returned: always |
| 173 |
sample: /subscriptions/xx-xx-xx-xx/resourceGroups/mycluster-eastus/providers/Microsoft.Network/ |
| 174 |
virtualNetworks/mycluster-vnet/subnets/mycluster-worker |
| 175 |
encryptionAtHost: |
| 176 |
description: |
| 177 |
- Whether master virtual machines are encrypted at host. |
| 178 |
type: str |
| 179 |
returned: always |
| 180 |
sample: Disabled |
| 181 |
disk_encryption_set_id: |
| 182 |
description: |
| 183 |
- The resource ID of an associated DiskEncryptionSet, if applicable. |
| 184 |
type: str |
| 185 |
returned: successd |
| 186 |
sample: null |
| 187 |
workerProfiles: |
| 188 |
description: |
| 189 |
- Configuration of OpenShift cluster VMs. |
| 190 |
returned: always |
| 191 |
type: complex |
| 192 |
contains: |
| 193 |
name: |
| 194 |
description: |
| 195 |
- Unique name of the pool profile in the context of the subscription and resource group. |
| 196 |
returned: always |
| 197 |
type: str |
| 198 |
sample: worker |
| 199 |
count: |
| 200 |
description: |
| 201 |
- Number of agents (VMs) to host docker containers. |
| 202 |
returned: always |
| 203 |
type: int |
| 204 |
sample: 3 |
| 205 |
vmSize: |
| 206 |
description: |
| 207 |
- Size of agent VMs. |
| 208 |
returned: always |
| 209 |
type: str |
| 210 |
sample: Standard_D4s_v3 |
| 211 |
diskSizeGB: |
| 212 |
description: |
| 213 |
- disk size in GB. |
| 214 |
returned: always |
| 215 |
type: int |
| 216 |
sample: 128 |
| 217 |
subnetId: |
| 218 |
description: |
| 219 |
- Subnet ID for worker pool. |
| 220 |
returned: always |
| 221 |
type: str |
| 222 |
sample: /subscriptions/xx-xx-xx-xx/resourceGroups/mycluster-eastus/providers/Microsoft.Network/ |
| 223 |
virtualNetworks/mycluster-vnet/subnets/mycluster-worker |
| 224 |
encryptionAtHost: |
| 225 |
description: |
| 226 |
- Whether worker virtual machines are encrypted at host. |
| 227 |
type: str |
| 228 |
returned: always |
| 229 |
sample: Disabled |
| 230 |
ingressProfiles: |
| 231 |
description: |
| 232 |
- Ingress configruation. |
| 233 |
returned: always |
| 234 |
type: list |
| 235 |
sample: [{"name": "default", "visibility": "Public"}, ] |
| 236 |
apiserverProfile: |
| 237 |
description: |
| 238 |
- API server configuration. |
| 239 |
returned: always |
| 240 |
type: complex |
| 241 |
contains: |
| 242 |
visibility: |
| 243 |
description: |
| 244 |
- api server visibility. |
| 245 |
returned: always |
| 246 |
type: str |
| 247 |
sample: Public |
| 248 |
''' |
| 249 |
|
| 250 |
import json |
| 251 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBaseExt |
| 252 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_rest import GenericRestClient |
| 253 |
|
| 254 |
|
| 255 |
class Actions: |
| 256 |
NoAction, Create, Update, Delete = range(4) |
| 257 |
|
| 258 |
|
| 259 |
class AzureRMOpenShiftManagedClustersInfo(AzureRMModuleBaseExt): |
| 260 |
def __init__(self): |
| 261 |
self.module_arg_spec = dict( |
| 262 |
resource_group=dict( |
| 263 |
type='str' |
| 264 |
), |
| 265 |
name=dict( |
| 266 |
type='str' |
| 267 |
) |
| 268 |
) |
| 269 |
|
| 270 |
self.resource_group = None |
| 271 |
self.name = None |
| 272 |
|
| 273 |
self.results = dict(changed=False) |
| 274 |
self.mgmt_client = None |
| 275 |
self.state = None |
| 276 |
self.url = None |
| 277 |
self.status_code = [200] |
| 278 |
|
| 279 |
self.query_parameters = {} |
| 280 |
self.query_parameters['api-version'] = '2023-09-04' |
| 281 |
self.header_parameters = {} |
| 282 |
self.header_parameters['Content-Type'] = 'application/json; charset=utf-8' |
| 283 |
|
| 284 |
self.mgmt_client = None |
| 285 |
super(AzureRMOpenShiftManagedClustersInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False) |
| 286 |
|
| 287 |
def exec_module(self, **kwargs): |
| 288 |
|
| 289 |
for key in self.module_arg_spec: |
| 290 |
setattr(self, key, kwargs[key]) |
| 291 |
|
| 292 |
self.mgmt_client = self.get_mgmt_svc_client(GenericRestClient, |
| 293 |
base_url=self._cloud_environment.endpoints.resource_manager) |
| 294 |
|
| 295 |
if (self.resource_group is not None and self.name is not None): |
| 296 |
self.results['clusters'] = self.get() |
| 297 |
elif (self.resource_group is not None): |
| 298 |
self.results['clusters'] = self.list() |
| 299 |
else: |
| 300 |
self.results['clusters'] = self.listall() |
| 301 |
return self.results |
| 302 |
|
| 303 |
def get(self): |
| 304 |
response = None |
| 305 |
results = {} |
| 306 |
|
| 307 |
self.url = ('/subscriptions' + |
| 308 |
'/{{ subscription_id }}' + |
| 309 |
'/resourceGroups' + |
| 310 |
'/{{ resource_group }}' + |
| 311 |
'/providers' + |
| 312 |
'/Microsoft.RedHatOpenShift' + |
| 313 |
'/openShiftClusters' + |
| 314 |
'/{{ open_shift_managed_cluster_name }}') |
| 315 |
self.url = self.url.replace('{{ subscription_id }}', self.subscription_id) |
| 316 |
self.url = self.url.replace('{{ resource_group }}', self.resource_group) |
| 317 |
self.url = self.url.replace('{{ open_shift_managed_cluster_name }}', self.name) |
| 318 |
|
| 319 |
try: |
| 320 |
response = self.mgmt_client.query(self.url, |
| 321 |
'GET', |
| 322 |
self.query_parameters, |
| 323 |
self.header_parameters, |
| 324 |
None, |
| 325 |
self.status_code, |
| 326 |
600, |
| 327 |
30) |
| 328 |
results = json.loads(response.body()) |
| 329 |
|
| 330 |
except Exception as e: |
| 331 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 332 |
return {} |
| 333 |
|
| 334 |
return self.format_item(results) |
| 335 |
|
| 336 |
def list(self): |
| 337 |
response = None |
| 338 |
results = {} |
| 339 |
|
| 340 |
self.url = ('/subscriptions' + |
| 341 |
'/{{ subscription_id }}' + |
| 342 |
'/resourceGroups' + |
| 343 |
'/{{ resource_group }}' + |
| 344 |
'/providers' + |
| 345 |
'/Microsoft.RedHatOpenShift' + |
| 346 |
'/openShiftClusters') |
| 347 |
self.url = self.url.replace('{{ subscription_id }}', self.subscription_id) |
| 348 |
self.url = self.url.replace('{{ resource_group }}', self.resource_group) |
| 349 |
|
| 350 |
try: |
| 351 |
response = self.mgmt_client.query(self.url, |
| 352 |
'GET', |
| 353 |
self.query_parameters, |
| 354 |
self.header_parameters, |
| 355 |
None, |
| 356 |
self.status_code, |
| 357 |
600, |
| 358 |
30) |
| 359 |
results = json.loads(response.body()) |
| 360 |
|
| 361 |
except Exception as e: |
| 362 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 363 |
|
| 364 |
return [self.format_item(x) for x in results['value']] if results.get('value') else [] |
| 365 |
|
| 366 |
def listall(self): |
| 367 |
response = None |
| 368 |
results = {} |
| 369 |
|
| 370 |
self.url = ('/subscriptions' + |
| 371 |
'/{{ subscription_id }}' + |
| 372 |
'/providers' + |
| 373 |
'/Microsoft.RedHatOpenShift' + |
| 374 |
'/openShiftClusters') |
| 375 |
self.url = self.url.replace('{{ subscription_id }}', self.subscription_id) |
| 376 |
|
| 377 |
try: |
| 378 |
response = self.mgmt_client.query(self.url, |
| 379 |
'GET', |
| 380 |
self.query_parameters, |
| 381 |
self.header_parameters, |
| 382 |
None, |
| 383 |
self.status_code, |
| 384 |
600, |
| 385 |
30) |
| 386 |
results = json.loads(response.body()) |
| 387 |
|
| 388 |
except Exception as e: |
| 389 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 390 |
return results |
| 391 |
|
| 392 |
|
| 393 |
def format_item(self, item): |
| 394 |
return item |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
def main(): |
| 408 |
AzureRMOpenShiftManagedClustersInfo() |
| 409 |
|
| 410 |
|
| 411 |
if __name__ == '__main__': |
| 412 |
main() |