Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_postgresqlflexibleconfiguration_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_postgresqlflexibleconfiguration_info
14 version_added: "2.2.0"
15 short_description: Get Azure PostgreSQL Flexible Configuration facts
16 description:
17 - Get facts of Azure PostgreSQL Flexible 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 - xuzhang3 (@xuzhang3)
40 - Fred-sun (@Fred-sun)
41
42 '''
43
44 EXAMPLES = '''
45 - name: Get specific setting of PostgreSQL configuration
46 azure_rm_postgresqlflexibleconfiguration_info:
47 resource_group: myResourceGroup
48 server_name: testpostgresqlserver
49 name: deadlock_timeout
50
51 - name: Get all settings of PostgreSQL Flexible Configuration
52 azure_rm_postgresqlflexibleconfiguration_info:
53 resource_group: myResourceGroup
54 server_name: testpostgresqlserver
55 '''
56
57 RETURN = '''
58 settings:
59 description:
60 - A list of dictionaries containing PostgreSQL Flexible Server settings.
61 returned: always
62 type: complex
63 contains:
64 id:
65 description:
66 - Setting resource ID.
67 returned: always
68 type: str
69 sample: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.DBforPostgreSQL/flexibleServers/post2/configurations/xmloption"
70 name:
71 description:
72 - Setting name.
73 returned: always
74 type: str
75 sample: deadlock_timeout
76 server_name:
77 description:
78 - The name of the post gresql flexible server.
79 type: str
80 returned: always
81 sample: post2
82 resource_group:
83 description:
84 - Name of the server's resource group.
85 type: str
86 returned: always
87 sample: testRG
88 value:
89 description:
90 - Setting value.
91 returned: always
92 type: raw
93 sample: 1000
94 description:
95 description:
96 - Description of the configuration.
97 returned: always
98 type: str
99 sample: Deadlock timeout.
100 source:
101 description:
102 - Source of the configuration.
103 returned: always
104 type: str
105 sample: system-default
106 '''
107
108 try:
109 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
110 from azure.core.exceptions import ResourceNotFoundError
111 except ImportError:
112 # This is handled in azure_rm_common
113 pass
114
115
116 class AzureRMPostgreSQLFlexibleConfigurationInfo(AzureRMModuleBase):
117 def __init__(self):
118 # define user inputs into argument
119 self.module_arg_spec = dict(
120 resource_group=dict(
121 type='str',
122 required=True
123 ),
124 server_name=dict(
125 type='str',
126 required=True
127 ),
128 name=dict(
129 type='str'
130 )
131 )
132 # store the results of the module operation
133 self.results = dict(
134 changed=False
135 )
136 self.resource_group = None
137 self.server_name = None
138 self.name = None
139 super(AzureRMPostgreSQLFlexibleConfigurationInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False)
140
141 def exec_module(self, **kwargs):
142 for key in self.module_arg_spec:
143 setattr(self, key, kwargs[key])
144
145 if self.name is not None:
146 self.results['settings'] = self.get()
147 else:
148 self.results['settings'] = self.list_by_server()
149 return self.results
150
151 def get(self):
152 '''
153 Gets facts of the specified PostgreSQL Flexible Configuration.
154
155 :return: deserialized PostgreSQL Flexible Configurationinstance state dictionary
156 '''
157 response = None
158 try:
159 response = self.postgresql_flexible_client.configurations.get(resource_group_name=self.resource_group,
160 server_name=self.server_name,
161 configuration_name=self.name)
162 self.log("Response : {0}".format(response))
163 except ResourceNotFoundError as e:
164 self.log('Could not get requested setting, Exception as {0}'.format(e))
165 return []
166
167 return [self.format_item(response)]
168
169 def list_by_server(self):
170 '''
171 Gets facts of the specified PostgreSQL Flexible Configuration.
172
173 :return: deserialized PostgreSQL Flexible Configurationinstance state dictionary
174 '''
175 response = None
176 results = []
177 try:
178 response = self.postgresql_flexible_client.configurations.list_by_server(resource_group_name=self.resource_group,
179 server_name=self.server_name)
180 self.log("Response : {0}".format(response))
181 except Exception as e:
182 self.log('List the flexible server config get exception, except as {0}'.format(e))
183 return []
184
185 if response is not None:
186 for item in response:
187 results.append(self.format_item(item))
188
189 return results
190
191 def format_item(self, item):
192 d = item.as_dict()
193 d = {
194 'resource_group': self.resource_group,
195 'server_name': self.server_name,
196 'id': d['id'],
197 'name': d['name'],
198 'value': d['value'],
199 'description': d['description'],
200 'source': d['source']
201 }
202 return d
203
204
205 def main():
206 AzureRMPostgreSQLFlexibleConfigurationInfo()
207
208
209 if __name__ == '__main__':
210 main()