Improving error message and undefining of network objects
[nitsi.git] / src / nitsi / network.py
index f13dd0e..8c15160 100644 (file)
@@ -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