Exemple #1
0
def check(ctx, acknowledge):
    """Performs some basic system configuration tests to estimate platform health

    The checks range from file and folder location existance to checking if there
    is a system isomer user"""

    etc_path = get_etc_path()
    prefix_path = get_prefix_path()

    log("Checking etc in '%s' and prefix in '%s'" % (etc_path, prefix_path))

    def check_exists(path):
        if not os.path.exists(path):
            log("Location '%s' does not exist" % path, lvl=warn)
        elif acknowledge:
            log("Location '%s' exists" % path)

    locations_etc = ['', 'isomer.conf', 'instances']

    locations_prefix = [
        'var/lib/isomer', 'var/local/isomer', 'var/cache/isomer',
        'var/log/isomer', 'var/run/isomer', 'var/backups/isomer',
        'var/www/challenges'
    ]

    for location in locations_etc:
        check_exists(os.path.join(etc_path, location))
    for location in locations_prefix:
        check_exists(os.path.join(prefix_path, location))

    try:
        pwd.getpwnam("isomer")
        log("Isomer user exists")
    except KeyError:
        log("Isomer user does not exist", lvl=warn)
Exemple #2
0
def configure(ctx):
    """Generate a skeleton configuration for Isomer (needs sudo)"""

    if os.path.exists(get_etc_path()):
        abort(EXIT_NOT_OVERWRITING_CONFIGURATION)
    ctx = create_configuration(ctx)

    finish(ctx)
Exemple #3
0
def configure(ctx):
    """Generate a skeleton configuration for Isomer (needs sudo)"""

    if os.path.exists(os.path.join(get_etc_path(), "isomer.conf")):
        abort(EXIT_NOT_OVERWRITING_CONFIGURATION)
    ctx = create_configuration(ctx)
    write_configuration(ctx.obj['config'])

    finish(ctx)
Exemple #4
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
Exemple #5
0
def load_configuration():
    """Read the main system configuration"""

    filename = os.path.join(get_etc_path(), "isomer.conf")

    try:
        with open(filename, "r") as f:
            config = loads(f.read())
            log("Isomer configuration loaded.", lvl=debug)
    except FileNotFoundError:
        log("Configuration not found.", lvl=warn)
        return None

    return config
Exemple #6
0
def write_configuration(config):
    """Write the main system configuration"""

    filename = os.path.join(get_etc_path(), "isomer.conf")

    try:
        with open(filename, "w") as f:
            f.write(dumps(config))
        log("Isomer configuration stored.", lvl=debug)
    except PermissionError:
        log(
            "PermissionError: Could not write instance management configuration file",
            lvl=error,
        )
        warn_error(EXIT_NO_PERMISSION)
Exemple #7
0
def _install_provisions(ctx, import_file=None, skip_provisions=False):
    """Load provisions into database"""

    instance_configuration = ctx.obj["instance_configuration"]
    env = get_next_environment(ctx)
    env_path = get_path("lib", "")

    log("Installing provisioning data")

    if not skip_provisions:
        success, result = run_process(
            os.path.join(env_path, "repository"),
            [
                os.path.join(env_path, "venv", "bin", "python3"),
                "./iso",
                "-nc",
                "--flog",
                "5",
                "--config-path",
                get_etc_path(),
                "-i",
                instance_configuration["name"],
                "-e",
                env,
                "install",
                "provisions",
            ],
            # Note: no sudo necessary as long as we do not enforce
            # authentication on databases
        )
        if not success:
            log("Could not provision data:", lvl=error)
            log(format_result(result), lvl=error)
            return False

    if import_file is not None:
        log("Importing backup")
        log(ctx.obj, pretty=True)
        host, port = ctx.obj["dbhost"].split(":")
        load(host, int(port), ctx.obj["dbname"], import_file)

    return True
Exemple #8
0
def _system_all(ctx):

    use_sudo = ctx.obj["use_sudo"]

    config_path = get_etc_path()
    log("Generating configuration at", config_path)
    if os.path.exists(config_path):
        abort(EXIT_NOT_OVERWRITING_CONFIGURATION)
    ctx = create_configuration(ctx)

    log("Installing Isomer system wide")
    install_isomer(ctx.obj["platform"],
                   use_sudo,
                   show=ctx.obj["log_actions"],
                   omit_platform=ctx.obj['omit_platform'],
                   omit_common=True)

    log("Adding Isomer system user")
    _add_system_user(use_sudo)

    log("Creating Isomer filesystem locations")
    _create_system_folders(use_sudo)
Exemple #9
0
def _install_frontend(ctx):
    """Install and build the frontend"""

    env = get_next_environment(ctx)
    env_path = get_path("lib", "")

    instance_configuration = ctx.obj["instance_configuration"]

    user = instance_configuration["user"]

    log("Building frontend")

    success, result = run_process(
        os.path.join(env_path, "repository"),
        [
            os.path.join(env_path, "venv", "bin", "python3"),
            "./iso",
            "-nc",
            "--config-path",
            get_etc_path(),
            "--prefix-path",
            get_prefix_path(),
            "-i",
            instance_configuration["name"],
            "-e",
            env,
            "--clog",
            "10",
            "install",
            "frontend",
            "--rebuild",
        ],
        sudo=user,
    )
    if not success:
        log(format_result(result), lvl=error)
        return False

    return True