Network: handle object cleanup
This commit is contained in:
parent
b06ce7c12b
commit
260417bcd0
1 changed files with 14 additions and 0 deletions
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue