diff options
author | Niko Hermanns <nikolas.hermanns@ericsson.com> | 2016-11-30 11:59:44 +0100 |
---|---|---|
committer | Nikolas Hermanns <nikolas.hermanns@ericsson.com> | 2016-12-13 11:26:00 +0100 |
commit | 416f9cf177801cecfe39f5249d73e3a4a85f0bbd (patch) | |
tree | bea48ec45edc10489aa76d348b0dbfbb1cf4d7ab /odl-pipeline/lib/utils/service.py | |
parent | b9eb7024b014cba0d299b1cf3b01e179c7d0482e (diff) |
adding odl-pipeline
Change-Id: I1c08883f0d68a61ce9e10c5596aec1a259eed71f
Signed-off-by: Nikolas Hermanns <nikolas.hermanns@ericsson.com>
Diffstat (limited to 'odl-pipeline/lib/utils/service.py')
-rwxr-xr-x | odl-pipeline/lib/utils/service.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/odl-pipeline/lib/utils/service.py b/odl-pipeline/lib/utils/service.py new file mode 100755 index 0000000..39cdce5 --- /dev/null +++ b/odl-pipeline/lib/utils/service.py @@ -0,0 +1,67 @@ +# +# Copyright (c) 2015 All rights reserved +# This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# +import sys +import yaml +import argparse +import traceback +from utils_log import LOG, LOG_PATH +from abc import abstractmethod + + +class Service(object): + + def start(self): + try: + self._run() + except Exception as ex: + LOG.error(ex.message) + LOG.error(traceback.format_exc()) + LOG.error("For more logs check: %(log_path)s" + % {'log_path': LOG_PATH}) + sys.exit(1) + + def _run(self): + parser = self._create_cli_parser() + sys_args = parser.parse_args() + config = self.read_config(sys_args) + self.run(sys_args, config) + + @abstractmethod + def run(self, sys_args, config): + # Do something + return + + @abstractmethod + def create_cli_parser(self, parser): + # Read in own sys args + return parser + + def _create_cli_parser(self): + parser = argparse.ArgumentParser(description='OVS Debugger') + # parser.add_argument('-c', '--config', help="Path to config.yaml", + # required=False) + # parser.add_argument('--boolean', help="", + # required=False, action='store_true') + return self.create_cli_parser(parser) + + def read_config(self, sys_args): + if not hasattr(sys_args, 'config'): + return None + if not sys_args.config: + config_path = './etc/config.yaml' + else: + config_path = sys_args.config + try: + with open(config_path) as f: + return yaml.load(f) + except yaml.scanner.ScannerError as ex: + LOG.error("Yaml file corrupt. Try putting spaces after the " + "colons.") + raise ex |