Skip to content

Commit

Permalink
Upgrade azure-mgmt-rdbms to 10.0.0 (#884)
Browse files Browse the repository at this point in the history
* Upgrade azure-mgmt-rdbms to 10.0.0

* add new change

* add new change

* small change

* missing char
  • Loading branch information
Fred-sun authored Jul 19, 2022
1 parent fcff5ba commit dfe66e1
Show file tree
Hide file tree
Showing 29 changed files with 253 additions and 298 deletions.
3 changes: 3 additions & 0 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ def postgresql_client(self):
self.log('Getting PostgreSQL client')
if not self._postgresql_client:
self._postgresql_client = self.get_mgmt_svc_client(PostgreSQLManagementClient,
is_track2=True,
base_url=self._cloud_environment.endpoints.resource_manager)
return self._postgresql_client

Expand All @@ -1187,6 +1188,7 @@ def mysql_client(self):
self.log('Getting MySQL client')
if not self._mysql_client:
self._mysql_client = self.get_mgmt_svc_client(MySQLManagementClient,
is_track2=True,
base_url=self._cloud_environment.endpoints.resource_manager)
return self._mysql_client

Expand All @@ -1195,6 +1197,7 @@ def mariadb_client(self):
self.log('Getting MariaDB client')
if not self._mariadb_client:
self._mariadb_client = self.get_mgmt_svc_client(MariaDBManagementClient,
is_track2=True,
base_url=self._cloud_environment.endpoints.resource_manager)
return self._mariadb_client

Expand Down
28 changes: 13 additions & 15 deletions plugins/modules/azure_rm_mariadbconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@
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.rdbms.mysql import MariaDBManagementClient
from azure.core.exceptions import ResourceNotFoundError
from azure.core.polling import LROPoller
from msrest.serialization import Model
except ImportError:
# This is handled in azure_rm_common
Expand Down Expand Up @@ -188,27 +187,26 @@ def create_update_configuration(self):
self.log("Creating / Updating the Configuration instance {0}".format(self.name))

try:
response = self.mariadb_client.configurations.create_or_update(resource_group_name=self.resource_group,
server_name=self.server_name,
configuration_name=self.name,
value=self.value,
source='user-override')
response = self.mariadb_client.configurations.begin_create_or_update(resource_group_name=self.resource_group,
server_name=self.server_name,
configuration_name=self.name,
parameters={'value': self.value, 'source': 'user-override'})
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 Configuration instance.')
self.fail("Error creating the Configuration instance: {0}".format(str(exc)))
return response.as_dict()

def delete_configuration(self):
self.log("Deleting the Configuration instance {0}".format(self.name))
try:
response = self.mariadb_client.configurations.create_or_update(resource_group_name=self.resource_group,
server_name=self.server_name,
configuration_name=self.name,
source='system-default')
except CloudError as e:
response = self.mariadb_client.configurations.begin_create_or_update(resource_group_name=self.resource_group,
server_name=self.server_name,
configuration_name=self.name,
parameters={'source': 'system-default'})
except Exception as e:
self.log('Error attempting to delete the Configuration instance.')
self.fail("Error deleting the Configuration instance: {0}".format(str(e)))

Expand All @@ -224,7 +222,7 @@ def get_configuration(self):
found = True
self.log("Response : {0}".format(response))
self.log("Configuration instance : {0} found".format(response.name))
except CloudError as e:
except ResourceNotFoundError as e:
self.log('Did not find the Configuration instance.')
if found is True:
return response.as_dict()
Expand Down
20 changes: 8 additions & 12 deletions plugins/modules/azure_rm_mariadbconfiguration_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@

from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
try:
from msrestazure.azure_exceptions import CloudError
from msrestazure.azure_operation import AzureOperationPoller
from azure.mgmt.rdbms.mariadb import MariaDBManagementClient
from azure.core.exceptions import ResourceNotFoundError
from msrest.serialization import Model
except ImportError:
# This is handled in azure_rm_common
Expand All @@ -124,7 +123,6 @@ def __init__(self):
)
# store the results of the module operation
self.results = dict(changed=False)
self.mgmt_client = None
self.resource_group = None
self.server_name = None
self.name = None
Expand All @@ -137,8 +135,6 @@ 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(MariaDBManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager)

if self.name is not None:
self.results['settings'] = self.get()
Expand All @@ -155,11 +151,11 @@ def get(self):
response = None
results = []
try:
response = self.mgmt_client.configurations.get(resource_group_name=self.resource_group,
server_name=self.server_name,
configuration_name=self.name)
response = self.mariadb_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 CloudError as e:
except ResourceNotFoundError as e:
self.log('Could not get facts for Configurations.')

if response is not None:
Expand All @@ -176,10 +172,10 @@ def list_by_server(self):
response = None
results = []
try:
response = self.mgmt_client.configurations.list_by_server(resource_group_name=self.resource_group,
server_name=self.server_name)
response = self.mariadb_client.configurations.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 as e:
self.log('Could not get facts for Configurations.')

if response is not None:
Expand Down
35 changes: 15 additions & 20 deletions plugins/modules/azure_rm_mariadbdatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@

try:
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
from azure.mgmt.rdbms.mariadb import MariaDBManagementClient
from msrestazure.azure_exceptions import CloudError
from msrest.polling import LROPoller
from azure.core.exceptions import ResourceNotFoundError
from azure.core.polling import LROPoller
from msrest.serialization import Model
except ImportError:
# This is handled in azure_rm_common
Expand Down Expand Up @@ -142,7 +141,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 All @@ -165,9 +163,6 @@ def exec_module(self, **kwargs):
old_response = None
response = None

self.mgmt_client = self.get_mgmt_svc_client(MariaDBManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager)

resource_group = self.get_resource_group(self.resource_group)

old_response = self.get_mariadbdatabase()
Expand Down Expand Up @@ -238,14 +233,14 @@ def create_update_mariadbdatabase(self):
self.log("Creating / Updating the MariaDB 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.mariadb_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 MariaDB Database instance.')
self.fail("Error creating the MariaDB Database instance: {0}".format(str(exc)))
return response.as_dict()
Expand All @@ -258,10 +253,10 @@ def delete_mariadbdatabase(self):
'''
self.log("Deleting the MariaDB 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)
except CloudError as e:
response = self.mariadb_client.databases.begin_delete(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name)
except Exception as e:
self.log('Error attempting to delete the MariaDB Database instance.')
self.fail("Error deleting the MariaDB Database instance: {0}".format(str(e)))

Expand All @@ -276,13 +271,13 @@ def get_mariadbdatabase(self):
self.log("Checking if the MariaDB 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.mariadb_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("MariaDB Database instance : {0} found".format(response.name))
except CloudError as e:
except ResourceNotFoundError as e:
self.log('Did not find the MariaDB Database instance.')
if found is True:
return response.as_dict()
Expand Down
7 changes: 3 additions & 4 deletions plugins/modules/azure_rm_mariadbdatabase_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@

try:
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
from msrestazure.azure_exceptions import CloudError
from azure.mgmt.rdbms.mariadb import MariaDBManagementClient
from azure.core.exceptions import ResourceNotFoundError
from msrest.serialization import Model
except ImportError:
# This is handled in azure_rm_common
Expand Down Expand Up @@ -161,7 +160,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 as e:
self.log('Could not get facts for Databases.')

if response is not None:
Expand All @@ -176,7 +175,7 @@ def list_by_server(self):
response = self.mariadb_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 as e:
self.fail("Error listing for server {0} - {1}".format(self.server_name, str(e)))

if response is not None:
Expand Down
29 changes: 15 additions & 14 deletions plugins/modules/azure_rm_mariadbfirewallrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@

try:
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
from msrestazure.azure_exceptions import CloudError
from msrest.polling import LROPoller
from azure.mgmt.rdbms.mariadb import MariaDBManagementClient
from azure.core.exceptions import ResourceNotFoundError
from azure.core.polling import LROPoller
from msrest.serialization import Model
except ImportError:
# This is handled in azure_rm_common
Expand Down Expand Up @@ -128,6 +127,7 @@ def __init__(self):

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

super(AzureRMMariaDbFirewallRule, self).__init__(derived_arg_spec=self.module_arg_spec,
Expand All @@ -140,6 +140,8 @@ def exec_module(self, **kwargs):
for key in list(self.module_arg_spec.keys()):
if hasattr(self, key):
setattr(self, key, kwargs[key])
if key in ['start_ip_address', 'end_ip_address']:
self.parameters[key] = kwargs[key]

old_response = None
response = None
Expand Down Expand Up @@ -210,15 +212,14 @@ def create_update_firewallrule(self):
self.log("Creating / Updating the MariaDB firewall rule instance {0}".format(self.name))

try:
response = self.mariadb_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)
response = self.mariadb_client.firewall_rules.begin_create_or_update(resource_group_name=self.resource_group,
server_name=self.server_name,
firewall_rule_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 MariaDB firewall rule instance.')
self.fail("Error creating the MariaDB firewall rule instance: {0}".format(str(exc)))
return response.as_dict()
Expand All @@ -231,10 +232,10 @@ def delete_firewallrule(self):
'''
self.log("Deleting the MariaDB firewall rule instance {0}".format(self.name))
try:
response = self.mariadb_client.firewall_rules.delete(resource_group_name=self.resource_group,
server_name=self.server_name,
firewall_rule_name=self.name)
except CloudError as e:
response = self.mariadb_client.firewall_rules.begin_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 MariaDB firewall rule instance.')
self.fail("Error deleting the MariaDB firewall rule instance: {0}".format(str(e)))

Expand All @@ -255,7 +256,7 @@ def get_firewallrule(self):
found = True
self.log("Response : {0}".format(response))
self.log("MariaDB firewall rule instance : {0} found".format(response.name))
except CloudError as e:
except ResourceNotFoundError as e:
self.log('Did not find the MariaDB firewall rule instance.')
if found is True:
return response.as_dict()
Expand Down
Loading

0 comments on commit dfe66e1

Please sign in to comment.