Beispiel #1
0
def script(configuration, script_path, script_args):
    """Run a script managed by claw with the provided configuration
       as context."""
    conf = Configuration(configuration)
    if not conf.exists():
        raise NO_INIT
    if not os.path.isfile(script_path):
        for scripts_dir in settings.scripts:
            possible_script_path = scripts_dir / script_path
            possible_script_path2 = scripts_dir / '{0}.py'.format(script_path)
            if possible_script_path.isfile():
                script_path = possible_script_path
                break
            if possible_script_path2.isfile():
                script_path = possible_script_path2
                break
        else:
            raise argh.CommandError('Could not locate {0}'.format(script_path))
    exec_globs = exec_env.exec_globals(script_path)
    execfile(script_path, exec_globs)
    if script_args and script_args[0] in exec_globs:
        func = script_args[0]
        script_args = script_args[1:]
    else:
        func = 'script'
    script_func = exec_globs.get(func)
    if not script_func:
        raise argh.CommandError('Cannot find a function to execute. Did you '
                                'add a default "script" function?')
    try:
        current_configuration.set(conf)
        argh.dispatch_command(script_func, argv=script_args)
    finally:
        current_configuration.clear()
Beispiel #2
0
def script(configuration, script_path, script_args):
    """Run a script managed by claw with the provided configuration
       as context."""
    conf = Configuration(configuration)
    if not conf.exists():
        raise NO_INIT
    if not os.path.isfile(script_path):
        for scripts_dir in settings.scripts:
            possible_script_path = scripts_dir / script_path
            possible_script_path2 = scripts_dir / '{0}.py'.format(script_path)
            if possible_script_path.isfile():
                script_path = possible_script_path
                break
            if possible_script_path2.isfile():
                script_path = possible_script_path2
                break
        else:
            raise argh.CommandError('Could not locate {0}'.format(script_path))
    exec_globs = exec_env.exec_globals(script_path)
    execfile(script_path, exec_globs)
    if script_args and script_args[0] in exec_globs:
        func = script_args[0]
        script_args = script_args[1:]
    else:
        func = 'script'
    script_func = exec_globs.get(func)
    if not script_func:
        raise argh.CommandError('Cannot find a function to execute. Did you '
                                'add a default "script" function?')
    try:
        current_configuration.set(conf)
        argh.dispatch_command(script_func, argv=script_args)
    finally:
        current_configuration.clear()
Beispiel #3
0
def teardown(configuration):
    """Teardown a configuration based environment."""
    conf = Configuration(configuration)
    if not conf.exists():
        raise NO_INIT
    with conf.dir:
        cfy.teardown(force=True, ignore_deployments=True).wait()
Beispiel #4
0
def teardown(configuration):
    """Teardown a configuration based environment."""
    conf = Configuration(configuration)
    if not conf.exists():
        raise NO_INIT
    with conf.dir:
        cfy.teardown(force=True, ignore_deployments=True).wait()
Beispiel #5
0
def cleanup(configuration,
            inputs_override=None,
            manager_blueprint_override=None):
    """Clean all infrastructure in a configuration based environment."""
    conf = Configuration(configuration)
    temp_configuration = False
    if not conf.exists():
        temp_configuration = True
        generate(configuration,
                 inputs_override=inputs_override,
                 manager_blueprint_override=manager_blueprint_override)
    if not temp_configuration and (inputs_override or
                                   manager_blueprint_override):
        conf.logger.warn('Inputs override or manager blueprints override '
                         'was passed, but an existing configuration was '
                         'found so they are ignored and the existing '
                         'configuration will be used.')
    try:
        conf.claw_handler.cleanup()
    finally:
        if temp_configuration:
            conf.dir.rmtree_p()
            with settings.configurations:
                if os.path.islink(CURRENT_CONFIGURATION):
                    os.remove(CURRENT_CONFIGURATION)
Beispiel #6
0
def bootstrap(configuration,
              inputs_override=None,
              manager_blueprint_override=None,
              reset=False):
    """Bootstrap a configuration based environment."""
    conf = Configuration(configuration)
    if not conf.exists() or reset:
        generate(configuration=configuration,
                 inputs_override=inputs_override,
                 manager_blueprint_override=manager_blueprint_override,
                 reset=reset)
    with conf.dir:
        if conf.cli_config_path.exists():
            raise ALREADY_INITIALIZED
        cfy.init().wait()
        with conf.patch.cli_config as patch:
            patch.obj['colors'] = True
        cfy.bootstrap(blueprint_path=conf.manager_blueprint_path,
                      inputs=conf.inputs_path).wait()
        cli_settings = load_cloudify_working_dir_settings()
        with conf.patch.handler_configuration as patch:
            patch.obj.update({
                'manager_ip': cli_settings.get_management_server(),
                'manager_key': cli_settings.get_management_key(),
                'manager_user': cli_settings.get_management_user()
            })
Beispiel #7
0
def cleanup(configuration,
            inputs_override=None,
            manager_blueprint_override=None):
    """Clean all infrastructure in a configuration based environment."""
    conf = Configuration(configuration)
    temp_configuration = False
    if not conf.exists():
        temp_configuration = True
        generate(configuration,
                 inputs_override=inputs_override,
                 manager_blueprint_override=manager_blueprint_override)
    if not temp_configuration and (inputs_override or
                                   manager_blueprint_override):
        conf.logger.warn('Inputs override or manager blueprints override '
                         'was passed, but an existing configuration was '
                         'found so they are ignored and the existing '
                         'configuration will be used.')
    try:
        conf.claw_handler.cleanup()
    finally:
        if temp_configuration:
            conf.dir.rmtree_p()
            with settings.configurations:
                if os.path.islink(CURRENT_CONFIGURATION):
                    os.remove(CURRENT_CONFIGURATION)
