Created
February 22, 2011 11:17
-
-
Save ekohl/838528 to your computer and use it in GitHub Desktop.
Initial stab at libvirt to ganeti
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 | |
from lxml import etree | |
sort_disks = lambda d: next(d.iter("target")).get("dev") | |
def main(host, opts): | |
#Connect to some hypervisor. | |
conn=libvirt.open("qemu:///system") | |
#Iterate through all available domains. | |
for id in conn.listDomainsID(): | |
#Initialize the domain object. | |
dom=conn.lookupByID(id) | |
tree=etree.fromstring(dom.XMLDesc(0)) | |
# Set up basic command | |
print "gnt-instance add -n", host, opts, | |
# Add a sorted list of mac addresses | |
macs = set(s.get("address") for s in tree.xpath("devices/interface/mac")) | |
for i, mac in enumerate(filter(None, macs)): | |
print "--net=%d:mac=%s" % (i, mac), | |
# Add a sorted list of disks | |
disks = tree.xpath('//devices/disk[@device="disk"]') | |
for i, dev in enumerate(sorted(disks, key=sort_disks)): | |
print "--disk %d:adopt=%s" % (i, next(dev.iter("source")).get("dev")), | |
# Hostname (with domain fix) | |
print "%s.xentower.nl" % dom.name() | |
if __name__=="__main__": | |
main("green.xentower.nl", "-t plain -o debootstrap+default") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment