From 8fa1373a67da1801bd1df121851d6a619d002499 Mon Sep 17 00:00:00 2001 From: Zhijun Zhao Date: Thu, 23 Nov 2017 16:30:38 +0800 Subject: [PATCH] Fix azure_rm_acs due to Azure breaking API change --- lib/ansible/module_utils/azure_rm_common.py | 6 ++-- .../modules/cloud/azure/azure_rm_acs.py | 31 +++++++++++++++---- packaging/requirements/requirements-azure.txt | 2 +- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/ansible/module_utils/azure_rm_common.py b/lib/ansible/module_utils/azure_rm_common.py index d27f4af5d53..a5930a20bc7 100644 --- a/lib/ansible/module_utils/azure_rm_common.py +++ b/lib/ansible/module_utils/azure_rm_common.py @@ -780,12 +780,14 @@ class AzureRMModuleBase(object): def web_client(self): self.log('Getting web client') if not self._web_client: - self._web_client = self.get_mgmt_svc_client(WebSiteManagementClient, base_url=self.base_url) + self._web_client = self.get_mgmt_svc_client(WebSiteManagementClient, + base_url=self._cloud_environment.endpoints.resource_manager) return self._web_client @property def containerservice_client(self): self.log('Getting container service client') if not self._containerservice_client: - self._containerservice_client = self.get_mgmt_svc_client(ContainerServiceClient) + self._containerservice_client = self.get_mgmt_svc_client(ContainerServiceClient, + base_url=self._cloud_environment.endpoints.resource_manager) return self._containerservice_client diff --git a/lib/ansible/modules/cloud/azure/azure_rm_acs.py b/lib/ansible/modules/cloud/azure/azure_rm_acs.py index 409fe0ce4fe..acd4bda8495 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_acs.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_acs.py @@ -62,6 +62,11 @@ options: - 1 - 3 - 5 + vm_size: + description: + - The VM Size of each of the Agent Pool VM's (e.g. Standard_F1 / Standard_D2v2). + required: true + default: Standard_D2v2 dns_prefix: description: - The DNS Prefix to use for the Container Service master nodes. @@ -325,8 +330,10 @@ def create_master_profile_instance(masterprofile): ''' return ContainerServiceMasterProfile( count=masterprofile[0]['count'], - dns_prefix=masterprofile[0]['dns_prefix'] - ) + dns_prefix=masterprofile[0]['dns_prefix'], + vm_size=masterprofile[0]['vm_size'], + first_consecutive_static_ip=None + ) def create_diagnostics_profile_instance(diagprofile): @@ -365,7 +372,7 @@ def create_acs_dict(acs): orchestrator_profile=create_orchestrator_profile_dict(acs.orchestrator_profile), master_profile=create_master_profile_dict(acs.master_profile), linux_profile=create_linux_profile_dict(acs.linux_profile), - service_principal_profile=acs.service_principal_profile, + service_principal_profile=create_service_principal_profile_dict(acs.service_principal_profile), diagnostics_profile=create_diagnotstics_profile_dict(acs.diagnostics_profile), provisioning_state=acs.provisioning_state, agent_pool_profiles=create_agent_pool_profiles_dict(acs.agent_pool_profiles), @@ -396,10 +403,22 @@ def create_master_profile_dict(masterprofile): results = dict( count=masterprofile.count, fqdn=masterprofile.fqdn, + vm_size=masterprofile.vm_size, dns_prefix=masterprofile.dns_prefix ) return results +def create_service_principal_profile_dict(serviceprincipalprofile): + ''' + Helper method to deserialize a ContainerServiceServicePrincipalProfile to a dict + :param: serviceprincipalprofile: ContainerServiceServicePrincipalProfile with the Azure callback object + :return: dict with the state on Azure + ''' + results = dict( + client_id=serviceprincipalprofile.client_id, + secret=serviceprincipalprofile.secret + ) + return results def create_diagnotstics_profile_dict(diagnosticsprofile): ''' @@ -564,12 +583,12 @@ class AzureRMContainerService(AzureRMModuleBase): to_be_updated = True # Cannot Update the master count for now // Uncomment this block in the future to support it - if response['master_profile'].get('count') != self.master_profile[0].get('count'): + if response['master_profile'].get('count') != self.master_profile[0].get('count') or response['master_profile'].get('vm_size') != self.master_profile[0].get('vm_size'): # self.log(("Master Profile Count Diff, Was {0} / Now {1}" # .format(response['master_profile'].count, # self.master_profile[0].get('count')))) # to_be_updated = True - self.module.warn("master_profile.count cannot be updated") + self.module.warn("master_profile.count or master_profile.vm_size cannot be updated") # Cannot Update the SSH Key for now // Uncomment this block in the future to support it if response['linux_profile'].get('ssh_key') != self.linux_profile[0].get('ssh_key'): @@ -649,7 +668,7 @@ class AzureRMContainerService(AzureRMModuleBase): location=self.location, tags=self.tags, orchestrator_profile=create_orch_platform_instance(self.orchestration_platform), - service_principal_profile=service_principal_profile, + service_principal_profile=create_service_principal_profile_instance(self.service_principal), linux_profile=create_linux_profile_instance(self.linux_profile), master_profile=create_master_profile_instance(self.master_profile), agent_pool_profiles=agentpools, diff --git a/packaging/requirements/requirements-azure.txt b/packaging/requirements/requirements-azure.txt index cc2ce7e006e..adb575510a3 100644 --- a/packaging/requirements/requirements-azure.txt +++ b/packaging/requirements/requirements-azure.txt @@ -13,4 +13,4 @@ azure-mgmt-keyvault>=0.40.0,<0.41 azure-mgmt-batch>=4.1.0,<5 azure-mgmt-sql>=0.7.1,<0.8 azure-mgmt-web>=0.32.0,<0.33 -azure-mgmt-containerservice>=1.0.0 \ No newline at end of file +azure-mgmt-containerservice>=2.0.0,<3.0.0 \ No newline at end of file