]>
Commit | Line | Data |
---|---|---|
3ab701aa JS |
1 | #!/usr/bin/python3 |
2 | ||
1ed8ca9f JS |
3 | import logging |
4 | import os | |
5 | ||
6 | logger = logging.getLogger("nitsi.network") | |
7 | ||
3ab701aa JS |
8 | # # A class which define and undefine a virtual network based on an xml file |
9 | class network(): | |
7005787e | 10 | def __init__(self, libvirt_con, network_xml_file): |
1ed8ca9f | 11 | self.log = logger.getChild(os.path.basename(network_xml_file)) |
7005787e | 12 | self.con = libvirt_con |
3ab701aa JS |
13 | try: |
14 | with open(network_xml_file) as fobj: | |
15 | self.network_xml = fobj.read() | |
16 | except FileNotFoundError as error: | |
17 | self.log.error("No such file: {}".format(vm_xml_file)) | |
18 | ||
19 | def define(self): | |
8b744f18 | 20 | self.network = self.con.networkDefineXML(self.network_xml) |
3ab701aa JS |
21 | |
22 | if network == None: | |
23 | self.log.error("Failed to define virtual network") | |
24 | ||
25 | def start(self): | |
26 | self.network.create() | |
27 | ||
28 | def undefine(self): | |
29 | self.network.destroy() |