Fix migrate problem
This commit is contained in:
parent
f032dbefac
commit
6aca8f9fee
|
@ -68,8 +68,10 @@ class NodeInstance(threading.Thread):
|
||||||
least_mem = node_freemem
|
least_mem = node_freemem
|
||||||
least_host = node.getname()
|
least_host = node.getname()
|
||||||
|
|
||||||
self.zk.set('/domains/' + domain + '/state', 'flush'.encode('ascii'))
|
transaction = self.zk.transaction()
|
||||||
self.zk.set('/domains/' + domain + '/hypervisor', least_host.encode('ascii'))
|
transaction.set_data('/domains/' + domain + '/state', 'migrate'.encode('ascii'))
|
||||||
|
transaction.set_data('/domains/' + domain + '/hypervisor', least_host.encode('ascii'))
|
||||||
|
transaction.commit()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.name == socket.gethostname():
|
if self.name == socket.gethostname():
|
||||||
|
|
|
@ -102,14 +102,12 @@ class VMInstance:
|
||||||
|
|
||||||
# Migrate the VM to a target host
|
# Migrate the VM to a target host
|
||||||
def migrate_vm(self):
|
def migrate_vm(self):
|
||||||
self.zk.set(self.zkey + '/state', 'migrate'.encode('ascii'))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dest_conn = libvirt.open('qemu+tcp://%s/system' % self.hypervisor)
|
dest_conn = libvirt.open('qemu+tcp://%s/system' % self.hypervisor)
|
||||||
if dest_conn == None:
|
if dest_conn == None:
|
||||||
raise
|
raise
|
||||||
except:
|
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 + '/hypervisor', self.thishypervisor.name.encode('ascii'))
|
||||||
self.zk.set(self.zkey + '/state', 'start'.encode('ascii'))
|
self.zk.set(self.zkey + '/state', 'start'.encode('ascii'))
|
||||||
return
|
return
|
||||||
|
@ -141,7 +139,7 @@ class VMInstance:
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
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:
|
if not self.domuuid in self.thishypervisor.domain_list:
|
||||||
self.thishypervisor.domain_list.append(self.domuuid)
|
self.thishypervisor.domain_list.append(self.domuuid)
|
||||||
break
|
break
|
||||||
|
@ -179,7 +177,7 @@ class VMInstance:
|
||||||
self.receive_migrate()
|
self.receive_migrate()
|
||||||
|
|
||||||
# VM should be migrated away from this hypervisor
|
# 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()
|
self.migrate_vm()
|
||||||
|
|
||||||
# VM is already running and should be
|
# VM is already running and should be
|
||||||
|
|
2
pvc.py
2
pvc.py
|
@ -30,7 +30,7 @@ def migrate_domain(domuuid, target):
|
||||||
zk = kazoo.client.KazooClient(hosts='127.0.0.1:2181')
|
zk = kazoo.client.KazooClient(hosts='127.0.0.1:2181')
|
||||||
zk.start()
|
zk.start()
|
||||||
transaction = zk.transaction()
|
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'))
|
transaction.set_data('/domains/%s/hypervisor' % domuuid, target.encode('ascii'))
|
||||||
results = transaction.commit()
|
results = transaction.commit()
|
||||||
zk.stop()
|
zk.stop()
|
||||||
|
|
Loading…
Reference in New Issue