Adding sql client to common (#44825)
This commit is contained in:
parent
b0cee34ca1
commit
78eb4724a0
4 changed files with 30 additions and 31 deletions
|
@ -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')
|
||||
|
|
|
@ -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,7 +428,7 @@ 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,
|
||||
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)
|
||||
|
@ -452,7 +448,7 @@ 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,
|
||||
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:
|
||||
|
@ -470,7 +466,7 @@ 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,
|
||||
response = self.sql_client.databases.get(resource_group_name=self.resource_group,
|
||||
server_name=self.server_name,
|
||||
database_name=self.name)
|
||||
found = True
|
||||
|
|
|
@ -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,7 +264,7 @@ 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,
|
||||
response = self.sql_client.servers.create_or_update(self.resource_group,
|
||||
self.name,
|
||||
self.parameters)
|
||||
if isinstance(response, AzureOperationPoller):
|
||||
|
@ -287,7 +283,7 @@ class AzureRMServers(AzureRMModuleBase):
|
|||
'''
|
||||
self.log("Deleting the SQL Server instance {0}".format(self.name))
|
||||
try:
|
||||
response = self.mgmt_client.servers.delete(self.resource_group,
|
||||
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.')
|
||||
|
@ -304,7 +300,7 @@ 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,
|
||||
response = self.sql_client.servers.get(self.resource_group,
|
||||
self.name)
|
||||
found = True
|
||||
self.log("Response : {0}".format(response))
|
||||
|
|
|
@ -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,7 +163,7 @@ class AzureRMServersFacts(AzureRMModuleBase):
|
|||
response = None
|
||||
results = {}
|
||||
try:
|
||||
response = self.mgmt_client.servers.get(resource_group_name=self.resource_group,
|
||||
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:
|
||||
|
@ -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.')
|
||||
|
|
Loading…
Reference in a new issue