i want add sound card to domain xml when guest start,after google,i found libvirt provide hook function.
i follow the instruction to make a python,and boot a guest,but after use "virsh edit" its still dont have sound card config
/etc/libvirt/hooks/qemu:
#!/usr/bin/python
import sys
import re
import os
hooklog = '/tmp/hook.log'
log = open(hooklog, 'w')
stdinxml = sys.stdin.readlines()
if sys.argv[2] == 'start':
log.write("hook start,domain name: %s \n" % sys.argv[1])
maxslot=-1
for line in stdinxml:
slotm = re.search("slot='(?P<slotnum>0x[0-9a-fA-F]{2})'", line)
if slotm:
slotnum = int(slotm.group('slotnum'),0)
if slotnum > maxslot:
maxslot = slotnum
if '</devices>' in line:
log.write("insert sound card config \n")
slotnum = maxslot + 1
line = " <sound model='ich6'>\n"
line = line + " <address type='pci' domain='0x0000' bus='0x00' slot='0x%0.2X' function='0x0'/>\n" % slotnum
line = line + " </sound>\n"
line = line + " </devices>\n"
stdoutxml = ''.join(line)
sys.stdout.write(stdoutxml)
tail -f /tmp/hook.log:
hook start,domain name: instance-00000222
insert sound card config
tail /var/log/libvirt/libvirtd.log:
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
in these log,hook script seems to executed,but not effective.
can anyone tell me where is wrong?