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

Upgrade azure-mgmt-resource to 21.1.0 #960

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def default_api_version(self):
),
'ManagementGroupsClient': '2020-05-01',
'NetworkManagementClient': '2019-11-01',
'ResourceManagementClient': '2017-05-10',
'ResourceManagementClient': '2019-10-01',
'SearchManagementClient': '2020-08-01',
'StorageManagementClient': '2021-06-01',
'SubscriptionClient': '2019-11-01',
Expand Down Expand Up @@ -1061,6 +1061,7 @@ def subscription_client(self):
self._subscription_client = self.get_mgmt_svc_client(SubscriptionClient,
base_url=self._cloud_environment.endpoints.resource_manager,
suppress_subscription_id=True,
is_track2=True,
api_version='2019-11-01')
return self._subscription_client

Expand Down Expand Up @@ -1099,13 +1100,14 @@ def rm_client(self):
if not self._resource_client:
self._resource_client = self.get_mgmt_svc_client(ResourceManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
api_version='2017-05-10')
is_track2=True,
api_version='2019-10-01')
return self._resource_client

@property
def rm_models(self):
self.log("Getting resource manager models")
return ResourceManagementClient.models("2017-05-10")
return ResourceManagementClient.models("2019-10-01")

@property
def image_client(self):
Expand Down Expand Up @@ -1368,6 +1370,7 @@ def lock_client(self):
if not self._lock_client:
self._lock_client = self.get_mgmt_svc_client(ManagementLockClient,
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True,
api_version='2016-09-01')
return self._lock_client

Expand Down
23 changes: 11 additions & 12 deletions plugins/modules/azure_rm_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@

try:
from itertools import chain
from azure.common.exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
from azure.mgmt.resource.resources import ResourceManagementClient
from azure.mgmt.network import NetworkManagementClient
Expand Down Expand Up @@ -499,7 +498,7 @@ def exec_module(self, **kwargs):
self.destroy_resource_group()
self.results['changed'] = True
self.results['msg'] = "deployment deleted"
except CloudError:
except Exception:
# resource group does not exist
pass

Expand Down Expand Up @@ -533,21 +532,21 @@ def deploy_template(self):
rg = self.rm_client.resource_groups.get(self.resource_group)
if rg.tags:
update_tags, self.tags = self.update_tags(rg.tags)
except CloudError:
except ResourceNotFoundError:
# resource group does not exist
pass

params = self.rm_models.ResourceGroup(location=self.location, tags=self.tags)

try:
self.rm_client.resource_groups.create_or_update(self.resource_group, params)
except CloudError as exc:
except Exception as exc:
self.fail("Resource group create_or_update failed with status code: %s and message: %s" %
(exc.status_code, exc.message))
try:
result = self.rm_client.deployments.create_or_update(self.resource_group,
self.name,
deploy_parameter)
result = self.rm_client.deployments.begin_create_or_update(self.resource_group,
self.name,
{'properties': deploy_parameter})

