Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_postgresqlserver_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_postgresqlserver_info
14 version_added: "0.1.2"
15 short_description: Get Azure PostgreSQL Server facts
16 description:
17 - Get facts of PostgreSQL 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 PostgreSQL Server
45 azure_rm_postgresqlserver_info:
46 resource_group: myResourceGroup
47 name: server_name
48
49 - name: List instances of PostgreSQL Server
50 azure_rm_postgresqlserver_info:
51 resource_group: myResourceGroup
52 tags:
53 - key
54 '''
55
56 RETURN = '''
57 servers:
58 description:
59 - A list of dictionaries containing facts for PostgreSQL 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.DBforPostgreSQL/servers/po
69 stgreabdud1223"
70 resource_group:
71 description:
72 - Resource group name.
73 returned: always
74 type: str
75 sample: myResourceGroup
76 name:
77 description:
78 - Resource name.
79 returned: always
80 type: str
81 sample: postgreabdud1223
82 location:
83 description:
84 - The location the resource resides in.
85 returned: always
86 type: str
87 sample: eastus
88 sku:
89 description:
90 - The SKU of the server.
91 returned: always
92 type: complex
93 contains:
94 name:
95 description:
96 - The name of the SKU.
97 returned: always
98 type: str
99 sample: GP_Gen4_2
100 tier:
101 description:
102 - The tier of the particular SKU.
103 returned: always
104 type: str
105 sample: GeneralPurpose
106 capacity:
107 description:
108 - The scale capacity.
109 returned: always
110 type: int
111 sample: 2
112 storage_mb:
113 description:
114 - The maximum storage allowed for a server.
115 returned: always
116 type: int
117 sample: 128000
118 enforce_ssl:
119 description:
120 - Enable SSL enforcement.
121 returned: always
122 type: bool
123 sample: False
124 admin_username:
125 description:
126 - The administrator's login name of a server.
127 returned: always
128 type: str
129 sample: serveradmin
130 version:
131 description:
132 - Server version.
133 returned: always
134 type: str
135 sample: "9.6"
136 user_visible_state:
137 description:
138 - A state of a server that is visible to user.
139 returned: always
140 type: str
141 sample: Ready
142 fully_qualified_domain_name:
143 description:
144 - The fully qualified domain name of a server.
145 returned: always
146 type: str
147 sample: postgreabdud1223.postgres.database.azure.com
148 backup_retention_days:
149 description:
150 - Backup retention period between 7 and 35 days. 7 days by default if not set.
151 returned: always
152 type: int
153 sample: 7
154 geo_redundant_backup:
155 description:
156 - Choose between locally redundant(default) or geo-redundant backup. This cannot be updated after first deployment.
157 returned: always
158 type: str
159 sample: Disabled
160 tags:
161 description:
162 - Tags assigned to the resource. Dictionary of string:string pairs.
163 type: dict
164 sample: { tag1: abc }
165 '''
166
167
168 try:
169 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
170 from azure.core.exceptions import ResourceNotFoundError
171 except ImportError:
172 # This is handled in azure_rm_common
173 pass
174
175
176 class AzureRMPostgreSqlServersInfo(AzureRMModuleBase):
177 def __init__(self):
178 # define user inputs into argument
179 self.module_arg_spec = dict(
180 resource_group=dict(
181 type='str',
182 required=True
183 ),
184 name=dict(
185 type='str'
186 ),
187 tags=dict(
188 type='list',
189 elements='str'
190 )
191 )
192 # store the results of the module operation
193 self.results = dict(
194 changed=False
195 )
196 self.resource_group = None
197 self.name = None
198 self.tags = None
199 super(AzureRMPostgreSqlServersInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=True)
200
201 def exec_module(self, **kwargs):
202
203 for key in self.module_arg_spec:
204 setattr(self, key, kwargs[key])
205
206 if (self.resource_group is not None and
207 self.name is not None):
208 self.results['servers'] = self.get()
209 elif (self.resource_group is not None):
210 self.results['servers'] = self.list_by_resource_group()
211 return self.results
212
213 def get(self):
214 response = None
215 results = []
216 try:
217 response = self.postgresql_client.servers.get(resource_group_name=self.resource_group,
218 server_name=self.name)
219 self.log("Response : {0}".format(response))
220 except ResourceNotFoundError as e:
221 self.log('Could not get facts for PostgreSQL Server.')
222
223 if response and self.has_tags(response.tags, self.tags):
224 results.append(self.format_item(response))
225
226 return results
227
228 def list_by_resource_group(self):
229 response = None
230 results = []
231 try:
232 response = self.postgresql_client.servers.list_by_resource_group(resource_group_name=self.resource_group)
233 self.log("Response : {0}".format(response))
234 except Exception as e:
235 self.log('Could not get facts for PostgreSQL Servers.')
236
237 if response is not None:
238 for item in response:
239 if self.has_tags(item.tags, self.tags):
240 results.append(self.format_item(item))
241
242 return results
243
244 def format_item(self, item):
245 d = item.as_dict()
246 d = {
247 'id': d['id'],
248 'resource_group': self.resource_group,
249 'name': d['name'],
250 'sku': d['sku'],
251 'location': d['location'],
252 'storage_mb': d['storage_profile']['storage_mb'],
253 'storage_autogrow': (d['storage_profile']['storage_autogrow'] == 'Enabled'),
254 'version': d['version'],
255 'enforce_ssl': (d['ssl_enforcement'] == 'Enabled'),
256 'admin_username': d['administrator_login'],
257 'user_visible_state': d['user_visible_state'],
258 'fully_qualified_domain_name': d['fully_qualified_domain_name'],
259 'geo_redundant_backup': d['storage_profile']['geo_redundant_backup'],
260 'backup_retention_days': d['storage_profile']['backup_retention_days'],
261 'tags': d.get('tags')
262 }
263
264 return d
265
266
267 def main():
268 AzureRMPostgreSqlServersInfo()
269
270
271 if __name__ == '__main__':
272 main()