Network: handle object cleanup

This commit is contained in:
Théophile Bastian 2020-03-09 12:24:37 +01:00
parent b06ce7c12b
commit 260417bcd0

View file

@ -62,3 +62,17 @@ class Network(util.NumberedClass):
) )
self.lxc_network = self.conn.networkCreateXML(xml) self.lxc_network = self.conn.networkCreateXML(xml)
def cleanup(self):
if self.lxc_network:
self.lxc_network.destroy()
def __enter__(self):
self.create()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.cleanup()
def __del__(self):
self.cleanup()