From: Jonatan Schlag Date: Sat, 19 May 2018 08:48:52 +0000 (+0200) Subject: Improving error message and undefining of network objects X-Git-Url: http://git.ipfire.org/?p=nitsi.git;a=commitdiff_plain;h=6ec03557d503bf732d72728887f1d8b4109be1e3 Improving error message and undefining of network objects Signed-off-by: Jonatan Schlag --- diff --git a/src/nitsi/network.py b/src/nitsi/network.py index f13dd0e..8c15160 100644 --- a/src/nitsi/network.py +++ b/src/nitsi/network.py @@ -10,20 +10,31 @@ class network(): def __init__(self, libvirt_con, network_xml_file): self.log = logger.getChild(os.path.basename(os.path.dirname(network_xml_file))) self.con = libvirt_con + self.network = None try: with open(network_xml_file) as fobj: + self.log.info("Reading xml file for network") self.network_xml = fobj.read() except FileNotFoundError as error: self.log.error("No such file: {}".format(network_xml_file)) + raise error def define(self): + self.log.info("Going to define network") self.network = self.con.networkDefineXML(self.network_xml) if network == None: self.log.error("Failed to define virtual network") def start(self): + self.log.info("Starting Network") self.network.create() def undefine(self): - self.network.destroy() \ No newline at end of file + if self.network != None: + if self.network.isActive() == 1: + self.log.info("Shutting down network") + self.network.destroy() + + self.log.info("Undefining network") + self.network.undefine() \ No newline at end of file