Beispiel #1
0
def reset_devices():
    cli.info_2("Reseting devices configuration")
    ready = cli.ask_yes_no("Sure you want to remove all devices conf?", default=False)
    if not ready:
        return

    if reset_writers():
        display_success("Devices configuration removed.")
    else:
        display_error("Failed to reset devices configuration.")
    pause()
Beispiel #2
0
def configure_credentials():
    """get username/password/api_url from user and save to config file"""
    cli.info_2("Credentials")
    config = read_conf()

    username = get_valid_string("Username", nonempty_validator, config.get("username"))
    password = get_valid_string("Password", nonempty_validator, config.get("password"))
    api_url = get_valid_string(
        "API URL – use `reset` to use default",
        nonempty_validator,
        config.get("api_url", DEFAULT_API_URL),
    )
    if api_url == "reset":
        api_url = DEFAULT_API_URL
    s3_access_key = get_valid_string(
        "S3 Access Key", nonempty_validator, config.get("s3_access_key")
    )
    s3_secret_key = get_valid_string(
        "S3 Secret Key", nonempty_validator, config.get("s3_secret_key")
    )

    update_conf(
        {
            "username": username,
            "password": password,
            "api_url": api_url,
            "s3_access_key": s3_access_key,
            "s3_secret_key": s3_secret_key,
        }
    )
    cli.info_2(
        "Saved crentials as",
        cli.bold,
        username,
        cli.reset,
        "/",
        cli.bold,
        password,
        cli.reset,
        "for",
        cli.bold,
        api_url,
        cli.reset,
        "with",
        cli.bold,
        s3_access_key,
        cli.reset,
        "and",
        cli.bold,
        s3_secret_key,
    )

    pause()
Beispiel #3
0
def display_toggle_host():
    enabled = read_conf().get("enabled", False)
    answer = cli.ask_yes_no(
        "You are about to {} this host. Are you sure?".format(
            "disable" if enabled else "enable"))
    if answer:
        enabled = not enabled  # toggled
        ns = "enabled" if enabled else "disabled"
        if toggle_host(enabled):
            display_success("Successfuly {} host!".format(ns))
        else:
            display_error("Error: host could not be {}.".format(ns))

        pause()
Beispiel #4
0
def add_device():
    cli.info_2("Please remove all SD-cards from all writers.")
    ready = cli.ask_yes_no("Ready?", default=False)
    if not ready:
        return

    cli.info(
        "Great! Now please insert",
        cli.bold,
        "one",
        cli.reset,
        "SD-card into the writer you want to configure.",
    )
    cli.info_3("waiting for card", end="")
    block_name = None
    while block_name is None:
        time.sleep(1)
        cli.dot()
        block_name = find_device()
    cli.info("FOUND")

    # we now have a new DEVICE.
    device_id = get_device_id(block_name)
    slot = get_next_slot()

    # update configured writers list
    writers = read_conf().get("writers", {})
    writers.update({slot: device_id})
    if update_conf({"writers": writers}):
        display_success(
            "Found your",
            humanfriendly.format_size(get_block_size(block_name), binary=True),
            "card on",
            cli.bold,
            block_name,
            cli.reset,
            "({})".format(get_display_name(block_name)),
            ".\n",
            "Assigned slot:",
            cli.bold,
            slot,
        )
    else:
        display_error("Failed to configure a slot for", cli.bold, block_name)

    pause()
Beispiel #5
0
def configure_iface():

    # pick interface
    ifaces = list(get_interfaces())
    iface = display_menu("Choose Interface:", choices=ifaces, with_cancel=True)
    cli.info("You selected", cli.bold, iface)
    iface_config = get_iface_config(iface)
    from pprint import pprint as pp

    pp(iface_config)

    # select method (dhcp, fixed)
    dhcp = "dhcp"
    fixed = "fixed"
    methods = [dhcp, fixed]
    method = display_menu("Connection method:",
                          choices=methods,
                          with_cancel=True)

    if method == dhcp:
        if save_network_config(iface, dhcp=True):
            cli.info_2(
                "Saved your",
                cli.bold,
                iface,
                cli.reset,
                "configuration as",
                cli.bold,
                "DHCP",
            )
        else:
            display_error("Unable to save DHCP network config for", cli.bold,
                          iface)

        pause()

        return

    # fixed method config

    # get address
    address = get_valid_string("IP Address",
                               ipadress_validator,
                               default=iface_config["address"])
    cli.info("You entered", cli.bold, address)

    netmask = get_valid_string("Netmask",
                               ipadress_validator,
                               default=iface_config["netmask"])
    cli.info("You entered", cli.bold, netmask)

    gateway = get_valid_string("Gateway",
                               ipadress_validator,
                               default=iface_config["gateway"])
    cli.info("You entered", cli.bold, gateway)

    if save_network_config(iface,
                           dhcp=False,
                           address=address,
                           netmask=netmask,
                           gateway=gateway):
        cli.info_2(
            "Saved your",
            cli.bold,
            iface,
            cli.reset,
            "configuration as",
            cli.bold,
            address,
            cli.reset,
            "/",
            cli.bold,
            netmask,
            cli.reset,
            "/",
            cli.bold,
            gateway,
        )
    else:
        display_error("Unable to save fixed network config for", cli.bold,
                      iface)

    pause()