kvm: support usb devices
authorGuido Trotter <ultrotter@google.com>
Fri, 11 Jan 2013 17:47:09 +0000 (17:47 +0000)
committerGuido Trotter <ultrotter@google.com>
Mon, 14 Jan 2013 14:36:30 +0000 (15:36 +0100)
All in one go, comma separated usb devices of all types.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/constants.py
lib/hypervisor/hv_kvm.py
man/gnt-instance.rst

index a5a758d..1344951 100644 (file)
@@ -831,6 +831,7 @@ HV_CPU_CORES = "cpu_cores"
 HV_CPU_THREADS = "cpu_threads"
 HV_CPU_SOCKETS = "cpu_sockets"
 HV_SOUNDHW = "soundhw"
+HV_USB_DEVICES = "usb_devices"
 
 
 HVS_PARAMETER_TYPES = {
@@ -895,6 +896,7 @@ HVS_PARAMETER_TYPES = {
   HV_CPU_THREADS: VTYPE_INT,
   HV_CPU_SOCKETS: VTYPE_INT,
   HV_SOUNDHW: VTYPE_STRING,
+  HV_USB_DEVICES: VTYPE_STRING,
   }
 
 HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
@@ -1963,6 +1965,7 @@ HVC_DEFAULTS = {
     HV_CPU_THREADS: 0,
     HV_CPU_SOCKETS: 0,
     HV_SOUNDHW: "",
+    HV_USB_DEVICES: "",
     },
   HT_FAKE: {},
   HT_CHROOT: {
index aa629b5..47b0330 100644 (file)
@@ -536,6 +536,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     constants.HV_CPU_THREADS: hv_base.OPT_NONNEGATIVE_INT_CHECK,
     constants.HV_CPU_SOCKETS: hv_base.OPT_NONNEGATIVE_INT_CHECK,
     constants.HV_SOUNDHW: hv_base.NO_CHECK,
+    constants.HV_USB_DEVICES: hv_base.NO_CHECK,
     }
 
   _MIGRATION_STATUS_RE = re.compile("Migration\s+status:\s+(\w+)",
@@ -1339,6 +1340,11 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     if hvp[constants.HV_SOUNDHW]:
       kvm_cmd.extend(["-soundhw", hvp[constants.HV_SOUNDHW]])
 
+    # Various types of usb devices, comma separated
+    if hvp[constants.HV_USB_DEVICES]:
+      for dev in hvp[constants.HV_USB_DEVICES].split(","):
+        kvm_cmd.extend(["-usbdevice", dev])
+
     # Save the current instance nics, but defer their expansion as parameters,
     # as we'll need to generate executable temp files for them.
     kvm_nics = instance.nics
index 9837e5c..276c824 100644 (file)
@@ -655,6 +655,14 @@ soundhw
     Comma separated list of emulated sounds cards, or "all" to enable
     all the available ones.
 
+usb\_devices
+    Valid for the KVM hypervisor.
+
+    Comma separated list of usb devices. These can be emulated devices
+    or passthrough ones, and each one gets passed to kvm with its own
+    ``-usbdevice`` option. See the **qemu**\(1) manpage for the syntax
+    of the possible components.
+
 
 The ``-O (--os-parameters)`` option allows customisation of the OS
 parameters. The actual parameter names and values depends on the OS