1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Adding sql client to common (#44825)

This commit is contained in:
Zim Kalinowski 2018-08-30 12:44:36 +08:00 committed by Yunge Zhu
parent b0cee34ca1
commit 78eb4724a0
4 changed files with 30 additions and 31 deletions

View file

@ -153,6 +153,7 @@ try:
from azure.mgmt.trafficmanager import TrafficManagerManagementClient
from azure.storage.cloudstorageaccount import CloudStorageAccount
from adal.authentication_context import AuthenticationContext
from azure.mgmt.sql import SqlManagementClient
from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient
from azure.mgmt.rdbms.mysql import MySQLManagementClient
from azure.mgmt.containerregistry import ContainerRegistryManagementClient
@ -283,6 +284,7 @@ class AzureRMModuleBase(object):
self._web_client = None
self._marketplace_client = None
self._containerservice_client = None
self._sql_client = None
self._mysql_client = None
self._postgresql_client = None
self._containerregistry_client = None
@ -1073,6 +1075,14 @@ class AzureRMModuleBase(object):
base_url=self._cloud_environment.endpoints.resource_manager)
return self._containerservice_client
@property
def sql_client(self):
self.log('Getting SQL client')
if not self._sql_client:
self._sql_client = self.get_mgmt_svc_client(SqlManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager)
return self._sql_client
@property
def postgresql_client(self):
self.log('Getting PostgreSQL client')

View file

@ -303,7 +303,6 @@ class AzureRMDatabases(AzureRMModuleBase):
self.parameters = dict()
self.results = dict(changed=False)
self.mgmt_client = None
self.state = None
self.to_do = Actions.NoAction
@ -351,9 +350,6 @@ class AzureRMDatabases(AzureRMModuleBase):
old_response = None
response = None
self.mgmt_client = self.get_mgmt_svc_client(SqlManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager)
resource_group = self.get_resource_group(self.resource_group)
if "location" not in self.parameters:
@ -432,10 +428,10 @@ class AzureRMDatabases(AzureRMModuleBase):
self.log("Creating / Updating the SQL Database instance {0}".format(self.name))
try:
response = self.mgmt_client.databases.create_or_update(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name,
parameters=self.parameters)
response = self.sql_client.databases.create_or_update(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name,
parameters=self.parameters)
if isinstance(response, AzureOperationPoller):
response = self.get_poller_result(response)
@ -452,9 +448,9 @@ class AzureRMDatabases(AzureRMModuleBase):
'''
self.log("Deleting the SQL Database instance {0}".format(self.name))
try:
response = self.mgmt_client.databases.delete(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name)
response = self.sql_client.databases.delete(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name)
except CloudError as e:
self.log('Error attempting to delete the SQL Database instance.')
self.fail("Error deleting the SQL Database instance: {0}".format(str(e)))
@ -470,9 +466,9 @@ class AzureRMDatabases(AzureRMModuleBase):
self.log("Checking if the SQL Database instance {0} is present".format(self.name))
found = False
try:
response = self.mgmt_client.databases.get(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name)
response = self.sql_client.databases.get(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name)
found = True
self.log("Response : {0}".format(response))
self.log("SQL Database instance : {0} found".format(response.name))

View file

@ -165,7 +165,6 @@ class AzureRMServers(AzureRMModuleBase):
self.parameters = dict()
self.results = dict(changed=False)
self.mgmt_client = None
self.state = None
self.to_do = Actions.NoAction
@ -195,9 +194,6 @@ class AzureRMServers(AzureRMModuleBase):
response = None
results = dict()
self.mgmt_client = self.get_mgmt_svc_client(SqlManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager)
resource_group = self.get_resource_group(self.resource_group)
if "location" not in self.parameters:
@ -268,9 +264,9 @@ class AzureRMServers(AzureRMModuleBase):
self.log("Creating / Updating the SQL Server instance {0}".format(self.name))
try:
response = self.mgmt_client.servers.create_or_update(self.resource_group,
self.name,
self.parameters)
response = self.sql_client.servers.create_or_update(self.resource_group,
self.name,
self.parameters)
if isinstance(response, AzureOperationPoller):
response = self.get_poller_result(response)
@ -287,8 +283,8 @@ class AzureRMServers(AzureRMModuleBase):
'''
self.log("Deleting the SQL Server instance {0}".format(self.name))
try:
response = self.mgmt_client.servers.delete(self.resource_group,
self.name)
response = self.sql_client.servers.delete(self.resource_group,
self.name)
except CloudError as e:
self.log('Error attempting to delete the SQL Server instance.')
self.fail("Error deleting the SQL Server instance: {0}".format(str(e)))
@ -304,8 +300,8 @@ class AzureRMServers(AzureRMModuleBase):
self.log("Checking if the SQL Server instance {0} is present".format(self.name))
found = False
try:
response = self.mgmt_client.servers.get(self.resource_group,
self.name)
response = self.sql_client.servers.get(self.resource_group,
self.name)
found = True
self.log("Response : {0}".format(response))
self.log("SQL Server instance : {0} found".format(response.name))

View file

@ -139,7 +139,6 @@ class AzureRMServersFacts(AzureRMModuleBase):
changed=False,
ansible_facts=dict()
)
self.mgmt_client = None
self.resource_group = None
self.server_name = None
super(AzureRMServersFacts, self).__init__(self.module_arg_spec)
@ -147,8 +146,6 @@ class AzureRMServersFacts(AzureRMModuleBase):
def exec_module(self, **kwargs):
for key in self.module_arg_spec:
setattr(self, key, kwargs[key])
self.mgmt_client = self.get_mgmt_svc_client(SqlManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager)
if (self.resource_group is not None and
self.server_name is not None):
@ -166,8 +163,8 @@ class AzureRMServersFacts(AzureRMModuleBase):
response = None
results = {}
try:
response = self.mgmt_client.servers.get(resource_group_name=self.resource_group,
server_name=self.server_name)
response = self.sql_client.servers.get(resource_group_name=self.resource_group,
server_name=self.server_name)
self.log("Response : {0}".format(response))
except CloudError as e:
self.log('Could not get facts for Servers.')
@ -186,7 +183,7 @@ class AzureRMServersFacts(AzureRMModuleBase):
response = None
results = {}
try:
response = self.mgmt_client.servers.list_by_resource_group(resource_group_name=self.resource_group)
response = self.sql_client.servers.list_by_resource_group(resource_group_name=self.resource_group)
self.log("Response : {0}".format(response))
except CloudError as e:
self.log('Could not get facts for Servers.')