def connected_timeout(dummy: int) -> None: active_ssid: Optional[str] active_ssid = nm.get_active_ssid(modemgr.get_state_device("CONNECTED")) log.debug("connected_timeout comparing {} to {}".format( connection, active_ssid)) if connection != active_ssid: log.warning("Connection lost on timeout") dev = modemgr.get_state_device("CONNECTED") set_state("CONNECTING", candidate_connections(dev)) if modemgr.get_mode() == modemgr.MULTI_MODE: wpa.check_wpa(modemgr.get_ap_device().Interface) active_ssid = nm.get_active_ssid(modemgr.get_state_device("HOTSPOT")) if not active_ssid: log.warning("Hotspot lost on timeout") set_state("HOTSPOT") defroute_devname: Optional[str] = routemgr.defroute_dev() ap_dev: NetworkManager.Device = modemgr.get_ap_device() link_dev: NetworkManager.Device = modemgr.get_link_device() if defroute_devname == nm.device_name(ap_dev): # default route is bad. Disconnect link and count on state # processing to restore log.error("AP is holding default route while CONNECTED, kicking") nm.disconnect(link_dev)
def add_hosts(hosts: List[str]) -> None: establish_group() int_mapping = get_interface_mapping() devices: Optional[List["NetworkManager.Device"]] = nm.get_devices() if devices is None: log.error("Null device list returned in add_hosts()") return if not devices: log.error("No devices found in add_hosts()") return entries: bool = False for device in devices: name = nm.device_name(device) addr = nm.get_active_ip(device) addr6 = nm.get_active_ip6(device) log.debug("add_hosts: {}, {}".format(name, addr)) try: if name in nm.get_phys_dev_names() and name in int_mapping: index = int_mapping[name] try: if addr and addr != "0.0.0.0": for host in hosts: log.debug("Add A record {}-{}-{}".format( host, index, addr)) make_a_record(host, index, addr) entries = True if addr6: for host in hosts: log.debug("Add AAAA record {}-{}-{}".format( host, index, addr6)) make_aaaa_record(host, index, addr6) entries = True if addr6 or (addr and addr != "0.0.0.0"): log.debug("Add service {}, {}, {}-{}".format( host, index, addr, addr6)) add_service(hosts[0], index, addr, addr6) except Exception: log.error("Exception encountered adding avahi record") clear_entries(emphatic=True) entries = False except NetworkManager.ObjectVanished as e: log.error( "Unrecoverable NetworkManager Error - exiting - {}".format( str(e))) os.kill(os.getpid(), signal.SIGTERM) if group and entries: group.Commit()
def add_hosts(hosts): establish_group() int_mapping = get_interface_mapping() for device in nm.get_devices(): name = nm.device_name(device) addr = nm.get_active_ip(device) if (name in nm.get_phys_dev_names() and name in int_mapping and addr): index = int_mapping[name] for host in hosts: make_a_record(host, index, addr) add_service(hosts[0], index, addr) group.Commit()
def run_cmds(cmds): linkdev = nm.device_name(modemgr.get_link_device()) apdev = nm.device_name(modemgr.get_ap_device()) for cmd in cmds: subprocess.call(cmd.format(link=linkdev, ap=apdev), shell=True)