From a87bf4bc4a9ad344764447175f32562fff85a23f Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Tue, 12 Jun 2018 01:54:01 -0400 Subject: [PATCH] Clean up some handling of restarting dead VMs --- NodeInstance.py | 27 ++++++++------------------- VMInstance.py | 3 +++ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/NodeInstance.py b/NodeInstance.py index 165638f0..5577ddef 100644 --- a/NodeInstance.py +++ b/NodeInstance.py @@ -200,28 +200,17 @@ class NodeInstance(): else: self.daemon_state = 'start' - # Toggle state management of dead VMs + # Toggle state management of dead VMs to restart them for domain, instance in self.s_domain.items(): if instance.inshutdown == False and domain in self.domain_list: - if instance.getstate() == 'start' and instance.gethypervisor() == self.name and instance.dom == None: - instance.manage_vm_state() - - if instance.dom == None: - try: - self.domain_list.remove(domain) - except: - pass - else: - try: - state = instance.dom.state()[0] - except: - state = libvirt.VIR_DOMAIN_NOSTATE - - if state != libvirt.VIR_DOMAIN_RUNNING: + if instance.getstate() == 'start' and instance.gethypervisor() == self.name: + if instance.getdom() != None: try: - self.domain_list.remove(domain) - except: - pass + if instance.getdom().state()[0] != libvirt.VIR_DOMAIN_RUNNING: + raise + except Exception as e: + # Toggle a state "change" + self.zk.set('/domains/{}/state'.format(domain), instance.getstate().encode('ascii')) # Set our information in zookeeper self.name = conn.getHostname() diff --git a/VMInstance.py b/VMInstance.py index 33e2adb4..15e84529 100644 --- a/VMInstance.py +++ b/VMInstance.py @@ -54,6 +54,9 @@ class VMInstance: def gethypervisor(self): return self.hypervisor + def getdom(self): + return self.dom + # Start up the VM def start_vm(self, xmlconfig): ansiiprint.echo('Starting VM', '{}:'.format(self.domuuid), 'i')