diff --git a/VMInstance.py b/VMInstance.py index 15e84529..db7a84e4 100644 --- a/VMInstance.py +++ b/VMInstance.py @@ -99,6 +99,7 @@ class VMInstance: except ValueError: pass ansiiprint.echo('Successfully terminated VM', '{}:'.format(self.domuuid), 'o') + self.dom = None self.instop = False # Stop the VM forcibly @@ -251,11 +252,11 @@ class VMInstance: return 0 # VM should be stopped - if running == libvirt.VIR_DOMAIN_RUNNING and self.state == "stop" and self.hypervisor == self.thishypervisor.name: + if running == libvirt.VIR_DOMAIN_RUNNING and self.state == "stop" and self.hypervisor == self.thishypervisor.name and self.dom != None: self.stop_vm() # VM should be shut down - elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "shutdown" and self.hypervisor == self.thishypervisor.name: + elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "shutdown" and self.hypervisor == self.thishypervisor.name and self.dom != None: self.shutdown_vm() # VM should be migrated to this hypervisor @@ -263,11 +264,11 @@ class VMInstance: 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: + elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "migrate" and self.hypervisor != self.thishypervisor.name and self.dom != None: self.migrate_vm() # VM should be running but not on this hypervisor - elif running == libvirt.VIR_DOMAIN_RUNNING and self.state != "migrate" and self.hypervisor != self.thishypervisor.name: + elif running == libvirt.VIR_DOMAIN_RUNNING and self.state != "migrate" and self.hypervisor != self.thishypervisor.name and self.dom != None: self.terminate_vm() # VM is already running and should be diff --git a/pvc.py b/pvc.py index 0df93292..151cb159 100755 --- a/pvc.py +++ b/pvc.py @@ -867,7 +867,8 @@ def _vm_list(hypervisor): # Open a Zookeeper connection zk = pvcf.startZKConnection(zk_host) - vm_list = zk.get_children('/domains') + vm_list_raw = zk.get_children('/domains') + vm_list = [] vm_list_output = [] vm_hypervisor = {} @@ -878,13 +879,18 @@ def _vm_list(hypervisor): vm_memory = {} vm_vcpu = {} - # Gather information for printing - for vm in vm_list: + # If we're limited, remove other nodes' VMs + for vm in vm_list_raw: # Check hypervisor to avoid unneeded ZK calls vm_hypervisor[vm] = zk.get('/domains/{}/hypervisor'.format(vm))[0].decode('ascii') - if hypervisor != None and vm_hypervisor[vm] != hypervisor: - continue + if hypervisor != None: + if vm_hypervisor[vm] == hypervisor: + vm_list.append(vm) + else: + vm_list.append(vm) + # Gather information for printing + for vm in vm_list: vm_state[vm] = zk.get('/domains/{}/state'.format(vm))[0].decode('ascii') vm_lasthypervisor = zk.get('/domains/{}/lasthypervisor'.format(vm))[0].decode('ascii') if vm_lasthypervisor != '':