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

SQL Database enhancements #681

Merged
merged 22 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d0e4814
prevent list index out of range errors when comparing dicts with empt…
l3ender Nov 11, 2021
cf579dd
update sql sdk; support new fields and admin password change
l3ender Nov 11, 2021
e602a31
Merge branch 'dev' into sql-enhancements
l3ender Nov 22, 2021
81eb3c2
Merge branch 'dev' into sql-enhancements
l3ender Nov 23, 2021
4047620
minor lint fixes
l3ender Nov 23, 2021
71e4065
Merge remote-tracking branch 'upstream/dev' into sql-enhancements
l3ender Nov 29, 2021
b8fcc34
disable log warning for non-sensitive parameter
l3ender Nov 29, 2021
699e82a
correct sku idempotency check
l3ender Dec 5, 2021
3a7d3e9
Merge remote-tracking branch 'upstream/dev' into sql-enhancements
l3ender Feb 13, 2022
cfb27d0
add support for azure ad admin on sql server
l3ender Feb 13, 2022
6d49c03
bump version added after module release
l3ender Feb 13, 2022
0f28c23
add tests for sql server with azure ad admin
l3ender Feb 13, 2022
4589d2c
add example for creating sql server with azure ad
l3ender Feb 13, 2022
db07611
add additional output for sql server + test coverage
l3ender Feb 15, 2022
8b85d66
Merge remote-tracking branch 'upstream/dev' into sql-enhancements
l3ender Feb 26, 2022
998438d
Merge remote-tracking branch 'upstream/dev' into sql-enhancements
l3ender Mar 10, 2022
3e9fd56
disable test case as per review comment
l3ender Mar 10, 2022
b7d7235
correct test case which requires restore happen in same region
l3ender Mar 10, 2022
37cb927
clean up sql tests related to aad group
l3ender Mar 10, 2022
06c0d85
Merge branch 'dev' into sql-enhancements
l3ender Mar 23, 2022
a157db6
remove tasks loading ad group info
l3ender Mar 31, 2022
1cc2a56
conditionally run azuread tasks
l3ender Apr 1, 2022
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
11 changes: 2 additions & 9 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,8 @@ 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)
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True)
return self._sql_client

@property
Expand All @@ -1196,14 +1197,6 @@ def mariadb_client(self):
base_url=self._cloud_environment.endpoints.resource_manager)
return self._mariadb_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 containerregistry_client(self):
self.log('Getting container registry mgmt client')
Expand Down
32 changes: 15 additions & 17 deletions plugins/modules/azure_rm_sqldatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,9 @@

try:
import dateutil.parser
from msrestazure.azure_exceptions import CloudError
from msrest.polling import LROPoller
from azure.mgmt.sql import SqlManagementClient
from azure.core.exceptions import ResourceNotFoundError
from azure.core.polling import LROPoller
from azure.mgmt.sql.models import Sku
from msrest.serialization import Model
except ImportError:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -361,7 +359,6 @@ def __init__(self):
choices=['present', 'absent']
)
)
mutually_exclusive = ['sku', 'edition']

self.resource_group = None
self.server_name = None
Expand Down Expand Up @@ -461,7 +458,7 @@ def exec_module(self, **kwargs):
(self.parameters['max_size_bytes'] != old_response['max_size_bytes'])):
self.to_do = Actions.Update
if (('sku' in self.parameters) and
(self.parameters['sku'] != old_response['sku'])):
(self.parameters['sku'].as_dict() != old_response['sku'])):
self.to_do = Actions.Update
update_tags, newtags = self.update_tags(
old_response.get('tags', dict()))
Expand Down Expand Up @@ -518,14 +515,13 @@ def create_update_sqldatabase(self):
"Creating / Updating the SQL Database instance {0}".format(self.name))

try:
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)
response = self.sql_client.databases.begin_create_or_update(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name,
parameters=self.parameters)
if isinstance(response, LROPoller):
response = self.get_poller_result(response)

