Commit 70d8491f authored by Jose A. Lopes's avatar Jose A. Lopes

Destroy Xen domain only if necessary

Check if a given Xen domain still exists after a 'xm shutdown' before
destroying it.  This check is necessary in order to cope with Xen
domains created with other version of Ganeti, given that an instance
created in or prior to Ganeti 2.10 will be cleaned up automatically
and thus calling 'xm destroy' is unnecessary and will lead to an
error, whereas instances from the more recent versions of Ganeti do
require 'xm destroy' as it is part of the instance shutdown detection
feature.
Signed-off-by: default avatarJose A. Lopes <jabolopes@google.com>
Reviewed-by: default avatarHrvoje Ribicic <riba@google.com>
parent 059ed766
......@@ -683,10 +683,28 @@ class XenHypervisor(hv_base.BaseHypervisor):
def _DestroyInstance(self, name, hvparams):
result = self._RunXen(["destroy", name], hvparams)
if result.failed:
raise errors.HypervisorError("Failed to destroy instance %s: %s, %s" %
(name, result.fail_reason, result.output))
# Destroy a domain only if necessary
#
# This method checks if the domain has already been destroyed before
# issuing the 'destroy' command. This step is necessary to handle
# domains created by other versions of Ganeti. For example, an
# instance created with 2.10 will be destroy by the
# '_ShutdownInstance', thus not requiring an additional destroy,
# which would cause an error if issued. See issue 619.
def _DestroyInstanceIfAlive(self, name, hvparams):
instance_info = self.GetInstanceInfo(name, hvparams=hvparams)
if instance_info is None:
raise errors.HypervisorError("Failed to destroy instance %s, already"
" destroyed" % name)
else:
self._DestroyInstance(name, hvparams)
def _StopInstance(self, name, force, hvparams):
"""Stop an instance.
......@@ -708,7 +726,7 @@ class XenHypervisor(hv_base.BaseHypervisor):
self._DestroyInstance(name, hvparams)
else:
self._ShutdownInstance(name, hvparams, instance_info[4])
self._DestroyInstance(name, hvparams)
self._DestroyInstanceIfAlive(name, hvparams)
# Remove configuration file if stopping/starting instance was successful
self._RemoveConfigFile(name)
......
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