Beispiel #8
0
def cleanup(configuration):
    """Clean all infrastructure in a configuration based environment."""
    conf = Configuration(configuration)
    temp_configuration = False
    if not conf.exists():
        temp_configuration = True
        generate(configuration)
    try:
        conf.claw_handler.cleanup()
    finally:
        if temp_configuration:
            conf.dir.rmtree_p()
Beispiel #9
0
def cleanup(configuration):
    """Clean all infrastructure in a configuration based environment."""
    conf = Configuration(configuration)
    temp_configuration = False
    if not conf.exists():
        temp_configuration = True
        generate(configuration)
    try:
        conf.claw_handler.cleanup()
    finally:
        if temp_configuration:
            conf.dir.rmtree_p()
Beispiel #10
0
def status(configuration):
    """See the status of an environment specified by a configuration."""
    conf = Configuration(configuration)
    if not conf.exists():
        raise NO_INIT
    manager_ip = conf.handler_configuration.get('manager_ip')
    if not manager_ip:
        raise NO_BOOTSTRAP
    try:
        version = conf.client.manager.get_version()['version']
        conf.logger.info('[{0}] Running ({1})'.format(manager_ip, version))
    except requests.exceptions.ConnectionError:
        raise argh.CommandError('[{0}] Not reachable'.format(manager_ip))
Beispiel #11
0
def status(configuration):
    """See the status of an environment specified by a configuration."""
    conf = Configuration(configuration)
    if not conf.exists():
        raise NO_INIT
    manager_ip = conf.handler_configuration.get('manager_ip')
    if not manager_ip:
        raise NO_BOOTSTRAP
    try:
        version = conf.client.manager.get_version()['version']
        conf.logger.info('[{0}] Running ({1})'.format(manager_ip, version))
    except requests.exceptions.ConnectionError:
        raise argh.CommandError('[{0}] Not reachable'.format(manager_ip))
Beispiel #12
0
def bootstrap(configuration,
              inputs_override=None,
              manager_blueprint_override=None,
              reset=False):
    """Bootstrap a configuration based environment."""
    conf = Configuration(configuration)
    if not conf.exists() or reset:
        generate(configuration=configuration,
                 inputs_override=inputs_override,
                 manager_blueprint_override=manager_blueprint_override,
                 reset=reset)
    with conf.dir:
        cfy.init(conf)
        cfy.bootstrap(blueprint_path=conf.manager_blueprint_path,
                      inputs=conf.inputs_path)
        with conf.patch.handler_configuration as patch:
            patch.obj.update({
                'manager_ip': cfy.get_manager_ip(),
                'manager_key': cfy.get_manager_key(),
                'manager_user': cfy.get_manager_user()
            })
Beispiel #13
0
def generate_blueprint(configuration, blueprint, reset=False):
    """Generate a blueprint inside a configuration."""
    conf = Configuration(configuration)
    if not conf.exists():
        raise NO_INIT
    blueprints_yaml = settings.load_blueprints_yaml()
    blueprint = conf.blueprint(blueprint)
    blueprint.blueprint_configuration = _generate_configuration(
        cmd_inputs_override=None,
        cmd_blueprint_override=None,
        conf_obj=blueprint,
        conf_key='blueprints',
        conf_name=blueprint.blueprint_name,
        conf_additional=None,
        conf_blueprint_key='blueprint',
        blueprint_dir_name='blueprint',
        blueprint_override_key='blueprint_override',
        blueprint_override_template_key=None,
        blueprint_path=blueprint.blueprint_path,
        reset=reset,
        properties=conf.properties,
        user_yaml=blueprints_yaml)
Beispiel #14
0
def generate_blueprint(configuration, blueprint, reset=False):
    """Generate a blueprint inside a configuration."""
    conf = Configuration(configuration)
    if not conf.exists():
        raise NO_INIT
    blueprints_yaml = settings.load_blueprints_yaml()
    blueprint = conf.blueprint(blueprint)
    blueprint.blueprint_configuration = _generate_configuration(
        cmd_inputs_override=None,
        cmd_blueprint_override=None,
        conf_obj=blueprint,
        conf_key='blueprints',
        conf_name=blueprint.blueprint_name,
        conf_additional=None,
        conf_blueprint_key='blueprint',
        blueprint_dir_name='blueprint',
        blueprint_override_key='blueprint_override',
        blueprint_override_template_key=None,
        blueprint_path=blueprint.blueprint_path,
        reset=reset,
        properties=conf.properties,
        user_yaml=blueprints_yaml)
Beispiel #15
0
def bootstrap(configuration,
              inputs_override=None,
              manager_blueprint_override=None,
              reset=False):
    """Bootstrap a configuration based environment."""
    conf = Configuration(configuration)
    if not conf.exists() or reset:
        generate(configuration=configuration,
                 inputs_override=inputs_override,
                 manager_blueprint_override=manager_blueprint_override,
                 reset=reset)
    with conf.dir:
        cfy.init().wait()
        with conf.patch.cli_config as patch:
            patch.obj['colors'] = True
        cfy.bootstrap(blueprint_path=conf.manager_blueprint_path,
                      inputs=conf.inputs_path).wait()
        cli_settings = load_cloudify_working_dir_settings()
        with conf.patch.handler_configuration as patch:
            patch.obj.update({
                'manager_ip': cli_settings.get_management_server(),
                'manager_key': cli_settings.get_management_key(),
                'manager_user': cli_settings.get_management_user()
            })