Commit 58d38b02 authored by Iustin Pop's avatar Iustin Pop
Browse files

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: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 9b65e0d4
......@@ -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)
......
......@@ -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
......
......@@ -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")
......
......@@ -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")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment