From: Jonatan Schlag Date: Fri, 27 Apr 2018 15:44:44 +0000 (+0200) Subject: Move network class into an own file X-Git-Url: http://git.ipfire.org/?p=nitsi.git;a=commitdiff_plain;h=3ab701aa1349aa26a36cedcf70314a1181b7052b Move network class into an own file Signed-off-by: Jonatan Schlag --- diff --git a/network.py b/network.py new file mode 100644 index 0000000..223930b --- /dev/null +++ b/network.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +# # A class which define and undefine a virtual network based on an xml file +class network(): + def __init__(self, network_xml_file): + self.log = log(4) + self.con = libvirt_con("qemu:///system") + try: + with open(network_xml_file) as fobj: + self.network_xml = fobj.read() + except FileNotFoundError as error: + self.log.error("No such file: {}".format(vm_xml_file)) + + def define(self): + self.network = self.con.con.networkDefineXML(self.network_xml) + + if network == None: + self.log.error("Failed to define virtual network") + + def start(self): + self.network.create() + + def undefine(self): + self.network.destroy() \ No newline at end of file diff --git a/test.py b/test.py index a3d6a0d..1ec64f8 100755 --- a/test.py +++ b/test.py @@ -48,31 +48,6 @@ class libvirt_con(): -# A class which define and undefine a virtual network based on an xml file -class network(): - def __init__(self, network_xml_file): - self.log = log(4) - self.con = libvirt_con("qemu:///system") - try: - with open(network_xml_file) as fobj: - self.network_xml = fobj.read() - except FileNotFoundError as error: - self.log.error("No such file: {}".format(vm_xml_file)) - - def define(self): - self.network = self.con.con.networkDefineXML(self.network_xml) - - if network == None: - self.log.error("Failed to define virtual network") - - def start(self): - self.network.create() - - def undefine(self): - self.network.destroy() - - - class RecipeExeption(Exception): pass