Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_batchaccountapplication_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2024 xuzhang3 (@xuzhang3), Fred-sun (@Fred-sun)
4 #
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8 __metaclass__ = type
9
10 DOCUMENTATION = '''
11 ---
12 module: azure_rm_batchaccountapplication_info
13 version_added: "3.0.0"
14 short_description: Get the Batch Account Application facts
15 description:
16 - Get the Batch Account Application 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 application.
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 Application by name
44 azure_rm_batchaccountapplication_info:
45 resource_group: MyResGroup
46 batch_account_name: batchname01
47 name: mybatchaccount
48
49 - name: List the Batch Account Application
50 azure_rm_batchaccountapplication_info:
51 resource_group: MyResGroup
52 batch_account_name: batchname01
53 '''
54
55 RETURN = '''
56 batch_account_application:
57 description:
58 - Contains information about an application in a Batch account.
59 type: complex
60 returned: always
61 contains:
62 id:
63 description:
64 - The ID of the batch account application.
65 type: str
66 returned: always
67 sample: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.Batch/batchAccounts/batch01/applications/app01"
68 resource_group:
69 description:
70 - The resource group name.
71 type: str
72 returned: always
73 sample: testRG
74 batch_account_name:
75 description:
76 - The name of the batch account.
77 type: str
78 returned: always
79 sample: batch01
80 name:
81 description:
82 - The name of the application.
83 type: str
84 returned: always
85 sample: app01
86 allow_updates:
87 description:
88 - A value indicating whether packages within the application may be overwritten using the same version string.
89 type: str
90 returned: always
91 sample: true
92 default_version:
93 description:
94 - The package to use if a client requests the application but does not specify a version.
95 - This property can only be set to the name of an existing package.
96 type: str
97 returned: always
98 sample: null
99 display_name:
100 description:
101 - The display name for the application.
102 type: str
103 returned: always
104 sample: testbatch
105 type:
106 description:
107 - The type of the resource.
108 type: str
109 returned: always
110 sample: Microsoft.Batch/batchAccounts/applications
111 '''
112
113 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase
114
115 try:
116 from azure.core.exceptions import ResourceNotFoundError
117 except ImportError:
118 # This is handled in azure_rm_common
119 pass
120
121
122 class AzureRMBatchAccountApplicationInfo(AzureRMModuleBase):
123 """Configuration class for an Azure RM Batch Account Application package resource"""
124
125 def __init__(self):
126 self.module_arg_spec = dict(
127 resource_group=dict(
128 type='str',
129 required=True,
130 ),
131 batch_account_name=dict(
132 type='str',
133 required=True
134 ),
135 name=dict(
136 type='str',
137 ),
138 )
139
140 self.resource_group = None
141 self.batch_account_name = None
142 self.name = None
143
144 self.results = dict(changed=False)
145
146 super(AzureRMBatchAccountApplicationInfo, self).__init__(derived_arg_spec=self.module_arg_spec,
147 supports_check_mode=True,
148 supports_tags=False)
149
150 def exec_module(self, **kwargs):
151 """Main module execution method"""
152
153 for key in list(self.module_arg_spec.keys()):
154 setattr(self, key, kwargs[key])
155
156 response = []
157
158 if self.name is not None:
159 response = [self.get_batchaccount_application()]
160 else:
161 response = self.list_by_batchaccount_application()
162
163 self.results['batch_account_application'] = [self.format_item(item) for item in response]
164
165 return self.results
166
167 def list_by_batchaccount_application(self):
168 self.log("List all Batch Account in the batch account {0}".format(self.batch_account_name))
169 result = []
170 response = []
171 try:
172 response = self.batch_account_client.application.list(resource_group_name=self.resource_group,
173 account_name=self.batch_account_name)
174 self.log("Response : {0}".format(response))
175 except Exception as e:
176 self.log('Did not find the Batch Account instance. Exception as {0}'.format(e))
177 for item in response:
178 result.append(item.as_dict())
179 return result
180
181 def get_batchaccount_application(self):
182 '''
183 Gets the properties of the specified Batch Account Application
184 '''
185 self.log("Fetch the Batch Account instance {0} is present".format(self.name))
186 try:
187 response = self.batch_account_client.application.get(resource_group_name=self.resource_group,
188 account_name=self.batch_account_name,
189 application_name=self.name)
190 self.log("Response : {0}".format(response))
191 except ResourceNotFoundError:
192 self.log('Did not find the Batch Account Application instance.')
193 return
194 return response.as_dict()
195
196 def format_item(self, item):
197 result = {
198 'resource_group': self.resource_group,
199 'batch_account_name': self.batch_account_name,
200 'id': item['id'],
201 'name': item['name'],
202 'type': item['type'],
203 'display_name': item['display_name'],
204 'allow_updates': item['allow_updates'],
205 'default_version': item['default_version'] if item.get('default_version') is not None else None
206 }
207 return result
208
209
210 def main():
211 """Main execution"""
212 AzureRMBatchAccountApplicationInfo()
213
214
215 if __name__ == '__main__':
216 main()