Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_mysqlconfiguration_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_mysqlconfiguration_info
14 version_added: "0.1.2"
15 short_description: Get Azure MySQL Configuration facts
16 description:
17 - Get facts of Azure MySQL 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 - Zim Kalinowski (@zikalino)
40
41 '''
42
43 EXAMPLES = '''
44 - name: Get specific setting of MySQL Server
45 azure_rm_mysqlconfiguration_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_mysqlconfiguration_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/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.DBforMySQL/servers/testmysqlser
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 AzureRMMySqlConfigurationInfo(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(changed=False)
122 self.resource_group = None
123 self.server_name = None
124 self.name = None
125 super(AzureRMMySqlConfigurationInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False)
126
127 def exec_module(self, **kwargs):
128
129 for key in self.module_arg_spec:
130 setattr(self, key, kwargs[key])
131
132 if self.name is not None:
133 self.results['settings'] = self.get()
134 else:
135 self.results['settings'] = self.list_by_server()
136 return self.results
137
138 def get(self):
139 '''
140 Gets facts of the specified MySQL Configuration.
141
142 :return: deserialized MySQL Configurationinstance state dictionary
143 '''
144 response = None
145 results = []
146 try:
147 response = self.mysql_client.configurations.get(resource_group_name=self.resource_group,
148 server_name=self.server_name,
149 configuration_name=self.name)
150 self.log("Response : {0}".format(response))
151 except ResourceNotFoundError as e:
152 self.log('Could not get facts for Configurations.')
153
154 if response is not None:
155 results.append(self.format_item(response))
156
157 return results
158
159 def list_by_server(self):
160 '''
161 Gets facts of the specified MySQL Configuration.
162
163 :return: deserialized MySQL Configurationinstance state dictionary
164 '''
165 response = None
166 results = []
167 try:
168 response = self.mysql_client.configurations.list_by_server(resource_group_name=self.resource_group,
169 server_name=self.server_name)
170 self.log("Response : {0}".format(response))
171 except Exception as e:
172 self.log('Could not get facts for Configurations.')
173
174 if response is not None:
175 for item in response:
176 results.append(self.format_item(item))
177
178 return results
179
180 def format_item(self, item):
181 d = item.as_dict()
182 d = {
183 'resource_group': self.resource_group,
184 'server_name': self.server_name,
185 'id': d['id'],
186 'name': d['name'],
187 'value': d['value'],
188 'description': d['description'],
189 'source': d['source']
190 }
191 return d
192
193
194 def main():
195 AzureRMMySqlConfigurationInfo()
196
197
198 if __name__ == '__main__':
199 main()