-
Notifications
You must be signed in to change notification settings - Fork 7
/
cluesserver
executable file
·626 lines (508 loc) · 24.4 KB
/
cluesserver
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
#!/usr/bin/env python
#
# CLUES - Cluster Energy Saving System
# Copyright (C) 2015 - GRyCAP - Universitat Politecnica de Valencia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import sys
import time
import json
import clueslib.reports
_ERROR_IMPORTING=None
try:
from clues.version import VERSION
import clues.configserver as configserver
import cpyutils.rpcweb
import cpyutils.eventloop
import clueslib.request
import clueslib.platform
# import clueslib.schedulers_extra
# import clueslib.evaluate
class clues_web_server(cpyutils.rpcweb.web_class):
def _access_page(self):
return "<html><body><form method=get>secret token<input type=text name=\"secret\" id=\"secret\"><input type=submit></body></html>"
# <style>body {font-family: arial;} </style>\
def _mainpage(self):
query = self.query
return "<html><head>\
<link rel=\"stylesheet\" href=\"http://csszengarden.com/examples/style.css\">\
<script src=\"http://code.jquery.com/jquery-latest.min.js\" type=\"text/javascript\"></script>\
<script language=\"javascript\" type=\"text/javascript\">\
var timeout = setInterval(reloadHosts, 5000);\
var timeout = setInterval(reloadRequests, 5000);\
var timeout = setInterval(reloadJobs, 2000);\
function reloadHosts () {$('#hosts').load('/status/hosts%s');}\
function reloadRequests () {$('#requests').load('/status/requests%s');}\
function reloadJobs () {$('#jobs').load('/status/jobs%s');}\
</script>\
<body><a href=\"/%s\">clear filter</a>\
<h1 class='expand-hosts'>Hosts</h1>\
<div id='hosts'>\
</div>\
<h1 class='expand-requests'>Requests</h1>\
<div id='requests'>\
</div>\
<h1 class='expand-jobs'>Jobs</h1>\
<div id='jobs'>\
</div>\
%%s</body>\
<script language=\"javascript\" type=\"text/javascript\">\
$('.expand-hosts').click(function(){$('#hosts').slideToggle('slow');});\
$('.expand-requests').click(function(){$('#requests').slideToggle('slow');});\
$('.expand-jobs').click(function(){$('#jobs').slideToggle('slow');});\
reloadHosts();reloadJobs();reloadRequests();</script>\
</html>" % (query, query, query, query)
def _status(self, path, secret, ref = ""):
global CLUES_DAEMON
if path == 'hosts':
succeed, nodeinfo = rawstatus(secret, "")
if not succeed:
return "info not available"
nodes = nodeinfo.get_list()
node_rows = []
en_str = { True:'enabled', False:'disabled'}
now = cpyutils.eventloop.now()
for k in sorted(nodes):
n = nodes[k]
days = int((now - n.timestamp_state) / 86400)
node_str="<tr><td><a href=\"/host/%s%s\">%s</a></td><td>%s</td><td>%s</td><td>%sd %s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % (n.name, ref, n.name[:24], (n.state2str[n.state])[:8], en_str[n.enabled], days, time.strftime("%Hh%M\'%S\"", time.gmtime(now - n.timestamp_state)), str(n.slots_count-n.slots_free), str(n.memory_total-n.memory_free), str(n.slots_count), str(n.memory_total))
node_rows.append(node_str)
return "<table>%s</table>" % "\n".join(node_rows)
if path == 'jobs':
return "%s<br>%s" % (cpyutils.eventloop.now(), str(CLUES_DAEMON.get_job_list()).replace("\n","<br>"))
if path == 'requests':
import clueslib.schedulers
booking_system = clueslib.schedulers.get_booking_system()
retval = "%s<br><h2>booking system</h2>%s<br>" % (str(CLUES_DAEMON.get_requests_list()), str(booking_system))
return str(retval.replace("\n","<br>"))
return "Not available"
def _get_var(self, varname):
secret = ""
for vv in self.query.lstrip("?").split("&"):
va = vv.split("=")
key = None
val = None
if len(va) == 2:
key, val = va
if key == varname:
secret = val
return secret
def _get_host(self, secret, hostname):
success, result = get_node_description(secret, hostname, False)
if success:
import clueslib.cluesd
import clueslib.node
import time
#db = clueslib.cluesd.NodeData()
#changes = db.retrieve_node_state_history(hostname, True)
changes_str = ""
#for (state, timestamp) in changes:
# if changes_str == "":
# change_str = "began in state '%s' @ %s" % (clueslib.node.Node.state2str[int(state)], time.strftime("%b %d %Y %H:%M:%S", time.gmtime(long(timestamp))))
# else:
# change_str = "changed to state '%s' @ %s" % (clueslib.node.Node.state2str[int(state)], time.strftime("%b %d %Y %H:%M:%S", time.gmtime(long(timestamp))))
# changes_str="%s%s<BR>" % (changes_str, change_str)
return changes_str + result.replace(";","<BR>")
return "Could not get info"
def reports(self, url, secret):
filename = "/".join(url).lstrip('/').replace('../', '')
if filename == '':
filename='index.html'
_LOGGER.debug("web request: %s" % filename)
if filename in [ "cluesdata.js", "cluesdata.json" ]:
hostdata, min_t, max_t = clueslib.reports.get_reports_data(configserver._CONFIGURATION_CLUES.DB_CONNECTION_STRING, 0, cpyutils.eventloop.now())
requests, min_t_r, max_t_r = clueslib.reports.get_requests_data(configserver._CONFIGURATION_CLUES.DB_CONNECTION_STRING, 0, cpyutils.eventloop.now())
if hostdata is None:
return "failed to get data from the database"
else:
if min_t is None: min_t = 0
if max_t is None: max_t = 0
result = {"hostevents":hostdata,"requests":requests, "mintime_avail": min_t, "maxtime_avail": max_t, "t": cpyutils.eventloop.now()}
if filename == "cluesdata.js":
return "var cluesdata=%s;" % json.dumps(result)
else:
return "%s" % json.dumps(result)
else:
if configserver._CONFIGURATION_GENERAL.PATH_REPORTS_WEB == "":
return "reports are deactivated"
import os
filename = os.path.realpath("%s/%s" % (configserver._CONFIGURATION_GENERAL.PATH_REPORTS_WEB, filename))
data=""
try:
filehandler = open(filename, 'r')
except:
return "could not get the requested file"
data=filehandler.read()
import re
data=re.sub('[^:]href="(?!http|#)([^"]*)"', 'href="\\1?secret=%s"' % secret, data)
data=re.sub('src="(?!http)([^"]*)"', 'src="/reports/\\1?secret=%s"' % secret, data)
return data
def GET(self, url):
self.query = "?"+"?".join(url.split("?")[1:])
url = url.split("?")[0]
path = url.lstrip("/").split("/")
secret = self._get_var("secret")
if (secret == "") or (secret is None):
return self._access_page()
succeed, explain = AUTH_ENGINE.check_secret(secret)
if not succeed:
return self._access_page()
if len(path) > 1 and path[0] == 'status':
return self._status("/".join(path[1:]), secret, self.query)
if path[0]=='reports':
return self.reports(path[1:], secret)
if path[0]=='host':
# print web.ctx.path
# print self._mainpage() % self._get_host("/".join(path[1:]))
return self._mainpage() % self._get_host(self._get_var("secret"), "/".join(path[1:]))
return self._mainpage() % ""
pass
vv = url.lstrip("/").split("/")
hdetail = None
if len(vv) == 2:
if vv[0] == 'host':
hdetail = vv[1]
if hdetail is not None:
success, hdetail = get_node_description(secret, hdetail, False)
else:
hdetail=""
success, requests = get_requests(secret)
global CLUES_DAEMON
retval="<html><body><table>%s</table>\n%s\n%s\n%s\n</body></html>" % ("\n".join(node_rows), requests.replace("\n","<BR>"), hdetail.replace(";", "<BR>"), str(CLUES_DAEMON).replace("\n","<BR>"))
return retval
except Exception as e:
_ERROR_IMPORTING = e
pass
import cpyutils.log
cpyutils.log.include_timestamp()
_LOGGER = cpyutils.log.Log("SERVER")
_LOGGER.level = logging.DEBUG
def GET_CLUES_DAEMON():
global CLUES_DAEMON
print(CLUES_DAEMON)
return CLUES_DAEMON
class Authentication_secret(object):
def __init__(self, SECRET):
self._SECRET = SECRET
def check_secret(self, secret):
if secret == self._SECRET:
return True, "Secret key correct"
return False, "Error checking the secret key. Please check the configuration file and the CLUES_SECRET_TOKEN setting"
AUTH_ENGINE = Authentication_secret("")
def version():
return VERSION
def login(sec_info):
global AUTH_ENGINE
succeed, explain = AUTH_ENGINE.check_secret(sec_info)
if succeed:
return True, sec_info
return False, "Could not authorize user"
def rawstatus(sec_info, nname):
global AUTH_ENGINE
succeed, explain = AUTH_ENGINE.check_secret(sec_info)
if not succeed:
return False, explain
global CLUES_DAEMON
nodelist = CLUES_DAEMON.get_nodelist()
return True, nodelist
def status(sec_info, nname):
#global AUTH_ENGINE
#succeed, explain = AUTH_ENGINE.check_secret(sec_info)
#if not succeed:
# return False, explain
#
#global CLUES_DAEMON
#nodelist = CLUES_DAEMON.get_nodelist()
succeed, nodelist = rawstatus(sec_info, nname)
if not succeed:
return False, nodelist
fmt_hea = "%-24s %8s %8s %11s %14s %15s"
fmt_str = "%-24s %8s %8s %11s %4s,%-9s %3s,%-9s"
legend = fmt_hea % ("node", "state", "enabled", "time stable", "(cpu,mem) used", "(cpu,mem) total")
head = "-"*24 + "---" + "-"*8 + "---" + "-"*8 + "---" + "-"*11 + "---" + "-"*14 + "---" + "-"*15
retval = "%s\n%s\n" % (legend, head)
now = cpyutils.eventloop.now()
head = "-"*24 + "---" + "-"*8 + "---" + "-"*8 + "---"
en_str = { True:'enabled', False:'disabled'}
nodes = nodelist.get_list()
for k in sorted(nodes):
n = nodes[k]
n_str = fmt_str % (n.name[:24], (n.state2str[n.state])[:8], en_str[n.enabled], time.strftime("%Hh%M\'%S\"", time.gmtime(now - n.timestamp_state)), str(n.slots_count-n.slots_free), str(n.memory_total-n.memory_free), str(n.slots_count), str(n.memory_total))
retval = "%s%s\n" % (retval, n_str)
return True, retval
def poweron(sec_info, node):
global AUTH_ENGINE
succeed, explain = AUTH_ENGINE.check_secret(sec_info)
# _LOGGER.debug("poweron result: %s" % succeed)
if not succeed:
return False, explain
global CLUES_DAEMON
success, nname = CLUES_DAEMON.power_on(node, True)
if not success:
return False, "could not power on the node %s" % node
else:
return True, "node %s powered on" % nname
def poweroff(sec_info, node):
global AUTH_ENGINE
succeed, explain = AUTH_ENGINE.check_secret(sec_info)
# _LOGGER.debug("poweroff result: %s" % succeed)
if not succeed:
return False, explain
global CLUES_DAEMON
success, nname = CLUES_DAEMON.power_off(node, True)
if not success:
return False, "could not power off the node %s" % node
else:
return True, "node %s powered off" % nname
def reset_node_state(sec_info, node):
global AUTH_ENGINE
succeed, explain = AUTH_ENGINE.check_secret(sec_info)
if not succeed:
return False, explain
global CLUES_DAEMON
success, msg = CLUES_DAEMON.reset_node_state(node)
if not success:
return False, "could not reset the node %s (%s)" % (node, msg)
else:
return True, msg
def enable_node(sec_info, nname, enable):
global AUTH_ENGINE
succeed, explain = AUTH_ENGINE.check_secret(sec_info)
# _LOGGER.debug("enable_node result: %s" % succeed)
if not succeed:
return False, explain
global CLUES_DAEMON
succeed, explain = CLUES_DAEMON.enable_host(nname, enable)
if enable:
opres = ("enabled", "enable")
else:
opres = ("disabled", "disable")
if succeed:
return True, "node %s successfully %s" % (nname, opres[0])
else:
return False, "could not %s node %s (%s)" % (opres[1], nname, explain)
def request_create(sec_info, cpu, memory, taskcount, maxtaskspernode = -1, request_string = "", job_id = -1, job_nodes = []):
global AUTH_ENGINE
succeed, explain = AUTH_ENGINE.check_secret(sec_info)
# _LOGGER.debug("request_create result: %s" % succeed)
if not succeed:
return False, explain
global CLUES_DAEMON
# TODO: it is pending to include other feaures for the nodes (i.e. keywords or expression to evaluate the nodes)
if job_id < 0:
job_id = None
job_nodes = []
if maxtaskspernode <= 0:
maxtaskspernode = taskcount
r = clueslib.request.Request(clueslib.request.ResourcesNeeded(cpu, memory, [ request_string ], taskcount, taskcount), job_id, job_nodes)
r_id = CLUES_DAEMON.request(r)
return True, r_id
def request_wait(sec_info, req_id, timeout):
global AUTH_ENGINE
succeed, explain = AUTH_ENGINE.check_secret(sec_info)
# _LOGGER.debug("request_wait result: %s (explain: %s)" % (succeed, explain))
if not succeed:
return False, explain
global CLUES_DAEMON
start_time = cpyutils.eventloop.now()
# TODO: should we launch this wait in other thread, just to avoid hanging the server?
while CLUES_DAEMON.request_in_queue(req_id):
current_time = cpyutils.eventloop.now()
if (timeout > 0) and ((current_time - start_time) > timeout):
return True, False
time.sleep(0.5)
return True, True
def request_pending(sec_info, req_id):
global AUTH_ENGINE
succeed, explain = AUTH_ENGINE.check_secret(sec_info)
if not succeed:
return False, explain
global CLUES_DAEMON
return True, CLUES_DAEMON.request_in_queue(req_id)
def get_node_description(sec_info, nname, xml = True):
global AUTH_ENGINE
succeed, explain = AUTH_ENGINE.check_secret(sec_info)
# _LOGGER.debug("get_node_description result: %s" % succeed)
if not succeed:
return False, explain
global CLUES_DAEMON
node = CLUES_DAEMON.get_node(nname)
if node is None:
return False, "node is not managed by CLUES"
if xml:
return True, node.toxml()
else:
return True, node.tokeywordstr()
def get_requests(sec_info):
global AUTH_ENGINE
succeed, explain = AUTH_ENGINE.check_secret(sec_info)
# _LOGGER.debug("get_request result: %s" % succeed)
if not succeed:
return False, explain
global CLUES_DAEMON
return True, str(CLUES_DAEMON.get_requests_list())
#--------------------
def main_loop(custom_lrms = None, custom_power_mgr = None, callback_before_loop = None, args_to_callback_before_loop = []):
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-s", "--simmulated-time", dest="RT_MODE", action="store_false", default=True, help="runs app in real time")
parser.add_option("-r", "--random-seed", dest="RANDOM_SEED", default=None, help="the seed to initialize the random number generator")
(options, args) = parser.parse_args()
if (options.RANDOM_SEED is not None):
try:
options.RANDOM_SEED=int(options.RANDOM_SEED)
except:
raise Exception("invalid random seed %s (it must be an integer)" % options.RANDOM_SEED)
import random
_LOGGER.info("initialize random seed using parameter: %ld" % options.RANDOM_SEED )
random.seed(options.RANDOM_SEED)
try:
LOG_FILE=configserver._CONFIGURATION_GENERAL.LOG_FILE
LOG_LEVEL=configserver._CONFIGURATION_GENERAL.LOG_LEVEL
except:
LOG_FILE=None
LOG_LEVEL=logging.DEBUG
# logging.basicConfig(filename=LOG_FILE,level=LOG_LEVEL,format="[%(levelname)s] %(asctime)-15s %(message)s")
cpyutils.log.Log.setup(LOG_FILE, LOG_LEVEL)
if _ERROR_IMPORTING is not None:
if isinstance(_ERROR_IMPORTING, ImportError):
logging.critical("Error starting CLUES because there is a missing class: %s" % str(_ERROR_IMPORTING))
else:
logging.critical("Error starting CLUES: %s" % str(_ERROR_IMPORTING))
sys.exit(-1)
cpyutils.eventloop.create_eventloop(options.RT_MODE)
global AUTH_ENGINE
AUTH_ENGINE = Authentication_secret(configserver._CONFIGURATION_GENERAL.CLUES_SECRET_TOKEN)
# -------------------------------------------------------------------------------
# This is how we can integrate to a ONE deployment
# i.e. monitoring the hosts
# -------------------------------------------------------------------------------
# import plugins.one
# LRMS = plugins.one.lrms()
# -------------------------------------------------------------------------------
# This is how we can integrate to a PBS deployment
# i.e. monitoring the hosts
# -------------------------------------------------------------------------------
# import plugins.pbs
# LRMS = plugins.pbs.lrms()
'''
import plugins.pbs
LRMS = plugins.pbs.lrms()
import plugins.one
POW_MGR = plugins.one.powermanager()
'''
if custom_lrms is None and configserver._CONFIGURATION_GENERAL.LRMS_CLASS == "":
logging.error("a LRMS class must be defined for CLUES, you should use LRMS_CLASS in the clues2.cfg file")
exit(-1)
if custom_power_mgr is None and configserver._CONFIGURATION_GENERAL.POWERMANAGER_CLASS == "":
logging.warning("a POWERMANAGER class must be defined for CLUES, you should use POWERMANAGER_CLASS in the clues2.cfg file")
configserver._CONFIGURATION_GENERAL.POWERMANAGER_CLASS = None
import importlib
if custom_lrms is None:
try:
LRMS_CLASS=importlib.import_module(configserver._CONFIGURATION_GENERAL.LRMS_CLASS)
_LOGGER.info("activating lrms: \"%s\"" % configserver._CONFIGURATION_GENERAL.LRMS_CLASS)
except Exception as e:
logging.error(e)
logging.error("could not import the LRMS class stated in LRMS_CLASS (%s) from the clues2.cfg file" % configserver._CONFIGURATION_GENERAL.LRMS_CLASS)
exit(-1)
if custom_power_mgr is None:
if configserver._CONFIGURATION_GENERAL.POWERMANAGER_CLASS is not None:
try:
POWERMANAGER_CLASS=importlib.import_module(configserver._CONFIGURATION_GENERAL.POWERMANAGER_CLASS)
_LOGGER.info("activating powermanager: \"%s\"" % configserver._CONFIGURATION_GENERAL.POWERMANAGER_CLASS)
except Exception as e:
logging.error(e)
logging.error("could not import the POWERMANAGER class stated in POWERMANAGER_CLASS (%s) from the clues2.cfg file" % configserver._CONFIGURATION_GENERAL.POWERMANAGER_CLASS)
exit(-1)
else:
logging.warning("it is not defined any POWERMANAGER class in the configuration file. CLUES will not be able to power on or off the nodes")
global LRMS
if custom_lrms is None:
try:
LRMS=LRMS_CLASS.lrms()
except Exception as e:
logging.error(e)
logging.error("cannot use %s as a plugin for LRMS in CLUES, because the 'lrms' class is not defined" % configserver._CONFIGURATION_GENERAL.LRMS_CLASS)
exit(-1)
else:
LRMS = custom_lrms
logging.debug("LRMS %s initialized" % LRMS.get_id())
POW_MGR = None
if custom_power_mgr is None:
if configserver._CONFIGURATION_GENERAL.POWERMANAGER_CLASS is not None:
try:
POW_MGR=POWERMANAGER_CLASS.powermanager()
except Exception as e:
logging.error(e)
logging.error("cannot use %s as a plugin for POWERMANAGER in CLUES, because the 'powermanager' class is not defined" % configserver._CONFIGURATION_GENERAL.POWERMANAGER_CLASS)
exit(-1)
else:
POW_MGR = custom_power_mgr
import clueslib.platform
# server = cpyutils.rpcweb.XMLRPCServer("localhost", configserver._CONFIGURATION_GENERAL.CLUES_PORT, web_class = clues_web_server)
server = cpyutils.rpcweb.XMLRPCServer(configserver._CONFIGURATION_GENERAL.CLUES_HOST, configserver._CONFIGURATION_GENERAL.CLUES_PORT, web_class = clues_web_server)
'''
server.register_function(qsub)
server.register_function(qstat)
server.register_function(pbsnodes)
server.register_function(cluesnodes)
'''
# Production
server.register_function(version)
server.register_function(login)
server.register_function(status)
server.register_function(poweron)
server.register_function(poweroff)
server.register_function(enable_node)
server.register_function(reset_node_state)
server.register_function(request_create)
server.register_function(request_wait)
server.register_function(request_pending)
server.register_function(get_requests)
server.register_function(get_node_description)
server.start_in_thread()
global PLATFORM
PLATFORM = clueslib.platform.Platform(LRMS, POW_MGR)
from clueslib.cluesd import CluesDaemon
global CLUES_DAEMON
# Here we will instantiate the schedulers
active_schedulers = []
scheduler_classes = configserver.config_scheduling.SCHEDULER_CLASSES.split(",")
for sclass in scheduler_classes:
sclass = sclass.strip()
valid_scheduler = False
try:
_LOGGER.debug("loading class %s for scheduling" % sclass)
class_name = clueslib.helpers.str_to_class(sclass)
valid_scheduler = True
except NameError:
_LOGGER.error("CLUES does not have access to class \"%s\" to create the scheduler" % sclass)
except TypeError:
_LOGGER.error("\"%s\" is not a valid class to create the scheduler" % sclass)
if valid_scheduler:
current_scheduler = class_name()
if not isinstance(current_scheduler, clueslib.schedulers.CLUES_Scheduler):
_LOGGER.error("ignoring scheduler \"%s\" because it is not a valid class to create the scheduler" % sclass)
else:
_LOGGER.info("Activating scheduler \"%s\"" % sclass)
active_schedulers.append(current_scheduler)
CLUES_DAEMON = CluesDaemon(PLATFORM, active_schedulers)
_LOGGER.debug("CLUES server starting")
if callback_before_loop is not None:
callback_before_loop(*args_to_callback_before_loop)
CLUES_DAEMON.loop(options.RT_MODE)
if __name__ == '__main__':
main_loop()