<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 12/15/2015 04:36 AM, Andrei
Perietanu wrote:<br>
</div>
<blockquote
cite="mid:CAE0VCzHPKTUnADtmDcgjazaYsW9ApLKJ6_q5zBD+rJ1te5RgBg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div style="font-size:12.8000001907349px"><font face="verdana,
sans-serif" color="#666666">Tanks for the reply Eric.</font></div>
<div style="font-size:12.8000001907349px"><font face="verdana,
sans-serif" color="#666666"> 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. </font></div>
<div style="font-size:12.8000001907349px"><font face="verdana,
sans-serif" color="#666666"> </font><span
style="color:rgb(102,102,102);font-family:verdana,sans-serif">I
can't use virsh edit because I need this whole behavior
scripted.</span></div>
<div style="font-size:12.8000001907349px"><font face="verdana,
sans-serif" color="#666666"> 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?</font></div>
</div>
</blockquote>
<br>
<font color="#666666"><font face="verdana, sans-serif">If you
"define" a domain that already exists, the new definition
replaces the existing one, but not until the domain has been
powered off - the next time it is started, the new config takes
effect. There is no need to "undefine" or separately
"re-define".<br>
<br>
So the solution to your problem is to simply replace the final
two lines of your example code (open() and f.write()) with
Eric's suggested line:<br>
</font></font><br>
<font color="#666666"><font face="verdana, sans-serif">
vm.defineXML(xml) <br>
<br>
That's it.<br>
<br>
(BTW, please make your replies inline rather that top-posting.
It makes it much easier to follow the discussion)<br>
<br>
<br>
</font></font>
<blockquote
cite="mid:CAE0VCzHPKTUnADtmDcgjazaYsW9ApLKJ6_q5zBD+rJ1te5RgBg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra"><br clear="all">
<div>
<div class="gmail_signature">
<div><font face="verdana, sans-serif" color="#666666">Andrei</font></div>
</div>
</div>
<br>
<div class="gmail_quote">On Fri, Dec 11, 2015 at 5:25 PM, Eric
Blake <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:eblake@redhat.com" target="_blank">eblake@redhat.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex"><span
class="">On 12/11/2015 07:26 AM, Andrei Perietanu wrote:<br>
> I am trying to change a domain configuration from a
python script. More<br>
> specific, I want to edit the VNC settings. You
can't do this using the<br>
> libvirt API so you have to edit the domain
configuration:<br>
<br>
</span>Umm, the libvirt API _is_ how you edit the domain
configuration.<br>
<span class=""><br>
><br>
> Fo exmple, to disable VNC for a domain 'test1':<br>
><br>
> vmXml = vm.XMLDesc(0)<br>
> root = ET.fromstring(vmXml)<br>
> devices = root.find('./devices')<br>
> graphics = devices.find('graphics')<br>
> devices.remove(graphics)<br>
> xml = ET.tostring(root)<br>
> with open('path_to/test1.xml', 'w') as f:<br>
> f.write(xml)<br>
<br>
</span>Writing to path_to/test1.xml is not necessary (it's
merely a convenient<br>
way for you to have a point-in-time snapshot of what the
domain XML<br>
was); what you are really looking for is to write the XML
back to<br>
libvirt, via:<br>
<br>
vm.defineXML(xml)<br>
<span class=""><br>
> So the question really is: where is the domain
configuration stored? Am I<br>
> editing the write file, or am I missing something?<br>
<br>
</span>The official copy is stored in memory, so the only
supported way to<br>
manipulate it is via libvirt API. Libvirt happens to copy
its memory<br>
into files located under /etc/libvirt for persistence
reasons, but<br>
modifying those files behind libvirt's back is not a good
idea - in<br>
fact, those files start with the disclaimer:<br>
<!--<br>
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE
LIKELY TO BE<br>
OVERWRITTEN AND LOST. Changes to this xml configuration
should be made<br>
using:<br>
virsh edit domain<br>
or other application using the libvirt API.<br>
--><br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Eric Blake eblake redhat com <a
moz-do-not-send="true" href="tel:%2B1-919-301-3266"
value="+19193013266">+1-919-301-3266</a><br>
Libvirt virtualization library <a
moz-do-not-send="true" href="http://libvirt.org"
rel="noreferrer" target="_blank"><a class="moz-txt-link-freetext" href="http://libvirt.org">http://libvirt.org</a></a><br>
<br>
</font></span></blockquote>
</div>
<br>
</div>
</div>
<br>
<p><img moz-do-not-send="true"
src="http://www.klasonline.com/klas_telecom_email_sig_1_01.jpg"></p>
<p><span style="font-family:Arial;font-size:x-small">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.</span></p>
<p><span style="font-family:Arial;font-size:x-small">Klas Telecom
Inc., a Virginia Corporation with offices at 1101 30th St. NW,
Washington, DC 20007.</span></p>
<p>
<font color="#000000"><font face="Arial"><font size="1">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.</font></font></font></p>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
libvirt-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:libvirt-users@redhat.com">libvirt-users@redhat.com</a>
<a class="moz-txt-link-freetext" href="https://www.redhat.com/mailman/listinfo/libvirt-users">https://www.redhat.com/mailman/listinfo/libvirt-users</a></pre>
</blockquote>
<br>
</body>
</html>