Esempio n. 1
0
 def awx(self, tosca_template_path=None, tosca_template_dict=None):
     tosca_service_is_up = ToscaHelper.service_is_up(sure_tosca_base_url)
     if tosca_service_is_up:
         tosca_helper = ToscaHelper(sure_tosca_base_url,
                                    tosca_template_path)
         node_templates = tosca_template_dict['topology_template'][
             'node_templates']
         awx = AWXService(api_url=awx_base_url,
                          username=awx_username,
                          password=awx_password)
         topology_template_workflow_steps = {}
         for tosca_node_name in node_templates:
             tosca_node = node_templates[tosca_node_name]
             logger.info('Resolving function values for: ' +
                         tosca_node_name)
             tosca_node = tosca_helper.resolve_function_values(tosca_node)
             logger.info('Creating workflow steps for: ' + tosca_node_name)
             node_workflow_steps = awx.create_workflow_templates(tosca_node)
             topology_template_workflow_steps.update(node_workflow_steps)
         workflows = tosca_helper.get_workflows()
         if workflows:
             launched_ids = []
             for workflow_name in workflows:
                 workflow = workflows[workflow_name]
                 description = None
                 if 'description' in workflow:
                     description = workflow['description']
                 wf_ids = awx.create_workflow(description=description,
                                              workflow_name=workflow_name)
                 logger.info('Created workflow with ID: ' + str(wf_ids[0]))
                 workflow_node_ids = awx.create_dag(
                     workflow_id=wf_ids[0],
                     tosca_workflow=workflow,
                     topology_template_workflow_steps=
                     topology_template_workflow_steps,
                     workflow_name=workflow_name)
                 logger.info('Added nodes to workflow')
                 for wf_id in wf_ids:
                     wf_job_ids = awx.launch(wf_id)
                     launched_ids += wf_job_ids
Esempio n. 2
0
def awx(tosca_template_path=None, tosca_template_dict=None):
    awx_inst = None
    global tosca_helper
    try:
        tosca_service_is_up = ToscaHelper.service_is_up(sure_tosca_base_url)
        if tosca_service_is_up:
            logger.info('Initializing ToscaHelper')
            tosca_helper = ToscaHelper(sure_tosca_base_url,
                                       tosca_template_path)
            node_templates = tosca_template_dict['topology_template'][
                'node_templates']
            logger.info('Initializing AWXService')
            awx_inst = AWXService(api_url=awx_base_url,
                                  username=awx_username,
                                  password=awx_password,
                                  tosca_helper=tosca_helper)
            logger.info('Creating organization: sdia')
            organization_id = awx_inst.create_organization('sdia')

            for tosca_node_name in node_templates:
                tosca_node = node_templates[tosca_node_name]
                logger.info('Resolving function values for: ' +
                            tosca_node_name)
                tosca_node = tosca_helper.resolve_function_values(tosca_node)

            workflows = tosca_helper.get_workflows()
            if workflows:
                for workflow_name in workflows:
                    topology_template_workflow_steps = {}
                    workflow = workflows[workflow_name]
                    can_run = tosca_helper.check_workflow_preconditions(
                        workflow, tosca_template_dict)
                    logger.info('workflow: ' + workflow_name + ' can run: ' +
                                str(can_run))
                    if can_run:
                        steps = workflow['steps']
                        for step_name in steps:
                            logger.info('Created step_name: ' + str(step_name))
                            node_workflow_steps = awx_inst.create_workflow_templates(
                                tosca_workflow_step=steps[step_name],
                                organization_id=organization_id,
                                node_templates=node_templates,
                                step_name=step_name,
                                workflow_name=workflow_name)
                            topology_template_workflow_steps.update(
                                node_workflow_steps)

                        tosca_template_dict = execute_workflows(
                            workflow=workflow,
                            workflow_name=workflow_name,
                            topology_template_workflow_steps=
                            topology_template_workflow_steps,
                            awx=awx_inst,
                            tosca_template_dict=tosca_template_dict)
        else:
            raise Exception('Could not connect to sure tosca at ' +
                            sure_tosca_base_url)
    except Exception as ex:
        track = traceback.format_exc()
        print(track)
        raise
    finally:
        if awx_inst and delete_templates_after_execution:
            awx_inst.clean_up_execution()
    tosca_template_dict = encrypt_credentials(tosca_template_dict)
    response = {'toscaTemplate': tosca_template_dict}
    logger.info("Returning Deployment")
    logger.info("Output message:" + json.dumps(response))
    return json.dumps(response)