コード例 #1
0
def generate(configuration,
             inputs_override=None,
             manager_blueprint_override=None,
             reset=False):
    """Generate a configuration."""
    conf = Configuration(configuration)
    suites_yaml = settings.load_suites_yaml()
    conf.handler_configuration = _generate_configuration(
        cmd_inputs_override=inputs_override,
        cmd_blueprint_override=manager_blueprint_override,
        conf_obj=conf,
        conf_key='handler_configurations',
        conf_name=configuration,
        conf_additional={'install_manager_blueprint_dependencies': False},
        conf_blueprint_key='manager_blueprint',
        blueprint_dir_name='manager-blueprint',
        blueprint_override_key='manager_blueprint_override',
        blueprint_override_template_key='manager_blueprint_override_templates',
        blueprint_path=conf.manager_blueprint_path,
        reset=reset,
        properties=None,
        user_yaml=suites_yaml)
    with settings.configurations:
        if os.path.exists(CURRENT_CONFIGURATION):
            os.remove(CURRENT_CONFIGURATION)
        os.symlink(configuration, CURRENT_CONFIGURATION)
コード例 #2
0
def deploy(configuration,
           blueprint,
           skip_generation=False,
           reset=False,
           timeout=1800):
    """Deploy (upload, create deployment and install) a blueprint
       in a configuration based environment."""
    conf = Configuration(configuration)
    if not conf.dir.isdir():
        raise NO_INIT
    bp = conf.blueprint(blueprint)
    if not skip_generation:
        generate_blueprint(configuration=configuration,
                           blueprint=blueprint,
                           reset=reset)
    with conf.dir:
        cfy.blueprints.upload(blueprint_path=bp.blueprint_path,
                              blueprint_id=blueprint).wait()
        cfy.deployments.create(blueprint_id=blueprint,
                               deployment_id=blueprint,
                               inputs=bp.inputs_path).wait()
        cfy.executions.start(workflow='install',
                             deployment_id=blueprint,
                             include_logs=True,
                             timeout=timeout).wait()
コード例 #3
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()
コード例 #4
0
ファイル: commands.py プロジェクト: dankilman/claw
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)
コード例 #5
0
ファイル: commands.py プロジェクト: carriercomm/claw
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()
コード例 #6
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()
コード例 #7
0
ファイル: commands.py プロジェクト: AviaE/claw
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)
コード例 #8
0
ファイル: commands.py プロジェクト: AviaE/claw
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()
            })
コード例 #9
0
ファイル: commands.py プロジェクト: carriercomm/claw
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()
コード例 #10
0
ファイル: commands.py プロジェクト: carriercomm/claw
def generate(configuration,
             inputs_override=None,
             manager_blueprint_override=None,
             reset=False):
    """Generate a configuration."""
    conf = Configuration(configuration)
    suites_yaml = settings.load_suites_yaml()
    conf.handler_configuration = _generate_configuration(
        cmd_inputs_override=inputs_override,
        cmd_blueprint_override=manager_blueprint_override,
        conf_obj=conf,
        conf_key='handler_configurations',
        conf_name=configuration,
        conf_additional={'install_manager_blueprint_dependencies': False},
        conf_blueprint_key='manager_blueprint',
        blueprint_dir_name='manager-blueprint',
        blueprint_override_key='manager_blueprint_override',
        blueprint_override_template_key='manager_blueprint_override_templates',
        blueprint_path=conf.manager_blueprint_path,
        reset=reset,
        properties=None,
        user_yaml=suites_yaml)
    with settings.configurations:
        if os.path.exists(CURRENT_CONFIGURATION):
            os.remove(CURRENT_CONFIGURATION)
        os.symlink(configuration, CURRENT_CONFIGURATION)
コード例 #11
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()
コード例 #12
0
ファイル: commands.py プロジェクト: carriercomm/claw
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()
コード例 #13
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))
コード例 #14
0
ファイル: commands.py プロジェクト: carriercomm/claw
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))
コード例 #15
0
def _cleanup_deployments(configuration, cancel_executions, blueprint=None):
    conf = Configuration(configuration)
    if not conf.dir.isdir():
        raise NO_INIT
    with conf.dir:
        _wait_for_executions(conf, blueprint, cancel_executions)
        if blueprint:
            deployments = blueprints = [blueprint]
        else:
            deployments = [
                d.id for d in conf.client.deployments.list(_include=['id'])
            ]
            blueprints = [
                b.id for b in conf.client.blueprints.list(_include=['id'])
            ]
        _wait_for_executions(conf, blueprint, cancel_executions)
        for deployment_id in deployments:
            try:
                cfy.executions.start(workflow='uninstall',
                                     deployment_id=deployment_id,
                                     include_logs=True).wait()
                _wait_for_executions(conf, deployment_id, cancel_executions)
                cfy.deployments.delete(deployment_id=deployment_id,
                                       ignore_live_nodes=True).wait()
            except Exception as e:
                conf.logger.warn('Failed cleaning deployment: {0} [1]'.format(
                    deployment_id, e))
        for blueprint_id in blueprints:
            try:
                cfy.blueprints.delete(blueprint_id=blueprint_id).wait()
            except Exception as e:
                conf.logger.warn('Failed cleaning blueprint: {0} [1]'.format(
                    blueprint_id, e))
コード例 #16
0
ファイル: commands.py プロジェクト: dankilman/claw
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()
            })
コード例 #17
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)
コード例 #18
0
ファイル: commands.py プロジェクト: carriercomm/claw
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)
コード例 #19
0
ファイル: commands.py プロジェクト: carriercomm/claw
def deploy(configuration, blueprint,
           skip_generation=False,
           reset=False,
           timeout=1800):
    """Deploy (upload, create deployment and install) a blueprint
       in a configuration based environment."""
    conf = Configuration(configuration)
    if not conf.dir.isdir():
        raise NO_INIT
    bp = conf.blueprint(blueprint)
    if not skip_generation:
        generate_blueprint(configuration=configuration,
                           blueprint=blueprint,
                           reset=reset)
    with conf.dir:
        cfy.blueprints.upload(blueprint_path=bp.blueprint_path,
                              blueprint_id=blueprint).wait()
        cfy.deployments.create(blueprint_id=blueprint,
                               deployment_id=blueprint,
                               inputs=bp.inputs_path).wait()
        cfy.executions.start(workflow='install',
                             deployment_id=blueprint,
                             include_logs=True,
                             timeout=timeout).wait()
コード例 #20
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()
            })
コード例 #21
0
ファイル: completion.py プロジェクト: dankilman/claw
 def existing_blueprints(self, prefix, parsed_args, **kwargs):
     conf = Configuration(parsed_args.configuration)
     return (b for b in self.all_blueprints(prefix)
             if (conf.blueprints_dir / b).exists())