deployment_result = None
if self.wait_for_deployment_completion:
Expand All @@ -556,7 +555,7 @@ def deploy_template(self):
'Succeeded']:
time.sleep(self.wait_for_deployment_polling_period)
deployment_result = self.rm_client.deployments.get(self.resource_group, self.name)
except CloudError as exc:
except Exception as exc:
failed_deployment_operations = self._get_failed_deployment_operations(self.name)
self.log("Deployment failed %s: %s" % (exc.status_code, exc.message))
error_msg = self._error_msg_from_cloud_error(exc)
Expand All @@ -575,9 +574,9 @@ def destroy_resource_group(self):
Destroy the targeted resource group
"""
try:
result = self.rm_client.resource_groups.delete(self.resource_group)
result = self.rm_client.resource_groups.begin_delete(self.resource_group)
result.wait() # Blocking wait till the delete is finished
except CloudError as e:
except Exception as e:
if e.status_code == 404 or e.status_code == 204:
return
else:
Expand All @@ -595,7 +594,7 @@ def _get_failed_nested_operations(self, current_operations):
try:
nested_operations = self.rm_client.deployment_operations.list(self.resource_group,
nested_deployment)
except CloudError as exc:
except Exception as exc:
self.fail("List nested deployment operations failed with status code: %s and message: %s" %
(exc.status_code, exc.message))
new_nested_operations = self._get_failed_nested_operations(nested_operations)
Expand All @@ -609,7 +608,7 @@ def _get_failed_deployment_operations(self, name):

try:
operations = self.rm_client.deployment_operations.list(self.resource_group, name)
except CloudError as exc:
except Exception as exc:
self.fail("Get deployment failed with status code: %s and message: %s" %
(exc.status_code, exc.message))
try:
Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/azure_rm_deployment_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
from azure.mgmt.devtestlabs import DevTestLabsClient
from msrest.serialization import Model
except ImportError:
Expand Down Expand Up @@ -170,7 +170,7 @@ def get(self):
try:
response = self.rm_client.deployments.get(self.resource_group, deployment_name=self.name)
self.log("Response : {0}".format(response))
except CloudError as e:
except ResourceNotFoundError as e:
self.log('Could not get facts for Deployment.')

if response:
Expand All @@ -184,7 +184,7 @@ def list(self):
try:
response = self.rm_client.deployments.list_by_resource_group(self.resource_group)
self.log("Response : {0}".format(response))
except CloudError as e:
except Exception as e:
self.log('Could not get facts for Deployment.')

if response is not None:
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/azure_rm_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -170,19 +170,19 @@ def exec_module(self, **kwargs):
def delete_lock(self, scope):
try:
return self.lock_client.management_locks.delete_by_scope(scope, self.name)
except CloudError as exc:
except Exception as exc:
self.fail('Error when deleting lock {0} for {1}: {2}'.format(self.name, scope, exc.message))

def create_or_update_lock(self, scope, lock):
try:
return self.lock_client.management_locks.create_or_update_by_scope(scope, self.name, lock)
except CloudError as exc:
except Exception as exc:
self.fail('Error when creating or updating lock {0} for {1}: {2}'.format(self.name, scope, exc.message))

def get_lock(self, scope):
try:
return self.lock_client.management_locks.get_by_scope(scope, self.name)
except CloudError as exc:
except ResourceNotFoundError as exc:
if exc.status_code in [404]:
return None
self.fail('Error when getting lock {0} for {1}: {2}'.format(self.name, scope, exc.message))
Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/azure_rm_resourcegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
'''

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
pass

Expand Down Expand Up @@ -193,7 +193,7 @@ def exec_module(self, **kwargs):
if self.location and normalize_location_name(self.location) != results['location']:
self.fail("Resource group '{0}' already exists in location '{1}' and cannot be "
"moved.".format(self.name, results['location']))
except CloudError:
except ResourceNotFoundError:
self.log('Resource group {0} does not exist'.format(self.name))
if self.state == 'present':
self.log("CHANGED: resource group {0} does not exist but requested state is "
Expand Down Expand Up @@ -246,7 +246,7 @@ def create_or_update_resource_group(self, params):

def delete_resource_group(self):
try:
poller = self.rm_client.resource_groups.delete(self.name)
poller = self.rm_client.resource_groups.begin_delete(self.name)
self.get_poller_result(poller)
except Exception as exc:
self.fail("Error delete resource group {0} - {1}".format(self.name, str(exc)))
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/azure_rm_resourcegroup_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
'''

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
except Exception:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -192,7 +192,7 @@ def get_item(self):

try:
item = self.rm_client.resource_groups.get(self.name)
except CloudError:
except ResourceNotFoundError:
pass

if item and self.has_tags(item.tags, self.tags):
Expand All @@ -204,7 +204,7 @@ def list_items(self):
self.log('List all items')
try:
response = self.rm_client.resource_groups.list()
except CloudError as exc:
except Exception as exc:
self.fail("Failed to list all items - {0}".format(str(exc)))

results = []
Expand All @@ -222,7 +222,7 @@ def list_by_rg(self, name):
results.append(response.next().as_dict())
except StopIteration:
pass
except CloudError as exc:
except Exception as exc:
self.fail('Error when listing resources under resource group {0}: {1}'.format(name, exc.message or str(exc)))
return results

Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/azure_rm_subscription_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
'''

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
except Exception:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -176,7 +176,7 @@ def get_item(self):

try:
item = self.subscription_client.subscriptions.get(self.id)
except CloudError:
except ResourceNotFoundError:
pass

result = self.to_dict(item)
Expand All @@ -187,7 +187,7 @@ def list_items(self):
self.log('List all items')
try:
response = self.subscription_client.subscriptions.list()
except CloudError as exc:
except Exception as exc:
self.fail("Failed to list all items - {0}".format(str(exc)))

results = []
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/azure_rm_virtualmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2070,7 +2070,7 @@ def delete_nsg(self, resource_group, name):
def delete_managed_disks(self, managed_disk_ids):
for mdi in managed_disk_ids:
try:
poller = self.rm_client.resources.delete_by_id(mdi, '2017-03-30')
poller = self.rm_client.resources.begin_delete_by_id(mdi, '2017-03-30')
self.get_poller_result(poller)
except Exception as exc:
self.fail("Error deleting managed disk {0} - {1}".format(mdi, str(exc)))
Expand Down
2 changes: 1 addition & 1 deletion requirements-azure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ azure-mgmt-network==19.1.0
azure-mgmt-nspkg==2.0.0
azure-mgmt-privatedns==1.0.0
azure-mgmt-redis==13.0.0
azure-mgmt-resource==10.2.0
azure-mgmt-resource==21.1.0
azure-mgmt-rdbms==10.0.0
azure-mgmt-search==8.0.0
azure-mgmt-servicebus==7.1.0
Expand Down