Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
from serial_connection import serial_connection
from serial_connection import serial_connection
-from test import libvirt_con
-
import os
import libvirt
class machine():
import os
import libvirt
class machine():
- def __init__(self, vm_xml_file, snapshot_xml_file, image, root_uid, username, password):
+ def __init__(self, libvirt_con, vm_xml_file, snapshot_xml_file, image, root_uid, username, password):
- self.con = libvirt_con("qemu:///system")
try:
with open(vm_xml_file) as fobj:
self.vm_xml = fobj.read()
try:
with open(vm_xml_file) as fobj:
self.vm_xml = fobj.read()
# # A class which define and undefine a virtual network based on an xml file
class network():
# # A class which define and undefine a virtual network based on an xml file
class network():
- def __init__(self, network_xml_file):
+ def __init__(self, libvirt_con, network_xml_file):
- self.con = libvirt_con("qemu:///system")
try:
with open(network_xml_file) as fobj:
self.network_xml = fobj.read()
try:
with open(network_xml_file) as fobj:
self.network_xml = fobj.read()
def error(self, string):
print("ERROR: {}".format(string))
def error(self, string):
print("ERROR: {}".format(string))
-class libvirt_con():
- def __init__(self, uri):
- self.log = log(4)
- self.uri = uri
- self.connection = None
-
- def get_domain_from_name(self, name):
- dom = self.con.lookupByName(name)
-
- if dom == None:
- raise BaseException
- return dom
-
- @property
- def con(self):
- if self.connection == None:
- try:
- self.connection = libvirt.open(self.uri)
- except BaseException as error:
- self.log.error("Could not connect to: {}".format(self.uri))
-
- self.log.debug("Connected to: {}".format(self.uri))
- return self.connection
-
- return self.connection
-
-
-
class test():
def __init__(self, path):
self.log = log(4)
class test():
def __init__(self, path):
self.log = log(4)
import os
import configparser
import os
import configparser
# Should return all vms and networks in a list
# and should provide the path to the necessary xml files
# Should return all vms and networks in a list
# and should provide the path to the necessary xml files
self.log.debug(self.machines)
self.log.debug(self.networks)
self.log.debug(self.machines)
self.log.debug(self.networks)
+ self.uri = self.config["DEFAULT"]["uri"]
+
+ try:
+ self.con = libvirt.open(self.uri)
+ except BaseException as error:
+ self.log.error("Could not connect to: {}".format(self.uri))
+
+ self.log.debug("Connected to: {}".format(self.uri))
+
def get_networks(self):
networks = {}
for _network in self.networks:
self.log.debug(_network)
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"])))
+ networks.setdefault(_network, network(self.con, os.path.normpath(self.path + "/" + self.config[_network]["xml_file"])))
return networks
def get_machines(self):
return networks
def get_machines(self):
for _machine in self.machines:
self.log.debug(_machine)
machines.setdefault(_machine, machine(
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"],
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"],