def do_pre_deploy(self): """ runs pre deploy script if exists """ # Set provider type for post-bootstrap app.env['JUJU_PROVIDERTYPE'] = model_info('default')['provider-type'] pre_deploy_sh = os.path.join(app.config['spell-dir'], 'conjure/steps/00_pre-deploy') if os.path.isfile(pre_deploy_sh) \ and os.access(pre_deploy_sh, os.X_OK): utils.pollinate(app.session_id, 'J001') utils.info("Running pre deployment tasks.") try: sh = run(pre_deploy_sh, shell=True, stdout=PIPE, stderr=PIPE, env=app.env) result = json.loads(sh.stdout.decode('utf8')) if result['returnCode'] > 0: utils.error("Failed to run pre-deploy task: " "{}".format(result['message'])) sys.exit(1) utils.info("Finished pre deploy task: {}".format( result['message'])) except Exception as e: utils.error( "Failed to run pre deploy task: {}".format(e)) sys.exit(1)
def __post_bootstrap_exec(self): """ Executes post-bootstrap.sh if exists """ info = model_info(app.current_model) # Set our provider type environment var so that it is # exposed in future processing tasks app.env['JUJU_PROVIDERTYPE'] = info['provider-type'] app.env['JUJU_CONTROLLER'] = app.current_controller app.env['JUJU_MODEL'] = app.current_model _post_bootstrap_sh = path.join(app.config['spell-dir'], 'steps/00_post-bootstrap') app.log.debug( 'Checking for post bootstrap task: {}'.format(_post_bootstrap_sh)) if path.isfile(_post_bootstrap_sh) \ and os.access(_post_bootstrap_sh, os.X_OK): app.ui.set_footer('Running post-bootstrap tasks...') track_event("Juju Post-Bootstrap", "Started", "") app.log.debug( "post_bootstrap running: {}".format(_post_bootstrap_sh)) try: future = async .submit( partial(check_output, _post_bootstrap_sh, shell=True, env=app.env), self.__handle_exception) if future: future.add_done_callback(self.__post_bootstrap_done) except Exception as e: return self.__handle_exception(e)
def __post_bootstrap_exec(self): """ Executes post-bootstrap.sh if exists """ info = model_info(app.current_model) # Set our provider type environment var so that it is # exposed in future processing tasks app.env['JUJU_PROVIDERTYPE'] = info['provider-type'] _post_bootstrap_sh = path.join(app.config['spell-dir'], 'steps/00_post-bootstrap') app.log.debug( 'Checking for post bootstrap task: {}'.format(_post_bootstrap_sh)) if path.isfile(_post_bootstrap_sh) \ and os.access(_post_bootstrap_sh, os.X_OK): app.ui.set_footer('Running post-bootstrap tasks...') utils.pollinate(app.session_id, 'J001') app.log.debug("post_bootstrap running: {}".format( _post_bootstrap_sh )) try: future = async.submit(partial(check_output, _post_bootstrap_sh, shell=True, env=app.env), self.__handle_exception) future.add_done_callback(self.__post_bootstrap_done) except Exception as e: return self.__handle_exception(e)
def __post_bootstrap_exec(self): """ Executes post-bootstrap.sh if exists """ info = model_info(juju.get_current_model()) # Set our provider type environment var so that it is # exposed in future processing tasks app.env['JUJU_PROVIDERTYPE'] = info['provider-type'] _post_bootstrap_sh = path.join(app.config['spell-dir'], 'conjure/steps/00_post-bootstrap') app.log.debug( 'Checking for post bootstrap task: {}'.format(_post_bootstrap_sh)) if path.isfile(_post_bootstrap_sh) \ and os.access(_post_bootstrap_sh, os.X_OK): app.ui.set_footer('Running post-bootstrap tasks...') utils.pollinate(app.session_id, 'J001') app.log.debug("post_bootstrap running: {}".format( _post_bootstrap_sh )) try: future = async.submit(partial(check_output, _post_bootstrap_sh, shell=True, env=app.env), self.__handle_exception) future.add_done_callback(self.__post_bootstrap_done) except Exception as e: return self.__handle_exception(e)
def do_post_bootstrap(self): """ runs post bootstrap script if exists """ # Set provider type for post-bootstrap app.env['JUJU_PROVIDERTYPE'] = model_info('default')['provider-type'] post_bootstrap_sh = os.path.join(app.config['spell-dir'], 'steps/00_post-bootstrap') if os.path.isfile(post_bootstrap_sh) \ and os.access(post_bootstrap_sh, os.X_OK): utils.pollinate(app.session_id, 'J001') utils.info("Running post-bootstrap tasks.") try: sh = utils.run(post_bootstrap_sh, shell=True, stdout=PIPE, stderr=PIPE, env=app.env) result = json.loads(sh.stdout.decode('utf8')) utils.info("Finished post bootstrap task: {}".format( result['message'])) except Exception as e: utils.warning( "Failed to run post bootstrap task: {}".format(e)) sys.exit(1)
def _pre_deploy_exec(self): """ runs pre deploy script if exists """ app.env['JUJU_PROVIDERTYPE'] = model_info( app.current_model)['provider-type'] app.env['JUJU_CONTROLLER'] = app.current_controller app.env['JUJU_MODEL'] = app.current_model app.env['CONJURE_UP_SPELLSDIR'] = app.argv.spells_dir pre_deploy_sh = os.path.join(app.config['spell-dir'], 'steps/00_pre-deploy') if os.path.isfile(pre_deploy_sh) \ and os.access(pre_deploy_sh, os.X_OK): track_event("Juju Pre-Deploy", "Started", "") msg = "Running pre-deployment tasks." app.log.debug(msg) app.ui.set_footer(msg) out = utils.run(pre_deploy_sh, shell=True, stdout=PIPE, stderr=PIPE, env=app.env) try: return json.loads(out.stdout.decode()) except json.decoder.JSONDecodeError as e: app.log.exception(out.stdout.decode()) app.log.exception(out.stderr.decode()) raise Exception(out) return { 'message': 'No pre deploy necessary', 'returnCode': 0, 'isComplete': True }
def do_post_bootstrap(self): """ runs post bootstrap script if exists """ # Set provider type for post-bootstrap info = model_info(app.current_model) app.env['JUJU_PROVIDERTYPE'] = info['provider-type'] app.env['JUJU_CONTROLLER'] = app.current_controller app.env['JUJU_MODEL'] = app.current_model post_bootstrap_sh = os.path.join(app.config['spell-dir'], 'steps/00_post-bootstrap') if os.path.isfile(post_bootstrap_sh) \ and os.access(post_bootstrap_sh, os.X_OK): utils.info("Running post-bootstrap tasks.") try: sh = utils.run(post_bootstrap_sh, shell=True, stdout=PIPE, stderr=PIPE, env=app.env) result = json.loads(sh.stdout.decode('utf8')) utils.info("Finished post bootstrap task: {}".format( result['message'])) except Exception as e: utils.warning( "Failed to run post bootstrap task: {}".format(e)) sys.exit(1)
def _pre_deploy_exec(self): """ runs pre deploy script if exists """ app.env['JUJU_PROVIDERTYPE'] = model_info( app.current_model)['provider-type'] app.env['JUJU_CONTROLLER'] = app.current_controller app.env['JUJU_MODEL'] = app.current_model pre_deploy_sh = os.path.join(app.config['spell-dir'], 'steps/00_pre-deploy') if os.path.isfile(pre_deploy_sh) \ and os.access(pre_deploy_sh, os.X_OK): track_event("Juju Pre-Deploy", "Started", "") msg = "Running pre-deployment tasks." app.log.debug(msg) app.ui.set_footer(msg) return utils.run(pre_deploy_sh, shell=True, stdout=PIPE, stderr=PIPE, env=app.env) return json.dumps({ 'message': 'No pre deploy necessary', 'returnCode': 0, 'isComplete': True })
def _pre_deploy_exec(self): """ runs pre deploy script if exists """ app.env['JUJU_PROVIDERTYPE'] = model_info( juju.get_current_model())['provider-type'] pre_deploy_sh = os.path.join(app.config['spell-dir'], 'conjure/steps/00_pre-deploy') if os.path.isfile(pre_deploy_sh) \ and os.access(pre_deploy_sh, os.X_OK): utils.pollinate(app.session_id, 'J001') msg = "Running pre-deployment tasks." app.log.debug(msg) app.ui.set_footer(msg) return run(pre_deploy_sh, shell=True, stdout=PIPE, stderr=PIPE, env=app.env) return json.dumps({'message': 'No pre deploy necessary', 'returnCode': 0, 'isComplete': True})
def do_pre_deploy(self): """ runs pre deploy script if exists """ # Set provider type for post-bootstrap app.env['JUJU_PROVIDERTYPE'] = model_info( app.current_model)['provider-type'] app.env['JUJU_CONTROLLER'] = app.current_controller app.env['JUJU_MODEL'] = app.current_model app.env['CONJURE_UP_SPELLSDIR'] = app.argv.spells_dir pre_deploy_sh = os.path.join(app.config['spell-dir'], 'steps/00_pre-deploy') if os.path.isfile(pre_deploy_sh) \ and os.access(pre_deploy_sh, os.X_OK): utils.info("Running pre deployment tasks.") try: sh = utils.run(pre_deploy_sh, shell=True, stdout=PIPE, stderr=PIPE, env=app.env) try: result = json.loads(sh.stdout.decode('utf8')) except json.decoder.JSONDecodeError as e: utils.error(sh.stdout.decode()) utils.error(sh.stderr.decode()) sys.exit(1) if result['returnCode'] > 0: utils.error("Failed to run pre-deploy task: " "{}".format(result['message'])) sys.exit(1) utils.info("Finished pre deploy task: {}".format( result['message'])) except Exception as e: utils.error("Failed to run pre deploy task: {}".format(e)) sys.exit(1)
def _pre_deploy_exec(self): """ runs pre deploy script if exists """ app.env['JUJU_PROVIDERTYPE'] = model_info( app.current_model)['provider-type'] app.env['JUJU_CONTROLLER'] = app.current_controller app.env['JUJU_MODEL'] = app.current_model pre_deploy_sh = os.path.join(app.config['spell-dir'], 'steps/00_pre-deploy') if os.path.isfile(pre_deploy_sh) \ and os.access(pre_deploy_sh, os.X_OK): track_event("Juju Pre-Deploy", "Started", "") msg = "Running pre-deployment tasks." app.log.debug(msg) app.ui.set_footer(msg) return utils.run(pre_deploy_sh, shell=True, stdout=PIPE, stderr=PIPE, env=app.env) return json.dumps({'message': 'No pre deploy necessary', 'returnCode': 0, 'isComplete': True})
def do_step(step_model, step_widget, message_cb, gui=False): """ Processes steps in the background Arguments: step: a step to run message_cb: log writer gui: optionally set an UI components if GUI Returns: Step title and results message """ # merge the step_widget input data into our step model if gui: step_widget.clear_button() for i in step_model.additional_input: try: matching_widget = [ x for x in step_widget.additional_input if x['key'] == i['key'] ][0] i['input'] = matching_widget['input'].value except IndexError as e: app.log.error("Tried to pull a value from an " "invalid input: {}/{}".format( e, matching_widget)) try: info = model_info(app.current_model) except: juju.login(force=True) info = model_info(app.current_model) # Set our provider type environment var so that it is # exposed in future processing tasks app.env['JUJU_PROVIDERTYPE'] = info['provider-type'] # Set current juju controller and model app.env['JUJU_CONTROLLER'] = app.current_controller app.env['JUJU_MODEL'] = app.current_model if info['provider-type'] == "maas": app.log.debug("MAAS CONFIG: {}".format(app.maas)) # Expose MAAS endpoints and tokens app.env['MAAS_ENDPOINT'] = app.maas.endpoint app.env['MAAS_APIKEY'] = app.maas.api_key # Set environment variables so they can be accessed from the step scripts set_env(step_model.additional_input) if not os.access(step_model.path, os.X_OK): app.log.error("Step {} not executable".format(step_model.path)) message_cb("Running step: {}".format(step_model.title)) if gui: step_widget.set_icon_state('waiting') app.log.debug("Executing script: {}".format(step_model.path)) with open(step_model.path + ".out", 'w') as outf: with open(step_model.path + ".err", 'w') as errf: utils.run_script(step_model.path, stderr=errf, stdout=outf) try: with open(step_model.path + ".out") as outf: lines = outf.readlines() try: result = json.loads(lines[-1]) except json.decoder.JSONDecodeError as e: raise Exception("Unable to parse json ({}): {}".format( e, lines)) except: raise Exception("Could not read output from step " "{}: {}".format(step_model.path, lines)) if 'returnCode' not in result: raise Exception("Invalid last message from step: {}".format(result)) if result['returnCode'] > 0: app.log.error("Failure in step: {}".format(result['message'])) raise Exception(result['message']) step_model.result = result['message'] message_cb("{} completed.".format(step_model.title)) return (step_model, step_widget)
def do_step(step_model, step_widget, message_cb, gui=False): """ Processes steps in the background Arguments: step: a step to run message_cb: log writer gui: optionally set an UI components if GUI Returns: Step title and results message """ # merge the step_widget input data into our step model if gui: step_widget.clear_button() for i in step_model.additional_input: try: matching_widget = [ x for x in step_widget.additional_input if x['key'] == i['key']][0] i['input'] = matching_widget['input'].value except IndexError as e: app.log.error( "Tried to pull a value from an " "invalid input: {}/{}".format(e, matching_widget)) info = model_info(app.current_model) # Set our provider type environment var so that it is # exposed in future processing tasks app.env['JUJU_PROVIDERTYPE'] = info['provider-type'] if gui: # These environment variables must be set on the CLI or exported # in shell set_env(step_model.additional_input) if not os.access(step_model.path, os.X_OK): app.log.error("Step {} not executable".format(step_model.path)) message_cb("Running step: {}".format(step_model.title)) if gui: step_widget.set_icon_state('waiting') app.log.debug("Executing script: {}".format(step_model.path)) with open(step_model.path + ".out", 'w') as outf: with open(step_model.path + ".err", 'w') as errf: utils.run_script(step_model.path, stderr=errf, stdout=outf) try: with open(step_model.path + ".out") as outf: lines = outf.readlines() result = json.loads(lines[-1]) except: raise Exception("Could not read output from step " "{}".format(step_model.path)) if 'returnCode' not in result: raise Exception("Invalid last message from step: {}".format(result)) if result['returnCode'] > 0: app.log.error( "Failure in step: {}".format(result['message'])) raise Exception(result['message']) step_model.result = result['message'] message_cb("{} done, result:".format(step_model.title, step_model.result)) return (step_model, step_widget)