<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"> I am facing a strange issue where I remove some devices from a VM’s xml before creating the domain, but both device types are still present in the VM, but with a different definition.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>Background</b>:<o:p></o:p></p>
<p class="MsoNormal"> I am attempting to inject or remove some devices from specific VMs before they are brought up. More specifically, I'd like to update the instance's domain XML on the compute host before the instance is launched, as part of Nova Compute.
This is to be done programmatically, not manually. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">However, the build_instance hook in Nova compute doesn't quite let one do that. In the 'pre' hook, the instance XML is not yet defined. In the post hook, it is defined but it already too late because the domain has been created from the
xml.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>What I did</b>:<o:p></o:p></p>
<p class="MsoNormal">So, as an experiment, I modified nova/virt/libvirt/libvirt.py, specifically
<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">def spawn(...):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> disk_info = ...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> self._create_image(...)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> xml = self._get_guest_xml(..., write_to_disk=<span style="color:red">False</span>)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> # -- <span style="color:red">
Modify the xml here and write it to libvirt.xml</span><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> self._create_domain_and_network(context, xml, ...)<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Also, I verified in <span style="font-family:"Courier New"">
_create_domain</span>, just before:<o:p></o:p></p>
<p class="MsoNormal"> <span style="font-family:"Courier New"">domain = self._conn.defineXML(xml)<o:p></o:p></span></p>
<p class="MsoNormal">that the xml is as I intended.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>Problem</b>:<o:p></o:p></p>
<p class="MsoNormal">But it doesn't work. In this experiment, I am trying to remove the memballoon (virtio) device and an USB device from the domain XML. But both show up in the VM under lspci after the VM boots up, but with a different definition.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The original XML had:<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <input type="tablet" bus="usb"/><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <memballoon model="virtio"> <stats period="10"/> </memballoon><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Both got removed. But 'virsh dumpxml' of the VM shows:<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <controller type='usb' index='0'><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <alias name='usb0'/><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </controller><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <memballoon model='virtio'><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <alias name='balloon0'/><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </memballoon></span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Where are these devices coming from, since they are not present in the defineXML that nova.compute.libvirt driver invokes?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Cheers,<o:p></o:p></p>
<p class="MsoNormal">Sundar<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<br>
<hr>
<font face="Arial" color="Black" size="2"><br>
Confidentiality Notice.<br>
This message may contain information that is confidential or otherwise protected from disclosure. If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution, or copying of this message, or any attachments,
is strictly prohibited. If you have received this message in error, please advise the sender by reply e-mail, and delete the message and any attachments. Thank you.<br>
</font>
</body>
</html>