Example #1
0
def run_script(ctx, script, arguments, resources, language):
    supported_langs = {"bash", "python"}

    if language not in supported_langs:
        msg = "Unknown language: {}. Available languages: {}."
        raise NonRecoverableError(
            msg.format(language, ", ".join(supported_langs)))

    workdir = tempfile.mkdtemp()
    ctx.logger.info("Created working directory {}".format(workdir))

    ctx.logger.info("Getting '{}' script".format(script))
    local_script = utils.obtain_resource(ctx,
                                         script,
                                         dir=workdir,
                                         keep_name=True)
    cmd = map(str, [language, local_script] + arguments)

    ctx.logger.info("Getting resources".format(script))
    for res in resources:
        utils.obtain_resource(ctx, res, dir=workdir, keep_name=True)

    ctx.logger.info("Running command: {}".format(" ".join(cmd)))
    proc = subprocess.Popen(cmd,
                            stdin=open(os.devnull, "r"),
                            cwd=workdir,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT)
    for line in iter(proc.stdout.readline, ""):
        ctx.logger.info(line.strip())
    proc.wait()

    shutil.rmtree(workdir)

    if proc.returncode != 0:
        msg = "Script terminated with non-zero ({}) status."
        raise NonRecoverableError(msg.format(proc.returncode))

    ctx.instance.runtime_properties["ip"] = ctx.instance.host_ip
    ctx.instance.runtime_properties["fqdn"] = utils.get_fqdn()
def run_script(ctx, script, arguments, resources, language):
    supported_langs = {"bash", "python"}

    if language not in supported_langs:
        msg = "Unknown language: {}. Available languages: {}."
        raise NonRecoverableError(
            msg.format(language, ", ".join(supported_langs))
        )

    workdir = tempfile.mkdtemp()
    ctx.logger.info("Created working directory {}".format(workdir))

    ctx.logger.info("Getting '{}' script".format(script))
    local_script = utils.obtain_resource(ctx, script, dir=workdir,
                                         keep_name=True)
    cmd = map(str, [language, local_script] + arguments)

    ctx.logger.info("Getting resources".format(script))
    for res in resources:
        utils.obtain_resource(ctx, res, dir=workdir, keep_name=True)

    ctx.logger.info("Running command: {}".format(" ".join(cmd)))
    proc = subprocess.Popen(cmd, stdin=open(os.devnull, "r"), cwd=workdir,
                            stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    for line in iter(proc.stdout.readline, ""):
        ctx.logger.info(line.strip())
    proc.wait()

    shutil.rmtree(workdir)

    if proc.returncode != 0:
        msg = "Script terminated with non-zero ({}) status."
        raise NonRecoverableError(msg.format(proc.returncode))

    ctx.instance.runtime_properties["ip"] = ctx.instance.host_ip
    ctx.instance.runtime_properties["fqdn"] = utils.get_fqdn()
Example #3
0
def copy_fqdn_from_target(ctx, property):
    msg = "Copying FQDN of '{}' into '{}' runtime property"
    ctx.logger.info(msg.format(ctx.target.instance.id, property))
    ctx.source.instance.runtime_properties[property] = utils.get_fqdn()
def copy_fqdn_from_target(ctx, property):
    msg = "Copying FQDN of '{}' into '{}' runtime property"
    ctx.logger.info(msg.format(ctx.target.instance.id, property))
    ctx.source.instance.runtime_properties[property] = utils.get_fqdn()