diff --git a/lib/backend.py b/lib/backend.py index 6147a468418f9162f6fecabe84db5296cb1d7138..a1bc244b4e49aa64e669bd5313d7aa162b0d204b 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -980,7 +980,14 @@ def MigrationInfo(instance): @param instance: the instance definition """ - return (True, '') + hyper = hypervisor.GetHypervisor(instance.hypervisor) + try: + info = hyper.MigrationInfo(instance) + except errors.HypervisorError, err: + msg = "Failed to fetch migration information" + logging.exception(msg) + return (False, '%s: %s' % (msg, err)) + return (True, info) def AcceptInstance(instance, info, target): @@ -994,6 +1001,13 @@ def AcceptInstance(instance, info, target): @param target: target host (usually ip), on this node """ + hyper = hypervisor.GetHypervisor(instance.hypervisor) + try: + hyper.AcceptInstance(instance, info, target) + except errors.HypervisorError, err: + msg = "Failed to accept instance" + logging.exception(msg) + return (False, '%s: %s' % (msg, err)) return (True, "Accept successfull") @@ -1008,6 +1022,13 @@ def FinalizeMigration(instance, info, success): @param success: whether the migration was a success or a failure """ + hyper = hypervisor.GetHypervisor(instance.hypervisor) + try: + hyper.FinalizeMigration(instance, info, success) + except errors.HypervisorError, err: + msg = "Failed to finalize migration" + logging.exception(msg) + return (False, '%s: %s' % (msg, err)) return (True, "Migration Finalized") diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py index 0962004f50a9fef3e1157abdfe1a814b7eed4afc..ebae830a173667ee04e53e3c96390f121b3f7f03 100644 --- a/lib/hypervisor/hv_base.py +++ b/lib/hypervisor/hv_base.py @@ -57,6 +57,7 @@ class BaseHypervisor(object): def GetInstanceInfo(self, instance_name): """Get instance properties. + @type instance_name: string @param instance_name: the instance name @return: tuple (name, id, memory, vcpus, state, times) @@ -96,20 +97,63 @@ class BaseHypervisor(object): """ raise NotImplementedError + def MigrationInfo(self, instance): + """Get instance information to perform a migration. + + By default assume no information is needed. + + @type instance: L{objects.Instance} + @param instance: instance to be migrated + @rtype: string/data (opaque) + @return: instance migration information - serialized form + + """ + return '' + + def AcceptInstance(self, instance, info, target): + """Prepare to accept an instance. + + By default assume no preparation is needed. + + @type instance: L{objects.Instance} + @param instance: instance to be accepted + @type info: string/data (opaque) + @param info: migration information, from the source node + @type target: string + @param target: target host (usually ip), on this node + + """ + pass + + def FinalizeMigration(self, instance, info, success): + """Finalized an instance migration. + + Should finalize or revert any preparation done to accept the instance. + Since by default we do no preparation, we also don't have anything to do + + @type instance: L{objects.Instance} + @param instance: instance whose migration is being aborted + @type info: string/data (opaque) + @param info: migration information, from the source node + @type success: boolean + @param success: whether the migration was a success or a failure + + """ + pass + def MigrateInstance(self, name, target, live): """Migrate an instance. - Arguments: - - name: the name of the instance - - target: the target of the migration (usually will be IP and not name) - - live: whether to do live migration or not - - Returns: none, errors will be signaled by exception. + @type name: string + @param name: name of the instance to be migrated + @type target: string + @param target: hostname (usually ip) of the target node + @type live: boolean + @param live: whether to do a live or non-live migration """ raise NotImplementedError - @classmethod def CheckParameterSyntax(cls, hvparams): """Check the given parameters for validity.