def _deploy_arm_template_core(resource_group_name, template_file=None, template_uri=None, deployment_name=None, parameter_list=None, mode='incremental', validate_only=False, no_wait=False): from azure.mgmt.resource.resources.models import DeploymentProperties, TemplateLink if bool(template_uri) == bool(template_file): raise CLIError('please provide either template file path or uri, but not both') parameters = _merge_parameters(parameter_list) template = None template_link = None if template_uri: template_link = TemplateLink(uri=template_uri) else: template = get_file_json(template_file) missing = _find_missing_parameters(parameters, template) if len(missing) > 0: prompt_parameters = _prompt_for_parameters(missing) for param_name in prompt_parameters: parameters[param_name] = prompt_parameters[param_name] properties = DeploymentProperties(template=template, template_link=template_link, parameters=parameters, mode=mode) smc = get_mgmt_service_client(ResourceManagementClient) if validate_only: return smc.deployments.validate(resource_group_name, deployment_name, properties, raw=no_wait) else: return smc.deployments.create_or_update(resource_group_name, deployment_name, properties, raw=no_wait)
def _deploy_arm_template_core(resource_group_name, template_file=None, template_uri=None, deployment_name=None, parameters=None, mode='incremental', validate_only=False, no_wait=False): from azure.mgmt.resource.resources.models import DeploymentProperties, TemplateLink if bool(template_uri) == bool(template_file): raise CLIError('please provide either template file path or uri, but not both') if parameters: parameters = json.loads(parameters) if parameters: parameters = parameters.get('parameters', parameters) template = None template_link = None if template_uri: template_link = TemplateLink(uri=template_uri) else: template = get_file_json(template_file) properties = DeploymentProperties(template=template, template_link=template_link, parameters=parameters, mode=mode) smc = get_mgmt_service_client(ResourceManagementClient) if validate_only: return smc.deployments.validate(resource_group_name, deployment_name, properties, raw=no_wait) else: return smc.deployments.create_or_update(resource_group_name, deployment_name, properties, raw=no_wait)
def run(self, subscription_id, deployment_name, group_name, template_uri, parameters_uri): credentials = self.credentials resource_client = ResourceManagementClient( ResourceManagementClientConfiguration( credentials, subscription_id)) template = TemplateLink( uri=template_uri, ) parameters = ParametersLink( uri=parameters_uri, ) result = resource_client.deployments.create_or_update( group_name, deployment_name, Deployment( properties=DeploymentProperties( mode=DeploymentMode.incremental, template_link=template, parameters_link=parameters, ) ) ) return result
def __init__(self, **kwargs): """ Args: All Azure supported sections are allowed, plus: - BuildId(str): The build ID. This will be merged to the parameters dict. All arguments provided will be set as object attributes, but the attributes not supported by the resources API will be unset after initialization so the attributes can be fed to the API wholesale. """ super().__init__(**kwargs) # Can't have both template and templateLink if hasattr(self, "templateLink") and hasattr(self, "template"): raise SystemExit( f"Please specify either template and templateLink") if hasattr(self, "templateLink"): self.templateLink = TemplateLink(self.templateLink) if hasattr(self, "parametersLink"): self.parametersLink = ParametersLink(self.parametersLink) if hasattr(self, "template"): # If template not already a dict, render from path/URL if not isinstance(self.template, dict): parsed_url, template_body = \ gpwm.renderers.get_template_body(self.template) if parsed_url.path[-5:] == ".mako": if not hasattr(self, "parameters"): self.parameters = {} self.parameters["build_id"] = self.BuildId args = [self.name, template_body, self.parameters] template = gpwm.renderers.parse_mako(*args) # mako doesn't need Parameters as they're available to the # template as python variables del self.parameters elif parsed_url.path[-6:] == ".jinja": args = [self.name, template_body, self.parameters] template = gpwm.renderers.parse_jinja(*args) # jinja doesn't need Parameters as they're available to the # template as python variables del self.parameters elif parsed_url.path[-5:] == ".json": args = [self.name, template_body, self.parameters] template = gpwm.renderers.parse_json(*args) elif parsed_url.path[-5:] == ".yaml": args = [self.name, template_body, self.parameters] template = gpwm.renderers.parse_yaml(*args) else: raise SystemExit("file extension not supported") self.template = template self.api_client = AzureClient().get( "resource.ResourceManagementClient")
def deploy_acs_template( cls, azure_wrapper, template_uri, location, group_name, public_key, master_prefix, agent_prefix, admin_name, oauth_enabled: Union[bool, str], vm_size, agent_count, name_suffix, vm_diagnostics_enabled: bool): """ Creates a new resource group and deploys a ACS DC/OS template to it """ assert master_prefix != agent_prefix, 'Master and agents must have unique prefixs' validate_hostname_prefix(master_prefix) validate_hostname_prefix(agent_prefix) deployment_name = DEPLOYMENT_NAME.format(group_name) # Resource group must be created before validation can occur if azure_wrapper.rmc.resource_groups.check_existence(group_name): raise Exception("Group name already exists / taken: {}".format(group_name)) log.info('Starting resource group_creation') with contextlib.ExitStack() as stack: azure_wrapper.rmc.resource_groups.create_or_update( group_name, ResourceGroup(location=location)) stack.callback(azure_wrapper.rmc.resource_groups.delete, group_name) log.info('Resource group created: {}'.format(group_name)) template_params = { 'sshRSAPublicKey': public_key, # must be lower or validation will fail 'masterEndpointDNSNamePrefix': master_prefix, 'agentEndpointDNSNamePrefix': agent_prefix, 'linuxAdminUsername': admin_name, 'agentVMSize': vm_size, 'agentCount': agent_count, 'nameSuffix': name_suffix, 'oauthEnabled': repr(oauth_enabled).lower(), # oauth uses string, vm diagnostic uses bool 'enableVMDiagnostics': vm_diagnostics_enabled} log.info('Provided template parameters: {}'.format(template_params)) # azure requires that parameters be provided as {key: {'value': value}} template_parameters = {k: {'value': v} for k, v in template_params.items()} deployment_properties = DeploymentProperties( template_link=TemplateLink(uri=template_uri), mode=DeploymentMode.incremental, parameters=template_parameters) log.info('Checking with Azure to validate template deployment') result = azure_wrapper.rmc.deployments.validate( group_name, deployment_name, properties=deployment_properties) if result.error: for details in result.error.details: log.error('{}: {}'.format(details.code, details.message)) error_msgs = '\n'.join(['{}: {}'.format(d.code, d.message) for d in result.error.details]) raise Exception("Template verification failed!\n{}".format(error_msgs)) log.info('Template successfully validated') log.info('Starting template deployment') azure_wrapper.rmc.deployments.create_or_update( group_name, deployment_name, deployment_properties) stack.pop_all() return cls(group_name, azure_wrapper)
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 run(params): credentials = ServicePrincipalCredentials( client_id=params['client_id'], secret=params['client_secret'], tenant=params['tenant_id'], ) resource_client = ResourceManagementClient(credentials, params['subscription_id']) log.info('Created service principal, resource manager client') # Instantiate objs for deployment use_custom_cidr = 'vnet_address_prefix' in params and params[ 'vnet_address_prefix'] template_uri = CUSTOM_CIDR_TEMPLATE_URI if use_custom_cidr else CUSTOM_CIDR_TEMPLATE_URI template_link = TemplateLink(uri=template_uri) log.info('Using template URI: {}'.format(template_uri)) # Deployment request deployment_params = { 'location': { 'value': params['location'] }, 'workspaceName': { 'value': params['workspace_name'] }, 'pricingTier': { 'value': params['pricing_tier'] } } if use_custom_cidr: deployment_params['vnetAddressPrefix'] = { 'value': params['vnet_address_prefix'] } log.info('Using custom CIDR range') deployment_properties = { 'mode': DeploymentMode.incremental, 'template_link': template_link, 'parameters': deployment_params } log.debug('Deployment properties:', deployment_properties) resource_deployment_res = resource_client.deployments.create_or_update( params['rg_name'], params['deployment_name'], deployment_properties) log.info('Created or updated deployment') log.debug('Deployment response: {}'.format(resource_deployment_res)) return 'https://' + params['location'] + '.azuredatabricks.net'
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 main(): validate_env() location = os.getenv('AZURE_LOCATION', 'East US') credentials = azure.common.credentials.ServicePrincipalCredentials( client_id=os.environ['AZURE_CLIENT_ID'], secret=os.environ['AZURE_CLIENT_SECRET'], tenant=os.environ['AZURE_TENANT_ID']) subscription_id = os.environ['AZURE_SUBSCRIPTION_ID'] template = TemplateLink(uri=os.environ['AZURE_TEMPLATE_URL']) # tenant_id = os.environ.get('AZURE_TENANT_ID') # client_id = os.environ.get('AZURE_CLIENT_ID') # client_secret = os.environ.get('AZURE_CLIENT_SECRET') group_name = 'testing' + ''.join(random.choice('01234567890abcdef') for n in range(10)) deployment_name = 'deployment{}'.format(uuid.uuid4().hex) rmc = ResourceManagementClient(credentials, subscription_id) template_parameters = get_env_params() # Output resource group print("Resource group name: {}".format(group_name)) print("Deployment name: {}".format(deployment_name)) azure_cluster = { 'resource_group_name': group_name, 'deployment_name': deployment_name} pkgpanda.util.write_json('azure-cluster.json', azure_cluster) # Create a new resource group print("Creating new resource group in location: {}".format(location)) if rmc.resource_groups.check_existence(group_name): print("ERROR: Group name already exists / taken: {}".format(group_name)) rmc.resource_groups.create_or_update( group_name, ResourceGroup(location=location)) test_successful = False try: deployment_properties = DeploymentProperties( template_link=template, mode=DeploymentMode.incremental, parameters=template_parameters) # Use RPC against azure to validate the ARM template is well-formed result = rmc.deployments.validate(group_name, deployment_name, properties=deployment_properties) if result.error: print("Template verification failed\n{}".format(result.error), file=sys.stderr) sys.exit(1) # Actually create a template deployment print("Creating template deployment ...") deploy_poller = rmc.deployments.create_or_update(group_name, deployment_name, deployment_properties) # Stop after 45 attempts (each one takes up to one minute) @retry(stop_max_attempt_number=45) def poll_deploy(): res = deploy_poller.result(timeout=60) print("Current deploy state: {}".format(res.properties.provisioning_state)) assert deploy_poller.done(), "Not done deploying." print("Waiting for template to deploy ...") try: poll_deploy() except: print("Current deploy status:\n{}".format(deploy_poller.result(0))) raise print("Template deployed successfully") assert deploy_poller.done(), "Deployment failed / polling didn't reach deployment done." deployment_result = deploy_poller.result() print(deployment_result.properties.outputs) master_lb = deployment_result.properties.outputs['masterFQDN']['value'] print("Template deployed using SSH private key: https://mesosphere.onelogin.com/notes/18444") print("For troubleshooting, master0 can be reached using: ssh -p 2200 {}@{}".format( get_value('linuxAdminUsername'), master_lb)) # Run test now, so grab IPs nmc = NetworkManagementClient(credentials, subscription_id) ip_buckets = { 'master': [], 'private': [], 'public': []} for resource in rmc.resource_groups.list_resources( group_name, filter=("resourceType eq 'Microsoft.Network/networkInterfaces' or " "resourceType eq 'Microsoft.Compute/virtualMachineScaleSets'")): if resource.type == 'Microsoft.Network/networkInterfaces': nics = [nmc.network_interfaces.get(group_name, resource.name)] elif resource.type == 'Microsoft.Compute/virtualMachineScaleSets': nics = list(nmc.network_interfaces.list_virtual_machine_scale_set_network_interfaces( virtual_machine_scale_set_name=resource.name, resource_group_name=group_name)) else: raise('Unexpected resourceType: {}'.format(resource.type)) for bucket_name in ip_buckets.keys(): if bucket_name in resource.name: for n in nics: for config in n.ip_configurations: ip_buckets[bucket_name].append(config.private_ip_address) print('Detected IP configuration: {}'.format(ip_buckets)) with Tunnel(get_value('linuxAdminUsername'), 'ssh_key', master_lb, port=2200) as t: integration_test( tunnel=t, test_dir='/home/{}'.format(get_value('linuxAdminUsername')), dcos_dns=ip_buckets['master'][0], master_list=ip_buckets['master'], agent_list=ip_buckets['private'], public_agent_list=ip_buckets['public'], provider='azure', test_dns_search=False, add_env=get_test_config(), pytest_cmd=os.getenv('DCOS_PYTEST_CMD', "py.test -vv -s -rs -m 'not ccm' ") + os.getenv('CI_FLAGS', '')) test_successful = True except Exception as ex: traceback.print_exc() print("ERROR: exception {}".format(ex)) raise finally: if os.getenv('AZURE_CLEANUP') == 'false': print("Cluster must be cleaned up manually") print("Cluster details: {}".format(azure_cluster)) else: # Send a delete request # TODO(cmaloney): The old code had a retry around this: # @retry(wait_exponential_multiplier=1000, wait_exponential_max=60*1000, stop_max_delay=(30*60*1000)) poller = rmc.resource_groups.delete(group_name) # poll for the delete to complete print("Deleting resource group: {} ...".format(group_name)) @retry(wait_fixed=(5 * 1000), stop_max_delay=(60 * 60 * 1000)) def wait_for_delete(): assert poller.done(), "Timed out waiting for delete" print("Waiting for delete ...") wait_for_delete() print("Clean up successful") if test_successful: print("Azure test deployment succeeded") else: print("ERROR: Azure test deployment failed", file=sys.stderr) sys.exit(2)
def run(params): credentials = ServicePrincipalCredentials( client_id=params['client_id'], secret=params['client_secret'], tenant=params['tenant_id'], ) resource_client = ResourceManagementClient(credentials, params['subscription_id']) log.info('Created service principal, resource manager client') # Instantiate objs for deployment # use_custom_cidr = 'vnet_address_prefix' in params and params['vnet_address_prefix'] template_uri = ALL_IN_ONE template_link = TemplateLink(uri=template_uri) log.info('Using template URI: {}'.format(template_uri)) # Deployment request deployment_params = { 'location': { 'value': params['location'] }, 'workspaceName': { 'value': params['workspace_name'] }, 'pricingTier': { 'value': params['pricing_tier'] }, 'nsgName': { 'value': params['nsg_name'] }, 'vnetName': { 'value': params['vnet_name'] }, 'privateSubnetName': { 'value': params['private_subnet_name'] }, 'publicSubnetName': { 'value': params['public_subnet_name'] }, 'vnetCidr': { 'value': params['vnet_cidr'] }, 'privateSubnetCidr': { 'value': params['private_subnet_cidr'] }, 'publicSubnetCidr': { 'value': params['public_subnet_cidr'] }, 'enableNoPublicIp': { 'value': params['enable_npip'] }, 'createdBy': { 'value': params['created_by'] } } deployment_properties = { 'mode': DeploymentMode.incremental, 'template_link': template_link, 'parameters': deployment_params } log.debug('Deployment properties:', deployment_properties) resource_deployment_res = resource_client.deployments.create_or_update( params['rg_name'], params['deployment_name'], deployment_properties) log.info('Created or updated deployment') log.debug('Deployment response: {}'.format(resource_deployment_res)) workspace_url = get_deployment_status(params) return workspace_url
def run(): location = os.getenv('AZURE_LOCATION', 'East US') credentials = azure.common.credentials.ServicePrincipalCredentials( client_id=os.environ['AZURE_CLIENT_ID'], secret=os.environ['AZURE_CLIENT_SECRET'], tenant=os.environ['AZURE_TENANT_ID']) subscription_id = os.environ['AZURE_SUBSCRIPTION_ID'] template = TemplateLink(uri=os.environ['AZURE_TEMPLATE_URL']) # tenant_id = os.environ.get('AZURE_TENANT_ID') # client_id = os.environ.get('AZURE_CLIENT_ID') # client_secret = os.environ.get('AZURE_CLIENT_SECRET') group_name = 'tesing' + ''.join( random.choice('01234567890abcdef') for n in range(10)) deployment_name = 'deployment{}'.format(uuid.uuid4().hex) rmc = ResourceManagementClient(credentials, subscription_id) template_parameters = get_env_params() # Output resource group print("Resource group name: {}".format(group_name)) print("Deployment name: {}".format(deployment_name)) azure_cluster = { 'resource_group_name': group_name, 'deployment_name': deployment_name } pkgpanda.util.write_json('azure-cluster.json', azure_cluster) # Create a new resource group print("Creating new resource group in location: {}".format(location)) if rmc.resource_groups.check_existence(group_name): print( "ERROR: Group name already exists / taken: {}".format(group_name)) rmc.resource_groups.create_or_update(group_name, ResourceGroup(location=location)) test_successful = False try: deployment_properties = DeploymentProperties( template_link=template, mode=DeploymentMode.incremental, parameters=template_parameters) # Use RPC against azure to validate the ARM template is well-formed result = rmc.deployments.validate(group_name, deployment_name, properties=deployment_properties) if result.error: print("Template verification failed\n{}".format(result.error), file=sys.stderr) sys.exit(1) # Actually create a template deployment print("Creating template deployment ...") deploy_poller = rmc.deployments.create_or_update( group_name, deployment_name, deployment_properties) # Stop after 45 attempts (each one takes up to one minute) @retry(stop_max_attempt_number=45) def poll_deploy(): res = deploy_poller.result(timeout=60) print("Current deploy state: {}".format( res.properties.provisioning_state)) assert deploy_poller.done(), "Not done deploying." print("Waiting for template to deploy ...") try: poll_deploy() except: print("Current deploy status:\n{}".format(deploy_poller.result(0))) raise print("Template deployed successfully") assert deploy_poller.done( ), "Deployment failed / polling didn't reach deployment done." deployment_result = deploy_poller.result() print(deployment_result.properties.outputs) master_lb = deployment_result.properties.outputs['dnsAddress']['value'] master_url = "http://{}".format(master_lb) print( "Template deployed using SSH private key: https://mesosphere.onelogin.com/notes/18444" ) print( "For troubleshooting, master0 can be reached using: ssh -p 2200 core@{}" .format(master_lb)) @retry(wait_fixed=(5 * 1000), stop_max_delay=(15 * 60 * 1000)) def poll_on_dcos_ui_up(): r = get_dcos_ui(master_url) assert r is not None and r.status_code == requests.codes.ok, \ "Unable to reach DC/OS UI: {}".format(master_url) print("Waiting for DC/OS UI at: {} ...".format(master_url)) poll_on_dcos_ui_up() test_successful = True except Exception as ex: print("ERROR: exception {}".format(ex)) raise finally: # Send a delete request # TODO(cmaloney): The old code had a retry around this: # @retry(wait_exponential_multiplier=1000, wait_exponential_max=60*1000, stop_max_delay=(30*60*1000)) poller = rmc.resource_groups.delete(group_name) # poll for the delete to complete print("Deleting resource group: {} ...".format(group_name)) @retry(wait_fixed=(5 * 1000), stop_max_delay=(60 * 60 * 1000)) def wait_for_delete(): assert poller.done(), "Timed out waiting for delete" print("Waiting for delete ...") wait_for_delete() print("Clean up successful") if test_successful: print("Azure test deployment succeeded") else: print("ERROR: Azure test deployment failed", file=sys.stderr) sys.exit(2)
def run(): location = os.getenv('AZURE_LOCATION', 'East US') credentials = azure.common.credentials.ServicePrincipalCredentials( client_id=os.environ['AZURE_CLIENT_ID'], secret=os.environ['AZURE_CLIENT_SECRET'], tenant=os.environ['AZURE_TENANT_ID']) subscription_id = os.environ['AZURE_SUBSCRIPTION_ID'] template = TemplateLink(uri=os.environ['AZURE_TEMPLATE_URL']) # tenant_id = os.environ.get('AZURE_TENANT_ID') # client_id = os.environ.get('AZURE_CLIENT_ID') # client_secret = os.environ.get('AZURE_CLIENT_SECRET') group_name = 'tesing' + ''.join( random.choice('01234567890abcdef') for n in range(10)) deployment_name = 'deployment{}'.format(uuid.uuid4().hex) rmc = ResourceManagementClient(credentials, subscription_id) template_parameters = get_env_params() if template_parameters.get('numberOfPrivateSlaves'): assert template_parameters['numberOfPrivateSlaves'][ 'value'] >= 2, 'Test requires at least 2 private slaves!' else: template_parameters['numberOfPrivateSlaves'] = {'value': 2} if template_parameters.get('numberOfPublicSlaves'): assert template_parameters['numberOfPublicSlaves'][ 'value'] >= 1, 'Test requires at least 1 public slave!' else: template_parameters['numberOfPublicSlaves'] = {'value': 1} # Output resource group print("Resource group name: {}".format(group_name)) print("Deployment name: {}".format(deployment_name)) azure_cluster = { 'resource_group_name': group_name, 'deployment_name': deployment_name } pkgpanda.util.write_json('azure-cluster.json', azure_cluster) # Create a new resource group print("Creating new resource group in location: {}".format(location)) if rmc.resource_groups.check_existence(group_name): print( "ERROR: Group name already exists / taken: {}".format(group_name)) rmc.resource_groups.create_or_update(group_name, ResourceGroup(location=location)) test_successful = False try: deployment_properties = DeploymentProperties( template_link=template, mode=DeploymentMode.incremental, parameters=template_parameters) # Use RPC against azure to validate the ARM template is well-formed result = rmc.deployments.validate(group_name, deployment_name, properties=deployment_properties) if result.error: print("Template verification failed\n{}".format(result.error), file=sys.stderr) sys.exit(1) # Actually create a template deployment print("Creating template deployment ...") deploy_poller = rmc.deployments.create_or_update( group_name, deployment_name, deployment_properties) # Stop after 45 attempts (each one takes up to one minute) @retry(stop_max_attempt_number=45) def poll_deploy(): res = deploy_poller.result(timeout=60) print("Current deploy state: {}".format( res.properties.provisioning_state)) assert deploy_poller.done(), "Not done deploying." print("Waiting for template to deploy ...") try: poll_deploy() except: print("Current deploy status:\n{}".format(deploy_poller.result(0))) raise print("Template deployed successfully") assert deploy_poller.done( ), "Deployment failed / polling didn't reach deployment done." deployment_result = deploy_poller.result() print(deployment_result.properties.outputs) master_lb = deployment_result.properties.outputs['dnsAddress']['value'] master_url = "http://{}".format(master_lb) print( "Template deployed using SSH private key: https://mesosphere.onelogin.com/notes/18444" ) print( "For troubleshooting, master0 can be reached using: ssh -p 2200 core@{}" .format(master_lb)) @retry(wait_fixed=(5 * 1000), stop_max_delay=(15 * 60 * 1000)) def poll_on_dcos_ui_up(): r = get_dcos_ui(master_url) assert r is not None and r.status_code == requests.codes.ok, \ "Unable to reach DC/OS UI: {}".format(master_url) print("Waiting for DC/OS UI at: {} ...".format(master_url)) poll_on_dcos_ui_up() # Run test now, so grab IPs nmc = NetworkManagementClient(credentials, subscription_id) ip_buckets = { 'masterNodeNic': [], 'slavePrivateNic': [], 'slavePublicNic': [] } for resource in rmc.resource_groups.list_resources(group_name): for bucket_name, bucket in ip_buckets.items(): if resource.name.startswith(bucket_name): nic = nmc.network_interfaces.get(group_name, resource.name) all_ips = [] for config in nic.ip_configurations: all_ips.append(config.private_ip_address) bucket.extend(all_ips) with closing(SSHTunnel('core', 'ssh_key', master_lb, port=2200)) as t: integration_test( tunnel=t, test_dir='/home/core', dcos_dns=master_lb, master_list=ip_buckets['masterNodeNic'], agent_list=ip_buckets['slavePrivateNic'], public_agent_list=ip_buckets['slavePublicNic'], provider='azure', test_dns_search=False, pytest_dir=os.getenv( 'DCOS_PYTEST_DIR', '/opt/mesosphere/active/dcos-integration-test'), pytest_cmd=os.getenv('DCOS_PYTEST_CMD', "py.test -vv -m 'not ccm' ") + os.getenv('CI_FLAGS', '')) test_successful = True except Exception as ex: print("ERROR: exception {}".format(ex)) raise finally: # Send a delete request # TODO(cmaloney): The old code had a retry around this: # @retry(wait_exponential_multiplier=1000, wait_exponential_max=60*1000, stop_max_delay=(30*60*1000)) poller = rmc.resource_groups.delete(group_name) # poll for the delete to complete print("Deleting resource group: {} ...".format(group_name)) @retry(wait_fixed=(5 * 1000), stop_max_delay=(60 * 60 * 1000)) def wait_for_delete(): assert poller.done(), "Timed out waiting for delete" print("Waiting for delete ...") wait_for_delete() print("Clean up successful") if test_successful: print("Azure test deployment succeeded") else: print("ERROR: Azure test deployment failed", file=sys.stderr) sys.exit(2)
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)
client.resource_groups.create_or_update(group_name, resource_group_params, public_access=PublicAccess.Container) print("Created Resource Group:", group_name) # create deployment name deployment_name = 'testvm' # In[86]: # create deployment using templatelink template = TemplateLink( uri= 'https://raw.githubusercontent.com/dstolts/Azure_Classroom/master/Python/azuredeploy.json', ) parameters = ParametersLink( uri= 'https://raw.githubusercontent.com/dstolts/Azure_Classroom/master/Python/azuredeploy.parameters.json', ) result = client.deployments.create_or_update( group_name, deployment_name, properties=DeploymentProperties(mode=DeploymentMode.incremental, template_link=template, parameters_link=parameters)) pprint.pprint(result)