[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

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

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

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

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

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


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

And the XML file:

<domain type='xen' >
    <interface type='bridge'>
      <source bridge='xenbr0'/>
      <mac address='00:16:3e:24:27:a5'/>
      <script path='vif-bridge'/>
    <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'/>
    <console tty='/dev/pts/4'/>

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


More information about the libvir-list mailing list