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-cosmosdb to 6.4.0 #952

Merged
merged 10 commits into from
Aug 23, 2022
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
29 changes: 17 additions & 12 deletions plugins/modules/azure_rm_cosmosdbaccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
description:
- It can be a string containing resource id of a subnet.
- It can be a dictionary containing 'resource_group', 'virtual_network_name' and 'subnet_name'
ignore_missing_vnet_service_endpoint:
ignore_missing_v_net_service_endpoint:
description:
- Create Cosmos DB account without existing virtual network service endpoint.
type: bool
Expand Down Expand Up @@ -215,10 +215,11 @@
from ansible.module_utils.common.dict_transformations import _snake_to_camel

try:
from msrestazure.azure_exceptions import CloudError
from msrest.polling import LROPoller
from azure.core.polling import LROPoller
from azure.core.exceptions import ResourceNotFoundError
from msrestazure.azure_operation import AzureOperationPoller
from azure.mgmt.cosmosdb import CosmosDBManagementClient
from ansible.module_utils.six import string_types
except ImportError:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -326,7 +327,7 @@ def __init__(self):
type='str',
required=True
),
ignore_missing_vnet_service_endpoint=dict(
ignore_missing_v_net_service_endpoint=dict(
type='bool'
)
)
Expand Down Expand Up @@ -408,6 +409,7 @@ def exec_module(self, **kwargs):
response = None

self.mgmt_client = self.get_mgmt_svc_client(CosmosDBManagementClient,
is_track2=True,
base_url=self._cloud_environment.endpoints.resource_manager)

resource_group = self.get_resource_group(self.resource_group)
Expand Down Expand Up @@ -469,13 +471,13 @@ def create_update_databaseaccount(self):
self.log("Creating / Updating the Database Account instance {0}".format(self.name))

try:
response = self.mgmt_client.database_accounts.create_or_update(resource_group_name=self.resource_group,
account_name=self.name,
create_update_parameters=self.parameters)
response = self.mgmt_client.database_accounts.begin_create_or_update(resource_group_name=self.resource_group,
account_name=self.name,
create_update_parameters=self.parameters)
if isinstance(response, LROPoller) or isinstance(response, AzureOperationPoller):
response = self.get_poller_result(response)

