From 341e7373bb3acf823e138b2828e93850e461c579 Mon Sep 17 00:00:00 2001 From: Jonatan Schlag Date: Tue, 1 May 2018 09:37:50 +0200 Subject: [PATCH] Log all messages for a machine using the name of this machine Signed-off-by: Jonatan Schlag --- machine.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/machine.py b/machine.py index 867a8a0..7d5f148 100644 --- a/machine.py +++ b/machine.py @@ -21,7 +21,16 @@ class machine(): with open(vm_xml_file) as fobj: self.vm_xml = fobj.read() except FileNotFoundError as error: - self.log.error("No such file: {}".format(vm_xml_file)) + logger.error("No such file: {}".format(vm_xml_file)) + + try: + self.name = self.get_name() + except BaseException as error: + logger.error("Could not get name of the machine: {}".format(vm_xml_file)) + raise error + + self.log = logger.getChild(self.name) + self.log.debug("Name of this machine is {}".format(self.name)) try: with open(snapshot_xml_file) as fobj: @@ -93,6 +102,12 @@ class machine(): elem = xml_root.find("./devices/serial/source") return elem.get("path") + def get_name(self): + xml_root = ET.fromstring(self.vm_xml) + + elem = xml_root.find("./name") + return elem.text + def check_is_booted_up(self): serial_con = serial_connection(self.get_serial_device()) -- 2.39.2