def reset_network_config(): """restore initial blank /etc/network/configure""" if reset_netplan(): display_success("Network configuration has been reset via netplan.") else: display_error("Failed to reset network config via netplan.")
def configure_devices(): cli.info_1("Already configured writer devices") try: writers = get_writers() except Exception as exp: logger.error(exp) display_error( "Configured devices are not present! " "Reseting devices conf and disabling host.\n" "Please configure devices and re-enable it." ) reset_writers() disable_host() for writer in writers: cli.info( cli.blue, " *", cli.reset, cli.bold, "{slot}:/dev/{device}".format(**writer), cli.reset, "({name} at {device_id})".format(**writer), ) cli.info("") menu = OrderedDict( [ ("reset-writers", ("Reset writers config (remove ALL)", reset_devices)), ("add-device", ("Add one device", add_device)), ] ) display_menu("Choose:", menu=menu, with_cancel=True)
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()
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()
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()
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()