Skip to content

Commit

Permalink
Upgrade azure-mgmt-containerservice to 20.0.0 (#881)
Browse files Browse the repository at this point in the history
* Upgrade azure-mgmt-containerservice to 20.0.0

* small change
  • Loading branch information
Fred-sun authored Jul 19, 2022
1 parent b8e3192 commit f95ee0c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
6 changes: 4 additions & 2 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,21 +1146,23 @@ def containerservice_client(self):
if not self._containerservice_client:
self._containerservice_client = self.get_mgmt_svc_client(ContainerServiceClient,
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True,
api_version='2017-07-01')
return self._containerservice_client

@property
def managedcluster_models(self):
self.log("Getting container service models")
return ContainerServiceClient.models('2020-04-01')
return ContainerServiceClient.models('2022-02-01')

@property
def managedcluster_client(self):
self.log('Getting container service client')
if not self._managedcluster_client:
self._managedcluster_client = self.get_mgmt_svc_client(ContainerServiceClient,
base_url=self._cloud_environment.endpoints.resource_manager,
api_version='2020-04-01')
is_track2=True,
api_version='2022-02-01')
return self._managedcluster_client

@property
Expand Down
24 changes: 12 additions & 12 deletions plugins/modules/azure_rm_aks.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,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 @@ -994,20 +994,20 @@ def create_update_aks(self):
# self.log("agent_pool_profiles : {0}".format(parameters.agent_pool_profiles))

try:
poller = self.managedcluster_client.managed_clusters.create_or_update(self.resource_group, self.name, parameters)
poller = self.managedcluster_client.managed_clusters.begin_create_or_update(self.resource_group, self.name, parameters)
response = self.get_poller_result(poller)
response.kube_config = self.get_aks_kubeconfig()
return create_aks_dict(response)
except CloudError as exc:
except Exception as exc:
self.log('Error attempting to create the AKS instance.')
self.fail("Error creating the AKS instance: {0}".format(exc.message))

def update_aks_tags(self):
try:
poller = self.managedcluster_client.managed_clusters.update_tags(self.resource_group, self.name, self.tags)
poller = self.managedcluster_client.managed_clusters.begin_update_tags(self.resource_group, self.name, self.tags)
response = self.get_poller_result(poller)
return response.tags
except CloudError as exc:
except Exception as exc:
self.fail("Error attempting to update AKS tags: {0}".format(exc.message))

def create_update_agentpool(self, to_update_name_list):
Expand All @@ -1028,20 +1028,20 @@ def create_update_agentpool(self, to_update_name_list):
mode=profile["mode"]
)
try:
poller = self.managedcluster_client.agent_pools.create_or_update(self.resource_group, self.name, profile["name"], parameters)
poller = self.managedcluster_client.agent_pools.begin_create_or_update(self.resource_group, self.name, profile["name"], parameters)
response = self.get_poller_result(poller)
response_all.append(response)
except CloudError as exc:
except Exception as exc:
self.fail("Error attempting to update AKS agentpool: {0}".format(exc.message))
return create_agent_pool_profiles_dict(response_all)

def delete_agentpool(self, to_delete_name_list):
for name in to_delete_name_list:
self.log("Deleting the AKS agentpool {0}".format(name))
try:
poller = self.managedcluster_client.agent_pools.delete(self.resource_group, self.name, name)
poller = self.managedcluster_client.agent_pools.begin_delete(self.resource_group, self.name, name)
self.get_poller_result(poller)
except CloudError as exc:
except Exception as exc:
self.fail("Error attempting to update AKS agentpool: {0}".format(exc.message))

def delete_aks(self):
Expand All @@ -1052,10 +1052,10 @@ def delete_aks(self):
'''
self.log("Deleting the AKS instance {0}".format(self.name))
try:
poller = self.managedcluster_client.managed_clusters.delete(self.resource_group, self.name)
poller = self.managedcluster_client.managed_clusters.begin_delete(self.resource_group, self.name)
self.get_poller_result(poller)
return True
except CloudError as e:
except Exception as e:
self.log('Error attempting to delete the AKS instance.')
self.fail("Error deleting the AKS instance: {0}".format(e.message))
return False
Expand All @@ -1073,7 +1073,7 @@ def get_aks(self):
self.log("AKS instance : {0} found".format(response.name))
response.kube_config = self.get_aks_kubeconfig()
return create_aks_dict(response)
except CloudError:
except ResourceNotFoundError:
self.log('Did not find the AKS instance.')
return False

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

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

try:
item = self.managedcluster_client.managed_clusters.get(self.resource_group, self.name)
except CloudError:
except ResourceNotFoundError:
pass

if item and self.has_tags(item.tags, self.tags):
Expand All @@ -153,7 +152,7 @@ def list_items(self):

try:
response = self.managedcluster_client.managed_clusters.list(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
7 changes: 3 additions & 4 deletions plugins/modules/azure_rm_aksupgrade_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

try:
from msrestazure.azure_exceptions import CloudError
from azure.common import AzureHttpError
from azure.core.exceptions import ResourceNotFoundError
except Exception:
# handled in azure_rm_common
pass
Expand Down Expand Up @@ -168,14 +167,14 @@ def get_upgrades(self, name, resource_group):
self.log('Get properties for {0}'.format(self.name))
try:
cluster = self.managedcluster_client.managed_clusters.get(resource_group_name=resource_group, resource_name=name)
except CloudError as err:
except ResourceNotFoundError as err:
self.fail('Error when getting AKS cluster information for {0} : {1}'.format(self.name, err.message or str(err)))

self.log('Get available upgrade versions for {0}'.format(self.name))
try:
upgrade_profiles = self.managedcluster_client.managed_clusters.get_upgrade_profile(resource_group_name=resource_group,
resource_name=name)
except CloudError as err:
except ResourceNotFoundError as err:
self.fail('Error when getting upgrade versions for {0} : {1}'.format(self.name, err.message or str(err)))

return dict(
Expand Down
2 changes: 1 addition & 1 deletion requirements-azure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ azure-mgmt-core==1.3.0
azure-mgmt-containerinstance==1.4.0
azure-mgmt-containerregistry==9.1.0
azure-containerregistry==1.0.0
azure-mgmt-containerservice==9.1.0
azure-mgmt-containerservice==20.0.0
azure-mgmt-datalake-store==0.5.0
azure-mgmt-datafactory==2.0.0
azure-mgmt-dns==8.0.0
Expand Down

0 comments on commit f95ee0c

Please sign in to comment.