Get flush working properly

This commit is contained in:
Joshua Boniface 2018-06-04 02:22:59 -04:00
parent 55ebbea6cf
commit 1a72ee6414
2 changed files with 28 additions and 20 deletions

View File

@ -58,21 +58,30 @@ class NodeInstance(threading.Thread):
# Flush all VMs on the host
def flush(self):
for domain in self.domain_list:
print(domain)
# Determine the best target hypervisor
least_mem = (2^64)/8
least_load = 999.0
least_host = ""
for node in self.t_node:
node_freemem = node.getfreemem()
least_mem = 2**64
least_host = None
for node_name, node in self.t_node.items():
if node_name == self.name:
continue
node_freemem = int(node.getfreemem())
if node_freemem < least_mem:
least_mem = node_freemem
least_host = node.getname()
least_host = node_name
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()
if least_host == None:
print(">>> Failed to find valid migration target for %s" % domain)
transaction = self.zk.transaction()
transaction.set_data('/domains/' + domain + '/state', 'shutdown'.encode('ascii'))
transaction.commit()
else:
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()
# Wait 1s between migrations
time.sleep(1)
def run(self):
if self.name == socket.gethostname():
@ -136,8 +145,7 @@ class NodeInstance(threading.Thread):
flushed_node_list = []
inactive_node_list = []
for node in self.t_node:
node_name = node.getname()
for node_name in self.t_node:
state, stat = self.zk.get('/nodes/%s/state' % node_name)
node_state = state.decode('ascii')
if node_state == 'start':

14
pvcd.py
View File

@ -68,25 +68,22 @@ else:
t_node = dict()
s_domain = dict()
node_list = []
domain_list = []
@zk.ChildrenWatch('/nodes')
def updatenodes(new_node_list):
global node_list
node_list = new_node_list
print('Node list: %s' % node_list)
for node in node_list:
if node in t_node:
t_node[node].updatenodelist(t_node)
else:
t_node[node] = NodeInstance.NodeInstance(node, t_node, s_domain, zk);
if node == myhostname:
t_node[node].start()
time.sleep(0.2)
for node in node_list:
if node in t_node:
t_node[node].updatenodelist(t_node)
t_node[node] = NodeInstance.NodeInstance(node, t_node, s_domain, zk)
@zk.ChildrenWatch('/domains')
def updatedomains(new_domain_list):
global domain_list
domain_list = new_domain_list
print('Domain list: %s' % domain_list)
for domain in domain_list:
@ -96,6 +93,9 @@ def updatedomains(new_domain_list):
if node in t_node:
t_node[node].updatedomainlist(s_domain)
t_node[myhostname].start()
time.sleep(0.2)
while True:
# Tick loop
try: