Allow KVM commands to have a timeout
authorMichele Tartara <mtartara@google.com>
Fri, 7 Mar 2014 09:47:38 +0000 (10:47 +0100)
committerMichele Tartara <mtartara@google.com>
Fri, 7 Mar 2014 10:08:01 +0000 (11:08 +0100)
Modify the function that sends commands to the KVM monitor so that it is
possible to specify an optional timeout after which the command is killed.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

lib/hypervisor/hv_kvm.py

index 3c1bc8c..4a65c58 100644 (file)
@@ -1680,10 +1680,15 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     self._SaveKVMRuntime(instance, kvm_runtime)
     self._ExecuteKVMRuntime(instance, kvm_runtime, kvmhelp)
 
-  def _CallMonitorCommand(self, instance_name, command):
+  def _CallMonitorCommand(self, instance_name, command, timeout=None):
     """Invoke a command on the instance monitor.
 
     """
+    if timeout is not None:
+      timeout_cmd = "timeout %s" % (timeout, )
+    else:
+      timeout_cmd = ""
+
     # TODO: Replace monitor calls with QMP once KVM >= 0.14 is the minimum
     # version. The monitor protocol is designed for human consumption, whereas
     # QMP is made for programmatic usage. In the worst case QMP can also