diff --git a/lxc_net/container.py b/lxc_net/container.py index 12a9aa2..b2f60c0 100644 --- a/lxc_net/container.py +++ b/lxc_net/container.py @@ -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: diff --git a/lxc_net/parse_network.py b/lxc_net/parse_network.py index e4836a6..803f875 100644 --- a/lxc_net/parse_network.py +++ b/lxc_net/parse_network.py @@ -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)