(2.10) Make hotplug related method raise HotplugError
authorDimitris Aragiorgis <dimara@grnet.gr>
Fri, 11 Oct 2013 00:50:56 +0000 (03:50 +0300)
committerDimitris Aragiorgis <dimara@grnet.gr>
Tue, 17 Dec 2013 10:46:38 +0000 (12:46 +0200)
Hotplug is not supported by default and thus we raise
HotplugError() for hotplug related methods.
If a hypervisor wants to support it, we must override VerifyHotplugSupport()
and implement the Hot* method.

Backend invokes VerifyHotplugSupport() and raises RPCFail if an
exception is raised.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

lib/backend.py
lib/hypervisor/hv_base.py
lib/hypervisor/hv_chroot.py
lib/hypervisor/hv_fake.py
lib/hypervisor/hv_kvm.py
lib/hypervisor/hv_lxc.py
lib/hypervisor/hv_xen.py

index 575c048..1c81a6b 100644 (file)
@@ -1647,8 +1647,8 @@ def HotplugDevice(instance, action, dev_type, device, extra, seq):
   """
   hyper = hypervisor.GetHypervisor(instance.hypervisor)
   try:
   """
   hyper = hypervisor.GetHypervisor(instance.hypervisor)
   try:
-    hyper.HotplugSupported(instance, action, dev_type)
-  except (errors.HotplugError, errors.HypervisorError), err:
+    hyper.VerifyHotplugSupport(instance, action, dev_type)
+  except errors.HotplugError, err:
     _Fail("Hotplug is not supported: %s", err)
 
   if action == constants.HOTPLUG_ACTION_ADD:
     _Fail("Hotplug is not supported: %s", err)
 
   if action == constants.HOTPLUG_ACTION_ADD:
index 4a085d7..2f814b2 100644 (file)
@@ -539,27 +539,41 @@ class BaseHypervisor(object):
     else:
       return None
 
     else:
       return None
 
+  # pylint: disable=R0201,W0613
   def HotAddDevice(self, instance, dev_type, device, extra, seq):
     """Hot-add a device.
 
     """
   def HotAddDevice(self, instance, dev_type, device, extra, seq):
     """Hot-add a device.
 
     """
-    pass
+    raise errors.HotplugError("Hotplug is not supported by this hypervisor")
 
 
+  # pylint: disable=R0201,W0613
   def HotDelDevice(self, instance, dev_type, device, extra, seq):
     """Hot-del a device.
 
     """
   def HotDelDevice(self, instance, dev_type, device, extra, seq):
     """Hot-del a device.
 
     """
-    pass
+    raise errors.HotplugError("Hotplug is not supported by this hypervisor")
 
 
+  # pylint: disable=R0201,W0613
   def HotModDevice(self, instance, dev_type, device, extra, seq):
     """Hot-mod a device.
 
     """
   def HotModDevice(self, instance, dev_type, device, extra, seq):
     """Hot-mod a device.
 
     """
-    pass
+    raise errors.HotplugError("Hotplug is not supported by this hypervisor")
+
+  # pylint: disable=R0201,W0613
+  def VerifyHotplugSupport(self, instance, action, dev_type):
+    """Verifies that hotplug is supported.
 
 
-  def HotplugSupported(self, instance, action, dev_type):
-    """Whether hotplug is supported.
+    Hotplug is not supported by default. If a hypervisor wants to support
+    it it should override this method.
+
+    @type instance: L{objects.Instance}
+    @param instance: the instance object
+    @type action: string
+    @param action: one of the supported hotplug commands
+    @type dev_type: string
+    @param dev_type: one of the supported device types to hotplug
+    @raise errors.HotplugError: if hotplugging is not supported
 
 
-    Depends on instance's hvparam, the action. and the dev_type
     """
     """
-    raise NotImplementedError
+    raise errors.HotplugError("Hotplug is not supported by this hypervisor")
index 44df66a..5d88447 100644 (file)
@@ -321,9 +321,3 @@ class ChrootManager(hv_base.BaseHypervisor):
 
     """
     raise HypervisorError("Migration not supported by the chroot hypervisor")
 
     """
     raise HypervisorError("Migration not supported by the chroot hypervisor")
-
-  def HotplugSupported(self, instance, action, dev_type):
-    """Whether hotplug is supported.
-
-    """
-    raise HypervisorError("Hotplug not supported by the chroot hypervisor")
index 62d916a..c99e822 100644 (file)
@@ -341,9 +341,3 @@ class FakeHypervisor(hv_base.BaseHypervisor):
 
     """
     return objects.MigrationStatus(status=constants.HV_MIGRATION_COMPLETED)
 
     """
     return objects.MigrationStatus(status=constants.HV_MIGRATION_COMPLETED)
-
-  def HotplugSupported(self, instance, action, dev_type):
-    """Whether hotplug is supported.
-
-    """
-    raise errors.HypervisorError("Hotplug not supported by the fake hypervisor")
index 19b8a81..a2436ac 100644 (file)
@@ -1966,15 +1966,15 @@ class KVMHypervisor(hv_base.BaseHypervisor):
 
     dev.pci = int(free)
 
 
     dev.pci = int(free)
 
-  def HotplugSupported(self, instance, action, dev_type):
-    """Check if hotplug is supported.
+  def VerifyHotplugSupport(self, instance, action, dev_type):
+    """Verifies that hotplug is supported.
 
     Hotplug is *not* supported in case of:
      - qemu versions < 1.0
      - security models and chroot (disk hotplug)
      - fdsend module is missing (nic hot-add)
 
 
     Hotplug is *not* supported in case of:
      - qemu versions < 1.0
      - security models and chroot (disk hotplug)
      - fdsend module is missing (nic hot-add)
 
-    @raise errors.HypervisorError: in previous cases
+    @raise errors.HypervisorError: in one of the previous cases
 
     """
     output = self._CallMonitorCommand(instance.name, self._INFO_VERSION_CMD)
 
     """
     output = self._CallMonitorCommand(instance.name, self._INFO_VERSION_CMD)
@@ -2001,7 +2001,6 @@ class KVMHypervisor(hv_base.BaseHypervisor):
         action == constants.HOTPLUG_ACTION_ADD and not fdsend):
       raise errors.HotplugError("Cannot hot-add NIC."
                                 " fdsend python module is missing.")
         action == constants.HOTPLUG_ACTION_ADD and not fdsend):
       raise errors.HotplugError("Cannot hot-add NIC."
                                 " fdsend python module is missing.")
-    return True
 
   def _CallHotplugCommand(self, name, cmd):
     output = self._CallMonitorCommand(name, cmd)
 
   def _CallHotplugCommand(self, name, cmd):
     output = self._CallMonitorCommand(name, cmd)
index d47a0b1..b7054f5 100644 (file)
@@ -470,9 +470,3 @@ class LXCHypervisor(hv_base.BaseHypervisor):
 
     """
     raise HypervisorError("Migration is not supported by the LXC hypervisor")
 
     """
     raise HypervisorError("Migration is not supported by the LXC hypervisor")
-
-  def HotplugSupported(self, instance, action, dev_type):
-    """Whether hotplug is supported.
-
-    """
-    raise HypervisorError("Hotplug not supported by the LXC hypervisor")
index 1fac166..a25d838 100644 (file)
@@ -898,12 +898,6 @@ class XenHypervisor(hv_base.BaseHypervisor):
     finally:
       utils.RunCmd([constants.XEN_CMD, "debug", "R"])
 
     finally:
       utils.RunCmd([constants.XEN_CMD, "debug", "R"])
 
-  def HotplugSupported(self, instance, action, dev_type):
-    """Whether hotplug is supported.
-
-    """
-    raise errors.HypervisorError("Hotplug not supported by the xen hypervisor")
-
 
 class XenPvmHypervisor(XenHypervisor):
   """Xen PVM hypervisor interface"""
 
 class XenPvmHypervisor(XenHypervisor):
   """Xen PVM hypervisor interface"""