def deploy_template(self): """ Deploy the targeted template and parameters :param module: Ansible module containing the validated configuration for the deployment template :param client: resource management client for azure :param conn_info: connection info needed :return: """ deploy_parameter = DeploymentProperties() deploy_parameter.mode = self.deployment_mode if not self.parameters_link: deploy_parameter.parameters = self.parameters else: deploy_parameter.parameters_link = ParametersLink( uri=self.parameters_link ) if not self.template_link: deploy_parameter.template = self.template else: deploy_parameter.template_link = TemplateLink( uri=self.template_link ) params = ResourceGroup(location=self.location, tags=self.tags) try: self.rm_client.resource_groups.create_or_update(self.resource_group_name, params) except CloudError 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_name, self.deployment_name, deploy_parameter) deployment_result = self.get_poller_result(result) if self.wait_for_deployment_completion: while deployment_result.properties.provisioning_state not in ['Canceled', 'Failed', 'Deleted', 'Succeeded']: time.sleep(self.wait_for_deployment_polling_period) deployment_result = self.rm_client.deployments.get(self.resource_group_name, self.deployment_name) except CloudError as exc: failed_deployment_operations = self._get_failed_deployment_operations(self.deployment_name) self.log("Deployment failed %s: %s" % (exc.status_code, exc.message)) self.fail("Deployment failed with status code: %s and message: %s" % (exc.status_code, exc.message), failed_deployment_operations=failed_deployment_operations) if self.wait_for_deployment_completion and deployment_result.properties.provisioning_state != 'Succeeded': self.log("provisioning state: %s" % deployment_result.properties.provisioning_state) failed_deployment_operations = self._get_failed_deployment_operations(self.deployment_name) self.fail('Deployment failed. Deployment id: %s' % deployment_result.id, failed_deployment_operations=failed_deployment_operations) return deployment_result
def deploy_template(self): """ Deploy the targeted template and parameters :param module: Ansible module containing the validated configuration for the deployment template :param client: resource management client for azure :param conn_info: connection info needed :return: """ deploy_parameter = DeploymentProperties(self.deployment_mode) if not self.parameters_link: deploy_parameter.parameters = self.parameters else: deploy_parameter.parameters_link = ParametersLink( uri=self.parameters_link ) if not self.template_link: deploy_parameter.template = self.template else: deploy_parameter.template_link = TemplateLink( uri=self.template_link ) params = ResourceGroup(location=self.location, tags=self.tags) try: self.rm_client.resource_groups.create_or_update(self.resource_group_name, params) except CloudError 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_name, self.deployment_name, deploy_parameter) deployment_result = None if self.wait_for_deployment_completion: deployment_result = self.get_poller_result(result) while deployment_result.properties is None or deployment_result.properties.provisioning_state not in ['Canceled', 'Failed', 'Deleted', 'Succeeded']: time.sleep(self.wait_for_deployment_polling_period) deployment_result = self.rm_client.deployments.get(self.resource_group_name, self.deployment_name) except CloudError as exc: failed_deployment_operations = self._get_failed_deployment_operations(self.deployment_name) self.log("Deployment failed %s: %s" % (exc.status_code, exc.message)) self.fail("Deployment failed with status code: %s and message: %s" % (exc.status_code, exc.message), failed_deployment_operations=failed_deployment_operations) if self.wait_for_deployment_completion and deployment_result.properties.provisioning_state != 'Succeeded': self.log("provisioning state: %s" % deployment_result.properties.provisioning_state) failed_deployment_operations = self._get_failed_deployment_operations(self.deployment_name) self.fail('Deployment failed. Deployment id: %s' % deployment_result.id, failed_deployment_operations=failed_deployment_operations) return deployment_result
def deploy_template(module, client, conn_info): """ Deploy the targeted template and parameters :param module: Ansible module containing the validated configuration for the deployment template :param client: resource management client for azure :param conn_info: connection info needed :return: """ deployment_name = conn_info["deployment_name"] group_name = conn_info["resource_group_name"] deploy_parameter = DeploymentProperties() deploy_parameter.mode = "Complete" if module.params.get('parameters_link') is None: deploy_parameter.parameters = module.params.get('parameters') else: parameters_link = ParametersLink( uri=module.params.get('parameters_link')) deploy_parameter.parameters_link = parameters_link if module.params.get('template_link') is None: deploy_parameter.template = module.params.get('template') else: template_link = TemplateLink(uri=module.params.get('template_link')) deploy_parameter.template_link = template_link params = ResourceGroup(location=module.params.get('location'), tags=module.params.get('tags')) try: client.resource_groups.create_or_update(group_name, params) result = client.deployments.create_or_update(group_name, deployment_name, deploy_parameter) return result.result() # Blocking wait, return the Deployment object except CloudError as e: module.fail_json( msg='Deploy create failed with status code: %s and message: "%s"' % (e.status_code, e.message))
def deploy_template(module, client, conn_info): """ Deploy the targeted template and parameters :param module: Ansible module containing the validated configuration for the deployment template :param client: resource management client for azure :param conn_info: connection info needed :return: """ deployment_name = conn_info["deployment_name"] group_name = conn_info["resource_group_name"] deploy_parameter = DeploymentProperties() deploy_parameter.mode = "Complete" if module.params.get('parameters_link') is None: deploy_parameter.parameters = module.params.get('parameters') else: parameters_link = ParametersLink( uri = module.params.get('parameters_link') ) deploy_parameter.parameters_link = parameters_link if module.params.get('template_link') is None: deploy_parameter.template = module.params.get('template') else: template_link = TemplateLink( uri = module.params.get('template_link') ) deploy_parameter.template_link = template_link params = ResourceGroup(location=module.params.get('location'), tags=module.params.get('tags')) try: client.resource_groups.create_or_update(group_name, params) result = client.deployments.create_or_update(group_name, deployment_name, deploy_parameter) return result.result() # Blocking wait, return the Deployment object except CloudError as e: module.fail_json(msg='Deploy create failed with status code: %s and message: "%s"' % (e.status_code, e.message))
def _create_aks(self): with open(os.path.join(self.base_path, CreateAKS.PARAMETERS_JSON)) as in_file: parameters = json.load(in_file) parameters[u"resourceName"][u"value"] = self.context.aks_name parameters[u"agentCount"][u"value"] = self.context.node_count parameters[u"agentVMSize"][u'Value'] = self.context.vm_size parameters[u"osDiskSizeGB"][u'Value'] = int(self.context.os_disk_size) parameters[u"sshRSAPublicKey"][u'Value'] = self.context.public_key parameters[u"servicePrincipalClientId"][ u'Value'] = self.context.client_id parameters[u"servicePrincipalClientSecret"][ u'Value'] = self.context.secret parameters[u"kubernetesVersion"][u'Value'] = self.context.k8s_version parameters[u"dnsPrefix"][u'Value'] = "{0}-maprtech".format( self.context.aks_name) with open(os.path.join(self.base_path, CreateAKS.ARM_TEMPLATE_JSON)) as in_file: template = json.load(in_file) deployment_properties = DeploymentProperties() deployment_properties.template = template deployment_properties.parameters = parameters deployment_properties.mode = DeploymentMode.incremental Log.info( "{0}: Run K8S deployment test with {1} Nodes OS Disk Size {2}...". format(self.context.resource_group, self.context.node_count, self.context.os_disk_size), True) deployment_async_operation = self.resource_client.deployments.create_or_update( self.context.resource_group, "maprk8s.deployment", deployment_properties) deployment_async_operation.wait() Log.info("K8S cluster deployment complete", True)
def deploy_template(module, client, conn_info): """ Deploy the targeted template and parameters :param module: Ansible module containing the validated configuration for the deployment template :param client: resource management client for azure :param conn_info: connection info needed :return: """ deployment_name = conn_info["deployment_name"] group_name = conn_info["resource_group_name"] deploy_parameter = DeploymentProperties() deploy_parameter.mode = module.params.get('deployment_mode') if module.params.get('parameters_link') is None: deploy_parameter.parameters = module.params.get('parameters') else: parameters_link = ParametersLink( uri=module.params.get('parameters_link')) deploy_parameter.parameters_link = parameters_link if module.params.get('template_link') is None: deploy_parameter.template = module.params.get('template') else: template_link = TemplateLink(uri=module.params.get('template_link')) deploy_parameter.template_link = template_link params = ResourceGroup(location=module.params.get('location'), tags=module.params.get('tags')) try: client.resource_groups.create_or_update(group_name, params) result = client.deployments.create_or_update(group_name, deployment_name, deploy_parameter) deployment_result = result.result( ) # Blocking wait, return the Deployment object if module.params.get('wait_for_deployment_completion'): while not deployment_result.properties.provisioning_state in [ 'Canceled', 'Failed', 'Deleted', 'Succeeded' ]: deployment_result = client.deployments.get( group_name, deployment_name) time.sleep( module.params.get('wait_for_deployment_polling_period')) if deployment_result.properties.provisioning_state == 'Succeeded': return deployment_result failed_deployment_operations = get_failed_deployment_operations( module, client, group_name, deployment_name) module.fail_json( msg='Deployment failed. Deployment id: %s' % (deployment_result.id), failed_deployment_operations=failed_deployment_operations) except CloudError as e: failed_deployment_operations = get_failed_deployment_operations( module, client, group_name, deployment_name) module.fail_json( msg='Deploy create failed with status code: %s and message: "%s"' % (e.status_code, e.message), failed_deployment_operations=failed_deployment_operations)