except CloudError as exc:
except Exception as exc:
self.log('Error attempting to create the SQL Database instance.')
self.fail(
"Error creating the SQL Database instance: {0}".format(str(exc)))
Expand All @@ -539,10 +535,12 @@ def delete_sqldatabase(self):
'''
self.log("Deleting the SQL Database instance {0}".format(self.name))
try:
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:
response = self.sql_client.databases.begin_delete(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name)
if isinstance(response, LROPoller):
response = self.get_poller_result(response)
except Exception 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 @@ -565,7 +563,7 @@ def get_sqldatabase(self):
found = True
self.log("Response : {0}".format(response))
self.log("SQL Database instance : {0} found".format(response.name))
except CloudError as e:
except ResourceNotFoundError:
self.log('Did not find the SQL Database instance.')
if found is True:
return response.as_dict()
Expand Down
10 changes: 4 additions & 6 deletions plugins/modules/azure_rm_sqldatabase_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

try:
from msrestazure.azure_exceptions import CloudError
from azure.mgmt.sql import SqlManagementClient
from msrest.serialization import Model
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -217,7 +215,7 @@ def get(self):
server_name=self.server_name,
database_name=self.name)
self.log("Response : {0}".format(response))
except CloudError as e:
except ResourceNotFoundError:
self.log('Could not get facts for Databases.')

if response and self.has_tags(response.tags, self.tags):
Expand All @@ -233,7 +231,7 @@ def list_by_elastic_pool(self):
server_name=self.server_name,
elastic_pool_name=self.elastic_pool_name)
self.log("Response : {0}".format(response))
except CloudError as e:
except Exception:
self.fail('Could not get facts for Databases.')

if response is not None:
Expand All @@ -250,7 +248,7 @@ def list_by_server(self):
response = self.sql_client.databases.list_by_server(resource_group_name=self.resource_group,
server_name=self.server_name)
self.log("Response : {0}".format(response))
except CloudError as e:
except Exception:
self.fail('Could not get facts for Databases.')

if response is not None:
Expand Down
30 changes: 15 additions & 15 deletions plugins/modules/azure_rm_sqlfirewallrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

try:
from msrestazure.azure_exceptions import CloudError
from msrest.polling import LROPoller
from azure.mgmt.sql import SqlManagementClient
from msrest.serialization import Model
from azure.core.exceptions import ResourceNotFoundError
from azure.core.polling import LROPoller
from azure.mgmt.sql.models import FirewallRule
except ImportError:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -206,15 +205,16 @@ def create_update_firewallrule(self):
self.log("Creating / Updating the Firewall Rule instance {0}".format(self.name))

try:
params = FirewallRule(
name=self.name,
start_ip_address=self.start_ip_address,
end_ip_address=self.end_ip_address,
)
response = self.sql_client.firewall_rules.create_or_update(resource_group_name=self.resource_group,
server_name=self.server_name,
firewall_rule_name=self.name,
start_ip_address=self.start_ip_address,
end_ip_address=self.end_ip_address)
if isinstance(response, LROPoller):
response = self.get_poller_result(response)

except CloudError as exc:
parameters=params)
except Exception as exc:
self.log('Error attempting to create the Firewall Rule instance.')
self.fail("Error creating the Firewall Rule instance: {0}".format(str(exc)))
return response.as_dict()
Expand All @@ -227,10 +227,10 @@ def delete_firewallrule(self):
'''
self.log("Deleting the Firewall Rule instance {0}".format(self.name))
try:
response = self.sql_client.firewall_rules.delete(resource_group_name=self.resource_group,
server_name=self.server_name,
firewall_rule_name=self.name)
except CloudError as e:
self.sql_client.firewall_rules.delete(resource_group_name=self.resource_group,
server_name=self.server_name,
firewall_rule_name=self.name)
except Exception as e:
self.log('Error attempting to delete the Firewall Rule instance.')
self.fail("Error deleting the Firewall Rule instance: {0}".format(str(e)))

Expand All @@ -251,7 +251,7 @@ def get_firewallrule(self):
found = True
self.log("Response : {0}".format(response))
self.log("Firewall Rule instance : {0} found".format(response.name))
except CloudError as e:
except ResourceNotFoundError:
self.log('Did not find the Firewall Rule instance.')
if found is True:
return response.as_dict()
Expand Down
9 changes: 3 additions & 6 deletions plugins/modules/azure_rm_sqlfirewallrule_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

try:
from msrestazure.azure_exceptions import CloudError
from msrest.polling import LROPoller
from azure.mgmt.sql import SqlManagementClient
from msrest.serialization import Model
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -160,7 +157,7 @@ def get(self):
server_name=self.server_name,
firewall_rule_name=self.name)
self.log("Response : {0}".format(response))
except CloudError as e:
except ResourceNotFoundError:
self.log('Could not get facts for FirewallRules.')

if response is not None:
Expand All @@ -180,7 +177,7 @@ def list_by_server(self):
response = self.sql_client.firewall_rules.list_by_server(resource_group_name=self.resource_group,
server_name=self.server_name)
self.log("Response : {0}".format(response))
except CloudError as e:
except ResourceNotFoundError:
self.log('Could not get facts for FirewallRules.')

if response is not None:
Expand Down
Loading