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 hotspot_pass(): log.debug("Activating mdns") # IP tolerance for PI 2 for _ in range(5): log.debug("states: Calling nm.get_active_ip()") ip = nm.get_active_ip(modemgr.get_state_device('HOTSPOT')) if ip: mdns.clear_entries() mdns.add_hosts(dns_names) break time.sleep(1)
def connected_start(): global conn_list # IP tolerance for PI 2 for _ in range(5): log.debug("states: Calling nm.get_active_ip()") ip = nm.get_active_ip(modemgr.get_state_device('CONNECTED')) if ip: mdns.clear_entries() mdns.add_hosts(dns_names) break time.sleep(1) conn_list = []
def state_monitor(): # NetworkManager is crashing on the first call to attach. In two # interface mode, this leaves the hotspot interface with no IP # configuration. Detect this and recover if com_state != 'HOTSPOT': if modemgr.get_mode() == modemgr.MULTI_MODE: log.debug("state_monitor: Calling nm.get_active_ip()") ip = nm.get_active_ip(modemgr.get_state_device('HOTSPOT')) if not ip: log.warn("Hotspot lost IP configuration - resetting") hs_ssid = dns_to_conn(dns_names[0]) activate_connection(hs_ssid, 'HOTSPOT') # Keep this periodic task running return True
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 test_get_active_ip(device_fxt): assert nm.get_active_ip(nm.get_wifi_device()) == '1.2.3.4'
def test_get_active_ip(device_fxt): assert nm.get_active_ip() == '1.2.3.4'