2018-05-31 20:26:44 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from kazoo.client import KazooClient
|
|
|
|
from kazoo.client import KazooState
|
|
|
|
import libvirt
|
|
|
|
import sys
|
2018-05-31 21:49:23 -04:00
|
|
|
import socket
|
2018-05-31 20:26:44 -04:00
|
|
|
import uuid
|
|
|
|
import VMInstance
|
2018-05-31 21:49:23 -04:00
|
|
|
import NodeInstance
|
2018-05-31 20:26:44 -04:00
|
|
|
import time
|
2018-05-31 21:49:23 -04:00
|
|
|
import threading
|
|
|
|
import atexit
|
2018-05-31 20:26:44 -04:00
|
|
|
|
|
|
|
def help():
|
|
|
|
print("pvcd - Parallel Virtual Cluster management daemon")
|
|
|
|
# exit(0)
|
|
|
|
|
|
|
|
help()
|
|
|
|
|
|
|
|
# Connect to zookeeper
|
|
|
|
zk = KazooClient(hosts='127.0.0.1:2181')
|
|
|
|
try:
|
|
|
|
zk.start()
|
|
|
|
except:
|
|
|
|
print("Failed to connect to local Zookeeper instance")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
def zk_listener(state):
|
|
|
|
if state == KazooState.LOST:
|
|
|
|
# Register somewhere that the session was lost
|
|
|
|
pass
|
|
|
|
elif state == KazooState.SUSPENDED:
|
|
|
|
# Handle being disconnected from Zookeeper
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# Handle being connected/reconnected to Zookeeper
|
|
|
|
pass
|
|
|
|
|
|
|
|
zk.add_listener(zk_listener)
|
|
|
|
|
2018-05-31 21:49:23 -04:00
|
|
|
def cleanup():
|
|
|
|
t_node[socket.gethostname()].stop()
|
|
|
|
zk.stop()
|
2018-05-31 20:26:44 -04:00
|
|
|
|
2018-05-31 21:49:23 -04:00
|
|
|
atexit.register(cleanup)
|
2018-05-31 20:26:44 -04:00
|
|
|
|
2018-05-31 21:49:23 -04:00
|
|
|
node_list = zk.get_children('/nodes')
|
|
|
|
print(node_list)
|
2018-05-31 20:26:44 -04:00
|
|
|
|
2018-05-31 21:49:23 -04:00
|
|
|
domain_list = zk.get_children('/domains')
|
|
|
|
print(domain_list)
|
2018-05-31 20:26:44 -04:00
|
|
|
|
2018-05-31 21:49:23 -04:00
|
|
|
t_node = dict()
|
|
|
|
s_domain = dict()
|
2018-05-31 20:26:44 -04:00
|
|
|
|
2018-05-31 21:49:23 -04:00
|
|
|
for node in node_list:
|
|
|
|
t_node[node] = NodeInstance.NodeInstance(node, zk);
|
|
|
|
t_node[node].start()
|
2018-05-31 20:26:44 -04:00
|
|
|
|
2018-05-31 21:49:23 -04:00
|
|
|
for domain in domain_list:
|
|
|
|
s_domain[domain] = VMInstance.VMInstance(domain, zk, socket.gethostname());
|
2018-05-31 20:26:44 -04:00
|
|
|
|
|
|
|
while True:
|
|
|
|
# Tick loop
|
2018-05-31 21:49:23 -04:00
|
|
|
try:
|
|
|
|
time.sleep(1)
|
|
|
|
except:
|
|
|
|
cleanup()
|
|
|
|
exit(0)
|