Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2019 Zim Kalinowski, (@zikalino)
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_postgresqlconfiguration_info
14 version_added: "0.1.2"
15 short_description: Get Azure PostgreSQL Configuration facts
16 description:
17 - Get facts of Azure PostgreSQL Configuration.
18
19 options:
20 resource_group:
21 description:
22 - The name of the resource group that contains the resource.
23 required: True
24 type: str
25 server_name:
26 description:
27 - The name of the server.
28 required: True
29 type: str
30 name:
31 description:
32 - Setting name.
33 type: 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 specific setting of PostgreSQL configuration
45 azure_rm_postgresqlconfiguration_info:
46 resource_group: myResourceGroup
47 server_name: testpostgresqlserver
48 name: deadlock_timeout
49
50 - name: Get all settings of PostgreSQL Configuration
51 azure_rm_postgresqlconfiguration_info:
52 resource_group: myResourceGroup
53 server_name: testpostgresqlserver
54 '''
55
56 RETURN = '''
57 settings:
58 description:
59 - A list of dictionaries containing MySQL Server settings.
60 returned: always
61 type: complex
62 contains:
63 id:
64 description:
65 - Setting resource ID.
66 returned: always
67 type: str
68 sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testrg/providers/Microsoft.DBforPostgreSQL/servers/testpostgresqlser
69 ver/configurations/deadlock_timeout"
70 name:
71 description:
72 - Setting name.
73 returned: always
74 type: str
75 sample: deadlock_timeout
76 value:
77 description:
78 - Setting value.
79 returned: always
80 type: raw
81 sample: 1000
82 description:
83 description:
84 - Description of the configuration.
85 returned: always
86 type: str
87 sample: Deadlock timeout.
88 source:
89 description:
90 - Source of the configuration.
91 returned: always
92 type: str
93 sample: system-default
94 '''
95
96 try:
97 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
98 from azure.core.exceptions import ResourceNotFoundError
99 except ImportError:
100 # This is handled in azure_rm_common
101 pass
102
103
104 class AzureRMPostgreSQLConfigurationInfo(AzureRMModuleBase):
105 def __init__(self):
106 # define user inputs into argument
107 self.module_arg_spec = dict(
108 resource_group=dict(
109 type='str',
110 required=True
111 ),
112 server_name=dict(
113 type='str',
114 required=True
115 ),
116 name=dict(
117 type='str'
118 )
119 )
120 # store the results of the module operation
121 self.results = dict(
122 changed=False
123 )
124 self.resource_group = None
125 self.server_name = None
126 self.name = None
127 super(AzureRMPostgreSQLConfigurationInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False)
128
129 def exec_module(self, **kwargs):
130
131 for key in self.module_arg_spec:
132 setattr(self, key, kwargs[key])
133
134 if self.name is not None:
135 self.results['settings'] = self.get()
136 else:
137 self.results['settings'] = self.list_by_server()
138 return self.results
139
140 def get(self):
141 '''
142 Gets facts of the specified PostgreSQL Configuration.
143
144 :return: deserialized PostgreSQL Configurationinstance state dictionary
145 '''
146 response = None
147 results = []
148 try:
149 response = self.postgresql_client.configurations.get(resource_group_name=self.resource_group,
150 server_name=self.server_name,
151 configuration_name=self.name)
152 self.log("Response : {0}".format(response))
153 except ResourceNotFoundError as e:
154 self.fail('Could not get requested setting.')
155
156 if response is not None:
157 results.append(self.format_item(response))
158
159 return results
160
161 def list_by_server(self):
162 '''
163 Gets facts of the specified PostgreSQL Configuration.
164
165 :return: deserialized PostgreSQL Configurationinstance state dictionary
166 '''
167 response = None
168 results = []
169 try:
170 response = self.postgresql_client.configurations.list_by_server(resource_group_name=self.resource_group,
171 server_name=self.server_name)
172 self.log("Response : {0}".format(response))
173 except Exception as e:
174 self.fail('Could not get settings for server.')
175
176 if response is not None:
177 for item in response:
178 results.append(self.format_item(item))
179
180 return results
181
182 def format_item(self, item):
183 d = item.as_dict()
184 d = {
185 'resource_group': self.resource_group,
186 'server_name': self.server_name,
187 'id': d['id'],
188 'name': d['name'],
189 'value': d['value'],
190 'description': d['description'],
191 'source': d['source']
192 }
193 return d
194
195
196 def main():
197 AzureRMPostgreSQLConfigurationInfo()
198
199
200 if __name__ == '__main__':
201 main()