This repository was archived by the owner on Sep 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathrun.py
More file actions
85 lines (62 loc) · 2.52 KB
/
run.py
File metadata and controls
85 lines (62 loc) · 2.52 KB
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
'''
Copyright (c) 2012 Sven Reissmann <sven@0x80.io>
This file is part of the PyTgen traffic generator.
PyTgen 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.
PyTgen 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 PyTgen. If not, see <http://www.gnu.org/licenses/>.
'''
import logging
import signal
import platform
import core.runner
import core.scheduler
from core.generator import *
def create_jobs():
logging.getLogger('main').info('Creating jobs')
jobs = []
for next_job in Conf.jobdef:
logging.getLogger('main').info('creating %s', next_job)
job = core.scheduler.job(name = next_job[0],
action = eval(next_job[0])(next_job[2]),
interval = next_job[1][2],
start = next_job[1][0],
end = next_job[1][1])
jobs.append(job)
return jobs
if __name__ == '__main__':
# set hostbased parameters
hostname = platform.node()
log_file = 'logs/' + hostname + '.log'
config_file = "configs." + hostname
# load the hostbased configuration file
_Conf = __import__(config_file, globals(), locals(), ['Conf'], -1)
Conf = _Conf.Conf
# start logger
logging.basicConfig(level = Conf.loglevel,
format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt = '%Y-%m-%d %H:%M:%S',
filename = log_file)
logging.getLogger('main').info('Configuration %s loaded', config_file)
# start runner, create jobs, start scheduling
runner = core.runner(maxthreads = Conf.maxthreads)
jobs = create_jobs()
scheduler = core.scheduler(jobs = jobs,
runner = runner)
# Stop scheduler on exit
def signal_int(signal, frame):
logging.getLogger('main').info('Stopping scheduler')
scheduler.stop()
signal.signal(signal.SIGINT, signal_int)
# Run the scheduler
logging.getLogger('main').info('Starting scheduler')
scheduler.start()
scheduler.join(2 ** 31)
# Stop the runner
runner.stop()