[libvirt-users] libvirt domain configuration xml

Eric Blake eblake at redhat.com
Fri Dec 11 17:25:14 UTC 2015


On 12/11/2015 07:26 AM, Andrei Perietanu wrote:
> I am trying to change a domain configuration from a python script. More
> specific, I want to edit the VNC settings. You can't do this using the
> libvirt API so you have to edit the domain configuration:

Umm, the libvirt API _is_ how you edit the domain configuration.

> 
> Fo exmple, to disable VNC for a domain 'test1':
> 
> vmXml = vm.XMLDesc(0)
> root = ET.fromstring(vmXml)
> devices = root.find('./devices')
> graphics = devices.find('graphics')
> devices.remove(graphics)
> xml = ET.tostring(root)
> with open('path_to/test1.xml', 'w') as f:
> f.write(xml)

Writing to path_to/test1.xml is not necessary (it's merely a convenient
way for you to have a point-in-time snapshot of what the domain XML
was); what you are really looking for is to write the XML back to
libvirt, via:

vm.defineXML(xml)

> So the question really is: where is the domain configuration stored? Am I
> editing the write file, or am I missing something?

The official copy is stored in memory, so the only supported way to
manipulate it is via libvirt API.  Libvirt happens to copy its memory
into files located under /etc/libvirt for persistence reasons, but
modifying those files behind libvirt's back is not a good idea - in
fact, those files start with the disclaimer:
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made
using:
  virsh edit domain
or other application using the libvirt API.
-->

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20151211/b5dd0fb1/attachment.sig>


More information about the libvirt-users mailing list