Some fixes

This commit is contained in:
Joshua Boniface 2018-06-02 14:32:59 -04:00
parent 0e897faf21
commit d9a5895c4e
2 changed files with 24 additions and 14 deletions

View File

@ -78,7 +78,7 @@ class VMInstance:
# Receive the migration from another host (wait until VM is running) # Receive the migration from another host (wait until VM is running)
def receive_migrate(self): def receive_migrate(self):
while True: while True:
if self.dom.state() != libvirt.VIR_DOMAIN_RUNNING: if self.dom == None or self.dom.state() != libvirt.VIR_DOMAIN_RUNNING:
continue continue
else: else:
self.zk.set(self.zkey + '/status', b'start') self.zk.set(self.zkey + '/status', b'start')

36
pvc.py
View File

@ -16,17 +16,27 @@ def define_domain(domxmlfile):
print('Adding domain %s to database' % domuuid) print('Adding domain %s to database' % domuuid)
zk = kazoo.client.KazooClient(hosts='127.0.0.1:2181') zk = kazoo.client.KazooClient(hosts='127.0.0.1:2181')
try: zk.start()
zk.start() transaction = zk.transaction()
transaction = zk.transaction() transaction.create('/domains/%s' % domuuid, "".encode('ascii'))
transaction.create('/domains/%s' % domuuid, "".encode('ascii')) transaction.create('/domains/%s/state' % domuuid, "stop".encode('ascii'))
transaction.create('/domains/%s/state' % domuuid, "stop".encode('ascii')) transaction.create('/domains/%s/hypervisor' % domuuid, socket.gethostname().encode('ascii'))
transaction.create('/domains/%s/hypervisor' % domuuid, socket.gethostname().encode('ascii')) transaction.create('/domains/%s/xml' % domuuid, data.encode('ascii'))
transaction.create('/domains/%s/xml' % domuuid, data.encode('ascii')) results = transaction.commit()
results = transaction.commit() zk.stop()
zk.stop() zk.close()
zk.close()
except:
print('Failed to connect to local Zookeeper instance')
define_domain('/var/home/joshua/debian9.xml') 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/hypervisor' % domuuid, target.encode('ascii'))
results = transaction.commit()
zk.stop()
zk.close()
#define_domain('/var/home/joshua/debian9.xml')
migrate_domain('b1dc4e21-544f-47aa-9bb7-8af0bc443b78', 'test1.i.bonilan.net')
#migrate_domain('b1dc4e21-544f-47aa-9bb7-8af0bc443b78', 'test2.i.bonilan.net')