Fix some bugs

This commit is contained in:
Joshua Boniface 2018-06-04 02:34:03 -04:00
parent 1a72ee6414
commit c0c84036c3
1 changed files with 15 additions and 3 deletions

View File

@ -78,6 +78,7 @@ class NodeInstance(threading.Thread):
transaction = self.zk.transaction() transaction = self.zk.transaction()
transaction.set_data('/domains/' + domain + '/state', 'migrate'.encode('ascii')) transaction.set_data('/domains/' + domain + '/state', 'migrate'.encode('ascii'))
transaction.set_data('/domains/' + domain + '/hypervisor', least_host.encode('ascii')) transaction.set_data('/domains/' + domain + '/hypervisor', least_host.encode('ascii'))
transaction.set_data('/domains/' + domain + '/flushedhypervisor', self.name.encode('ascii'))
transaction.commit() transaction.commit()
# Wait 1s between migrations # Wait 1s between migrations
@ -100,12 +101,18 @@ class NodeInstance(threading.Thread):
# Gather data about hypervisor # Gather data about hypervisor
self.name = conn.getHostname() self.name = conn.getHostname()
self.cpucount = conn.getCPUMap()[0] self.cpucount = conn.getCPUMap()[0]
self.state = 'start'
self.zk.set(self.zkey + '/state', 'start'.encode('ascii'))
self.zk.set(self.zkey + '/cpucount', str(self.cpucount).encode('ascii')) self.zk.set(self.zkey + '/cpucount', str(self.cpucount).encode('ascii'))
print("Node hostname: %s" % self.name) print("Node hostname: %s" % self.name)
print("CPUs: %s" % self.cpucount) print("CPUs: %s" % self.cpucount)
# Get past state and update if needed
past_state = self.zk.get(self.zkey + '/state')[0].decode('ascii')
if past_state != 'flush':
self.state = 'start'
self.zk.set(self.zkey + '/state', 'start'.encode('ascii'))
else:
self.state = 'flush'
while True: while True:
# Toggle state management of all VMs # Toggle state management of all VMs
for domain, instance in self.s_domain.items(): for domain, instance in self.s_domain.items():
@ -152,7 +159,6 @@ class NodeInstance(threading.Thread):
active_node_list.append(node_name) active_node_list.append(node_name)
elif node_state == 'flush': elif node_state == 'flush':
flushed_node_list.append(node_name) flushed_node_list.append(node_name)
self.flush()
else: else:
inactive_node_list.append(node_name) inactive_node_list.append(node_name)
@ -160,6 +166,12 @@ class NodeInstance(threading.Thread):
print('Flushed nodes: %s' % flushed_node_list) print('Flushed nodes: %s' % flushed_node_list)
print('Inactive nodes: %s' % inactive_node_list) print('Inactive nodes: %s' % inactive_node_list)
# Do any actions my node requires
if self.state == 'flush':
self.flush()
elif self.state == 'unflush':
self.unflush()
# Sleep for 10s but with quick interruptability # Sleep for 10s but with quick interruptability
for x in range(0,100): for x in range(0,100):
time.sleep(0.1) time.sleep(0.1)