Debian Codegraph @

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

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