| 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_batchaccountapplicationpackage_info |
| 13 |
version_added: "3.0.0" |
| 14 |
short_description: Get the Batch Account Application Package facts |
| 15 |
description: |
| 16 |
- Get the Batch Account Application Package 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 |
application_name: |
| 30 |
description: |
| 31 |
- The name of the batch account application. |
| 32 |
type: str |
| 33 |
required: true |
| 34 |
name: |
| 35 |
description: |
| 36 |
- The name of the batch account application package. |
| 37 |
type: str |
| 38 |
|
| 39 |
extends_documentation_fragment: |
| 40 |
- azure.azcollection.azure |
| 41 |
|
| 42 |
author: |
| 43 |
- xuzhang3 (@xuzhang3) |
| 44 |
- Fred Sun (@Fred-sun) |
| 45 |
''' |
| 46 |
|
| 47 |
EXAMPLES = ''' |
| 48 |
- name: Get the Batch Account Application Package by name |
| 49 |
azure_rm_batchaccountapplicationpackage_info: |
| 50 |
resource_group: MyResGroup |
| 51 |
batch_account_name: batchname01 |
| 52 |
application_name: mybatchaccountapplication |
| 53 |
name: mybatchaccountapplicationpackage |
| 54 |
|
| 55 |
- name: List the Batch Account Application Package |
| 56 |
azure_rm_batchaccountapplicationpackage_info: |
| 57 |
resource_group: MyResGroup |
| 58 |
batch_account_name: batchname01 |
| 59 |
application_name: mybatchaccountapplication |
| 60 |
''' |
| 61 |
|
| 62 |
RETURN = ''' |
| 63 |
batch_account_application_package: |
| 64 |
description: |
| 65 |
- The specified application package/ |
| 66 |
type: complex |
| 67 |
returned: always |
| 68 |
contains: |
| 69 |
id: |
| 70 |
description: |
| 71 |
- The ID of the application package. |
| 72 |
type: str |
| 73 |
returned: always |
| 74 |
sample: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.Batch/batchAccounts/batch01/applications/app01/versions/version01" |
| 75 |
resource_group: |
| 76 |
description: |
| 77 |
- The resource group of the application package. |
| 78 |
type: str |
| 79 |
returned: always |
| 80 |
sample: testRG |
| 81 |
name: |
| 82 |
description: |
| 83 |
- The name of the resource. |
| 84 |
type: str |
| 85 |
returned: always |
| 86 |
sample: version01 |
| 87 |
batch_account_name: |
| 88 |
description: |
| 89 |
- The name of the batch account. |
| 90 |
type: str |
| 91 |
returned: always |
| 92 |
sample: batch01 |
| 93 |
application_name: |
| 94 |
description: |
| 95 |
- The name of the application. |
| 96 |
type: str |
| 97 |
returned: always |
| 98 |
sample: app01 |
| 99 |
etag: |
| 100 |
description: |
| 101 |
- The ETag of the resource, used for concurrency statements. |
| 102 |
type: str |
| 103 |
returned: always |
| 104 |
sample: 0x8DCFCE1E9B31502 |
| 105 |
format: |
| 106 |
description: |
| 107 |
- The format of the application package, if the package is active. |
| 108 |
type: str |
| 109 |
returned: always |
| 110 |
sample: zip |
| 111 |
last_activation_time: |
| 112 |
description: |
| 113 |
- The time at which the package was last activated, if the package is active. |
| 114 |
type: str |
| 115 |
returned: always |
| 116 |
sample: '2024-11-04T15:03:59.834538Z' |
| 117 |
state: |
| 118 |
description: |
| 119 |
- The current state of the application package. |
| 120 |
type: str |
| 121 |
returned: always |
| 122 |
sample: Active |
| 123 |
storage_url: |
| 124 |
description: |
| 125 |
- The URL for the application package in Azure Storage. |
| 126 |
type: str |
| 127 |
returned: always |
| 128 |
sample: null |
| 129 |
storage_url_expiry: |
| 130 |
description: |
| 131 |
- The UTC time at which the Azure Storage URL will expire. |
| 132 |
type: str |
| 133 |
returned: always |
| 134 |
sample: null |
| 135 |
type: |
| 136 |
description: |
| 137 |
- The type of the batch account application package. |
| 138 |
type: str |
| 139 |
returned: always |
| 140 |
sample: Microsoft.Batch/batchAccounts/applications/versions |
| 141 |
''' |
| 142 |
|
| 143 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase |
| 144 |
|
| 145 |
try: |
| 146 |
from azure.core.exceptions import HttpResponseError |
| 147 |
except ImportError: |
| 148 |
|
| 149 |
pass |
| 150 |
|
| 151 |
|
| 152 |
class AzureRMBatchAccountApplicationPackageInfo(AzureRMModuleBase): |
| 153 |
"""Configuration class for an Azure RM Batch Account Application Package resource""" |
| 154 |
|
| 155 |
def __init__(self): |
| 156 |
self.module_arg_spec = dict( |
| 157 |
resource_group=dict( |
| 158 |
type='str', |
| 159 |
required=True, |
| 160 |
), |
| 161 |
batch_account_name=dict( |
| 162 |
type='str', |
| 163 |
required=True |
| 164 |
), |
| 165 |
application_name=dict( |
| 166 |
type='str', |
| 167 |
required=True |
| 168 |
), |
| 169 |
name=dict( |
| 170 |
type='str', |
| 171 |
), |
| 172 |
) |
| 173 |
|
| 174 |
self.resource_group = None |
| 175 |
self.batch_account_name = None |
| 176 |
self.application_name = None |
| 177 |
self.name = None |
| 178 |
|
| 179 |
self.results = dict(changed=False) |
| 180 |
|
| 181 |
super(AzureRMBatchAccountApplicationPackageInfo, self).__init__(derived_arg_spec=self.module_arg_spec, |
| 182 |
supports_check_mode=True, |
| 183 |
supports_tags=False) |
| 184 |
|
| 185 |
def exec_module(self, **kwargs): |
| 186 |
"""Main module execution method""" |
| 187 |
|
| 188 |
for key in list(self.module_arg_spec.keys()): |
| 189 |
setattr(self, key, kwargs[key]) |
| 190 |
|
| 191 |
response = [] |
| 192 |
|
| 193 |
if self.name is not None: |
| 194 |
response = [self.get_application_package()] |
| 195 |
else: |
| 196 |
response = self.list_by_application_package() |
| 197 |
|
| 198 |
self.results['batch_account_application_package'] = [self.format_item(item) for item in response] |
| 199 |
|
| 200 |
return self.results |
| 201 |
|
| 202 |
def list_by_application_package(self): |
| 203 |
self.log("List all Batch Account Application Package in the batch account application {0}".format(self.batch_account_name)) |
| 204 |
result = [] |
| 205 |
response = [] |
| 206 |
try: |
| 207 |
response = self.batch_account_client.application_package.list(resource_group_name=self.resource_group, |
| 208 |
account_name=self.batch_account_name, |
| 209 |
application_name=self.application_name) |
| 210 |
self.log("Response : {0}".format(response)) |
| 211 |
except Exception as e: |
| 212 |
self.log('Did not find the Batch Account instance. Exception as {0}'.format(e)) |
| 213 |
for item in response: |
| 214 |
result.append(item.as_dict()) |
| 215 |
return result |
| 216 |
|
| 217 |
def get_application_package(self): |
| 218 |
''' |
| 219 |
Gets the properties of the specified Batch Account Application Package |
| 220 |
''' |
| 221 |
self.log("Fetch the Batch Account instance {0} is present".format(self.name)) |
| 222 |
try: |
| 223 |
response = self.batch_account_client.application_package.get(resource_group_name=self.resource_group, |
| 224 |
account_name=self.batch_account_name, |
| 225 |
application_name=self.application_name, |
| 226 |
version_name=self.name) |
| 227 |
self.log("Response : {0}".format(response)) |
| 228 |
except HttpResponseError: |
| 229 |
self.log('Did not find the Batch Account Application Package instance.') |
| 230 |
return |
| 231 |
return response.as_dict() if response else None |
| 232 |
|
| 233 |
def format_item(self, item): |
| 234 |
result = { |
| 235 |
'resource_group': self.resource_group, |
| 236 |
'batch_account_name': self.batch_account_name, |
| 237 |
'application_name': self.application_name, |
| 238 |
'id': item['id'], |
| 239 |
'name': item['name'], |
| 240 |
'type': item['type'], |
| 241 |
'etag': item['etag'], |
| 242 |
'state': item['state'], |
| 243 |
'format': item.get('format'), |
| 244 |
'storage_url': item.get('storage_url'), |
| 245 |
'storage_url_expiry': item.get('storage_url_expiry'), |
| 246 |
'last_activation_time': item.get('last_activation_time'), |
| 247 |
} if item is not None else None |
| 248 |
return result |
| 249 |
|
| 250 |
|
| 251 |
def main(): |
| 252 |
"""Main execution""" |
| 253 |
AzureRMBatchAccountApplicationPackageInfo() |
| 254 |
|
| 255 |
|
| 256 |
if __name__ == '__main__': |
| 257 |
main() |