From f28ec8993b23b6219ac3e9a03dc92790db13cbb9 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Mon, 19 Apr 2010 16:19:58 +0100 Subject: [PATCH] Add CleanupInstance hypervisor call Currently some hypervisors (namely kvm) need to do some cleanup after making sure an instance is stopped. With the moving of the retry cycle in backend those cleanups were never done. In order to solve this we add a new optional hypervisor function, CleanupInstance, which gets called at the end of the shutdown procedure, and which interested hypervisors can implement to be sure not to miss cleanup operations. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/backend.py | 5 +++++ lib/hypervisor/hv_base.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/backend.py b/lib/backend.py index b903d6287..761628ca5 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -1099,6 +1099,11 @@ def InstanceShutdown(instance, timeout): if iname in hyper.ListInstances(): _Fail("Could not shutdown instance %s even by destroy", iname) + try: + hyper.CleanupInstance(instance.name) + except errors.HypervisorError, err: + logging.warning("Failed to execute post-shutdown cleanup step: %s", err) + _RemoveBlockDevLinks(iname, instance.disks) diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py index af7aa9575..58db39599 100644 --- a/lib/hypervisor/hv_base.py +++ b/lib/hypervisor/hv_base.py @@ -130,6 +130,18 @@ class BaseHypervisor(object): """ raise NotImplementedError + def CleanupInstance(self, instance_name): + """Cleanup after a stopped instance + + This is an optional method, used by hypervisors that need to cleanup after + an instance has been stopped. + + @type instance_name: string + @param instance_name: instance name to cleanup after + + """ + pass + def RebootInstance(self, instance): """Reboot an instance.""" raise NotImplementedError -- GitLab