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

Adding sql client to common #44825

Merged
merged 3 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/ansible/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
from azure.mgmt.containerservice import ContainerServiceClient
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
except ImportError as exc:
Expand Down Expand Up @@ -274,6 +275,7 @@ def __init__(self, derived_arg_spec, bypass_checks=False, no_log=False,
self._dns_client = None
self._web_client = None
self._containerservice_client = None
self._sql_client = None
self._mysql_client = None
self._postgresql_client = None
self._adfs_authority_url = None
Expand Down Expand Up @@ -1060,6 +1062,14 @@ def containerservice_client(self):
base_url=self._cloud_environment.endpoints.resource_manager)
return self._containerservice_client

@property
def sql_client(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary to specify api versoin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it's not

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')
Expand Down
24 changes: 10 additions & 14 deletions lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ def __init__(self):
self.parameters = dict()

self.results = dict(changed=False)
self.mgmt_client = None
self.state = None
self.to_do = Actions.NoAction

Expand Down Expand Up @@ -351,9 +350,6 @@ def exec_module(self, **kwargs):
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:
Expand Down Expand Up @@ -432,10 +428,10 @@ def create_update_sqldatabase(self):
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering how this get merged at first place..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

server_name=self.server_name,
database_name=self.name,
parameters=self.parameters)
if isinstance(response, AzureOperationPoller):
response = self.get_poller_result(response)

Expand All @@ -452,9 +448,9 @@ def delete_sqldatabase(self):
'''
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)))
Expand All @@ -470,9 +466,9 @@ def get_sqldatabase(self):
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))
Expand Down
18 changes: 7 additions & 11 deletions lib/ansible/modules/cloud/azure/azure_rm_sqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def __init__(self):
self.parameters = dict()

self.results = dict(changed=False)
self.mgmt_client = None
self.state = None
self.to_do = Actions.NoAction

Expand Down Expand Up @@ -195,9 +194,6 @@ def exec_module(self, **kwargs):
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:
Expand Down Expand Up @@ -268,9 +264,9 @@ def create_update_sqlserver(self):
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)

Expand All @@ -287,8 +283,8 @@ def delete_sqlserver(self):
'''
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)))
Expand All @@ -304,8 +300,8 @@ def get_sqlserver(self):
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))
Expand Down
9 changes: 3 additions & 6 deletions lib/ansible/modules/cloud/azure/azure_rm_sqlserver_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,13 @@ def __init__(self):
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)

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):
Expand All @@ -166,8 +163,8 @@ def get(self):
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.')
Expand All @@ -186,7 +183,7 @@ def list_by_resource_group(self):
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.')
Expand Down