Example #1
0
def load_remotes():
    """Read the remote system configurations"""

    config = {}

    for root, _, files in os.walk(get_etc_remote_path()):
        for file in files:
            with open(os.path.join(root, file)) as f:
                config[file.rstrip(".conf")] = loads(f.read())
                log("Remote configuration loaded.", lvl=debug)

    return config
Example #2
0
def write_remote(remote):
    """Write a new or updated remote"""

    filename = os.path.join(get_etc_remote_path(), remote["name"] + ".conf")
    try:
        with open(filename, "w") as f:
            f.write(dumps(remote))
        log("Instance configuration stored.", lvl=debug)
    except PermissionError:
        log(
            "PermissionError: Could not write instance management configuration file",
            lvl=error,
        )
        abort(EXIT_NO_PERMISSION)
Example #3
0
def create_configuration(ctx):
    """Creates an initial configuration"""
    log("Creating new configuration from template", lvl=verbose)

    if not os.path.exists(get_etc_path()):
        try:
            os.makedirs(get_etc_path())
            os.makedirs(get_etc_instance_path())
            os.makedirs(get_etc_remote_path())
            os.makedirs(get_etc_remote_keys_path())
        except PermissionError:
            log(
                'PermissionError: Could not create configuration directory "%s"'
                % get_etc_path(),
                lvl=warn,
            )
            warn_error(EXIT_NO_PERMISSION)

    ctx.obj["config"] = configuration_template

    return ctx