def import_cr_template(github_hostname, github_repo_url, github_path, github_branch, github_token, type=None): iaas = IaaS() return iaas.import_template(github_hostname, github_repo_url, github_path, github_branch, github_token, type)
def life_cycle_stack(iaas, stack_name, git_branch, template_path, template, parameters, camVariables, delete_failed_deployment, delete=True, template_id=None, use_case='default'): ''' Deploy the template and wait until it finishes successfully. Destroy the stack after the deployment finished. ''' iaas = IaaS() result = {} result['name'] = stack_name stack = None logger = TestLogger(__name__) delete_deployment = True delete_template = True if not delete: delete_deployment = False if template_id: delete_template = False try: start_time = datetime.now() result['deploy_start_time'] = datetime.strftime(start_time, '%Y-%m-%d %H:%M:%S') logger.info('stack-name: %s' %stack_name) logger.info('delete_failed_deployment: %s' %delete_failed_deployment) logger.info('autoDestroy: %s' %delete) logger.info('delete Deployment: %s' %delete_deployment) logger.info('delete_template: %s' %delete_template) #logger.info('template: %s' %template) #logger.info('parameters: %s' %parameters) #logger.info('camVariables: %s' %camVariables) if not template_id: if 'starterlibrary' in template_path: template_path = '/'.join(template_path.split('/')[3:-1]) template_id = iaas.import_template( 'github', 'https://github.ibm.com/Orpheus/starterlibrary', template_path, git_branch, os.environ['GIT_TOKEN']) else: template_name = 'template_%s' % template_path.split('/')[-1][0:-3] template_path = '/%s' % '/'.join(template_path.split('/')[-3:-1]) template_id = iaas.import_template( 'github', 'https://github.ibm.com/OpenContent/%s' % template_name, template_path, git_branch, os.environ['GIT_TOKEN']) stack = iaas.deploy(stack_name, template_id, template, parameters, camVariables, use_case=use_case) iaas.waitForSuccess(stack, _10_MINUTES) # Will no longer delete the template after a successful deployment. CAM changed code to not # allow instances to be deleted if the template was destroyed. CAM 2.1.0.2 #if delete_template: # iaas.delete_template(template_id) # # Set to None after delete so we don't run the code in finally # template_id = None end_time = datetime.now() result['deploy_duration'] = (end_time - start_time) result['deploy_end_time'] = datetime.strftime(end_time, '%Y-%m-%d %H:%M:%S') #result['deploy_error'] = None except AuthException, ex: logger.warning('Authentication Error, re-authenticating\n%s' %ex) stack = None raise ex