forked from cu-csc/automaton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
automaton.py
executable file
·86 lines (75 loc) · 2.76 KB
/
automaton.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
import logging
import signal
from threading import Thread
from lib.logger import configure_logging
from lib.util import parse_options
from lib.util import read_config
from lib.config import Config
from resources.cloud.clouds import Cloud, Clouds
from resources.cluster.clusters import Clusters
from graphing.graphing import Graph
SIGEXIT = False
LOG = logging.getLogger(__name__)
class Automaton(Thread):
def __init__(self, config, clusters):
Thread.__init__(self)
self.config = config
self.clusters = clusters
def run(self):
LOG.info("Starting Automaton")
#TODO(pdmars): do something
# Code below demonstrates functionality of Cluster class:
#for cluster in self.clusters.list:
#cluster.connect()
#print "connect"
#cluster.launch()
#print "launching"
#cluster.log_info()
#print "log_info"
#fqdns = cluster.get_fqdns()
#cluster.terminate_all()
#print "terminate"
if self.config.options.show_id:
self.clusters.database.printdata()
if self.config.options.generate_graphs:
graph = Graph(self.config)
graph.generate_graph()
for cluster in self.clusters.list:
if self.config.options.launch_cluster:
cluster.connect()
cluster.launch()
if self.config.options.terminate_cluster:
cluster.connect()
if self.config.options.terminate_cluster=="all":
cluster.terminate_all()
else:
cluster.terminate(self.config.options.terminate_cluster)
if self.config.options.gather_logs:
cluster.connect()
cluster.download_logs()
if self.config.options.deploy_software:
cluster.connect()
cluster.deploy_software()
if self.config.options.excute_benchmarks:
cluster.connect()
cluster.excute_benchmarks()
def clean_exit(signum, frame):
global SIGEXIT
SIGEXIT = True
LOG.critical("Exit signal received. Exiting at the next sane time. "
"Please stand by.")
def main():
(options, args) = parse_options()
configure_logging(options.debug)
config = Config(options)
clusters = Clusters(config)
signal.signal(signal.SIGINT, clean_exit)
automaton = Automaton(config, clusters)
automaton.start()
# wake every seconed to make sure signals are handled by the main thread
# need this due to a quirk in the way Python threading handles signals
while automaton.isAlive():
automaton.join(timeout=1.0)
if __name__ == "__main__":
main()