Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added alternative destruction procedure

  • Loading branch information...
commit 8afd4df838f1371608808a2a967c910c40c74dea 1 parent 4421937
@timf timf authored
View
23 control/etc/workspace-control/libvirt.conf
@@ -11,6 +11,29 @@ vmm: xen3
template: libvirt_template.xml
+# New as of Nimbus IaaS 2.8
+# Config can be missing, will default to "destroy"
+# The historical behavior of Nimbus is to gracefully shutdown an instance
+# if it is going to be unpropagated back, otherwise it is a hard destroy.
+# The following setting will override the behavior of workspace-control and
+# actually attempt to gracefully shutdown the instance before destroying it.
+# This allows the node's kernel to cleanly shut things down like TCP
+# connections. Use "destroy" for the traditional behavior (the default
+# configuration) and use "shutdown" to trigger shutdown + destroy.
+
+destroy_method: destroy
+
+# New as of Nimbus IaaS 2.8
+# Config can be missing if destroy_method is destroy.
+# If using "shutdown" for "destroy_method", the following configuration will
+# control how much time is allowed before the graceful shutdown is abandoned.
+# The current implementation will wait the full grace period in all cases,
+# so set to something low like 5 seconds.
+# In seconds. Using < 1 is illegal.
+
+shutdown_grace: 5
+
+
[libvirt_connections]
# You should be able to connect using the "virsh" tool with these strings.
View
33 control/src/python/workspacecontrol/defaults/lvrt/lvrt_common.py
@@ -14,6 +14,9 @@
import lvrt_adapter_mock
import lvrt_model
+DESTROY_DESTROY = "destroy"
+DESTROY_SHUTDOWN = "shutdown"
+
class Platform:
zope.interface.implements(workspacecontrol.api.modules.IPlatform)
@@ -22,6 +25,7 @@ def __init__(self, params, common):
self.xen3 = False
self.kvm0 = False
self.create_flock = False
+ self.destroy_method = DESTROY_DESTROY
if params == None:
raise ProgrammingError("expecting params")
@@ -54,6 +58,27 @@ def __init__(self, params, common):
self.xen3 = True
else:
raise InvalidConfig("Unknown 'vmm' configuration in libvirt conf: '%s'" % adapter_conf)
+
+ destroy_method = self.p.get_conf_or_none("libvirt", "destroy_method")
+ if destroy_method is None:
+ self.c.log.debug("no destroy_method configured, assuming %s" % DESTROY_DESTROY)
+ elif destroy_method == DESTROY_DESTROY:
+ self.c.log.debug("destroy_method: %s" % DESTROY_DESTROY)
+ elif destroy_method == DESTROY_SHUTDOWN:
+ self.c.log.debug("destroy_method: %s" % DESTROY_SHUTDOWN)
+ self.destroy_method = DESTROY_SHUTDOWN
+ else:
+ raise InvalidConfig("Unknown 'destroy_method' configuration in libvirt conf: '%s'" % destroy_method)
+
+ if self.destroy_method == DESTROY_SHUTDOWN:
+ shutdown_grace = self.p.get_conf_or_none("libvirt", "shutdown_grace")
+ try:
+ self.shutdown_grace = int(shutdown_grace)
+ self.c.log.debug("shutdown_grace: %d" % self.shutdown_grace)
+ except ValueError:
+ raise InvalidConfig("The 'shutdown_grace' configuration in libvirt conf is not an integer: '%s'" % shutdown_grace)
+ if self.shutdown_grace < 1:
+ raise InvalidConfig("The 'shutdown_grace' configuration in libvirt conf is illegal, must be >= 1: '%s'" % shutdown_grace)
def validate(self):
@@ -126,7 +151,13 @@ def destroy(self, running_vm):
err = "could not find VM with name '%s'" % name
raise UnexpectedError(err)
try:
- vm.destroy()
+ if self.destroy_method == DESTROY_SHUTDOWN:
+ vm.shutdown()
+ # Simplest implementation is to wait the full grace period
+ time.sleep(self.shutdown_grace)
+ vm.destroy()
+ else:
+ vm.destroy()
except libvirt.libvirtError,e:
shorterr = "Problem destroying the '%s' VM: %s" % (name, str(e))
self.c.log.error(shorterr)

0 comments on commit 8afd4df

Please sign in to comment.
Something went wrong with that request. Please try again.