Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
def c_renew(name, hours):
    """ Set expiration date of Tengu to now + given hours
    NAME: name of Tengu
    HOURS: requested expiration hours"""
    okwhite('renewing slice {} for {} hours'.format(name, hours))
    env_conf = init_environment_config(name)
    env = PROVIDER.get(env_conf)
    env.renew(hours)
Ejemplo n.º 3
0
def c_renew_model(model, hours):
    """ Set expiration date of the model's underlying jFed experiment to now + given hours
    NAME: name of model
    HOURS: requested expiration hours"""
    okwhite('renewing slice {} for {} hours'.format(model, hours))
    env_conf = init_environment_config(model)
    env = get_provider(env_conf).get(env_conf)
    env.renew(hours)
Ejemplo n.º 4
0
def c_reload_model(name):
    """ Reload the model's machines. This will completely wipe the disk of the machines and put a new OS on them.
    NAME: name of model
    """
    if click.confirm(
            'Warning! This will wipe the disk of all the machines of the model "{}". Are you sure you want to continue?'
            .format(name)):
        okwhite('reloading all slivers in slice {}'.format(name))
        env_conf = init_environment_config(name)
        env = get_provider(env_conf).get(env_conf)
        env.reload()
Ejemplo n.º 5
0
def destroy_juju_environment(name):
    """ Destroy Juju environment and destroy Juju environment config files """
    env_conf = init_environment_config(name)
    if env_conf['locked']:
        fail('Cannot destroy locked environment')
    else:
        okwhite("removing juju environment from juju config files")
        with open(expanduser("~/.juju/environments.yaml"), 'r') as config_file:
            config = yaml.load(config_file)
        if config['environments'] is not None:
            config['environments'].pop(name, None)
        with open(expanduser("~/.juju/environments.yaml"), 'w') as config_file:
            config_file.write(yaml.dump(config, default_flow_style=False))
        okwhite("removing juju environment from juju environment folder")
        if os.path.isfile(expanduser("~/.juju/environments/%s.jenv" % name)):
            os.remove(expanduser("~/.juju/environments/%s.jenv" % name))
Ejemplo n.º 6
0
def downloadbigfiles(path):
    """Downloads url from .source files it finds in path"""
    # The top argument for walk
    topdir = os.path.realpath(path)
    okwhite("downloading bigfiles in %s " % topdir)
    # The extension to search for
    exten = '.source'
    # Walk through the directories
    for dirpath, dirnames, files in os.walk(topdir):  #pylint:disable=w0612
        # for all files in current directory
        for name in files:
            # If file is source file
            if name.lower().endswith(exten):
                source_path = os.path.join(dirpath, name)
                dest_path = source_path[:-len(exten)]
                # If file to download doesn't exist
                if not os.path.isfile(dest_path):
                    okwhite('{}'.format(dest_path))
                    with open(source_path, "r") as source_file:
                        first_line = source_file.readline().rstrip()
                        action = source_file.readline().rstrip()
                    # If source file contains download command
                    if first_line.startswith('command: '):
                        command = first_line.lstrip('command: ')
                        subprocess.check_output([command],
                                                shell=True,
                                                cwd=dirpath)
                    # if source file contains url
                    else:
                        url = first_line
                        okwhite('\t DOWNLOADING FROM: %s' % url)
                        urlopener = urllib.URLopener()
                        urlopener.retrieve(url, dest_path)
                    # if source file contains extract action
                    if action == "extract":
                        okwhite('\t EXTRACTING: %s' % dest_path)
                        tfile = tarfile.open(dest_path, 'r')
                        # Important to note that the following extraction is
                        # UNSAFE since .tar.gz archive could contain
                        # relative path like ../../ and overwrite other dirs
                        tfile.extractall(os.path.dirname(dest_path))
    okwhite("downloading bigfiles complete")
Ejemplo n.º 7
0
def wait_for_init(env_conf):
    """Waits until VW prepare script has happened"""
    bootstrap_host = env_conf['juju-env-conf']['bootstrap-host']
    bootstrap_user = env_conf['juju-env-conf']['bootstrap-user']
    okwhite('Waiting for {} to finish partition resize'.format(bootstrap_host))
    output = None
    while True:
        sys.stdout.write('.')
        sys.stdout.flush()
        try:
            output = subprocess.check_output([
                'ssh', '-o', 'StrictHostKeyChecking=no',
                '{}@{}'.format(bootstrap_user, bootstrap_host),
                '[[ -f /var/log/tengu-init-done ]] && echo "1"'
            ])
        except subprocess.CalledProcessError:
            pass
        if output and output.rstrip() == '1':
            break
        sleep(5)
    sys.stdout.write('\n')