Make this work better and stop bad VMs
This commit is contained in:
		@@ -95,7 +95,11 @@ class NodeInstance(threading.Thread):
 | 
			
		||||
        print("CPUs: %s" % self.cpucount)
 | 
			
		||||
 | 
			
		||||
        while True:
 | 
			
		||||
            # Make sure that the VMs we think we're running actually are
 | 
			
		||||
            # Toggle state management of all VMs
 | 
			
		||||
            for domain, instance in self.s_domain.items():
 | 
			
		||||
                instance.manage_vm_state()
 | 
			
		||||
 | 
			
		||||
            # Remove non-running VMs from our list
 | 
			
		||||
            for domain in self.domain_list:
 | 
			
		||||
                try:
 | 
			
		||||
                    buuid = uuid.UUID(domain).bytes
 | 
			
		||||
@@ -106,11 +110,6 @@ class NodeInstance(threading.Thread):
 | 
			
		||||
                except:
 | 
			
		||||
                    self.domain_list.remove(domain)
 | 
			
		||||
 | 
			
		||||
            # Toggle state management of all VMs to start any that are failed
 | 
			
		||||
            for domain, instance in self.s_domain.items():
 | 
			
		||||
                if instance.gethypervisor() == self.name and ( instance.getstate() == 'start' or instance.getstate() == 'migrate' ):
 | 
			
		||||
                    instance.manage_vm_state()
 | 
			
		||||
 | 
			
		||||
            # Set our information in zookeeper
 | 
			
		||||
            self.memfree = conn.getFreeMemory()
 | 
			
		||||
            self.cpuload = os.getloadavg()[0]
 | 
			
		||||
 
 | 
			
		||||
@@ -114,24 +114,34 @@ class VMInstance:
 | 
			
		||||
        except:
 | 
			
		||||
            running = libvirt.VIR_DOMAIN_NOSTATE
 | 
			
		||||
 | 
			
		||||
        # VM should be stopped
 | 
			
		||||
        if running == libvirt.VIR_DOMAIN_RUNNING and self.state == "stop" and self.hypervisor == self.thishypervisor.name:
 | 
			
		||||
            self.stop_vm()
 | 
			
		||||
 | 
			
		||||
        if running == libvirt.VIR_DOMAIN_RUNNING and self.state == "shutdown" and self.hypervisor == self.thishypervisor.name:
 | 
			
		||||
        # VM should not be running on this hypervisor
 | 
			
		||||
        elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "start" and self.hypervisor != self.thishypervisor.name:
 | 
			
		||||
            self.stop_vm()
 | 
			
		||||
 | 
			
		||||
        # VM should be shut down
 | 
			
		||||
        elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "shutdown" and self.hypervisor == self.thishypervisor.name:
 | 
			
		||||
            self.shutdown_vm()
 | 
			
		||||
 | 
			
		||||
        # VM should be migrated to this hypervisor
 | 
			
		||||
        elif running != libvirt.VIR_DOMAIN_RUNNING and self.state == "migrate" and self.hypervisor == self.thishypervisor.name:
 | 
			
		||||
            self.receive_migrate()
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
        # VM should be migrated away from this hypervisor
 | 
			
		||||
        elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "migrate" and self.hypervisor != self.thishypervisor.name:
 | 
			
		||||
            self.migrate_vm()
 | 
			
		||||
            
 | 
			
		||||
        # VM should be started
 | 
			
		||||
        elif running != libvirt.VIR_DOMAIN_RUNNING and self.state == "start" and self.hypervisor == self.thishypervisor.name:
 | 
			
		||||
            # Grab the domain information from Zookeeper
 | 
			
		||||
            domxml, domxmlstat = self.zk.get(self.zkey + '/xml')
 | 
			
		||||
            domxml = str(domxml.decode('ascii'))
 | 
			
		||||
            self.dom = self.start_vm(conn, domxml)
 | 
			
		||||
 | 
			
		||||
        # VM is already running and should be
 | 
			
		||||
        elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "start" and self.hypervisor == self.thishypervisor.name:
 | 
			
		||||
            if not self.domuuid in self.thishypervisor.domain_list:
 | 
			
		||||
                self.thishypervisor.domain_list.append(self.domuuid)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user