Humble Devassy Chirammal has uploaded a new change for review.
Change subject: hook: spiceoptions: To provide spice option attributes to vm ......................................................................
hook: spiceoptions: To provide spice option attributes to vm
This hook goes through VM definitions xml file and manipulate its graphics device if the protocol type is spice. This can be used to configure spice options. This hook script will be really useful to configure some of the spice optimization attributes and values like image, streaming, clipboard..etc
For ex:
<graphics type='spice' port='-1' tlsPort='-1' autoport='yes'> ****** <image compression='auto_glz'/> <streaming mode='filter'/> <clipboard copypaste='no'/> <mouse mode='client'/> </graphics>
Change-Id: I7761aab98cdc3a0d37bed7984ae540278e6bbf70 Signed-off-by: Humble Chirammal hchiramm@redhat.com --- M configure.ac M vdsm.spec.in M vdsm_hooks/Makefile.am A vdsm_hooks/spiceoptions/Makefile.am A vdsm_hooks/spiceoptions/README A vdsm_hooks/spiceoptions/before_vm_start.py 6 files changed, 248 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/22178/1
diff --git a/configure.ac b/configure.ac index ce05834..253fc90 100644 --- a/configure.ac +++ b/configure.ac @@ -295,6 +295,7 @@ vdsm_hooks/qos/Makefile vdsm_hooks/scratchpad/Makefile vdsm_hooks/smbios/Makefile + vdsm_hooks/spiceoptions/Makefile vdsm_hooks/sriov/Makefile vdsm_hooks/vhostmd/Makefile vdsm_hooks/vmdisk/Makefile diff --git a/vdsm.spec.in b/vdsm.spec.in index 385a29b..166ff3d 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -528,6 +528,15 @@ sr-iov hook enable to add virtual functions exposed by the device directly to a virtual machine.
+ +%package hook-spiceoptions +Summary: To configure spice options for vm +BuildArch: noarch + +%description hook-spiceoptions +This vdsm hook can be used to configure some of +the spice optimization attributes and values.. + %package hook-vmfex Summary: vmfex support for VDSM BuildArch: noarch @@ -1225,6 +1234,11 @@ %{_libexecdir}/%{vdsm_name}/hooks/after_vm_destroy/50_sriov %{_libexecdir}/%{vdsm_name}/hooks/before_vm_migrate_source/50_sriov
+ +%files hook-spiceoptions +%defattr(-, root, root, -) +%{_libexecdir}/%{vdsm_name}/hooks/before_vm_start/60_spiceoptions + %files hook-vmdisk %defattr(-, root, root, -) %{_libexecdir}/%{vdsm_name}/hooks/before_vm_start/50_vmdisk diff --git a/vdsm_hooks/Makefile.am b/vdsm_hooks/Makefile.am index 8d446bb..d8b213c 100644 --- a/vdsm_hooks/Makefile.am +++ b/vdsm_hooks/Makefile.am @@ -41,6 +41,7 @@ scratchpad \ smbios \ sriov \ + spiceoptions \ vmdisk \ vmfex endif diff --git a/vdsm_hooks/spiceoptions/Makefile.am b/vdsm_hooks/spiceoptions/Makefile.am new file mode 100644 index 0000000..0aa5486 --- /dev/null +++ b/vdsm_hooks/spiceoptions/Makefile.am @@ -0,0 +1,30 @@ +# +# Copyright 2013 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# +# +EXTRA_DIST = \ + before_vm_start.py + +install-data-local: + $(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/before_vm_start + $(INSTALL_SCRIPT) $(srcdir)/before_vm_start.py \ + $(DESTDIR)$(vdsmhooksdir)/before_vm_start/50_spiceoptions + +uninstall-local: + $(RM) $(DESTDIR)$(vdsmhooksdir)/before_vm_start/50_spiceoptions diff --git a/vdsm_hooks/spiceoptions/README b/vdsm_hooks/spiceoptions/README new file mode 100644 index 0000000..2bef8cc --- /dev/null +++ b/vdsm_hooks/spiceoptions/README @@ -0,0 +1,62 @@ +spiceoptions vdsm hook: +=============================== + +This hook goes through VM definitions xml file and manipulate its +graphics device if the protocol type is spice. This can be used to +configure spice options on the fly. That said, this hook script +will be really useful to configure some of the spice optimization +attributes and values.. + +For ex: + + <graphics type='spice' port='-1' tlsPort='-1' autoport='yes'> + ****** + <image compression='auto_glz'/> + <streaming mode='filter'/> + <clipboard copypaste='no'/> + <mouse mode='client'/> + </graphics> + +Spice supports variable compression settings for audio, images +and streaming. These settings are accessible via the compression +attribute in all following elements: image to set image compression +(accepts auto_glz, auto_lz, quic, glz, lz, off),jpeg for JPEG +compression for images over wan (accepts auto, never, always), +zlib for configuring wan image compression (accepts auto, never, always) +..etc. + +Streaming mode is set by the streaming element, settings its mode +attribute to one of filter, all or off. + +Copy & Paste functionality (via Spice agent) is set by the clipboard +element.It is enabled by default, and can be disabled by setting +the copypaste property to no. + +Mouse mode is set by the mouse element, setting its mode attribute +to one of server or client.If no mode is specified, the qemu default +will be used (client mode). + +Syntax: + spiceoptions={'element': {'attribute': 'value'},.. + +For ex: + spiceoptions={'image': {'compression': 'auto_glz'}, + 'jpeg': {'compressions': 'never'}, + 'streaming':{'mode':'filter'}, + 'clipboard':{'copypaste':'yes'}}..etc + + +Installation: +* Use the engine-config to append the appropriate custom property as such: + sudo engine-config -s UserDefinedVMProperties= + 'previousProperties;spiceoptions=^.*$' --cver=3.2 + +* Verify that the spiceoptions custom property was properly added: + sudo engine-config -g UserDefinedVMProperties + +Usage: +In the VM configuration window, open the custom properites tab +and add spiceoptions= + +NOTE: Live migration is **not** tested. + diff --git a/vdsm_hooks/spiceoptions/before_vm_start.py b/vdsm_hooks/spiceoptions/before_vm_start.py new file mode 100755 index 0000000..4b95742 --- /dev/null +++ b/vdsm_hooks/spiceoptions/before_vm_start.py @@ -0,0 +1,140 @@ +#!/usr/bin/python + +import os +import sys +import hooking +import traceback +import ast + +''' +Hook to configure spice options on a vm + +For ex: + +Syntax: + spiceoptions={'element': {'attribute': 'value'},.. + +For ex: + spiceoptions={'image': {'compression': 'auto_glz'}, + 'jpeg': {'compressions': 'never'}, + 'streaming':{'mode':'filter'}, + 'clipboard':{'copypaste':'yes'}}..etc + + + <graphics type='spice' port='-1' tlsPort='-1' autoport='yes'> + ****** + <image compression='auto_glz'/> + <streaming mode='filter'/> + <clipboard copypaste='no'/> + <mouse mode='client'/> + </graphics> +''' + + +imageCompList = ['auto_glz', 'auto_lz', 'quic', 'glz', 'lz', 'off'] + +jpegCompList = ['auto', 'never', 'always'] + +zlibCompList = ['auto', 'never', 'always'] + +copyPaste = ['yes', 'no'] + +strModeList = ['filter', 'all', 'off'] + +mouseModeList = ['server', 'client'] + +spiceDict = {'image': {'compression': imageCompList}, + 'jpeg': {'compression': jpegCompList}, + 'streaming': {'mode': strModeList}, + 'mouse': {'mode': mouseModeList}, + 'clipboard': {'copypaste': copyPaste}} + + +def createOptionElement(domxml, attrname, attroption, attrvalue): + if attrname == "jpeg": + jpegEle = domxml.createElement(attrname) + if attrvalue in jpegCompList: + jpegEle.setAttribute(attroption, attrvalue) + return jpegEle + else: + sys.stderr.write("\n InValid option:%s \t Available options are %s" + % (attrvalue, jpegCompList)) + elif attrname == "zlib": + zlibEle = domxml.createElement(attrname) + if attrvalue in zlibCompList: + zlibEle.setAttribute(attroption, attrvalue) + return zlibEle + else: + sys.stderr.write("\n InValid option:%s \t Available options are %s" + % (attrvalue, zlibCompList)) + elif attrname == "image": + imageEle = domxml.createElement(attrname) + if attrvalue in imageCompList: + imageEle.setAttribute(attroption, attrvalue) + return imageEle + else: + sys.stderr.write("\n InValid option:%s \t Available options are %s" + % (attrvalue, imageCompList)) + elif attrname == "streaming": + streamEle = domxml.createElement(attrname) + if attrvalue in strModeList: + streamEle.setAttribute(attroption, attrvalue) + return streamEle + else: + sys.stderr.write("\n InValid option:%s \t Available options are %s" + % (attrvalue, strModeList)) + elif attrname == "mouse": + mouseEle = domxml.createElement(attrname) + if attrvalue in mouseModeList: + mouseEle.setAttribute(attroption, attrvalue) + return mouseEle + else: + sys.stderr.write("\n InValid option:%s \t Available options are %s" + % (attrvalue, mouseModeList)) + + elif attrname == "clipboard": + clipEle = domxml.createElement(attrname) + if attrvalue in copyPaste: + clipEle.setAttribute(attroption, attrvalue) + return clipEle + else: + sys.stderr.write("\n InValid option:%s \t Available options are %s" + % (attrvalue, copyPaste)) + else: + sys.stderr.write('\n No Valid Element created for graphic device :%s\n' + % (attrname)) + + +if 'spiceoptions' in os.environ: + try: + attrName = '' + attrVal = '' + attrOpt = '' + domxml = hooking.read_domxml() + spiceOpt = ast.literal_eval(os.environ['spiceoptions']) + spiceOpt = dict((k.lower(), v) for k, v in spiceOpt.iteritems()) + for graphDev in domxml.getElementsByTagName('graphics'): + graphType = graphDev.getAttribute('type') + if graphType == 'spice': + for key, value in spiceOpt.items(): + if key not in spiceDict.keys(): + sys.stderr.write('\n Invalid KEY:%s \n' % (key,)) + else: + for ak, bk in value.items(): + if ak not in spiceDict[key].keys(): + sys.stderr.write("\n Invalid KEY in :%s[%s] " + "options are:%s \n" + % (key, ak, + spiceDict[key].keys())) + + else: + returnEle = createOptionElement( + domxml, key, ak, value[ak]) + if returnEle: + graphDev.appendChild(returnEle) + + hooking.write_domxml(domxml) + except: + sys.stderr.write('spiceoptions: [unexpected error]: %s\n' % + traceback.format_exc()) + sys.exit(2)