Skip to content

Instantly share code, notes, and snippets.

@dtantsur
Created July 15, 2019 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtantsur/fafd3c4878fec70ec6739fac0613b2c7 to your computer and use it in GitHub Desktop.
Save dtantsur/fafd3c4878fec70ec6739fac0613b2c7 to your computer and use it in GitHub Desktop.
Browse OpenStack mDNS records
#!/usr/bin/env python
from __future__ import print_function
import socket
import sys
import netifaces
import zeroconf
def log(_msg, *_args):
print('=', _msg % _args, file=sys.stderr)
def process_interface(stype, iface, addr):
zc = zeroconf.Zeroconf(interfaces=[addr])
try:
sinfo = zc.get_service_info(stype, stype)
finally:
zc.close()
if sinfo:
log("Found %s on %s (%s)", stype, iface, addr)
converted = socket.inet_ntoa(sinfo.address)
print(sinfo.type, '%s:%s' % (converted, sinfo.port), sinfo.properties)
else:
log("No %s exposed on %s", stype, iface)
if __name__ == '__main__':
try:
stype = sys.argv[1]
except IndexError:
sys.exit("Usage: %s (baremetal|baremetal-introspection)" % sys.argv[0])
stype = '%s._openstack._tcp.local.' % stype
for iface in netifaces.interfaces():
addrs = netifaces.ifaddresses(iface)
try:
addr = addrs[netifaces.AF_INET][0]['addr']
except KeyError:
log("No IPv4 addresses for interface %s", iface)
continue
process_interface(stype, iface, addr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment