]> git.ipfire.org Git - nitsi.git/commitdiff
Move the virtual_environ class into an own file
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Fri, 27 Apr 2018 14:31:17 +0000 (16:31 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Fri, 27 Apr 2018 14:31:17 +0000 (16:31 +0200)
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
test.py
virtual_environ.py [new file with mode: 0644]

diff --git a/test.py b/test.py
index 36d5277e4acb223539ab7b54b7482dac93cf642d..a3d6a0dca10db9b0fa0562810a8f2c1f2ef36c7b 100755 (executable)
--- a/test.py
+++ b/test.py
@@ -272,70 +272,6 @@ class test():
             self.virtual_networks[name].undefine()
 
 
-# Should return all vms and networks in a list
-# and should provide the path to the necessary xml files
-class virtual_environ():
-    def __init__(self, path):
-        self.log = log(4)
-        try:
-            self.path = os.path.abspath(path)
-        except BaseException as e:
-            self.log.error("Could not get absolute path")
-
-        self.log.debug(self.path)
-
-        self.settings_file = "{}/settings".format(self.path)
-        if not os.path.isfile(self.settings_file):
-            self.log.error("No such file: {}".format(self.settings_file))
-
-        self.log.debug(self.settings_file)
-        self.config = configparser.ConfigParser()
-        self.config.read(self.settings_file)
-        self.name = self.config["DEFAULT"]["name"]
-        self.machines_string = self.config["DEFAULT"]["machines"]
-        self.networks_string = self.config["DEFAULT"]["networks"]
-
-        self.machines = []
-        for machine in self.machines_string.split(","):
-            self.machines.append(machine.strip())
-
-        self.networks = []
-        for network in self.networks_string.split(","):
-            self.networks.append(network.strip())
-
-        self.log.debug(self.machines)
-        self.log.debug(self.networks)
-
-    def get_networks(self):
-        networks = {}
-        for _network in self.networks:
-            self.log.debug(_network)
-            networks.setdefault(_network, network(os.path.normpath(self.path + "/" + self.config[_network]["xml_file"])))
-        return networks
-
-    def get_machines(self):
-        machines = {}
-        for _machine in self.machines:
-            self.log.debug(_machine)
-            machines.setdefault(_machine, machine(
-                os.path.normpath(self.path + "/" + self.config[_machine]["xml_file"]),
-                os.path.normpath(self.path + "/" + self.config[_machine]["snapshot_xml_file"]),
-                self.config[_machine]["image"],
-                self.config[_machine]["root_uid"],
-                self.config[_machine]["username"],
-                self.config[_machine]["password"]))
-
-        return machines
-
-    @property
-    def machine_names(self):
-        return self.machines
-
-    @property
-    def network_names(self):
-        return self.networks
-
-
 if __name__ == "__main__":
     import argparse
 
diff --git a/virtual_environ.py b/virtual_environ.py
new file mode 100644 (file)
index 0000000..aaa07f1
--- /dev/null
@@ -0,0 +1,71 @@
+#!/usr/bin/python3
+
+from machine import machine
+
+from network import network
+
+import os
+import configparser
+
+# Should return all vms and networks in a list
+# and should provide the path to the necessary xml files
+class virtual_environ():
+    def __init__(self, path):
+        self.log = log(4)
+        try:
+            self.path = os.path.abspath(path)
+        except BaseException as e:
+            self.log.error("Could not get absolute path")
+
+        self.log.debug(self.path)
+
+        self.settings_file = "{}/settings".format(self.path)
+        if not os.path.isfile(self.settings_file):
+            self.log.error("No such file: {}".format(self.settings_file))
+
+        self.log.debug(self.settings_file)
+        self.config = configparser.ConfigParser()
+        self.config.read(self.settings_file)
+        self.name = self.config["DEFAULT"]["name"]
+        self.machines_string = self.config["DEFAULT"]["machines"]
+        self.networks_string = self.config["DEFAULT"]["networks"]
+
+        self.machines = []
+        for machine in self.machines_string.split(","):
+            self.machines.append(machine.strip())
+
+        self.networks = []
+        for network in self.networks_string.split(","):
+            self.networks.append(network.strip())
+
+        self.log.debug(self.machines)
+        self.log.debug(self.networks)
+
+    def get_networks(self):
+        networks = {}
+        for _network in self.networks:
+            self.log.debug(_network)
+            networks.setdefault(_network, network(os.path.normpath(self.path + "/" + self.config[_network]["xml_file"])))
+        return networks
+
+    def get_machines(self):
+        machines = {}
+        for _machine in self.machines:
+            self.log.debug(_machine)
+            machines.setdefault(_machine, machine(
+                os.path.normpath(self.path + "/" + self.config[_machine]["xml_file"]),
+                os.path.normpath(self.path + "/" + self.config[_machine]["snapshot_xml_file"]),
+                self.config[_machine]["image"],
+                self.config[_machine]["root_uid"],
+                self.config[_machine]["username"],
+                self.config[_machine]["password"]))
+
+        return machines
+
+    @property
+    def machine_names(self):
+        return self.machines
+
+    @property
+    def network_names(self):
+        return self.networks
\ No newline at end of file