Red Hat Bugzilla – Bug 1309271
VM creation fails by defineXML(), if not using domain.undefine().
Last modified: 2016-02-17 06:20:12 EST
Description of problem:
By redefine of Domain using the function "defineXML()" from libvirt-module in python, causes that Domain creation fails.
Domain has current state "shutdown()". In documentation of defineXML() I read:
"...A previous definition for this domain would be overridden if it already exists. ..."
But this works only than, before using the function undefine().
Version-Release number of selected component (if applicable):
Hypervisor: QEMU 2.0.0
Steps to Reproduce:
1. Define Domain with libvirt.defineXML(xml)
2. Create VM using domain.create()
3. Using domain.shutdown() function
4. Redefine Domain with libvirt.defineXML(xml)
5. New creation using domain.create()
File "/usr/lib/python2.7/dist-packages/libvirt.py", line 3240, in defineXML
if ret is None:raise libvirtError('virDomainDefineXML() failed', conn=self)
2016-02-17 08:41:16.552+0000: 1658: error : virDomainObjListAddLocked:2335 : operation failed: domain 'ecmprt11' already exists with uuid 491cf4b7-7573-4f36-acb8-52dbd9be8e48
Creation of Domain with new definition.
It works for me perfectly, if using between step 3 and 4 additionaly domain.undefine().
Is it only documentation bug, or I missunderstood the description of defineXML()?
Many thanks and best regards
libvirt 1.2.2 was never released in RHEL, moving to the upstream tracker.
It all depends on the XMLs you passed to defineXML (and you didn't attach them).
But in general, redefining a domain is only supported if the name and UUID in the new XML matches the original definition. Beware, if you don't specify any UUID libvirt will automatically assign it to a domain. Thus trying to redefine a domain with an XML which lacks UUID will never work. You should either generate the UUID in your script and use it in both XMLs or fetch it from libvirt after step 1 and use this UUID in step 4.