Raise a special exception, qmp.QmpCommandNotSupported, whenever an
unsupported QMP command is about to be executed. This is intended to
assist in falling back to the human monitor for hotplug operations. As
such, it is KVM-internal and therefore the exception is not defined
in ganeti.errors.

Signed-off-by: Apollon Oikonomopoulos <[email protected]>
---
 lib/hypervisor/hv_kvm/monitor.py | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/hypervisor/hv_kvm/monitor.py b/lib/hypervisor/hv_kvm/monitor.py
index fc6fac9..16bf7cc 100644
--- a/lib/hypervisor/hv_kvm/monitor.py
+++ b/lib/hypervisor/hv_kvm/monitor.py
@@ -35,6 +35,19 @@ from ganeti import utils
 from ganeti import serializer
 
 
+class QmpCommandNotSupported(errors.HypervisorError):
+  """QMP command not supported by the monitor.
+
+  This is raised in case a QmpMonitor instance is asked to execute a command
+  not supported by the instance.
+
+  This is a KVM-specific exception, intended to assist in falling back to using
+  the human monitor for operations QMP does not support.
+
+  """
+  pass
+
+
 class QmpMessage(object):
   """QEMU Messaging Protocol (QMP) message.
 
@@ -189,7 +202,7 @@ class QmpConnection(MonitorSocket):
   def __init__(self, monitor_filename):
     super(QmpConnection, self).__init__(monitor_filename)
     self._buf = ""
-    self.supported_commands = frozenset()
+    self.supported_commands = None
 
   def __enter__(self):
     self.connect()
@@ -330,6 +343,14 @@ class QmpConnection(MonitorSocket):
 
     """
     self._check_connection()
+
+    # During the first calls of Execute, the list of supported commands has not
+    # yet been populated, so we can't use it.
+    if (self.supported_commands is not None and
+        command not in self.supported_commands):
+      raise QmpCommandNotSupported("Instance does not support the '%s'"
+                                    " QMP command." % command)
+
     message = QmpMessage({self._EXECUTE_KEY: command})
     if arguments:
       message[self._ARGUMENTS_KEY] = arguments
-- 
1.9.1

Reply via email to