def c_status(name): """Show status of Tengu with given name NAME: name of Tengu """ env_conf = init_environment_config(name) env = PROVIDER.get(env_conf) responsedict = env.status if responsedict['short_status'] == 'READY': statusdict = responsedict['json_output'] try: okblue("Status of experiment is {}".format( statusdict['AMs'].values()[0]['amGlobalSliverStatus'])) okblue("Experiment will expire at {}".format( statusdict['earliestSliverExpireDate'])) except (yaml.parser.ParserError, ValueError, KeyError) as exc: print("could not parse status from ouptut. statusdict: ") PPRINTER.pprint(statusdict) raise exc else: okwhite("Status of jfed slice is {}. responsedict: ".format( responsedict['short_status'])) PPRINTER.pprint(responsedict) if JujuEnvironment.env_exists(name): okblue('Juju environment exists') else: okwhite("Juju environment doesn't exist")
def api_model_update(modelname): """ Deploys new bundle """ bundle = request.data # Write bundle bundle_path = tempfile.mkdtemp() + '/bundle.yaml' with open(bundle_path, 'w+') as bundle_file: bundle_file.write(bundle) # Create environment from bundle if not exist, else deploy bundle if JujuEnvironment.env_exists(modelname): env = JujuEnvironment(modelname) output = env.deploy_bundle(bundle_path, '--skip-unit-wait') else: try: output = subprocess.check_output( ['tengu', 'create-model', '--bundle', bundle_path, modelname], stderr=subprocess.STDOUT) except CalledProcessError as process_error: return create_response( 500, { "msg": "Failed to deploy bundle to environment {}. Output: {}". format(modelname, process_error.output) }) return create_response( 200, { "msg": "Sucessfully deployed bundle to environment {}. Output: {}".format( modelname, output) })
def create_juju(env_conf, provider_env): if JujuEnvironment.env_exists(env_conf['env-name']): fail( "Juju environment already exists. Remove it first with 'tengu destroy {}'" .format(env_conf['env-name'])) try: machines = provider_env.machines except Exception as ex: # pylint: disable=W0703 fail("Could not get machines from manifest", ex) # Create Juju environment env_conf['juju-env-conf']['bootstrap-host'] = machines.pop(0) env_conf.save() wait_for_init(env_conf) return JujuEnvironment.create(env_conf['env-name'], env_conf['juju-env-conf']['bootstrap-host'], env_conf['juju-env-conf'], machines)
def create_juju(env_conf, provider_env): if JujuEnvironment.env_exists(env_conf['env-name']): fail("Juju environment already exists. Remove it first with 'tengu destroy {}'".format(env_conf['env-name'])) try: machines = provider_env.machines except Exception as ex: # pylint: disable=W0703 fail("Could not get machines from manifest", ex) # Create Juju environment env_conf['juju-env-conf']['bootstrap-host'] = machines.pop(0) env_conf.save() wait_for_init(env_conf) return JujuEnvironment.create( env_conf['env-name'], env_conf['juju-env-conf']['bootstrap-host'], env_conf['juju-env-conf'], machines )
def api_model_update(modelname): """ Deploys new bundle """ bundle = request.data # Write bundle bundle_path = tempfile.mkdtemp() + '/bundle.yaml' with open(bundle_path, 'w+') as bundle_file: bundle_file.write(bundle) # Create environment from bundle if not exist, else deploy bundle if JujuEnvironment.env_exists(modelname): env = JujuEnvironment(modelname) output = env.deploy_bundle(bundle_path, '--skip-unit-wait') else: try: output = subprocess.check_output(['/opt/tengu/scripts/tengu.py', 'create', '--bundle', bundle_path, modelname]) except CalledProcessError as process_error: return create_response(500, {"msg": "Failed to deploy bundle to environment {}. Output: {}".format(modelname, process_error.output)}) return create_response(200, {"msg": "Sucessfully deployed bundle to environment {}. Output: {}".format(modelname, output)})
def c_status(name): """Show status of Tengu with given name NAME: name of Tengu """ env_conf = init_environment_config(name) env = PROVIDER.get(env_conf) responsedict = env.status if responsedict['short_status'] == 'READY': statusdict = responsedict['json_output'] try: okblue("Status of experiment is {}".format(statusdict['AMs'].values()[0]['amGlobalSliverStatus'])) okblue("Experiment will expire at {}".format(statusdict['earliestSliverExpireDate'])) except (yaml.parser.ParserError, ValueError, KeyError) as exc: print("could not parse status from ouptut. statusdict: ") PPRINTER.pprint(statusdict) raise exc else: okwhite("Status of jfed slice is {}. responsedict: ".format(responsedict['short_status'])) PPRINTER.pprint(responsedict) if JujuEnvironment.env_exists(name): okblue('Juju environment exists') else: okwhite("Juju environment doesn't exist")