Add node instances

This commit is contained in:
2018-05-31 21:49:23 -04:00
parent a81a6dd979
commit 92ddec311b
3 changed files with 95 additions and 39 deletions

62
pvcd.py
View File

@ -4,9 +4,13 @@ from kazoo.client import KazooClient
from kazoo.client import KazooState
import libvirt
import sys
import socket
import uuid
import VMInstance
import NodeInstance
import time
import threading
import atexit
def help():
print("pvcd - Parallel Virtual Cluster management daemon")
@ -35,50 +39,32 @@ def zk_listener(state):
zk.add_listener(zk_listener)
# Connect to libvirt
libvirt_name = "qemu:///system"
conn = libvirt.open(libvirt_name)
if conn == None:
print('Failed to open connection to %s' % libvirt_name)
exit(1)
def cleanup():
t_node[socket.gethostname()].stop()
zk.stop()
# Gather data about hypervisor
hostname = conn.getHostname()
nodeinfo = conn.getInfo()
numnodes = nodeinfo[4]
memlistNUMA = conn.getCellsFreeMemory(0, numnodes)
memlistTOTAL = conn.getFreeMemory()
atexit.register(cleanup)
print("Node hostname: %s" % hostname)
print("Free memory: %s" % memlistTOTAL)
cell = 0
for cellfreemem in memlistNUMA:
print('NUMA Node '+str(cell)+': '+str(cellfreemem)+' bytes free memory')
cell += 1
node_list = zk.get_children('/nodes')
print(node_list)
print('Virtualization type: '+conn.getType())
uri = conn.getURI()
print('Canonical URI: '+uri)
domain_list = zk.get_children('/domains')
print(domain_list)
print()
t_node = dict()
s_domain = dict()
map = conn.getCPUMap()
for node in node_list:
t_node[node] = NodeInstance.NodeInstance(node, zk);
t_node[node].start()
print("CPUs: " + str(map[0]))
print("Available: " + str(map[1]))
print()
def start_vm(vmname):
print("Starting VM %s" % vmname)
vm = VMInstance.VMInstance('b1dc4e21-544f-47aa-9bb7-8af0bc443b78', zk, hostname);
for domain in domain_list:
s_domain[domain] = VMInstance.VMInstance(domain, zk, socket.gethostname());
while True:
# Tick loop
time.sleep(1)
pass
conn.close()
zk.stop()
try:
time.sleep(1)
except:
cleanup()
exit(0)