From ab759374e636cd1f88adf002d664285fedee8833 Mon Sep 17 00:00:00 2001 From: Jonatan Schlag Date: Fri, 27 Apr 2018 16:31:17 +0200 Subject: [PATCH] Move the virtual_environ class into an own file Signed-off-by: Jonatan Schlag --- test.py | 64 ----------------------------------------- virtual_environ.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 64 deletions(-) create mode 100644 virtual_environ.py diff --git a/test.py b/test.py index 36d5277..a3d6a0d 100755 --- 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 index 0000000..aaa07f1 --- /dev/null +++ b/virtual_environ.py @@ -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 -- 2.39.2