More fixes

This commit is contained in:
Joshua Boniface 2018-05-31 23:28:26 -04:00
parent f8bee525b7
commit 59410bf2d9
3 changed files with 27 additions and 25 deletions

View File

@ -75,7 +75,6 @@ class NodeInstance(threading.Thread):
self.zk.set(self.zkey + '/memfree', str(self.memfree).encode('ascii')) self.zk.set(self.zkey + '/memfree', str(self.memfree).encode('ascii'))
self.zk.set(self.zkey + '/cpuload', str(self.cpuload).encode('ascii')) self.zk.set(self.zkey + '/cpuload', str(self.cpuload).encode('ascii'))
print("Free memory: %s | Load: %s" % ( self.memfree, self.cpuload )) print("Free memory: %s | Load: %s" % ( self.memfree, self.cpuload ))
print("Node list: %s" % self.node_list)
print("Active domains: %s" % self.domainlist) print("Active domains: %s" % self.domainlist)
for x in range(0,50): for x in range(0,50):
time.sleep(0.1) time.sleep(0.1)

View File

@ -18,15 +18,15 @@ class VMInstance:
# Watch for changes to the hypervisor field in Zookeeper # Watch for changes to the hypervisor field in Zookeeper
@zk.DataWatch(self.zkey + '/hypervisor') @zk.DataWatch(self.zkey + '/hypervisor')
def watch_hypervisor(data, stat): def watch_hypervisor(data, stat):
if self.hypervisor != data.decode('ascii'):
self.hypervisor = data.decode('ascii') self.hypervisor = data.decode('ascii')
print("Version: %s, data: %s" % (stat.version, self.hypervisor))
self.manage_vm_state() self.manage_vm_state()
# Watch for changes to the state field in Zookeeper # Watch for changes to the state field in Zookeeper
@zk.DataWatch(self.zkey + '/state') @zk.DataWatch(self.zkey + '/state')
def watch_state(data, stat): def watch_state(data, stat):
if self.state != data.decode('ascii'):
self.state = data.decode('ascii') self.state = data.decode('ascii')
print("Version: %s, data: %s" % (stat.version, self.state))
self.manage_vm_state() self.manage_vm_state()
# Start up the VM # Start up the VM
@ -77,6 +77,7 @@ class VMInstance:
self.zk.set(self.zkey + '/status', b'start') self.zk.set(self.zkey + '/status', b'start')
self.thishypervisor.domainlist.append(self.domuuid) self.thishypervisor.domainlist.append(self.domuuid)
break break
# #
# Main function to manage a VM (taking only self) # Main function to manage a VM (taking only self)
# #
@ -91,7 +92,10 @@ class VMInstance:
# Check the current state of the VM # Check the current state of the VM
try: try:
self.dom = conn.lookupByUUID(uuid.UUID(self.domuuid).bytes) self.dom = conn.lookupByUUID(uuid.UUID(self.domuuid).bytes)
if self.dom != None:
running = self.dom.state() running = self.dom.state()
else:
running = False
except: except:
running = False running = False

33
pvcd.py
View File

@ -59,26 +59,25 @@ else:
zk.create('%s/memfree' % mynodestring, '0'.encode('ascii')) zk.create('%s/memfree' % mynodestring, '0'.encode('ascii'))
zk.create('%s/cpuload' % mynodestring, '0.0'.encode('ascii')) zk.create('%s/cpuload' % mynodestring, '0.0'.encode('ascii'))
time.sleep(1)
def updatenodes():
node_list = zk.get_children('/nodes')
print(node_list)
for node in node_list:
if t_node[node] is None:
t_node[node] = NodeInstance.NodeInstance(node, node_list, zk);
else:
t_node[node].updatenodelist(node_list)
node_list = zk.get_children('/nodes')
domain_list = zk.get_children('/domains')
print(domain_list)
t_node = dict() t_node = dict()
s_domain = dict() s_domain = dict()
node_list = []
time.sleep(1) @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(node_list)
else:
t_node[node] = NodeInstance.NodeInstance(node, node_list, zk);
if t_node[node].name == myhostname:
t_node[node].start()
domain_list = zk.get_children('/domains')
print('Domain list: %s' % domain_list)
for domain in domain_list: for domain in domain_list:
s_domain[domain] = VMInstance.VMInstance(domain, zk, t_node[myhostname]); s_domain[domain] = VMInstance.VMInstance(domain, zk, t_node[myhostname]);