Tanks for the reply Eric.
  The only reason I'm not going through the API is because there is nothing in the API (AFIK), that will allow you to modify the VNC settings, i.e. enable/disable, change port number. So I figured, the only way to do it is to modify the XML. 
   I can't use virsh edit because I need this whole behavior scripted.
   So now if I want to change the VNC settings it looks like I have to read the XML, modify it, define it, actually re-define it (maybe I have to undefine it first?! ) and that's it - correct?

Andrei

On Fri, Dec 11, 2015 at 5:25 PM, Eric Blake <eblake@redhat.com> wrote:
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



The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you receive this in error please contact the sender and delete the material from any computer immediately. It is the policy of Klas  Limited to disavow the sending of offensive material and should you consider that the material contained in the message is offensive you should contact the sender immediately and also your I.T. Manager.

Klas Telecom Inc., a Virginia Corporation with offices at 1101 30th St. NW, Washington, DC 20007.

Klas Limited (Company Number 163303) trading as Klas Telecom, an Irish Limited Liability Company, with its registered office at Fourth Floor, One Kilmainham Square, Inchicore Road, Kilmainham, Dublin 8, Ireland.