Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2022 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
11 DOCUMENTATION = '''
12 ---
13 module: azure_rm_sqlmanagedinstance_info
14 version_added: "0.15.0"
15 short_description: Get Azure SQL managed instance facts
16 description:
17 - Get facts of Azure SQL managed instance facts.
18
19 options:
20 resource_group:
21 description:
22 - The name of the resource group that contains the resource.
23 type: str
24 name:
25 description:
26 - The name of the SQL managed instance.
27 type: str
28 tags:
29 description:
30 - Limit results by providing a list of tags. Format tags as 'key' or 'key:value'.
31 type: list
32 elements: 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 SQL managed instance by name
44 azure_rm_sqlmanagedinstance_info:
45 resource_group: testrg
46 name: testinstancename
47
48 - name: List SQL managed instance by resource group
49 azure_rm_sqlmanagedinstance_info:
50 resource_group: testrg
51
52 - name: List SQL managed instance by subscription and filter by tags
53 azure_rm_sqlmanagedinstance_info:
54 tags:
55 - foo
56 '''
57
58 RETURN = '''
59 sql_managed_instance:
60 description:
61 - A list of dictionaries containing facts for SQL Managed Instance.
62 returned: always
63 type: complex
64 contains:
65 id:
66 description:
67 - Resource ID.
68 returned: always
69 type: str
70 sample: "/subscription/xxx-xxx/resourceGroups/testRG/providers/Microsoft.Sql/managedInstances/fredsqlinstance"
71 name:
72 description:
73 - SQL managed instance name.
74 returned: always
75 type: str
76 sample: testmanagedinstance
77 location:
78 description:
79 - Resource location.
80 returned: always
81 type: str
82 sample: eastus
83 tags:
84 description:
85 - Resource tags.
86 returned: always
87 type: dict
88 sample: { 'taga':'aaa', 'tagb':'bbb' }
89 identity:
90 description:
91 - Azure Active Directory identity configuration for a resource.
92 returned: always
93 type: complex
94 contains:
95 principal_id:
96 description:
97 - The Azure Active Directory principal ID.
98 type: str
99 returned: always
100 sample: 895c-xxx-xxxbe
101 tenant_id:
102 description:
103 - The Azure Active Directory tenant ID.
104 type: str
105 returned: always
106 sample: 72fxxxxx-xxxx-xxxx-xxxx-xxxxxx11db47
107 type:
108 description:
109 - The identity type.
110 type: str
111 returned: always
112 sample: SystemAssigned
113 user_assigned_identities:
114 description:
115 - The resource ids of the user assigned identities to use.
116 type: str
117 returned: always
118 sample: null
119 sku:
120 description:
121 - An ARM Resource SKU.
122 returned: always
123 type: complex
124 contains:
125 name:
126 description:
127 - The name of the SKU.
128 returned: always
129 type: str
130 sample: BC_Gen4_2
131 tier:
132 description:
133 - The SKU tier.
134 returned: always
135 type: str
136 sample: BusinessCritical
137 capacity:
138 description:
139 - The SKU capacity.
140 returned: always
141 type: int
142 sample: 2
143 family:
144 description:
145 - If the service has different generations of hardware, for the same SKU, then that can be captured here.
146 type: str
147 returned: always
148 sample: Gen5
149 size:
150 description:
151 - Size of the particular SKU.
152 type: str
153 returned: always
154 sample: null
155 collation:
156 description:
157 - The collation of the SQL managed instance.
158 returned: always
159 type: str
160 sample: SQL_Latin1_General_CP1_CI_AS
161 administrator_login:
162 description:
163 - Administrator username for the managed instance.
164 type: str
165 returned: always
166 sample: azureuser
167 administrators:
168 description:
169 - The Azure Active Directory administrator of the server.
170 type: str
171 returned: always
172 sample: null
173 dns_zone:
174 description:
175 -The Dns Zone that the managed instance is in.
176 type: str
177 returned: always
178 sample: 8a23abba54cd
179 dns_zone_partner:
180 description:
181 - The resource id of another managed instance whose DNS zone this managed instance will share after creation.
182 type: str
183 returned: always
184 sample: null
185 fully_qualified_domain_name:
186 description:
187 - The fully qualified domain name of the managed instance.
188 type: str
189 returned: always
190 sample: fredsqlinstance.8a23abba54cd.database.windows.net
191 instance_pool_id:
192 description:
193 - The ID of the instance pool this managed server belongs to.
194 type: str
195 returned: always
196 sample: null
197 key_id:
198 description:
199 - A CMK URI of the key to use for encryption.
200 type: str
201 returned: always
202 sample: null
203 license_type:
204 description:
205 - The license type.
206 type: str
207 returned: always
208 sample: LicenseIncluded
209 maintenance_configuration_id:
210 description:
211 - Specifies maintenance configuration ID to apply to this managed instance.
212 type: str
213 returned: always
214 sample: /subscriptions/xxx-xxxx/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_Default
215 managed_instance_create_mode:
216 description:
217 - Specifies the mode of database creation.
218 type: str
219 returned: always
220 sample: null
221 minimal_tls_version:
222 description:
223 - Minimal TLS version. Allowed values 'None', '1.0', '1.1', '1.2'.
224 type: str
225 returned: always
226 sample: 1.2
227 primary_user_assigned_identity_id:
228 description:
229 - The resource ID of a user assigned identity to be used by default.
230 type: str
231 returned: always
232 sample: null
233 private_endpoint_connections:
234 description:
235 - List of private endpoint connections on a managed instance.
236 type: list
237 returned: always
238 sample: []
239 provisioning_state:
240 description:
241 - The Status of the SQL managed instance.
242 type: str
243 returned: always
244 sample: Successed
245 proxy_override:
246 description:
247 - Connection type used for connecting to the instance.
248 type: str
249 returned: always
250 sample: Proxy
251 public_data_endpoint_enabled:
252 description:
253 - Whether or not the public data endpoint is enabled.
254 type: bool
255 returned: always
256 sample: false
257 restore_point_in_time:
258 description:
259 - Specifies the point in time (ISO8601 format) of the source database that will be restored to create the new database.
260 type: str
261 returned: always
262 sample: null
263 source_managed_instance_id:
264 description:
265 - The resource identifier of the source managed instance associated with create operation of this instance.
266 type: str
267 returned: always
268 sample: null
269 state:
270 description:
271 - The state of the managed instance.
272 type: str
273 returned: always
274 sample: Ready
275 storage_account_type:
276 description:
277 - The storage account type used to store backups for this instance.
278 type: str
279 returned: always
280 sample: GRS
281 storage_size_in_gb:
282 description:
283 - Storage size in GB. Minimum value 32. Maximum value 8192.
284 type: int
285 returned: always
286 sample: 256
287 subnet_id:
288 description:
289 - Subnet resource ID for the managed instance.
290 type: str
291 returned: always
292 sample: /subscriptions/xxx-xxxx/resourceGroups/testRG/providers/Microsoft.Network/virtualNetworks/vnet-smi/subnets/sqi_sub
293 timezone_id:
294 description:
295 - ID of the timezone. Allowed values are timezones supported by Windows.
296 type: str
297 returned: always
298 sample: UTC
299 type:
300 description:
301 - The SQL managed instance type.
302 type: str
303 returned: always
304 sample: "Microsoft.Sql/managedInstances"
305 v_cores:
306 description:
307 - The number of vCores. Allowed values 8, 16, 24, 32, 40, 64, 80.
308 type: int
309 returned: always
310 sample: 8
311 zone_redundant:
312 description:
313 - Whether or not the multi-az is enabled.
314 type: bool
315 returned: always
316 sample: false
317 '''
318
319 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
320
321 try:
322 from azure.core.exceptions import ResourceNotFoundError
323 except ImportError:
324 # This is handled in azure_rm_common
325 pass
326
327
328 class AzureRMSqManagedInstanceInfo(AzureRMModuleBase):
329 def __init__(self):
330 # define user inputs into argument
331 self.module_arg_spec = dict(
332 resource_group=dict(
333 type='str',
334 ),
335 name=dict(
336 type='str',
337 ),
338 tags=dict(
339 type='list',
340 elements='str'
341 )
342 )
343 # store the results of the module operation
344 self.results = dict(
345 changed=False
346 )
347 self.resource_group = None
348 self.name = None
349 self.tags = None
350 super(AzureRMSqManagedInstanceInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=True)
351
352 def exec_module(self, **kwargs):
353 for key in self.module_arg_spec:
354 setattr(self, key, kwargs[key])
355
356 if self.name is not None and self.resource_group is not None:
357 self.results['sql_managed_instance'] = self.get()
358 elif self.resource_group is not None:
359 self.results['sql_managed_instance'] = self.list_by_resource_group()
360 else:
361 self.results['sql_managed_instance'] = self.list_by_subscription()
362 return self.results
363
364 def get(self):
365 response = None
366 results = []
367 try:
368 response = self.sql_client.managed_instances.get(resource_group_name=self.resource_group,
369 managed_instance_name=self.name)
370 self.log("Response : {0}".format(response))
371 except ResourceNotFoundError:
372 self.log('Could not get facts for SQL managed instance.')
373
374 if response and self.has_tags(response.tags, self.tags):
375 results.append(self.format_item(response))
376
377 return results
378
379 def list_by_resource_group(self):
380 response = None
381 results = []
382 try:
383 response = self.sql_client.managed_instances.list_by_resource_group(resource_group_name=self.resource_group)
384 self.log("Response : {0}".format(response))
385 except Exception:
386 self.fail('Could not list facts for SQL managed instance.')
387
388 if response is not None:
389 for item in response:
390 if self.has_tags(item.tags, self.tags):
391 results.append(self.format_item(item))
392
393 return results
394
395 def list_by_subscription(self):
396 response = None
397 results = []
398 try:
399 response = self.sql_client.managed_instances.list()
400 self.log("Response : {0}".format(response))
401 except Exception:
402 self.fail('Could not list facts for SQL Managed Instance.')
403
404 if response is not None:
405 for item in response:
406 if self.has_tags(item.tags, self.tags):
407 results.append(self.format_item(item))
408
409 return results
410
411 def format_item(self, item):
412 d = item.as_dict()
413 d = {
414 'resource_group': self.resource_group,
415 'id': d.get('id', None),
416 'name': d.get('name', None),
417 'location': d.get('location', None),
418 'type': d.get('type', None),
419 'tags': d.get('tags', None),
420 'identity': {
421 'user_assigned_identities': d.get('identity', {}).get('user_assigned_identities', None),
422 'principal_id': d.get('identity', {}).get('principal_id', None),
423 'type': d.get('identity', {}).get('type', None),
424 'tenant_id': d.get('identity', {}).get('tenant_id', None)
425 },
426 'sku': {
427 'name': d.get('sku', {}).get('name', None),
428 'size': d.get('sku', {}).get('size', None),
429 'family': d.get('sku', {}).get('family', None),
430 'tier': d.get('sku', {}).get('tier', None),
431 'capacity': d.get('sku', {}).get('capacity', None)
432 },
433 'provisioning_state': d.get('provisioning_state', None),
434 'managed_instance_create_mode': d.get('managed_instance_create_mode', None),
435 'fully_qualified_domain_name': d.get('fully_qualified_domain_name', None),
436 'administrator_login': d.get('administrator_login', None),
437 'subnet_id': d.get('subnet_id', None),
438 'state': d.get('state', None),
439 'license_type': d.get('license_type', None),
440 'v_cores': d.get('v_cores', None),
441 'storage_size_in_gb': d.get('storage_size_in_gb', None),
442 'collation': d.get('collation', None),
443 'dns_zone': d.get('dns_zone', None),
444 'dns_zone_partner': d.get('dns_zone_partner', None),
445 'public_data_endpoint_enabled': d.get('public_data_endpoint_enabled', None),
446 'source_managed_instance_id': d.get('source_managed_instance_id', None),
447 'restore_point_in_time': d.get('restore_point_in_time', None),
448 'proxy_override': d.get('proxy_override', None),
449 'timezone_id': d.get('timezone_id', None),
450 'instance_pool_id': d.get('instance_pool_id', None),
451 'maintenance_configuration_id': d.get('maintenance_configuration_id', None),
452 'private_endpoint_connections': d.get('private_endpoint_connections', None),
453 'minimal_tls_version': d.get('minimal_tls_version', None),
454 'storage_account_type': d.get('storage_account_type', None),
455 'zone_redundant': d.get('zone_redundant', None),
456 'primary_user_assigned_identity_id': d.get('primary_user_assigned_identity_id', None),
457 'key_id': d.get('key_id', None),
458 'administrators': d.get('administrators', None)
459 }
460 return d
461
462
463 def main():
464 AzureRMSqManagedInstanceInfo()
465
466
467 if __name__ == '__main__':
468 main()