Last active
February 13, 2017 17:11
-
-
Save nuriel77/dc325084472166fd05e81baa9177ecad to your computer and use it in GitHub Desktop.
get macs libvirt for brbm network interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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