[Libvir] Problems with defineXML in python..

Mark Dehus Mark.Dehus at colorado.edu
Wed Oct 10 03:20:27 UTC 2007


I am having some problems getting libvirt under python to work properly. 
I can setup new domains by using the createLinux() function, but when I
attempt to use defineXML() it fails with no reason given other then
"virDomainDefineXML() failed".  I am using the same XML file for both
functions.

This is on a Ubuntu 7.04 server running python 2.5 & libvirt 0.1.8 (from
the ubuntu universe repo).

Here is my test code:

import libvirt
import sys
import xml
import random

try:
    conn = libvirt.open(None)
except Exception, e:
    print e
if conn == None:
    print 'Failed to open connection to the hypervisor'
    sys.exit(1)
create = True

if create:
    xmlfile = open('webserv.xml')
    xmldesc = xmlfile.read()
    xmlfile.close()

    try:
#        webserv = conn.createLinux(xmldesc, 0)
        webserv = conn.defineXML(xmldesc)
    except Exception, e:
       print 'Failed to create webserv: %s' % e
       sys.exit(1)

    if webserv is None:
        print 'whoops this shouldnt happen!'

    conn.create(webserv)

    try:
        print "Domain 0: id %d running %s" % (webserv.ID(), webserv.OSType())
        print webserv.info()
        print webserv.XMLDesc(0)
    except Exception, e:
        print e
    #webserv.shutdown()

And the XML file:

<domain type='xen' >
  <name>webserv</name>
  <os>
    <type>linux</type>
    <kernel>/boot/vmlinuz-2.6.19-4-generic-amd64</kernel>
    <initrd>/boot/initrd.img-2.6.19-4-generic-amd64</initrd>
    <root>/dev/hda1</root>
  </os>
  <memory>1024</memory>
  <vcpu>1</vcpu>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <interface type='bridge'>
      <source bridge='xenbr0'/>
      <mac address='00:16:3e:24:27:a5'/>
      <script path='vif-bridge'/>
    </interface>
    <graphics type='vnc' port='5902'/>
    <disk type='file' device='disk'>
      <driver name='tap' type='aio'/>
      <source file='/virtual/images/webserv/webserv.img'/>
      <target dev='hda1'/>
    </disk>
    <console tty='/dev/pts/4'/>
  </devices>
</domain>

Am I missing something simple, or is there a bug?

Thanks!




More information about the libvir-list mailing list