From 6aca8f9fee914875b5698e2662075fa274ba3318 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sat, 2 Jun 2018 16:45:20 -0400 Subject: [PATCH] Fix migrate problem --- NodeInstance.py | 6 ++++-- VMInstance.py | 8 +++----- pvc.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/NodeInstance.py b/NodeInstance.py index fe4eaee0..b8189850 100644 --- a/NodeInstance.py +++ b/NodeInstance.py @@ -68,8 +68,10 @@ class NodeInstance(threading.Thread): least_mem = node_freemem least_host = node.getname() - self.zk.set('/domains/' + domain + '/state', 'flush'.encode('ascii')) - self.zk.set('/domains/' + domain + '/hypervisor', least_host.encode('ascii')) + transaction = self.zk.transaction() + transaction.set_data('/domains/' + domain + '/state', 'migrate'.encode('ascii')) + transaction.set_data('/domains/' + domain + '/hypervisor', least_host.encode('ascii')) + transaction.commit() def run(self): if self.name == socket.gethostname(): diff --git a/VMInstance.py b/VMInstance.py index f2905f28..44e22ba0 100644 --- a/VMInstance.py +++ b/VMInstance.py @@ -102,14 +102,12 @@ class VMInstance: # Migrate the VM to a target host def migrate_vm(self): - self.zk.set(self.zkey + '/state', 'migrate'.encode('ascii')) - try: dest_conn = libvirt.open('qemu+tcp://%s/system' % self.hypervisor) if dest_conn == None: raise except: - print('>>> Failed to open connection to qemu+ssh://%s/system' % self.hypervisor) + print('>>> Failed to open connection to qemu+tcp://%s/system' % self.hypervisor) self.zk.set(self.zkey + '/hypervisor', self.thishypervisor.name.encode('ascii')) self.zk.set(self.zkey + '/state', 'start'.encode('ascii')) return @@ -141,7 +139,7 @@ class VMInstance: except: pass else: - self.zk.set(self.zkey + '/status', b'start') + self.zk.set(self.zkey + '/status', 'start'.encode('ascii')) if not self.domuuid in self.thishypervisor.domain_list: self.thishypervisor.domain_list.append(self.domuuid) break @@ -179,7 +177,7 @@ class VMInstance: self.receive_migrate() # VM should be migrated away from this hypervisor - elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "start" and self.hypervisor != self.thishypervisor.name: + elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "migrate" and self.hypervisor != self.thishypervisor.name: self.migrate_vm() # VM is already running and should be diff --git a/pvc.py b/pvc.py index 05c5361a..0d07a80f 100755 --- a/pvc.py +++ b/pvc.py @@ -30,7 +30,7 @@ def migrate_domain(domuuid, target): zk = kazoo.client.KazooClient(hosts='127.0.0.1:2181') zk.start() transaction = zk.transaction() -# transaction.set_data('/domains/%s/state' % domuuid, 'migrate'.encode('ascii')) + transaction.set_data('/domains/%s/state' % domuuid, 'migrate'.encode('ascii')) transaction.set_data('/domains/%s/hypervisor' % domuuid, target.encode('ascii')) results = transaction.commit() zk.stop()