[libvirt] how to use libvirt hook scripts to modify domain xml while its start

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?

here is the format scripts: http://paste.openstack.org/show/75876/ On Wed, Apr 16, 2014 at 3:17 PM, cokabug <cokabug@gmail.com> wrote:
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?

On Wed, Apr 16, 2014 at 03:17:33PM +0800, cokabug wrote:
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
Hook scripts don't allow for modification of the XML config. They're just for triggering actions externally to libvirt. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
cokabug
-
Daniel P. Berrange