kk
Gabriel Morell





Discovering New Instances
posted July 28, 2015, 4 p.m.
all entries

In order to simply deploy of new Lambent devices, I decided to bake in a zeroconf (avahi) announce so that future clients could find all available instances. This worked great for the prototype kivy application being built in parallel and multiple instances could be controlled from a single interface.

Notes on my implementation

Because I was uncertain of how the interfaces on the host machine were configured. I bound the zeroconf announce to every available interface except virtual and the loopback. This ensured I would have working announced on every interface, be it wifi or ethernet.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def announce(self, discovery_name, port=8680):
    self.zeroconf = Zeroconf()

    self.zconfigs = []
    for i in netifaces.interfaces():
        if i.startswith("lo"):
            # remove loopback from announce
            continue
        if i.startswith("veth"):
            # remove docker interface from announce
            continue

        addrs = netifaces.ifaddresses(i)
        if addrs.keys() == [17]:
            continue

        for a in addrs[netifaces.AF_INET]:

            info_desc = {'path': '/progs_grp/', 'name': discovery_name, "port":port}
            config = ServiceInfo("_aether._tcp.local.",
                           "%s_%s_%s_lambent._aether._tcp.local." % (socket.gethostname(),i, port),
                           socket.inet_aton(a['addr']), port, 0, 0,
                           info_desc)
            try:
                self.zeroconf.register_service(config)
                self.zconfigs.append(config)
            except:
                print("Service %s failed to register" % config)
Filtering the output
Running Automated Deploys