From 2b2f672e39d7352ee09db96d3cbcf95f223b57a8 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sat, 2 Jun 2018 00:30:25 -0400 Subject: [PATCH] Catch libvirt startup errors and reset state to stop --- VMInstance.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/VMInstance.py b/VMInstance.py index 3f1cc5da..b315ad4e 100644 --- a/VMInstance.py +++ b/VMInstance.py @@ -32,9 +32,11 @@ class VMInstance: # Start up the VM def start_vm(self, conn, xmlconfig): print("Starting VM %s" % self.domuuid) - dom = conn.createXML(xmlconfig, 0) - if dom == None: - print('Failed to create a domain from an XML definition.') + try: + dom = conn.createXML(xmlconfig, 0) + except libvirt.libvirtError: + print('Failed to create domain %s' % self.domuuid) + self.zk.set(self.zkey + '/status', 'stop'.encode('ascii')) exit(1) if not self.domuuid in self.thishypervisor.domain_list: self.thishypervisor.domain_list.append(self.domuuid)