Container: call shutdown() in parallel to speed up cleanup

This commit is contained in:
Théophile Bastian 2020-03-19 23:32:44 +01:00
parent abe5fc6972
commit 9d383e3fd9
2 changed files with 17 additions and 2 deletions

View file

@ -201,6 +201,17 @@ class Container(util.LibvirtObject):
self.lxc_container = self.conn.createXML(xml)
def notify_cleanup(self):
""" This method can be called before `cleanup` to notify the host that a
cleanup will be performed soon, speeding the process up. """
if self.lxc_container:
try:
self.lxc_container.shutdown()
except libvirt.libvirtError as exn:
if not str(exn).startswith("Domain not found:"):
raise exn
# Else, the machine was already stopped: everything is fine
def cleanup(self):
if self.lxc_container:
try:

View file

@ -52,8 +52,8 @@ class Topology:
self.conn = conn
self.parsed = False
self.domains = None
self.links = None
self.domains = []
self.links = []
@requires_parsed
@requires_id_in_link_range
@ -159,6 +159,10 @@ class Topology:
print("{} domains: ".format("Starting" if state else "Stopping"), end="\t")
sys.stdout.flush()
if state is False:
for dom in self.domains:
dom.notify_cleanup()
for dom_id in range(len(self.domains)):
self.dom_setstate_single(dom_id, state, verbose, verbose_inline=True)