| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
DOCUMENTATION = ''' |
| 11 |
--- |
| 12 |
module: azure_rm_batchaccountpool_info |
| 13 |
version_added: "3.0.0" |
| 14 |
short_description: Get the Batch Account Pool facts |
| 15 |
description: |
| 16 |
- Get the Batch Account Pool facts. |
| 17 |
|
| 18 |
options: |
| 19 |
resource_group: |
| 20 |
description: |
| 21 |
- The name of the resource group in which to create the Batch Account. |
| 22 |
type: str |
| 23 |
required: true |
| 24 |
batch_account_name: |
| 25 |
description: |
| 26 |
- The name of the Batch Account. |
| 27 |
type: str |
| 28 |
required: true |
| 29 |
name: |
| 30 |
description: |
| 31 |
- The name of the batch account pool. |
| 32 |
type: str |
| 33 |
|
| 34 |
extends_documentation_fragment: |
| 35 |
- azure.azcollection.azure |
| 36 |
|
| 37 |
author: |
| 38 |
- xuzhang3 (@xuzhang3) |
| 39 |
- Fred Sun (@Fred-sun) |
| 40 |
''' |
| 41 |
|
| 42 |
EXAMPLES = ''' |
| 43 |
- name: Get the Batch Account Pool by name |
| 44 |
azure_rm_batchaccountpool_info: |
| 45 |
resource_group: MyResGroup |
| 46 |
batch_account_name: batchname01 |
| 47 |
name: mypool01 |
| 48 |
|
| 49 |
- name: List the Batch Account Pool |
| 50 |
azure_rm_batchaccountpool_info: |
| 51 |
resource_group: MyResGroup |
| 52 |
batch_account_name: batchname01 |
| 53 |
''' |
| 54 |
|
| 55 |
RETURN = ''' |
| 56 |
batch_account_pool: |
| 57 |
description: |
| 58 |
- Contains information about an pool in a Batch account. |
| 59 |
type: dict |
| 60 |
returned: always |
| 61 |
sample: { |
| 62 |
"allocation_state": "Steady", |
| 63 |
"allocation_state_transition_time": "2024-11-05T08:58:16.803138Z", |
| 64 |
"batch_account_name": "fredbatch02", |
| 65 |
"creation_time": "2024-11-05T08:58:15.399345Z", |
| 66 |
"current_dedicated_nodes": 0, |
| 67 |
"current_low_priority_nodes": 0, |
| 68 |
"deployment_configuration": { |
| 69 |
"virtual_machine_configuration": { |
| 70 |
"image_reference": { |
| 71 |
"offer": "ubuntu-hpc", |
| 72 |
"publisher": "microsoft-dsvm", |
| 73 |
"sku": "2204", |
| 74 |
"version": "latest" |
| 75 |
}, |
| 76 |
"node_agent_sku_id": "batch.node.ubuntu 22.04", |
| 77 |
"node_placement_configuration": { |
| 78 |
"policy": "Regional" |
| 79 |
}, |
| 80 |
"os_disk": { |
| 81 |
"caching": "None", |
| 82 |
"managed_disk": { |
| 83 |
"storage_account_type": "Premium_LRS" |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
}, |
| 88 |
"etag": "0x8DCFD77FC345CFE", |
| 89 |
"id": "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.Batch/batchAccounts/batch01/pools/pool01", |
| 90 |
"inter_node_communication": "Disabled", |
| 91 |
"last_modified": "2024-11-05T08:58:15.399347Z", |
| 92 |
"name": "poolfredbatch02--002", |
| 93 |
"network_configuration": { |
| 94 |
"dynamic_vnet_assignment_scope": "None", |
| 95 |
"enable_accelerated_networking": false, |
| 96 |
"endpoint_configuration": { |
| 97 |
"inbound_nat_pools": [ |
| 98 |
{ |
| 99 |
"backend_port": 33, |
| 100 |
"frontend_port_range_end": 49999, |
| 101 |
"frontend_port_range_start": 1, |
| 102 |
"name": "nat02", |
| 103 |
"protocol": "UDP" |
| 104 |
} |
| 105 |
] |
| 106 |
}, |
| 107 |
"public_ip_address_configuration": { |
| 108 |
"provision": "BatchManaged" |
| 109 |
}, |
| 110 |
"subnet_id": "/subscriptions/xxx-xxx/resourceGroups/testrg/providers/Microsoft.Network/virtualNetworks/vnet01/subnets/default" |
| 111 |
}, |
| 112 |
"provisioning_state": "Succeeded", |
| 113 |
"provisioning_state_transition_time": "2024-11-05T08:58:15.399345Z", |
| 114 |
"resize_operation_status": { |
| 115 |
"node_deallocation_option": "Requeue", |
| 116 |
"resize_timeout": "PT15M", |
| 117 |
"start_time": "2024-11-05T08:58:15.399317Z", |
| 118 |
"target_dedicated_nodes": 0 |
| 119 |
}, |
| 120 |
"resource_group": "v-xisuRG06", |
| 121 |
"scale_settings": { |
| 122 |
"fixed_scale": { |
| 123 |
"resize_timeout": "PT15M", |
| 124 |
"target_dedicated_nodes": 0, |
| 125 |
"target_low_priority_nodes": 0 |
| 126 |
} |
| 127 |
}, |
| 128 |
"target_node_communication_mode": "Default", |
| 129 |
"task_scheduling_policy": { |
| 130 |
"node_fill_type": "Pack" |
| 131 |
}, |
| 132 |
"task_slots_per_node": 1, |
| 133 |
"type": "Microsoft.Batch/batchAccounts/pools", |
| 134 |
"upgrade_policy": { |
| 135 |
"automatic_os_upgrade_policy": { |
| 136 |
"disable_automatic_rollback": false, |
| 137 |
"enable_automatic_os_upgrade": false, |
| 138 |
"os_rolling_upgrade_deferral": false, |
| 139 |
"use_rolling_upgrade_policy": false |
| 140 |
}, |
| 141 |
"mode": "Manual", |
| 142 |
"rolling_upgrade_policy": { |
| 143 |
"max_batch_instance_percent": 20, |
| 144 |
"max_unhealthy_instance_percent": 20, |
| 145 |
"max_unhealthy_upgraded_instance_percent": 20, |
| 146 |
"pause_time_between_batches": "P0D", |
| 147 |
"rollback_failed_instances_on_policy_breach": false |
| 148 |
} |
| 149 |
}, |
| 150 |
"vm_size": "STANDARD_D2S_V3" |
| 151 |
} |
| 152 |
''' |
| 153 |
|
| 154 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase |
| 155 |
|
| 156 |
try: |
| 157 |
from azure.core.exceptions import ResourceNotFoundError |
| 158 |
except ImportError: |
| 159 |
|
| 160 |
pass |
| 161 |
|
| 162 |
|
| 163 |
class AzureRMBatchAccountPoolInfo(AzureRMModuleBase): |
| 164 |
"""Configuration class for an Azure RM Batch Account Pool package resource""" |
| 165 |
|
| 166 |
def __init__(self): |
| 167 |
self.module_arg_spec = dict( |
| 168 |
resource_group=dict( |
| 169 |
type='str', |
| 170 |
required=True, |
| 171 |
), |
| 172 |
batch_account_name=dict( |
| 173 |
type='str', |
| 174 |
required=True |
| 175 |
), |
| 176 |
name=dict( |
| 177 |
type='str', |
| 178 |
), |
| 179 |
) |
| 180 |
|
| 181 |
self.resource_group = None |
| 182 |
self.batch_account_name = None |
| 183 |
self.name = None |
| 184 |
|
| 185 |
self.results = dict(changed=False) |
| 186 |
|
| 187 |
super(AzureRMBatchAccountPoolInfo, self).__init__(derived_arg_spec=self.module_arg_spec, |
| 188 |
supports_check_mode=True, |
| 189 |
supports_tags=False) |
| 190 |
|
| 191 |
def exec_module(self, **kwargs): |
| 192 |
"""Main module execution method""" |
| 193 |
|
| 194 |
for key in list(self.module_arg_spec.keys()): |
| 195 |
setattr(self, key, kwargs[key]) |
| 196 |
|
| 197 |
response = [] |
| 198 |
|
| 199 |
if self.name is not None: |
| 200 |
response = [self.get_batchaccount_pool()] |
| 201 |
else: |
| 202 |
response = self.list_by_batchaccount_pool() |
| 203 |
|
| 204 |
self.results['batch_account_pool'] = [self.format_item(item) for item in response] |
| 205 |
|
| 206 |
return self.results |
| 207 |
|
| 208 |
def list_by_batchaccount_pool(self): |
| 209 |
self.log("List all Batch Account in the batch account {0}".format(self.batch_account_name)) |
| 210 |
result = [] |
| 211 |
response = [] |
| 212 |
try: |
| 213 |
response = self.batch_account_client.pool.list_by_batch_account(resource_group_name=self.resource_group, |
| 214 |
account_name=self.batch_account_name) |
| 215 |
self.log("Response : {0}".format(response)) |
| 216 |
except Exception as e: |
| 217 |
self.log('Did not find the Batch Account instance. Exception as {0}'.format(e)) |
| 218 |
for item in response: |
| 219 |
result.append(item.as_dict()) |
| 220 |
return result |
| 221 |
|
| 222 |
def get_batchaccount_pool(self): |
| 223 |
''' |
| 224 |
Gets the properties of the specified Batch Account Pool |
| 225 |
''' |
| 226 |
self.log("Fetch the Batch Account instance {0} is present".format(self.name)) |
| 227 |
try: |
| 228 |
response = self.batch_account_client.pool.get(resource_group_name=self.resource_group, |
| 229 |
account_name=self.batch_account_name, |
| 230 |
pool_name=self.name) |
| 231 |
self.log("Response : {0}".format(response)) |
| 232 |
except ResourceNotFoundError: |
| 233 |
self.log('Did not find the Batch Account Pool instance.') |
| 234 |
return |
| 235 |
return response.as_dict() |
| 236 |
|
| 237 |
def format_item(self, item): |
| 238 |
if item is None: |
| 239 |
return |
| 240 |
result = item |
| 241 |
result['resource_group'] = self.resource_group |
| 242 |
result['batch_account_name'] = self.batch_account_name |
| 243 |
return result |
| 244 |
|
| 245 |
|
| 246 |
def main(): |
| 247 |
"""Main execution""" |
| 248 |
AzureRMBatchAccountPoolInfo() |
| 249 |
|
| 250 |
|
| 251 |
if __name__ == '__main__': |
| 252 |
main() |