except CloudError as exc:
except Exception as exc:
self.log('Error attempting to create the Database Account instance.')
self.fail("Error creating the Database Account instance: {0}".format(str(exc)))
return response.as_dict()
Expand All @@ -488,12 +490,12 @@ def delete_databaseaccount(self):
'''
self.log("Deleting the Database Account instance {0}".format(self.name))
try:
response = self.mgmt_client.database_accounts.delete(resource_group_name=self.resource_group,
account_name=self.name)
response = self.mgmt_client.database_accounts.begin_delete(resource_group_name=self.resource_group,
account_name=self.name)

if isinstance(response, LROPoller) or isinstance(response, AzureOperationPoller):
response = self.get_poller_result(response)
except CloudError as e:
except Exception as e:
self.log('Error attempting to delete the Database Account instance.')
self.fail("Error deleting the Database Account instance: {0}".format(str(e)))

Expand All @@ -516,7 +518,7 @@ def get_databaseaccount(self):
found = True
self.log("Response : {0}".format(response))
self.log("Database Account instance : {0} found".format(response.name))
except CloudError as e:
except ResourceNotFoundError as e:
self.log('Did not find the Database Account instance.')
if found is True:
return response.as_dict()
Expand Down Expand Up @@ -565,6 +567,9 @@ def default_compare(new, old, path, result):
if path == '/location' or path.endswith('location_name'):
new = new.replace(' ', '').lower()
old = new.replace(' ', '').lower()
if isinstance(old, string_types) and isinstance(new, string_types):
new = new.lower()
old = old.lower()
if new == old:
return True
else:
Expand Down
11 changes: 6 additions & 5 deletions plugins/modules/azure_rm_cosmosdbaccount_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
type: str
sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNet
works/testvnet/subnets/testsubnet1"
ignore_missing_vnet_service_endpoint:
ignore_missing_v_net_service_endpoint:
description:
- Create Cosmos DB account without existing virtual network service endpoint.
type: bool
Expand Down Expand Up @@ -378,7 +378,7 @@
from ansible.module_utils.common.dict_transformations import _camel_to_snake

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
from azure.mgmt.cosmosdb import CosmosDBManagementClient
except ImportError:
# This is handled in azure_rm_common
Expand Down Expand Up @@ -429,6 +429,7 @@ 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(CosmosDBManagementClient,
is_track2=True,
base_url=self._cloud_environment.endpoints.resource_manager)

if self.name is not None:
Expand All @@ -446,7 +447,7 @@ def get(self):
response = self.mgmt_client.database_accounts.get(resource_group_name=self.resource_group,
account_name=self.name)
self.log("Response : {0}".format(response))
except CloudError as e:
except ResourceNotFoundError as e:
self.log('Could not get facts for Database Account.')

if response and self.has_tags(response.tags, self.tags):
Expand All @@ -460,7 +461,7 @@ def list_by_resource_group(self):
try:
response = self.mgmt_client.database_accounts.list_by_resource_group(resource_group_name=self.resource_group)
self.log("Response : {0}".format(response))
except CloudError as e:
except Exception as e:
self.log('Could not get facts for Database Account.')

if response is not None:
Expand All @@ -476,7 +477,7 @@ def list_all(self):
try:
response = self.mgmt_client.database_accounts.list()
self.log("Response : {0}".format(response))
except CloudError as e:
except Exception as e:
self.log('Could not get facts for Database Account.')

if response is not None:
Expand Down
4 changes: 2 additions & 2 deletions requirements-azure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ azure-mgmt-trafficmanager==1.0.0b1
azure-mgmt-web==6.1.0
azure-nspkg==2.0.0
azure-storage-blob==12.11.0
msrest==0.6.21
msrest==0.7.1
msrestazure==0.6.4
azure-keyvault==1.0.0a1
azure-graphrbac==0.61.1
azure-mgmt-cosmosdb==0.15.0
azure-mgmt-cosmosdb==6.4.0
azure-mgmt-hdinsight==9.0.0
azure-mgmt-devtestlabs==3.0.0
azure-mgmt-loganalytics==12.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
resource_group: "{{ resource_group }}"
virtual_network_name: "{{ vnname }}"
subnet_name: "{{ subnetname }}"
ignore_missing_vnet_service_endpoint: yes
ignore_missing_v_net_service_endpoint: yes
register: output
- name: Assert the resource instance is well created
assert:
Expand All @@ -84,7 +84,7 @@
resource_group: "{{ resource_group }}"
virtual_network_name: "{{ vnname }}"
subnet_name: "{{ subnetname }}"
ignore_missing_vnet_service_endpoint: yes
ignore_missing_v_net_service_endpoint: yes
register: output
- name: Assert the state has not changed
assert:
Expand All @@ -109,7 +109,7 @@
resource_group: "{{ resource_group }}"
virtual_network_name: "{{ vnname }}"
subnet_name: "{{ subnetname }}"
ignore_missing_vnet_service_endpoint: yes
ignore_missing_v_net_service_endpoint: yes
enable_automatic_failover: yes
register: output
- name: Assert the state has changed
Expand All @@ -135,7 +135,7 @@
resource_group: "{{ resource_group }}"
virtual_network_name: "{{ vnname }}"
subnet_name: "{{ subnetname }}"
ignore_missing_vnet_service_endpoint: yes
ignore_missing_v_net_service_endpoint: yes
register: output
- name: Assert the resource instance is well created
assert:
Expand Down Expand Up @@ -278,7 +278,7 @@
resource_group: "{{ resource_group }}"
virtual_network_name: "{{ vnname }}"
subnet_name: "{{ subnetname }}"
ignore_missing_vnet_service_endpoint: yes
ignore_missing_v_net_service_endpoint: yes
enable_automatic_failover: yes
register: output
- name: Assert resource created
Expand Down