blob: 9f03cf0989e95a56708983f8f029ec5afa144db2 [file] [log] [blame]
Zsolt Harasztib71c2a02016-09-12 13:12:07 -07001#!/usr/bin/env python
2#
3# Copyright 2016 the original author or authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
Zsolt Harasztiadbb88d2016-09-12 21:24:57 -070018"""Virtual OLT Hardware Abstraction main entry point"""
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070019
20import argparse
Zsolt Harasztid7c7c482016-09-13 00:45:38 -070021import os
22
23import yaml
Zsolt Harasztiadbb88d2016-09-12 21:24:57 -070024
25from structlog_setup import setup_logging, DEFAULT_FLUENT_SERVER
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070026
27
28def parse_args():
29
30 parser = argparse.ArgumentParser()
31
Zsolt Harasztid7c7c482016-09-13 00:45:38 -070032 # generic parameters
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070033 parser.add_argument('--no-banner', dest='no_banner', action='store_true', default=False,
34 help='omit startup banner log lines')
35 parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', default=False,
Zsolt Haraszti59b7a882016-09-12 14:42:59 -070036 help='enable verbose logging')
37 parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', default=False,
38 help="suppress debug and info logs")
Zsolt Harasztid7c7c482016-09-13 00:45:38 -070039 parser.add_argument('-c', '--config', dest='config', action='store', default='./voltha.yml',
40 help='Path to voltha.yml config file. If relative, it is relative to main.py of voltha')
Zsolt Harasztiadbb88d2016-09-12 21:24:57 -070041
42 # placeholder
43 parser.add_argument('-i', '--interface', dest='interface', action='store', default='eth0',
44 help='ETH interface to send (default: eth0)')
45
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070046 return parser.parse_args()
47
48
Zsolt Harasztid7c7c482016-09-13 00:45:38 -070049def load_config(args):
50 path = args.config
51 if path.startswith('.'):
52 dir = os.path.dirname(os.path.abspath(__file__))
53 path = os.path.join(dir, path)
54 path = os.path.abspath(path)
55 with open(path) as fd:
56 config = yaml.load(fd)
57 return config
58
59
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070060def print_banner(args, log):
61 log.info(' _ ______ __ ________ _____ ')
62 log.info('| | / / __ \/ / /_ __/ / / / |')
63 log.info('| | / / / / / / / / / /_/ / /| |')
64 log.info('| |/ / /_/ / /___/ / / __ / ___ |')
65 log.info('|___/\____/_____/_/ /_/ /_/_/ |_|')
Zsolt Haraszti59b7a882016-09-12 14:42:59 -070066 log.info('(to stop: press Ctrl-C)')
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070067
68
69def cleanup(log):
70 """Execute before the reactor is shut down"""
71 log.info('exiting-on-keyboard-interrupt')
72
73
74def start_reactor(args, log):
75 from twisted.internet import reactor
76 reactor.callWhenRunning(lambda: log.info('twisted-reactor-started'))
77 reactor.addSystemEventTrigger('before', 'shutdown', lambda: cleanup(log))
78 reactor.run()
79
80
81def main():
82 args = parse_args()
Zsolt Harasztid7c7c482016-09-13 00:45:38 -070083 config = load_config(args)
84 log = setup_logging(config.get('logging', {}))
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070085 if not args.no_banner:
86 print_banner(args, log)
87 start_reactor(args, log) # will not return except Keyboard interrupt
88
89
90if __name__ == '__main__':
91 main()