Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flexible servers to support managed post gresql flexible server #1192

Merged
merged 23 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def default_api_version(self):
from azure.mgmt.sql import SqlManagementClient
from azure.mgmt.servicebus import ServiceBusManagementClient
from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient
from azure.mgmt.rdbms.postgresql_flexibleservers import PostgreSQLManagementClient as PostgreSQLFlexibleManagementClient
from azure.mgmt.rdbms.mysql import MySQLManagementClient
from azure.mgmt.rdbms.mariadb import MariaDBManagementClient
from azure.mgmt.containerregistry import ContainerRegistryManagementClient
Expand Down Expand Up @@ -415,6 +416,7 @@ def __init__(self, derived_arg_spec, bypass_checks=False, no_log=False,
self._mysql_client = None
self._mariadb_client = None
self._postgresql_client = None
self._postgresql_flexible_client = None
self._containerregistry_client = None
self._containerinstance_client = None
self._containerservice_client = None
Expand Down Expand Up @@ -1174,6 +1176,14 @@ def sql_client(self):
is_track2=True)
return self._sql_client

@property
def postgresql_flexible_client(self):
self.log('Getting PostgreSQL client')
if not self._postgresql_flexible_client:
self._postgresql_flexible_client = self.get_mgmt_svc_client(PostgreSQLFlexibleManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager)
return self._postgresql_flexible_client

@property
def postgresql_client(self):
self.log('Getting PostgreSQL client')
Expand Down
210 changes: 210 additions & 0 deletions plugins/modules/azure_rm_postgresqlflexibleconfiguration_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#!/usr/bin/python
#
# Copyright (c) 2024 xuzhang3 (@xuzhang3), Fred-sun (@Fred-sun)
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type


DOCUMENTATION = '''
---
module: azure_rm_postgresqlflexibleconfiguration_info
version_added: "2.2.0"
short_description: Get Azure PostgreSQL Flexible Configuration facts
description:
- Get facts of Azure PostgreSQL Flexible Configuration.

options:
resource_group:
description:
- The name of the resource group that contains the resource.
required: True
type: str
server_name:
description:
- The name of the server.
required: True
type: str
name:
description:
- Setting name.
type: str

extends_documentation_fragment:
- azure.azcollection.azure

author:
- xuzhang3 (@xuzhang3)
- Fred-sun (@Fred-sun)

'''

EXAMPLES = '''
- name: Get specific setting of PostgreSQL configuration
azure_rm_postgresqlflexibleconfiguration_info:
resource_group: myResourceGroup
server_name: testpostgresqlserver
name: deadlock_timeout

- name: Get all settings of PostgreSQL Flexible Configuration
azure_rm_postgresqlflexibleconfiguration_info:
resource_group: myResourceGroup
server_name: testpostgresqlserver
'''

RETURN = '''
settings:
description:
- A list of dictionaries containing MySQL Server settings.
returned: always
type: complex
contains:
id:
description:
- Setting resource ID.
returned: always
type: str
sample: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.DBforPostgreSQL/flexibleServers/post2/configurations/xmloption"
name:
description:
- Setting name.
returned: always
type: str
sample: deadlock_timeout
server_name:
description:
- The name of the post gresql flexible server.
type: str
returned: always
sample: post2
resource_group:
description:
- Name of the server's resource group.
type: str
returned: always
sample: testRG
value:
description:
- Setting value.
returned: always
type: raw
sample: 1000
description:
description:
- Description of the configuration.
returned: always
type: str
sample: Deadlock timeout.
source:
description:
- Source of the configuration.
returned: always
type: str
sample: system-default
'''

try:
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
# This is handled in azure_rm_common
pass


class AzureRMPostgreSQLFlexibleConfigurationInfo(AzureRMModuleBase):
def __init__(self):
# define user inputs into argument
self.module_arg_spec = dict(
resource_group=dict(
type='str',
required=True
),
server_name=dict(
type='str',
required=True
),
name=dict(
type='str'
)
)
# store the results of the module operation
self.results = dict(
changed=False
)
self.resource_group = None
self.server_name = None
self.name = None
super(AzureRMPostgreSQLFlexibleConfigurationInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False)

def exec_module(self, **kwargs):
for key in self.module_arg_spec:
setattr(self, key, kwargs[key])

if self.name is not None:
self.results['settings'] = self.get()
else:
self.results['settings'] = self.list_by_server()
return self.results

def get(self):
'''
Gets facts of the specified PostgreSQL Flexible Configuration.

:return: deserialized PostgreSQL Flexible Configurationinstance state dictionary
'''
response = None
try:
response = self.postgresql_flexible_client.configurations.get(resource_group_name=self.resource_group,
server_name=self.server_name,
configuration_name=self.name)
self.log("Response : {0}".format(response))
except ResourceNotFoundError as e:
self.log('Could not get requested setting, Exception as {0}'.format(e))
return []

return [self.format_item(response)]

def list_by_server(self):
'''
Gets facts of the specified PostgreSQL Flexible Configuration.

:return: deserialized PostgreSQL Flexible Configurationinstance state dictionary
'''
response = None
results = []
try:
response = self.postgresql_flexible_client.configurations.list_by_server(resource_group_name=self.resource_group,
server_name=self.server_name)
self.log("Response : {0}".format(response))
except Exception as e:
self.log('List the flexible server config get exception, except as {0}'.format(e))
return []

if response is not None:
for item in response:
results.append(self.format_item(item))

return results

def format_item(self, item):
d = item.as_dict()
d = {
'resource_group': self.resource_group,
'server_name': self.server_name,
'id': d['id'],
'name': d['name'],
'value': d['value'],
'description': d['description'],
'source': d['source']
}
return d


def main():
AzureRMPostgreSQLFlexibleConfigurationInfo()


if __name__ == '__main__':
main()
Loading