Esempio n. 1
0
def up(env=None, **kwargs):
    logging.debug('phase[up]: args=%s' % kwargs)

    # Generates a directory for results
    resultdir_name = kwargs['--env'] or \
            'enos_' + datetime.today().isoformat()

    resultdir = os.path.join(CALL_PATH, resultdir_name)
    # The result directory cannot be created if a related file exists
    if os.path.isfile(resultdir):
        logging.error("Result directory cannot be created due to %s" %
                      resultdir)
        sys.exit(1)

    # Create the result directory if it does not exist
    os.path.isdir(resultdir) or os.mkdir(resultdir)
    logging.info('Generate results in %s' % resultdir)
    env['resultdir'] = resultdir

    # Symlink the result directory with the current directory
    link = os.path.abspath(SYMLINK_NAME)

    os.path.lexists(link) and os.remove(link)
    try:
        os.symlink(env['resultdir'], link)
        logging.info("Symlinked %s to %s" % (env['resultdir'], link))
    except OSError:
        # An harmless error can occur due to a race condition when multiple
        # regions are simultaneously deployed
        logging.warning("Symlink %s to %s failed" % (env['resultdir'], link))
        pass

    # Loads the configuration file
    config_file = kwargs['-f']
    if os.path.isfile(config_file):
        env['config_file'] = config_file
        with open(config_file, 'r') as f:
            env['config'].update(yaml.load(f))
            logging.info("Reloaded config %s", env['config'])
    else:
        logging.error('Configuration file %s does not exist', config_file)
        sys.exit(1)

    # Calls the provider and initialise resources
    provider = make_provider(env)
    rsc, provider_net, eths = \
        provider.init(env['config'], CALL_PATH, kwargs['--force-deploy'])

    env['rsc'] = rsc
    env['provider_net'] = provider_net
    env['eths'] = eths

    # Generates inventory for ansible/kolla
    base_inventory = env['config']['inventory']
    inventory = os.path.join(env['resultdir'], 'multinode')
    generate_inventory(env['rsc'], base_inventory, inventory)
    logging.info('Generates inventory %s' % inventory)

    env['inventory'] = inventory

    wait_ssh(env)

    # Set variables required by playbooks of the application
    if 'ip' in env['config']['registry']:
        registry_vip = env['config']['registry']['ip']
    else:
        registry_vip = pop_ip(env)

    env['config'].update({
        'vip': pop_ip(env),
        'registry_vip': registry_vip,
        'influx_vip': pop_ip(env),
        'grafana_vip': pop_ip(env),
        'network_interface': eths[NETWORK_IFACE],
        'resultdir': env['resultdir'],
        'rabbitmq_password': "******",
        'database_password': "******",
        'external_vip': pop_ip(env)
    })

    # Executes hooks and runs playbook that initializes resources (eg,
    # installs the registry, install monitoring tools, ...)
    provider.before_preintsall(env)
    up_playbook = os.path.join(ANSIBLE_DIR, 'up.yml')
    run_ansible([up_playbook],
                inventory,
                extra_vars=env['config'],
                tags=kwargs['--tags'])
    provider.after_preintsall(env)
Esempio n. 2
0
File: enos.py Progetto: ivotron/enos
def up(env=None, **kwargs):
    logging.debug('phase[up]: args=%s' % kwargs)

    # Generate or get the directory for results
    env['resultdir'] = _set_resultdir(kwargs['--env'])
    logging.info("Directory for experiment results is %s", env['resultdir'])

    # Loads the configuration file
    config_file = os.path.abspath(kwargs['-f'])
    if os.path.isfile(config_file):
        env['config_file'] = config_file
        with open(config_file, 'r') as f:
            env['config'].update(yaml.load(f))
            logging.info("Reloaded configuration file %s", env['config_file'])
            logging.debug("Configuration is %s", env['config'])
    else:
        raise EnosFilePathError(
            config_file, "Configuration file %s does not exist" % config_file)

    # Calls the provider and initialise resources
    provider = make_provider(env)
    config = load_config(env['config'], provider.topology_to_resources,
                         provider.default_config())
    rsc, provider_net, eths = \
        provider.init(config, kwargs['--force-deploy'])

    env['rsc'] = rsc
    env['provider_net'] = provider_net
    env['eths'] = eths

    logging.debug("Provider ressources: %s", env['rsc'])
    logging.debug("Provider network information: %s", env['provider_net'])
    logging.debug("Provider network interfaces: %s", env['eths'])

    # Generates inventory for ansible/kolla
    base_inventory = seekpath(env['config']['inventory'])
    inventory = os.path.join(env['resultdir'], 'multinode')
    generate_inventory(env['rsc'], base_inventory, inventory)
    logging.info('Generates inventory %s' % inventory)

    env['inventory'] = inventory

    # Wait for resources to be ssh reachable
    wait_ssh(env)

    # Set variables required by playbooks of the application
    env['config'].update({
        'vip':
        pop_ip(env),
        'registry_vip':
        env['config']['registry'].get('ip') or pop_ip(env),
        'influx_vip':
        pop_ip(env),
        'grafana_vip':
        pop_ip(env),
        'network_interface':
        eths[NETWORK_IFACE],
        'resultdir':
        env['resultdir'],
        'rabbitmq_password':
        "******",
        'database_password':
        "******",
        'external_vip':
        pop_ip(env)
    })

    # Runs playbook that initializes resources (eg,
    # installs the registry, install monitoring tools, ...)
    up_playbook = os.path.join(ANSIBLE_DIR, 'up.yml')
    run_ansible([up_playbook],
                inventory,
                extra_vars=env['config'],
                tags=kwargs['--tags'])