Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_mysqlflexibleconfiguration_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_mysqlflexibleconfiguration_info
14 version_added: "2.7.0"
15 short_description: Get Azure MySQL Flexible Configuration facts
16 description:
17 - Get facts of Azure MySQL Flexible Configuration.
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 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 EXAMPLES = '''
44 - name: Get specific setting of MySQL Server
45 azure_rm_mysqlflexibleconfiguration_info:
46 resource_group: myResourceGroup
47 server_name: testmysqlserver
48 name: deadlock_timeout
49
50 - name: Get all settings of MySQL Server
51 azure_rm_mysqlflexibleconfiguration_info:
52 resource_group: myResourceGroup
53 server_name: server_name
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/xx-xx/resourceGroups/testRG/providers/Microsoft.DBforMySQL/flexibleservers/tstserver/configurations/deadlock_timeout"
69 server_name:
70 description:
71 - The MySQL flexible server name.
72 type: str
73 returned: always
74 sample: tstserver
75 name:
76 description:
77 - Setting name.
78 returned: always
79 type: str
80 sample: deadlock_timeout
81 value:
82 description:
83 - Setting value.
84 returned: always
85 type: raw
86 sample: 1000
87 source:
88 description:
89 - Source of the configuration.
90 returned: always
91 type: str
92 sample: system-default
93 '''
94
95 try:
96 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
97 from azure.core.exceptions import ResourceNotFoundError
98 except ImportError:
99 # This is handled in azure_rm_common
100 pass
101
102
103 class AzureRMMySqlFlexibleConfigurationInfo(AzureRMModuleBase):
104 def __init__(self):
105 # define user inputs into argument
106 self.module_arg_spec = dict(
107 resource_group=dict(
108 type='str',
109 required=True
110 ),
111 server_name=dict(
112 type='str',
113 required=True
114 ),
115 name=dict(
116 type='str'
117 )
118 )
119 # store the results of the module operation
120 self.results = dict(changed=False)
121 self.resource_group = None
122 self.server_name = None
123 self.name = None
124 super(AzureRMMySqlFlexibleConfigurationInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False)
125
126 def exec_module(self, **kwargs):
127 for key in self.module_arg_spec:
128 setattr(self, key, kwargs[key])
129
130 if self.name is not None:
131 self.results['settings'] = self.get()
132 else:
133 self.results['settings'] = self.list_by_server()
134 return self.results
135
136 def get(self):
137 '''
138 Gets facts of the specified MySQL Flexible Configuration.
139
140 :return: deserialized MySQL Flexible Configurationinstance state dictionary
141 '''
142 response = None
143 results = []
144 try:
145 response = self.mysql_flexible_client.configurations.get(resource_group_name=self.resource_group,
146 server_name=self.server_name,
147 configuration_name=self.name)
148 self.log("Response : {0}".format(response))
149 except ResourceNotFoundError as e:
150 self.log('Could not get facts for Configurations.')
151
152 if response is not None:
153 results.append(self.format_item(response))
154
155 return results
156
157 def list_by_server(self):
158 '''
159 Gets facts of the specified MySQL Flexible Configuration.
160
161 :return: deserialized MySQL Flexible Configurationinstance state dictionary
162 '''
163 response = None
164 results = []
165 try:
166 response = self.mysql_flexible_client.configurations.list_by_server(resource_group_name=self.resource_group,
167 server_name=self.server_name)
168 self.log("Response : {0}".format(response))
169 except Exception as e:
170 self.log('Could not get facts for Configurations.')
171
172 if response is not None:
173 for item in response:
174 results.append(self.format_item(item))
175
176 return results
177
178 def format_item(self, item):
179 d = item.as_dict()
180 d = {
181 'resource_group': self.resource_group,
182 'server_name': self.server_name,
183 'id': d['id'],
184 'name': d['name'],
185 'value': d['value'],
186 'source': d['source']
187 }
188 return d
189
190
191 def main():
192 AzureRMMySqlFlexibleConfigurationInfo()
193
194
195 if __name__ == '__main__':
196 main()