Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_mysqlflexibleserver_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
11 DOCUMENTATION = '''
12 ---
13 module: azure_rm_mysqlflexibleserver_info
14 version_added: "2.6.0"
15 short_description: Get Azure MySQL Flexible Server facts
16 description:
17 - Get facts of MySQL Flexible Server.
18
19 options:
20 resource_group:
21 description:
22 - The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal.
23 type: str
24 name:
25 description:
26 - The name of the server.
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 instance of MySQL Flexible Server
44 azure_rm_mysqlflexibleserver_info:
45 resource_group: myResourceGroup
46 name: server_name
47
48 - name: List instances of MySQL Flexible Server and filter by tags
49 azure_rm_mysqlflexibleserver_info:
50 resource_group: myResourceGroup
51
52 - name: List instances of MySQL Flexible Server
53 azure_rm_mysqlflexibleserver_info:
54 resource_group: myResourceGroup
55 tags:
56 - key
57 '''
58
59 RETURN = '''
60 servers:
61 description:
62 - A list of dictionaries containing facts for MySQL servers.
63 returned: always
64 type: complex
65 contains:
66 id:
67 description:
68 - Resource ID.
69 returned: always
70 type: str
71 sample: /subscriptions/xxxx-xxxx/resourceGroups/testRG/providers/Microsoft.DBforMySQL/flexibleServers/server01
72 resource_group:
73 description:
74 - Resource group name.
75 returned: always
76 type: str
77 sample: testRG
78 name:
79 description:
80 - Resource name.
81 returned: always
82 type: str
83 sample: server01
84 location:
85 description:
86 - The location the resource resides in.
87 returned: always
88 type: str
89 sample: eastus
90 sku:
91 description:
92 - The SKU of the server.
93 returned: always
94 type: complex
95 contains:
96 name:
97 description:
98 - The name of the SKU.
99 returned: always
100 type: str
101 sample: Standard_D32s_v3
102 tier:
103 description:
104 - The tier of the particular SKU.
105 returned: always
106 type: str
107 sample: GeneralPurpose
108 storage:
109 description:
110 - Storage related properties of a server.
111 type: complex
112 returned: always
113 contains:
114 storage_size_gb:
115 description:
116 - Max storage size allowed for a server.
117 returned: always
118 type: int
119 sample: 128000
120 iops:
121 description:
122 - Storage IOPS for a server.
123 returned: always
124 type: int
125 sample: 684
126 auto_grow:
127 description:
128 - Enable Storage Auto Grow or not.
129 returned: always
130 type: str
131 sample: Disabled
132 availability_zone:
133 description:
134 - Availability Zone information of the server.
135 returned: always
136 type: str
137 sample: 1
138 administrator_login:
139 description:
140 - The administrator's login name of a server.
141 returned: always
142 type: str
143 sample: serveradmin
144 backup:
145 description:
146 - Backup related properties of a server.
147 type: complex
148 returned: always
149 contains:
150 backup_retention_days:
151 description:
152 - Backup retention days for the server.
153 type: int
154 returned: always
155 sample: 7
156 geo_redundant_backup:
157 description:
158 - Whether or not geo redundant backup is enabled.
159 type: str
160 returned: always
161 sample: Disabled
162 version:
163 description:
164 - Server version.
165 returned: always
166 type: str
167 sample: "5.7"
168 state:
169 description:
170 - A state of a server that is visible to user.
171 returned: always
172 type: str
173 sample: Ready
174 fully_qualified_domain_name:
175 description:
176 - The fully qualified domain name of a server.
177 returned: always
178 type: str
179 sample: myabdud1223.mys.database.azure.com
180 high_availability:
181 description:
182 - High availability related properties of a server.
183 type: complex
184 returned: always
185 contains:
186 mode:
187 description:
188 - High availability mode for a server.
189 type: str
190 sample: Disabled
191 returned: always
192 standby_availability_zone:
193 description:
194 - Availability zone of the standby server.
195 type: str
196 sample: Availability zone of the standby server.
197 returned: always
198 network:
199 description:
200 - Network related properties of a server.
201 type: complex
202 returned: always
203 contains:
204 delegated_subnet_resource_id:
205 description:
206 - Delegated subnet resource id used to setup vnet for a server.
207 type: str
208 sample: null
209 returned: always
210 private_dns_zone_resource_id:
211 description:
212 - Private DNS zone resource id.
213 type: str
214 sample: null
215 returned: always
216 restore_point_in_time:
217 description:
218 - Restore point creation time (ISO8601 format), specifying the time to restore from.
219 type: str
220 returned: always
221 sample: null
222 source_server_resource_id:
223 description:
224 - The source MySQL server id.
225 type: str
226 returned: always
227 sample: null
228 tags:
229 description:
230 - Tags assigned to the resource. Dictionary of string:string pairs.
231 type: dict
232 returned: always
233 sample: { tag1: abc }
234 type:
235 description:
236 - The type of the resource.
237 type: str
238 returned: always
239 sample: Microsoft.DBforMySQL/flexibleServers
240 '''
241
242 try:
243 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
244 from azure.core.exceptions import HttpResponseError
245 except ImportError:
246 # This is handled in azure_rm_common
247 pass
248
249
250 class AzureRMMySqlFlexibleServerInfo(AzureRMModuleBase):
251 def __init__(self):
252 # define user inputs into argument
253 self.module_arg_spec = dict(
254 resource_group=dict(
255 type='str',
256 ),
257 name=dict(
258 type='str'
259 ),
260 tags=dict(
261 type='list',
262 elements='str'
263 )
264 )
265 self.results = dict(
266 changed=False
267 )
268 self.resource_group = None
269 self.name = None
270 self.tags = None
271 super(AzureRMMySqlFlexibleServerInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=True)
272
273 def exec_module(self, **kwargs):
274 for key in self.module_arg_spec:
275 setattr(self, key, kwargs[key])
276
277 if (self.resource_group is not None and self.name is not None):
278 self.results['servers'] = self.get()
279 elif (self.resource_group is not None):
280 self.results['servers'] = self.list_by_resource_group()
281 else:
282 self.results['servers'] = self.list_all()
283
284 return self.results
285
286 def get(self):
287 response = None
288 results = []
289 try:
290 response = self.mysql_flexible_client.servers.get(resource_group_name=self.resource_group,
291 server_name=self.name)
292 self.log("Response : {0}".format(response))
293 except HttpResponseError as e:
294 self.log('Could not get facts for MySQL Flexible Server. Exception as {0}'.format(e))
295
296 if response and self.has_tags(response.tags, self.tags):
297 results.append(self.format_item(response))
298
299 return results
300
301 def list_by_resource_group(self):
302 response = None
303 results = []
304 try:
305 response = self.mysql_flexible_client.servers.list_by_resource_group(resource_group_name=self.resource_group)
306 self.log("Response : {0}".format(response))
307 except HttpResponseError as e:
308 self.log('Could not get facts for MySQL Flexible Servers. Exception as {0}'.format(e))
309
310 if response is not None:
311 for item in response:
312 if self.has_tags(item.tags, self.tags):
313 results.append(self.format_item(item))
314 return results
315
316 def list_all(self):
317 response = None
318 results = []
319 try:
320 response = self.mysql_flexible_client.servers.list()
321 self.log("Response : {0}".format(response))
322 except HttpResponseError as e:
323 self.log('Could not get facts for MySQL Flexible Servers. Exception as {0}'.format(e))
324
325 if response is not None:
326 for item in response:
327 if self.has_tags(item.tags, self.tags):
328 results.append(self.format_item(item))
329 return results
330
331 def format_item(self, item):
332 results = dict(
333 resource_group=self.parse_resource_to_dict(item.id).get('resource_group'),
334 id=item.id,
335 name=item.name,
336 type=item.type,
337 tags=item.tags,
338 location=item.location,
339 sku=dict(),
340 administrator_login=item.administrator_login,
341 version=item.version,
342 availability_zone=item.availability_zone,
343 source_server_resource_id=item.source_server_resource_id,
344 restore_point_in_time=item.restore_point_in_time,
345 state=item.state,
346 fully_qualified_domain_name=item.fully_qualified_domain_name,
347 storage=dict(),
348 backup=dict(),
349 high_availability=dict(),
350 network=dict(),
351 )
352 if item.sku not in [None, 'None']:
353 results['sku']['name'] = item.sku.name
354 results['sku']['tier'] = item.sku.tier
355 if item.storage not in [None, 'None']:
356 results['storage']['storage_size_gb'] = item.storage.storage_size_gb
357 results['storage']['iops'] = item.storage.iops
358 results['storage']['auto_grow'] = item.storage.auto_grow
359 if item.high_availability not in [None, 'None']:
360 results['high_availability']['standby_availability_zone'] = item.high_availability.standby_availability_zone
361 results['high_availability']['mode'] = item.high_availability.mode
362 if item.backup not in [None, 'None']:
363 results['backup']['backup_retention_days'] = item.backup.backup_retention_days
364 results['backup']['geo_redundant_backup'] = item.backup.geo_redundant_backup
365 if item.network not in [None, 'None']:
366 results['network']['delegated_subnet_resource_id'] = item.network.delegated_subnet_resource_id
367 results['network']['private_dns_zone_resource_id'] = item.network.private_dns_zone_resource_id
368 return results
369
370
371 def main():
372 AzureRMMySqlFlexibleServerInfo()
373
374
375 if __name__ == '__main__':
376 main()