]>
git.ipfire.org Git - nitsi.git/blob - virtual_environ.py
3 from machine
import machine
5 from network
import network
11 # Should return all vms and networks in a list
12 # and should provide the path to the necessary xml files
13 class virtual_environ():
14 def __init__(self
, path
):
17 self
.path
= os
.path
.abspath(path
)
18 except BaseException
as e
:
19 self
.log
.error("Could not get absolute path")
21 self
.log
.debug(self
.path
)
23 self
.settings_file
= "{}/settings".format(self
.path
)
24 if not os
.path
.isfile(self
.settings_file
):
25 self
.log
.error("No such file: {}".format(self
.settings_file
))
27 self
.log
.debug(self
.settings_file
)
28 self
.config
= configparser
.ConfigParser()
29 self
.config
.read(self
.settings_file
)
30 self
.name
= self
.config
["DEFAULT"]["name"]
31 self
.machines_string
= self
.config
["DEFAULT"]["machines"]
32 self
.networks_string
= self
.config
["DEFAULT"]["networks"]
35 for machine
in self
.machines_string
.split(","):
36 self
.machines
.append(machine
.strip())
39 for network
in self
.networks_string
.split(","):
40 self
.networks
.append(network
.strip())
42 self
.log
.debug(self
.machines
)
43 self
.log
.debug(self
.networks
)
45 self
.uri
= self
.config
["DEFAULT"]["uri"]
48 self
.con
= libvirt
.open(self
.uri
)
49 except BaseException
as error
:
50 self
.log
.error("Could not connect to: {}".format(self
.uri
))
52 self
.log
.debug("Connected to: {}".format(self
.uri
))
54 def get_networks(self
):
56 for _network
in self
.networks
:
57 self
.log
.debug(_network
)
58 networks
.setdefault(_network
, network(self
.con
, os
.path
.normpath(self
.path
+ "/" + self
.config
[_network
]["xml_file"])))
61 def get_machines(self
):
63 for _machine
in self
.machines
:
64 self
.log
.debug(_machine
)
65 machines
.setdefault(_machine
, machine(
67 os
.path
.normpath(self
.path
+ "/" + self
.config
[_machine
]["xml_file"]),
68 os
.path
.normpath(self
.path
+ "/" + self
.config
[_machine
]["snapshot_xml_file"]),
69 self
.config
[_machine
]["image"],
70 self
.config
[_machine
]["root_uid"],
71 self
.config
[_machine
]["username"],
72 self
.config
[_machine
]["password"]))
77 def machine_names(self
):
81 def network_names(self
):