[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt-users] libvirt domain configuration xml



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

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]