]>
git.ipfire.org Git - nitsi.git/blob - virtual_environ.py
3 from machine
import machine
5 from network
import network
10 # Should return all vms and networks in a list
11 # and should provide the path to the necessary xml files
12 class virtual_environ():
13 def __init__(self
, path
):
16 self
.path
= os
.path
.abspath(path
)
17 except BaseException
as e
:
18 self
.log
.error("Could not get absolute path")
20 self
.log
.debug(self
.path
)
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
))
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"]
34 for machine
in self
.machines_string
.split(","):
35 self
.machines
.append(machine
.strip())
38 for network
in self
.networks_string
.split(","):
39 self
.networks
.append(network
.strip())
41 self
.log
.debug(self
.machines
)
42 self
.log
.debug(self
.networks
)
44 def get_networks(self
):
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"])))
51 def get_machines(self
):
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"]))
66 def machine_names(self
):
70 def network_names(self
):