From 11344a50d2e3662a47527e4f3f5d6436297065ec Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Mon, 9 Feb 2009 15:17:15 +0000
Subject: [PATCH] KVM: Add usb mouse type parameter

In some cases 'mouse' may work better than 'tablet', so we'll handle
both by allowing the user to specify a parameter. By default no mouse is
used.

Reviewed-by: iustinp
---
 lib/constants.py         |  3 +++
 lib/hypervisor/hv_kvm.py | 13 ++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/constants.py b/lib/constants.py
index 91b5a7c18..abfb1eafa 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -292,6 +292,7 @@ HV_KERNEL_PATH = "kernel_path"
 HV_INITRD_PATH = "initrd_path"
 HV_ROOT_PATH = "root_path"
 HV_SERIAL_CONSOLE = "serial_console"
+HV_USB_MOUSE = "usb_mouse"
 
 HVS_PARAMETERS = frozenset([
   HV_BOOT_ORDER,
@@ -308,6 +309,7 @@ HVS_PARAMETERS = frozenset([
   HV_INITRD_PATH,
   HV_ROOT_PATH,
   HV_SERIAL_CONSOLE,
+  HV_USB_MOUSE,
   ])
 
 # BE parameter names
@@ -481,6 +483,7 @@ HVC_DEFAULTS = {
     HV_BOOT_ORDER: "disk",
     HV_NIC_TYPE: HT_NIC_PARAVIRTUAL,
     HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
+    HV_USB_MOUSE: None,
     },
   HT_FAKE: {
     },
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index df83538e2..964fe9c03 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -62,6 +62,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     constants.HV_BOOT_ORDER,
     constants.HV_NIC_TYPE,
     constants.HV_DISK_TYPE,
+    constants.HV_USB_MOUSE,
     ]
 
   _MIGRATION_STATUS_RE = re.compile('Migration\s+status:\s+(\w+)',
@@ -285,10 +286,14 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       else:
         kvm_cmd.extend(['-append', root_append])
 
+    mouse_type = instance.hvparams[constants.HV_USB_MOUSE]
+    if mouse_type:
+      kvm_cmd.extend(['-usb'])
+      kvm_cmd.extend(['-usbdevice', mouse_type])
+
     # FIXME: handle vnc password
     vnc_bind_address = instance.hvparams[constants.HV_VNC_BIND_ADDRESS]
     if vnc_bind_address:
-      kvm_cmd.extend(['-usbdevice', 'tablet'])
       if utils.IsValidIP(vnc_bind_address):
         if instance.network_port > constants.VNC_BASE_PORT:
           display = instance.network_port - constants.VNC_BASE_PORT
@@ -784,6 +789,12 @@ class KVMHypervisor(hv_base.BaseHypervisor):
                                    (disk_type,
                                     constants.HT_KVM_VALID_DISK_TYPES))
 
+    mouse_type = hvparams[constants.HV_USB_MOUSE]
+    if mouse_type and mouse_type not in ('mouse', 'tablet'):
+      raise errors.HypervisorError("Invalid usb mouse type %s specified for"
+                                   " the KVM hyervisor. Please choose"
+                                   " 'mouse' or 'tablet'" % mouse_type)
+
   def ValidateParameters(self, hvparams):
     """Check the given parameters for validity.
 
-- 
GitLab