Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2017 Zim Kalinowski, <[email protected]>
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_mysqlserver_info
14 version_added: "0.1.2"
15 short_description: Get Azure MySQL Server facts
16 description:
17 - Get facts of MySQL 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 required: True
24 type: str
25 name:
26 description:
27 - The name of the server.
28 type: str
29 tags:
30 description:
31 - Limit results by providing a list of tags. Format tags as 'key' or 'key:value'.
32 type: list
33 elements: str
34
35 extends_documentation_fragment:
36 - azure.azcollection.azure
37
38 author:
39 - Zim Kalinowski (@zikalino)
40
41 '''
42
43 EXAMPLES = '''
44 - name: Get instance of MySQL Server
45 azure_rm_mysqlserver_info:
46 resource_group: myResourceGroup
47 name: server_name
48 tags:
49 - key
50
51 - name: List instances of MySQL Server
52 azure_rm_mysqlserver_info:
53 resource_group: myResourceGroup
54 '''
55
56 RETURN = '''
57 servers:
58 description:
59 - A list of dictionaries containing facts for MySQL servers.
60 returned: always
61 type: complex
62 contains:
63 id:
64 description:
65 - Resource ID.
66 returned: always
67 type: str
68 sample: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.DBforMySQL/servers/myabdud1223
69 resource_group:
70 description:
71 - Resource group name.
72 returned: always
73 type: str
74 sample: myResourceGroup
75 name:
76 description:
77 - Resource name.
78 returned: always
79 type: str
80 sample: myabdud1223
81 location:
82 description:
83 - The location the resource resides in.
84 returned: always
85 type: str
86 sample: eastus
87 sku:
88 description:
89 - The SKU of the server.
90 returned: always
91 type: complex
92 contains:
93 name:
94 description:
95 - The name of the SKU.
96 returned: always
97 type: str
98 sample: GP_Gen4_2
99 tier:
100 description:
101 - The tier of the particular SKU.
102 returned: always
103 type: str
104 sample: GeneralPurpose
105 capacity:
106 description:
107 - The scale capacity.
108 returned: always
109 type: int
110 sample: 2
111 storage_profile:
112 description:
113 - Storage Profile properties of a server.
114 type: complex
115 returned: always
116 contains:
117 storage_mb:
118 description:
119 - The maximum storage allowed for a server.
120 returned: always
121 type: int
122 sample: 128000
123 backup_retention_days:
124 description:
125 - Backup retention days for the server
126 returned: always
127 type: int
128 sample: 7
129 geo_redundant_backup:
130 description:
131 - Enable Geo-redundant or not for server backup.
132 returned: always
133 type: str
134 sample: Disabled
135 storage_autogrow:
136 description:
137 - Enable Storage Auto Grow.
138 returned: always
139 type: str
140 sample: Disabled
141 enforce_ssl:
142 description:
143 - Enable SSL enforcement.
144 returned: always
145 type: bool
146 sample: False
147 admin_username:
148 description:
149 - The administrator's login name of a server.
150 returned: always
151 type: str
152 sample: serveradmin
153 version:
154 description:
155 - Server version.
156 returned: always
157 type: str
158 sample: "9.6"
159 user_visible_state:
160 description:
161 - A state of a server that is visible to user.
162 returned: always
163 type: str
164 sample: Ready
165 fully_qualified_domain_name:
166 description:
167 - The fully qualified domain name of a server.
168 returned: always
169 type: str
170 sample: myabdud1223.mys.database.azure.com
171 tags:
172 description:
173 - Tags assigned to the resource. Dictionary of string:string pairs.
174 type: dict
175 sample: { tag1: abc }
176 '''
177
178 try:
179 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
180 from azure.core.exceptions import ResourceNotFoundError
181 except ImportError:
182 # This is handled in azure_rm_common
183 pass
184
185
186 class AzureRMMySqlServerInfo(AzureRMModuleBase):
187 def __init__(self):
188 # define user inputs into argument
189 self.module_arg_spec = dict(
190 resource_group=dict(
191 type='str',
192 required=True
193 ),
194 name=dict(
195 type='str'
196 ),
197 tags=dict(
198 type='list',
199 elements='str'
200 )
201 )
202 # store the results of the module operation
203 self.results = dict(
204 changed=False
205 )
206 self.resource_group = None
207 self.name = None
208 self.tags = None
209 super(AzureRMMySqlServerInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=True)
210
211 def exec_module(self, **kwargs):
212
213 for key in self.module_arg_spec:
214 setattr(self, key, kwargs[key])
215
216 if (self.resource_group is not None and
217 self.name is not None):
218 self.results['servers'] = self.get()
219 elif (self.resource_group is not None):
220 self.results['servers'] = self.list_by_resource_group()
221 return self.results
222
223 def get(self):
224 response = None
225 results = []
226 try:
227 response = self.mysql_client.servers.get(resource_group_name=self.resource_group,
228 server_name=self.name)
229 self.log("Response : {0}".format(response))
230 except ResourceNotFoundError as e:
231 self.log('Could not get facts for MySQL Server.')
232
233 if response and self.has_tags(response.tags, self.tags):
234 results.append(self.format_item(response))
235
236 return results
237
238 def list_by_resource_group(self):
239 response = None
240 results = []
241 try:
242 response = self.mysql_client.servers.list_by_resource_group(resource_group_name=self.resource_group)
243 self.log("Response : {0}".format(response))
244 except Exception as e:
245 self.log('Could not get facts for MySQL Servers.')
246
247 if response is not None:
248 for item in response:
249 if self.has_tags(item.tags, self.tags):
250 results.append(self.format_item(item))
251
252 return results
253
254 def format_item(self, item):
255 d = item.as_dict()
256 d = {
257 'id': d['id'],
258 'resource_group': self.resource_group,
259 'name': d['name'],
260 'sku': d['sku'],
261 'location': d['location'],
262 'storage_profile': d['storage_profile'],
263 'version': d['version'],
264 'enforce_ssl': (d['ssl_enforcement'] == 'Enabled'),
265 'admin_username': d['administrator_login'],
266 'user_visible_state': d['user_visible_state'],
267 'fully_qualified_domain_name': d['fully_qualified_domain_name'],
268 'tags': d.get('tags')
269 }
270
271 return d
272
273
274 def main():
275 AzureRMMySqlServerInfo()
276
277
278 if __name__ == '__main__':
279 main()