<div dir="ltr">here is the format scripts:<div><a href="http://paste.openstack.org/show/75876/">http://paste.openstack.org/show/75876/</a><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 16, 2014 at 3:17 PM, cokabug <span dir="ltr"><<a href="mailto:cokabug@gmail.com" target="_blank">cokabug@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>i want add sound card to domain xml when guest start,after google,i found libvirt provide hook function.</div>
<div>i follow the instruction to make a python,and boot a guest,but after use "virsh edit" its still dont have sound card config</div>
<div><br></div><div><br></div><div>/etc/libvirt/hooks/qemu:</div><div><div>#!/usr/bin/python</div><div><br></div><div>import sys</div><div>import re</div><div>import os</div><div><br></div><div>hooklog = '/tmp/hook.log'</div>

<div>log = open(hooklog, 'w')</div><div>stdinxml = sys.stdin.readlines()</div><div><br></div><div>if sys.argv[2] == 'start':</div><div>  log.write("hook start,domain name: %s \n" % sys.argv[1])</div>

<div>  maxslot=-1</div><div><br></div><div>  for line in stdinxml:</div><div>    slotm = re.search("slot='(?P<slotnum>0x[0-9a-fA-F]{2})'", line)</div><div>    if slotm:</div><div>      slotnum = int(slotm.group('slotnum'),0)</div>

<div>      if slotnum > maxslot:</div><div>        maxslot = slotnum</div><div>    if '</devices>' in line:</div><div>      log.write("insert sound card config \n")</div><div>      slotnum = maxslot + 1</div>

<div>      line = "    <sound model='ich6'>\n"</div><div>      line = line + "      <address type='pci' domain='0x0000' bus='0x00' slot='0x%0.2X' function='0x0'/>\n" % slotnum</div>

<div>      line = line + "    </sound>\n"</div><div>      line = line + "  </devices>\n"</div><div>    stdoutxml = ''.join(line)</div><div>    sys.stdout.write(stdoutxml)</div></div>

<div><br></div><div>tail -f /tmp/hook.log:</div><div><div>hook start,domain name: instance-00000222                              </div><div>insert sound card config                              </div><div><br></div><div>
tail /var/log/libvirt/libvirtd.log:</div>
<div>2014-04-16 07:13:39.159+0000: 52199: warning : qemuDomainObjTaint:1377 : Domain id=81 name='instance-00000222' uuid=974d62b7-f316-4f20-a91c-d11cb85980fe is tainted: high-privileges                                                                       </div>

</div><div><br></div><div>in these log,hook script seems to executed,but not effective.</div><div><br></div><div>can anyone tell me where is wrong?<br></div><div><br></div></div>
</blockquote></div><br></div>