Skip to content

Commit

Permalink
Upgrade azure-mgmt-cdn to 11.0.0 (#945)
Browse files Browse the repository at this point in the history
* Upgrade azure-mgmt-cdn to 12.0.0

* new change

* fix sanity error
  • Loading branch information
Fred-sun authored Aug 19, 2022
1 parent 16140f1 commit 6f82aad
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
37 changes: 19 additions & 18 deletions plugins/modules/azure_rm_cdnendpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
from ansible.module_utils.common.dict_transformations import _snake_to_camel

try:
from azure.mgmt.cdn.models import Endpoint, DeepCreatedOrigin, EndpointUpdateParameters, QueryStringCachingBehavior, ErrorResponseException
from azure.mgmt.cdn.models import Endpoint, DeepCreatedOrigin, EndpointUpdateParameters, QueryStringCachingBehavior
from azure.mgmt.cdn import CdnManagementClient
except ImportError:
# This is handled in azure_rm_common
Expand Down Expand Up @@ -359,7 +359,7 @@ def exec_module(self, **kwargs):
self.location = resource_group.location

if self.query_string_caching_behavior:
self.query_string_caching_behavior = _snake_to_camel(self.query_string_caching_behavior)
self.query_string_caching_behavior = _snake_to_camel(self.query_string_caching_behavior, capitalize_first=True)

response = self.get_cdnendpoint()

Expand Down Expand Up @@ -487,10 +487,10 @@ def create_cdnendpoint(self):
)

try:
poller = self.cdn_client.endpoints.create(self.resource_group, self.profile_name, self.name, parameters)
poller = self.cdn_client.endpoints.begin_create(self.resource_group, self.profile_name, self.name, parameters)
response = self.get_poller_result(poller)
return cdnendpoint_to_dict(response)
except ErrorResponseException as exc:
except Exception as exc:
self.log('Error attempting to create Azure CDN endpoint instance.')
self.fail("Error creating Azure CDN endpoint instance: {0}".format(exc.message))

Expand All @@ -515,10 +515,10 @@ def update_cdnendpoint(self):
)

try:
poller = self.cdn_client.endpoints.update(self.resource_group, self.profile_name, self.name, endpoint_update_properties)
poller = self.cdn_client.endpoints.begin_update(self.resource_group, self.profile_name, self.name, endpoint_update_properties)
response = self.get_poller_result(poller)
return cdnendpoint_to_dict(response)
except ErrorResponseException as exc:
except Exception as exc:
self.log('Error attempting to update Azure CDN endpoint instance.')
self.fail("Error updating Azure CDN endpoint instance: {0}".format(exc.message))

Expand All @@ -530,11 +530,11 @@ def delete_cdnendpoint(self):
'''
self.log("Deleting the Azure CDN endpoint {0}".format(self.name))
try:
poller = self.cdn_client.endpoints.delete(
poller = self.cdn_client.endpoints.begin_delete(
self.resource_group, self.profile_name, self.name)
self.get_poller_result(poller)
return True
except ErrorResponseException as e:
except Exception as e:
self.log('Error attempting to delete the Azure CDN endpoint.')
self.fail("Error deleting the Azure CDN endpoint: {0}".format(e.message))
return False
Expand All @@ -552,7 +552,7 @@ def get_cdnendpoint(self):
self.log("Response : {0}".format(response))
self.log("Azure CDN endpoint : {0} found".format(response.name))
return cdnendpoint_to_dict(response)
except ErrorResponseException:
except Exception:
self.log('Did not find the Azure CDN endpoint.')
return False

Expand All @@ -565,12 +565,12 @@ def start_cdnendpoint(self):
self.log(
"Starting the Azure CDN endpoint {0}".format(self.name))
try:
poller = self.cdn_client.endpoints.start(self.resource_group, self.profile_name, self.name)
poller = self.cdn_client.endpoints.begin_start(self.resource_group, self.profile_name, self.name)
response = self.get_poller_result(poller)
self.log("Response : {0}".format(response))
self.log("Azure CDN endpoint : {0} started".format(response.name))
return self.get_cdnendpoint()
except ErrorResponseException:
except Exception:
self.log('Fail to start the Azure CDN endpoint.')
return False

Expand All @@ -583,14 +583,14 @@ def purge_cdnendpoint(self):
self.log(
"Purging the Azure CDN endpoint {0}".format(self.name))
try:
poller = self.cdn_client.endpoints.purge_content(self.resource_group,
self.profile_name,
self.name,
content_paths=self.purge_content_paths)
poller = self.cdn_client.endpoints.begin_purge_content(self.resource_group,
self.profile_name,
self.name,
content_paths=self.purge_content_paths)
response = self.get_poller_result(poller)
self.log("Response : {0}".format(response))
return self.get_cdnendpoint()
except ErrorResponseException as e:
except Exception as e:
self.log('Fail to purge the Azure CDN endpoint.')
return False

Expand All @@ -603,12 +603,12 @@ def stop_cdnendpoint(self):
self.log(
"Stopping the Azure CDN endpoint {0}".format(self.name))
try:
poller = self.cdn_client.endpoints.stop(self.resource_group, self.profile_name, self.name)
poller = self.cdn_client.endpoints.begin_stop(self.resource_group, self.profile_name, self.name)
response = self.get_poller_result(poller)
self.log("Response : {0}".format(response))
self.log("Azure CDN endpoint : {0} stopped".format(response.name))
return self.get_cdnendpoint()
except ErrorResponseException:
except Exception:
self.log('Fail to stop the Azure CDN endpoint.')
return False

Expand Down Expand Up @@ -650,6 +650,7 @@ def get_cdn_client(self):
if not self.cdn_client:
self.cdn_client = self.get_mgmt_svc_client(CdnManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True,
api_version='2017-04-02')
return self.cdn_client

Expand Down
5 changes: 3 additions & 2 deletions plugins/modules/azure_rm_cdnendpoint_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def exec_module(self, **kwargs):

self.cdn_client = self.get_mgmt_svc_client(CdnManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True,
api_version='2017-04-02')

if self.name:
Expand All @@ -250,7 +251,7 @@ def get_item(self):
try:
item = self.cdn_client.endpoints.get(
self.resource_group, self.profile_name, self.name)
except ErrorResponseException:
except Exception:
pass

if item and self.has_tags(item.tags, self.tags):
Expand All @@ -266,7 +267,7 @@ def list_by_profile(self):
try:
response = self.cdn_client.endpoints.list_by_profile(
self.resource_group, self.profile_name)
except ErrorResponseException as exc:
except Exception as exc:
self.fail('Failed to list all items - {0}'.format(str(exc)))

results = []
Expand Down
27 changes: 13 additions & 14 deletions plugins/modules/azure_rm_cdnprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@
import uuid

try:
from azure.mgmt.cdn.models import Profile, Sku, ErrorResponseException
from azure.mgmt.cdn.models import Profile, Sku
from azure.mgmt.cdn import CdnManagementClient
except ImportError:
except ImportError as ec:
# This is handled in azure_rm_common
pass

Expand Down Expand Up @@ -222,16 +222,14 @@ def create_cdnprofile(self):
xid = str(uuid.uuid1())

try:
poller = self.cdn_client.profiles.create(self.resource_group,
self.name,
parameters,
custom_headers={'x-ms-client-request-id': xid}
)
poller = self.cdn_client.profiles.begin_create(self.resource_group,
self.name,
parameters)
response = self.get_poller_result(poller)
return cdnprofile_to_dict(response)
except ErrorResponseException as exc:
except Exception as exc:
self.log('Error attempting to create Azure CDN profile instance.')
self.fail("Error creating Azure CDN profile instance: {0}.\n Request id: {1}".format(exc.message, xid))
self.fail("Error Creating Azure CDN profile instance: {0}".format(exc.message))

def update_cdnprofile(self):
'''
Expand All @@ -242,10 +240,10 @@ def update_cdnprofile(self):
self.log("Updating the Azure CDN profile instance {0}".format(self.name))

