Move recipe class into an own file
[nitsi.git] / virtual_environ.py
CommitLineData
ab759374
JS
1#!/usr/bin/python3
2
3from machine import machine
4
5from network import network
6
7import os
8import configparser
9
10# Should return all vms and networks in a list
11# and should provide the path to the necessary xml files
12class virtual_environ():
13 def __init__(self, path):
14 self.log = log(4)
15 try:
16 self.path = os.path.abspath(path)
17 except BaseException as e:
18 self.log.error("Could not get absolute path")
19
20 self.log.debug(self.path)
21
22 self.settings_file = "{}/settings".format(self.path)
23 if not os.path.isfile(self.settings_file):
24 self.log.error("No such file: {}".format(self.settings_file))
25
26 self.log.debug(self.settings_file)
27 self.config = configparser.ConfigParser()
28 self.config.read(self.settings_file)
29 self.name = self.config["DEFAULT"]["name"]
30 self.machines_string = self.config["DEFAULT"]["machines"]
31 self.networks_string = self.config["DEFAULT"]["networks"]
32
33 self.machines = []
34 for machine in self.machines_string.split(","):
35 self.machines.append(machine.strip())
36
37 self.networks = []
38 for network in self.networks_string.split(","):
39 self.networks.append(network.strip())
40
41 self.log.debug(self.machines)
42 self.log.debug(self.networks)
43
44 def get_networks(self):
45 networks = {}
46 for _network in self.networks:
47 self.log.debug(_network)
48 networks.setdefault(_network, network(os.path.normpath(self.path + "/" + self.config[_network]["xml_file"])))
49 return networks
50
51 def get_machines(self):
52 machines = {}
53 for _machine in self.machines:
54 self.log.debug(_machine)
55 machines.setdefault(_machine, machine(
56 os.path.normpath(self.path + "/" + self.config[_machine]["xml_file"]),
57 os.path.normpath(self.path + "/" + self.config[_machine]["snapshot_xml_file"]),
58 self.config[_machine]["image"],
59 self.config[_machine]["root_uid"],
60 self.config[_machine]["username"],
61 self.config[_machine]["password"]))
62
63 return machines
64
65 @property
66 def machine_names(self):
67 return self.machines
68
69 @property
70 def network_names(self):
71 return self.networks