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

14
pvcd.py
View File

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