xen: remove the config file after migration
authorIustin Pop <iustin@google.com>
Tue, 24 Jun 2008 09:46:35 +0000 (09:46 +0000)
committerIustin Pop <iustin@google.com>
Tue, 24 Jun 2008 09:46:35 +0000 (09:46 +0000)
Since it's not good to have the instance definition file left on the
source one if the migration succeeded, we remove it after the ‘xm
migrate’ call.

In order to do this using the existing self._RemoveConfigFile, we change
the protocol for this method to take the instance name and not instance
object as parameter, as in the migration we don't have the instance
object (and the only other caller is cheap to modify).

Reviewed-by: imsnah

lib/hypervisor.py

index 791b7b5..5f507e5 100644 (file)
@@ -156,11 +156,11 @@ class XenHypervisor(BaseHypervisor):
     raise NotImplementedError
 
   @staticmethod
-  def _RemoveConfigFile(instance):
+  def _RemoveConfigFile(instance_name):
     """Remove the xen configuration file.
 
     """
-    utils.RemoveFile("/etc/xen/%s" % instance.name)
+    utils.RemoveFile("/etc/xen/%s" % instance_name)
 
   @staticmethod
   def _GetXMList(include_node):
@@ -254,7 +254,7 @@ class XenHypervisor(BaseHypervisor):
 
   def StopInstance(self, instance, force=False):
     """Stop an instance."""
-    self._RemoveConfigFile(instance)
+    self._RemoveConfigFile(instance.name)
     if force:
       command = ["xm", "destroy", instance.name]
     else:
@@ -350,6 +350,12 @@ class XenHypervisor(BaseHypervisor):
     if result.failed:
       raise errors.HypervisorError("Failed to migrate instance %s: %s" %
                                    (instance, result.output))
+    # remove old xen file after migration succeeded
+    try:
+      self._RemoveConfigFile(instance)
+    except EnvironmentError, err:
+      logger.Error("Failure while removing instance config file: %s" %
+                   str(err))
 
 
 class XenPvmHypervisor(XenHypervisor):