Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get macs libvirt for brbm network interface
#!/usr/bin/env python
import xml.etree.ElementTree as ET
import libvirt
import sys
import re
""" Find all mac addresses from domains
to be able to generate the instackenv.json
manually """
regex = r'^baremetalbrbm_[0-9]$'
def main():
conn = libvirt.openReadOnly('qemu:///system')
if conn == None:
print('Failed to open connection to qemu:///system')
exit(1)
domlist = conn.listAllDomains()
for dom in domlist:
if not re.search(regex, dom.name()):
continue
root = ET.fromstring(dom.XMLDesc())
searchString = "./devices/interface"
interface = root.find(searchString)
if interface is not None:
searchString = "./source[@network='brbm']"
source = interface.find(searchString)
if searchString is not None:
mac = interface.find('./mac').attrib['address']
print "%s: %s" % (dom.name(), mac)
else:
print "Did not find network for %s" % dom.name()
else:
print "Did not find interface entries for %s" % dom.name()
conn.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.