Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()