Created
October 2, 2013 22:33
-
-
Save fredhsu/6801488 to your computer and use it in GitHub Desktop.
Libvirt Python API sample, searching for a VM with a particular MAC address
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
import libvirt | |
import xml.etree.ElementTree as ET | |
def findDomainWithMac(conn, addr): | |
domlist = map(conn.lookupByID, conn.listDomainsID()) | |
for dom in domlist: | |
root = ET.fromstring(dom.XMLDesc()) | |
searchString = "./devices/interface/mac[@address='{0}']".format(addr) | |
if (root.find(searchString) is not None): | |
return dom | |
conn = libvirt.openReadOnly('qemu:///system') | |
domain = findDomainWithMac(conn, '52:54:00:b6:53:32') | |
print domain.name() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See my fork, notice the addition of the "0" on line 7: https://gist.github.com/nickgarvey/8229208