try:
poller = self.cdn_client.profiles.update(self.resource_group, self.name, self.tags)
poller = self.cdn_client.profiles.begin_update(self.resource_group, self.name, {'tags': self.tags})
response = self.get_poller_result(poller)
return cdnprofile_to_dict(response)
except ErrorResponseException as exc:
except Exception as exc:
self.log('Error attempting to update Azure CDN profile instance.')
self.fail("Error updating Azure CDN profile instance: {0}".format(exc.message))

Expand All @@ -257,11 +255,11 @@ def delete_cdnprofile(self):
'''
self.log("Deleting the CDN profile {0}".format(self.name))
try:
poller = self.cdn_client.profiles.delete(
poller = self.cdn_client.profiles.begin_delete(
self.resource_group, self.name)
self.get_poller_result(poller)
return True
except ErrorResponseException as e:
except Exception as e:
self.log('Error attempting to delete the CDN profile.')
self.fail("Error deleting the CDN profile: {0}".format(e.message))
return False
Expand All @@ -279,14 +277,15 @@ def get_cdnprofile(self):
self.log("Response : {0}".format(response))
self.log("CDN profile : {0} found".format(response.name))
return cdnprofile_to_dict(response)
except ErrorResponseException:
except Exception:
self.log('Did not find the CDN profile.')
return False

def get_cdn_client(self):
if not self.cdn_client:
self.cdn_client = self.get_mgmt_svc_client(CdnManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True,
api_version='2017-04-02')
return self.cdn_client

Expand Down
7 changes: 3 additions & 4 deletions plugins/modules/azure_rm_cdnprofile_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

try:
from azure.mgmt.cdn.models import ErrorResponseException
from azure.common import AzureHttpError
from azure.mgmt.cdn import CdnManagementClient
except Exception:
# handled in azure_rm_common
Expand Down Expand Up @@ -189,7 +187,7 @@ def get_item(self):
try:
item = self.cdn_client.profiles.get(
self.resource_group, self.name)
except ErrorResponseException:
except Exception:
pass

if item and self.has_tags(item.tags, self.tags):
Expand All @@ -205,7 +203,7 @@ def list_resource_group(self):
try:
response = self.cdn_client.profiles.list_by_resource_group(
self.resource_group)
except AzureHttpError as exc:
except Exception as exc:
self.fail('Failed to list all items - {0}'.format(str(exc)))

results = []
Expand Down Expand Up @@ -253,6 +251,7 @@ def get_cdn_client(self):
if not self.cdn_client:
self.cdn_client = self.get_mgmt_svc_client(CdnManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True,
api_version='2017-04-02')
return self.cdn_client

Expand Down
2 changes: 1 addition & 1 deletion requirements-azure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ azure-identity==1.7.0
azure-mgmt-apimanagement==0.2.0
azure-mgmt-authorization==0.51.1
azure-mgmt-batch==5.0.1
azure-mgmt-cdn==3.0.0
azure-mgmt-cdn==11.0.0
azure-mgmt-compute==26.1.0
azure-mgmt-containerinstance==9.0.0
azure-mgmt-core==1.3.0
Expand Down

0 comments on commit 6f82aad

Please sign in to comment.