From 8e7c883d72000caeb7a147d805ea6caec51e934b Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Wed, 18 Jul 2018 02:30:50 -0400 Subject: [PATCH] Correct some bugs and remove this_node aspect Addresses #9 --- pvc.py | 11 ++++------- pvcd/NodeInstance.py | 13 +++++-------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/pvc.py b/pvc.py index d7184139..5408004f 100755 --- a/pvc.py +++ b/pvc.py @@ -354,12 +354,12 @@ def verifyNode(zk_conn, node): click.echo('ERROR: No node named "{}" is present in the cluster.'.format(node)) exit(1) -def findTargetHypervisor(zk_conn, search_field, dom_uuid, this_node) +def findTargetHypervisor(zk_conn, search_field, dom_uuid) if search_field == 'mem': - return findTargetHypervisorMem(zk_conn, dom_uuid, this_node) + return findTargetHypervisorMem(zk_conn, dom_uuid) return None -def findTargetHypervisorMem(zk_conn, dom_uuid, this_node): +def findTargetHypervisorMem(zk_conn, dom_uuid): # Find a target node most_allocfree = 0 target_hypervisor = None @@ -367,9 +367,6 @@ def findTargetHypervisorMem(zk_conn, dom_uuid, this_node): hypervisor_list = zkhandler.listchildren(zk_conn, '/nodes') current_hypervisor = zkhandler.readdata(zk_conn, '/domains/{}/hypervisor'.format(dom_uuid)) - if current_hypervisor != this_node: - continue - for hypervisor in hypervisor_list: daemon_state = zkhandler.readdata(zk_conn, '/nodes/{}/daemonstate'.format(hypervisor)) domain_state = zkhandler.readdata(zk_conn, '/nodes/{}/domainstate'.format(hypervisor)) @@ -983,7 +980,7 @@ def move_vm(domain, target_hypervisor): current_hypervisor = zk_conn.get('/domains/{}/hypervisor'.format(dom_uuid))[0].decode('ascii') if target_hypervisor == None: - target_hypervisor = findTargetHypervisor(zk_conn, 'mem', dom_uuid, current_hypervisor) + target_hypervisor = findTargetHypervisor(zk_conn, 'mem', dom_uuid) else: if target_hypervisor == current_hypervisor: click.echo('ERROR: The VM "{}" is already running on hypervisor "{}".'.format(dom_uuid, current_hypervisor)) diff --git a/pvcd/NodeInstance.py b/pvcd/NodeInstance.py index 2b8eecb1..95c70846 100644 --- a/pvcd/NodeInstance.py +++ b/pvcd/NodeInstance.py @@ -144,7 +144,7 @@ class NodeInstance(): for dom_uuid in fixed_domain_list: ansiiprint.echo('Selecting target to migrate VM "{}"'.format(dom_uuid), '', 'i') - target_hypervisor = findTargetHypervisor(self.zk_conn, 'mem', dom_uuid, self.this_node) + target_hypervisor = findTargetHypervisor(self.zk_conn, 'mem', dom_uuid) if target_hypervisor == None: ansiiprint.echo('Failed to find migration target for VM "{}"; shutting down'.format(dom_uuid), '', 'e') zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(dom_uuid): 'shutdown' }) @@ -317,21 +317,18 @@ class NodeInstance(): ansiiprint.echo('{}Flushed nodes:{} {}'.format(ansiiprint.bold(), ansiiprint.end(), ' '.join(self.flushed_node_list)), '', 'c') # Find a target node -def findTargetHypervisor(zk_conn, search_field, dom_uuid, this_node): +def findTargetHypervisor(zk_conn, search_field, dom_uuid): if search_field == 'mem': - return findTargetHypervisorMem(zk_conn, dom_uuid, this_node) + return findTargetHypervisorMem(zk_conn, dom_uuid) return None -def findTargetHypervisorMem(zk_conn, search_field, dom_uuid, this_node): +def findTargetHypervisorMem(zk_conn, search_field, dom_uuid): most_allocfree = 0 target_hypervisor = None hypervisor_list = zkhandler.listchildren(zk_conn, '/nodes') current_hypervisor = zkhandler.readdata(zk_conn, '/domains/{}/hypervisor'.format(dom_uuid)) - if current_hypervisor != this_node: - continue - for hypervisor in hypervisor_list: daemon_state = zkhandler.readdata(zk_conn, '/nodes/{}/daemonstate'.format(hypervisor)) domain_state = zkhandler.readdata(zk_conn, '/nodes/{}/domainstate'.format(hypervisor)) @@ -398,7 +395,7 @@ def migrateFromFencedHost(zk_conn, node_name): ansiiprint.echo('Moving VMs from dead hypervisor "{}" to new hosts'.format(node_name), '', 'i') dead_node_running_domains = zkhandler.readdata(zk_conn, '/nodes/{}/runningdomains'.format(node_name)).split() for dom_uuid in dead_node_running_domains: - target_hypervisor = findTargetHypervisor(zk_conn, 'mem', dom_uuid, node_name) + target_hypervisor = findTargetHypervisor(zk_conn, 'mem', dom_uuid) ansiiprint.echo('Moving VM "{}" to hypervisor "{}"'.format(dom_uuid, target_hypervisor), '', 'i') zkhandler.writedata(zk_conn, {