From 58d38b02328fcbfc0c1f1637c6084006f5400023 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 4 Nov 2009 11:10:32 +0100
Subject: [PATCH] hypervisors: change MigrateInstance API

Currently the $hypervisor.MigrateInstance takes the instance name. This
patch changes it to take the instance object, such that other instance
properties (especially hvparams) are available to it.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/backend.py            |  2 +-
 lib/hypervisor/hv_base.py |  6 +++---
 lib/hypervisor/hv_kvm.py  |  7 ++++---
 lib/hypervisor/hv_xen.py  | 12 ++++++------
 4 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index 50abfb89f..7562e5cf7 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -1155,7 +1155,7 @@ def MigrateInstance(instance, target, live):
   hyper = hypervisor.GetHypervisor(instance.hypervisor)
 
   try:
-    hyper.MigrateInstance(instance.name, target, live)
+    hyper.MigrateInstance(instance, target, live)
   except errors.HypervisorError, err:
     _Fail("Failed to migrate instance: %s", err, exc=True)
 
diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py
index 21784d218..45316e0bc 100644
--- a/lib/hypervisor/hv_base.py
+++ b/lib/hypervisor/hv_base.py
@@ -232,11 +232,11 @@ class BaseHypervisor(object):
     """
     pass
 
-  def MigrateInstance(self, name, target, live):
+  def MigrateInstance(self, instance, target, live):
     """Migrate an instance.
 
-    @type name: string
-    @param name: name of the instance to be migrated
+    @type instance: L{object.Instance}
+    @param name: the instance to be migrated
     @type target: string
     @param target: hostname (usually ip) of the target node
     @type live: boolean
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index aada45bc7..118adcbc0 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -608,20 +608,21 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     else:
       self.StopInstance(instance, force=True)
 
-  def MigrateInstance(self, instance_name, target, live):
+  def MigrateInstance(self, instance, target, live):
     """Migrate an instance to a target node.
 
     The migration will not be attempted if the instance is not
     currently running.
 
-    @type instance_name: string
-    @param instance_name: name of the instance to be migrated
+    @type instance: L{objects.Instance}
+    @param instance: the instance to be migrated
     @type target: string
     @param target: ip address of the target node
     @type live: boolean
     @param live: perform a live migration
 
     """
+    instance_name = instance.name
     pidfile, pid, alive = self._InstancePidAlive(instance_name)
     if not alive:
       raise errors.HypervisorError("Instance not running, cannot migrate")
diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index 21dc37aff..cb194f766 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -392,27 +392,27 @@ class XenHypervisor(hv_base.BaseHypervisor):
     The migration will not be attempted if the instance is not
     currently running.
 
-    @type instance: string
-    @param instance: instance name
+    @type instance: L{objects.Instance}
+    @param instance: the instance to be migrated
     @type target: string
     @param target: ip address of the target node
     @type live: boolean
     @param live: perform a live migration
 
     """
-    if self.GetInstanceInfo(instance) is None:
+    if self.GetInstanceInfo(instance.name) is None:
       raise errors.HypervisorError("Instance not running, cannot migrate")
     args = ["xm", "migrate"]
     if live:
       args.append("-l")
-    args.extend([instance, target])
+    args.extend([instance.name, target])
     result = utils.RunCmd(args)
     if result.failed:
       raise errors.HypervisorError("Failed to migrate instance %s: %s" %
-                                   (instance, result.output))
+                                   (instance.name, result.output))
     # remove old xen file after migration succeeded
     try:
-      self._RemoveConfigFile(instance)
+      self._RemoveConfigFile(instance.name)
     except EnvironmentError:
       logging.exception("Failure while removing instance config file")
 
-- 
GitLab