| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
| 4 | ## |
| 5 | # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 6 | # This file is part of openvim |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 7 | # All Rights Reserved. |
| 8 | # |
| 9 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 10 | # not use this file except in compliance with the License. You may obtain |
| 11 | # a copy of the License at |
| 12 | # |
| 13 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | # |
| 15 | # Unless required by applicable law or agreed to in writing, software |
| 16 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 18 | # License for the specific language governing permissions and limitations |
| 19 | # under the License. |
| 20 | # |
| 21 | # For those usages not covered by the Apache License, Version 2.0 please |
| 22 | # contact with: nfvlabs@tid.es |
| 23 | ## |
| 24 | |
| tierno | 5106895 | 2017-04-26 15:09:48 +0200 | [diff] [blame] | 25 | """ |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 26 | This is the main program of openvim, it reads the configuration |
| 27 | and launches the rest of threads: http clients, openflow controller |
| 28 | and host controllers |
| tierno | 5106895 | 2017-04-26 15:09:48 +0200 | [diff] [blame] | 29 | """ |
| mirabal | 50a052f | 2017-03-27 18:08:07 +0200 | [diff] [blame] | 30 | |
| mirabal | 9f65710 | 2017-04-10 20:05:40 +0200 | [diff] [blame] | 31 | import osm_openvim.httpserver as httpserver |
| 32 | import osm_openvim.auxiliary_functions as af |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 33 | import sys |
| 34 | import getopt |
| 35 | import time |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 36 | import yaml |
| 37 | import os |
| 38 | from jsonschema import validate as js_v, exceptions as js_e |
| tierno | 5106895 | 2017-04-26 15:09:48 +0200 | [diff] [blame] | 39 | from osm_openvim.vim_schema import config_schema |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 40 | import logging |
| tierno | f13617a | 2016-09-08 11:42:10 +0200 | [diff] [blame] | 41 | import logging.handlers as log_handlers |
| tierno | f13617a | 2016-09-08 11:42:10 +0200 | [diff] [blame] | 42 | import socket |
| mirabal | 9f65710 | 2017-04-10 20:05:40 +0200 | [diff] [blame] | 43 | import osm_openvim.ovim as ovim |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 44 | |
| tierno | 5106895 | 2017-04-26 15:09:48 +0200 | [diff] [blame] | 45 | __author__ = "Alfonso Tierno" |
| 46 | __date__ = "$10-jul-2014 12:07:15$" |
| 47 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 48 | global config_dic |
| 49 | global logger |
| 50 | logger = logging.getLogger('vim') |
| 51 | |
| mirabal | 9f65710 | 2017-04-10 20:05:40 +0200 | [diff] [blame] | 52 | |
| tierno | f13617a | 2016-09-08 11:42:10 +0200 | [diff] [blame] | 53 | class LoadConfigurationException(Exception): |
| 54 | pass |
| 55 | |
| mirabal | 9f65710 | 2017-04-10 20:05:40 +0200 | [diff] [blame] | 56 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 57 | def load_configuration(configuration_file): |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 58 | default_tokens = {'http_port': 9080, 'http_host': 'localhost', |
| 59 | 'of_controller_nets_with_same_vlan': True, |
| 60 | 'host_ssh_keyfile': None, |
| 61 | 'network_vlan_range_start': 1000, |
| 62 | 'network_vlan_range_end': 4096, |
| 63 | 'log_level': "DEBUG", |
| 64 | 'log_level_db': "ERROR", |
| 65 | 'log_level_of': 'ERROR', |
| 66 | 'bridge_ifaces': {}, |
| 67 | 'network_type': 'ovs', |
| 68 | 'ovs_controller_user': 'osm_dhcp', |
| 69 | 'ovs_controller_file_path': '/var/lib/', |
| 70 | } |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 71 | try: |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 72 | # First load configuration from configuration file |
| 73 | # Check config file exists |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 74 | if not os.path.isfile(configuration_file): |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 75 | raise LoadConfigurationException("Configuration file '{}' does not exists".format(configuration_file)) |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 76 | |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 77 | # Read and parse file |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 78 | (return_status, code) = af.read_file(configuration_file) |
| 79 | if not return_status: |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 80 | raise LoadConfigurationException("Error loading configuration file '{}': {}".format( |
| 81 | configuration_file, code)) |
| 82 | config = yaml.load(code) |
| 83 | js_v(config, config_schema) |
| 84 | # Check default values tokens |
| 85 | for k, v in default_tokens.items(): |
| 86 | if k not in config: |
| 87 | config[k] = v |
| 88 | # Check vlan ranges |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 89 | if config["network_vlan_range_start"] + 10 >= config["network_vlan_range_end"]: |
| 90 | raise LoadConfigurationException( |
| 91 | "Error at configuration file '{}'. Invalid network_vlan_range less than 10 elements".format( |
| 92 | configuration_file)) |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 93 | return config |
| 94 | except yaml.YAMLError as exc: |
| 95 | error_pos = "" |
| 96 | if hasattr(exc, 'problem_mark'): |
| 97 | mark = exc.problem_mark |
| 98 | error_pos = " at position: ({}:{})".format(mark.line + 1, mark.column + 1) |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 99 | raise LoadConfigurationException("Bad YAML format at configuration file '{}'{}: {}\n" |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 100 | "Use a valid yaml format. Indentation matters, " |
| 101 | "and tabs characters are not valid".format( |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 102 | configuration_file, error_pos, exc)) |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 103 | except js_e.ValidationError as exc: |
| 104 | error_pos = "" |
| 105 | if len(exc.path) > 0: |
| 106 | error_pos = " at '{}'".format(":".join(map(str, exc.path))) |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 107 | raise LoadConfigurationException("Invalid field at configuration file '{}'{}: {}".format( |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 108 | configuration_file, error_pos, exc)) |
| 109 | |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 110 | # except Exception as e: |
| 111 | # raise LoadConfigurationException("Error loading configuration file '{}': {}".format(configuration_file, e)) |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 112 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 113 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 114 | def usage(): |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 115 | print ("Usage: {} [options]".format(sys.argv[0])) |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 116 | print (" -v|--version: prints current version") |
| 117 | print (" -c|--config FILE: loads the configuration file (default: osm_openvim/openvimd.cfg)") |
| 118 | print (" -h|--help: shows this help") |
| 119 | print (" -p|--port PORT: changes port number and overrides the port number in the configuration file " |
| 120 | "(default: 908)") |
| 121 | print (" -P|--adminport PORT: changes admin port number and overrides the port number in the configuration " |
| 122 | "file (default: not listen)") |
| 123 | print (" --dbname NAME: changes db_name and overrides the db_name in the configuration file") |
| 124 | # print( " --log-socket-host HOST: send logs to this host") |
| 125 | # print( " --log-socket-port PORT: send logs using this port (default: 9022)") |
| 126 | print (" --log-file FILE: send logs to this file") |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 127 | return |
| 128 | |
| 129 | |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 130 | def set_logging_file(log_file): |
| 131 | try: |
| 132 | file_handler = logging.handlers.RotatingFileHandler(log_file, maxBytes=100e6, backupCount=9, delay=0) |
| 133 | file_handler.setFormatter(log_formatter_simple) |
| 134 | logger.addHandler(file_handler) |
| 135 | # logger.debug("moving logs to '%s'", global_config["log_file"]) |
| 136 | # remove initial stream handler |
| 137 | logging.root.removeHandler(logging.root.handlers[0]) |
| 138 | print ("logging on '{}'".format(log_file)) |
| 139 | except IOError as e: |
| 140 | raise LoadConfigurationException( |
| 141 | "Cannot open logging file '{}': {}. Check folder exist and permissions".format(log_file, e)) |
| 142 | |
| 143 | |
| 144 | if __name__ == "__main__": |
| tierno | f13617a | 2016-09-08 11:42:10 +0200 | [diff] [blame] | 145 | hostname = socket.gethostname() |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 146 | # streamformat = "%(levelname)s (%(module)s:%(lineno)d) %(message)s" |
| 147 | log_formatter_complete = logging.Formatter('%(asctime)s.%(msecs)03d00Z[{host}@openmanod] %(filename)s:%(lineno)s ' |
| 148 | 'severity:%(levelname)s logger:%(name)s log:%(message)s'.format( |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 149 | host=hostname), |
| 150 | datefmt='%Y-%m-%dT%H:%M:%S') |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 151 | log_format_simple = "%(asctime)s %(levelname)s %(name)s %(filename)s:%(lineno)s %(message)s" |
| tierno | f13617a | 2016-09-08 11:42:10 +0200 | [diff] [blame] | 152 | log_formatter_simple = logging.Formatter(log_format_simple, datefmt='%Y-%m-%dT%H:%M:%S') |
| tierno | 5106895 | 2017-04-26 15:09:48 +0200 | [diff] [blame] | 153 | logging.basicConfig(format=log_format_simple, level=logging.DEBUG) |
| tierno | 57f7bda | 2017-02-09 12:01:55 +0100 | [diff] [blame] | 154 | logger = logging.getLogger('openvim') |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 155 | logger.setLevel(logging.DEBUG) |
| 156 | try: |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 157 | opts, args = getopt.getopt(sys.argv[1:], "hvc:p:P:", |
| 158 | ["config=", "help", "version", "port=", "adminport=", "log-file=", "dbname="]) |
| 159 | except getopt.GetoptError as err: |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 160 | # print help information and exit: |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 161 | logger.error("%s. Type -h for help", err) # will print something like "option -a not recognized" |
| 162 | # usage() |
| 163 | sys.exit(2) |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 164 | |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 165 | port = None |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 166 | port_admin = None |
| tierno | 5106895 | 2017-04-26 15:09:48 +0200 | [diff] [blame] | 167 | config_file = 'osm_openvim/openvimd.cfg' |
| tierno | f13617a | 2016-09-08 11:42:10 +0200 | [diff] [blame] | 168 | log_file = None |
| tierno | a36d64d | 2016-09-14 15:58:40 +0200 | [diff] [blame] | 169 | db_name = None |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 170 | |
| 171 | for o, a in opts: |
| 172 | if o in ("-v", "--version"): |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 173 | print ("openvimd version {} {}".format(ovim.ovim.get_version(), ovim.ovim.get_version_date())) |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 174 | print ("(c) Copyright Telefonica") |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 175 | sys.exit(0) |
| 176 | elif o in ("-h", "--help"): |
| 177 | usage() |
| 178 | sys.exit(0) |
| 179 | elif o in ("-c", "--config"): |
| 180 | config_file = a |
| 181 | elif o in ("-p", "--port"): |
| 182 | port = a |
| 183 | elif o in ("-P", "--adminport"): |
| 184 | port_admin = a |
| tierno | a36d64d | 2016-09-14 15:58:40 +0200 | [diff] [blame] | 185 | elif o in ("-P", "--dbname"): |
| 186 | db_name = a |
| tierno | f13617a | 2016-09-08 11:42:10 +0200 | [diff] [blame] | 187 | elif o == "--log-file": |
| 188 | log_file = a |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 189 | else: |
| 190 | assert False, "Unhandled option" |
| 191 | |
| tierno | 57f7bda | 2017-02-09 12:01:55 +0100 | [diff] [blame] | 192 | engine = None |
| tierno | 56c0c28 | 2017-02-10 14:52:55 +0100 | [diff] [blame] | 193 | http_thread = None |
| 194 | http_thread_admin = None |
| 195 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 196 | try: |
| tierno | f13617a | 2016-09-08 11:42:10 +0200 | [diff] [blame] | 197 | if log_file: |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 198 | set_logging_file(log_file) |
| 199 | # Load configuration file |
| 200 | config_dic = load_configuration(config_file) |
| 201 | if config_dic.get("dhcp_server"): |
| 202 | if config_dic["dhcp_server"].get("key"): |
| 203 | config_dic["dhcp_server"]["keyfile"] = config_dic["dhcp_server"].pop("key") |
| 204 | if config_dic.get("image_path"): |
| 205 | config_dic["host_image_path"] = config_dic.pop("image_path") |
| 206 | elif not config_dic.get("host_image_path"): |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 207 | config_dic["host_image_path"] = '/opt/VNF/images' # default value |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 208 | # print config_dic |
| tierno | f13617a | 2016-09-08 11:42:10 +0200 | [diff] [blame] | 209 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 210 | logger.setLevel(getattr(logging, config_dic['log_level'])) |
| tierno | f13617a | 2016-09-08 11:42:10 +0200 | [diff] [blame] | 211 | logger.critical("Starting openvim server command: '%s'", sys.argv[0]) |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 212 | # override parameters obtained by command line |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 213 | if port: |
| tierno | a36d64d | 2016-09-14 15:58:40 +0200 | [diff] [blame] | 214 | config_dic['http_port'] = port |
| 215 | if port_admin: |
| 216 | config_dic['http_admin_port'] = port_admin |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 217 | if db_name: |
| tierno | a36d64d | 2016-09-14 15:58:40 +0200 | [diff] [blame] | 218 | config_dic['db_name'] = db_name |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 219 | |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 220 | # check mode |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 221 | if 'mode' not in config_dic: |
| 222 | config_dic['mode'] = 'normal' |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 223 | # allow backward compatibility of test_mode option |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 224 | if 'test_mode' in config_dic and config_dic['test_mode'] == True: |
| 225 | config_dic['mode'] = 'test' |
| Mirabal | 7256d6b | 2016-12-15 10:51:19 +0000 | [diff] [blame] | 226 | if config_dic['mode'] == 'development' and config_dic['network_type'] == 'bridge' and \ |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 227 | ('development_bridge' not in config_dic or |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 228 | config_dic['development_bridge'] not in config_dic.get("bridge_ifaces", None)): |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 229 | error_msg = "'{}' is not a valid 'development_bridge', not one of the 'bridge_ifaces'".format(config_file) |
| 230 | print (error_msg) |
| 231 | logger.error(error_msg) |
| 232 | exit(1) |
| Mirabal | e9317ff | 2017-01-18 16:10:58 +0000 | [diff] [blame] | 233 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 234 | if config_dic['mode'] != 'normal': |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 235 | print ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') |
| 236 | print ("!! Warning, openvimd in TEST mode '{}'".format(config_dic['mode'])) |
| 237 | print ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') |
| tierno | 2db743b | 2017-03-28 17:23:15 +0200 | [diff] [blame] | 238 | config_dic['version'] = ovim.ovim.get_version() |
| tierno | 57f7bda | 2017-02-09 12:01:55 +0100 | [diff] [blame] | 239 | config_dic["logger_name"] = "openvim" |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 240 | |
| tierno | 57f7bda | 2017-02-09 12:01:55 +0100 | [diff] [blame] | 241 | engine = ovim.ovim(config_dic) |
| 242 | engine.start_service() |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 243 | |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 244 | # Create thread to listen to web requests |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 245 | http_thread = httpserver.httpserver(engine, 'http', config_dic['http_host'], config_dic['http_port'], |
| 246 | False, config_dic) |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 247 | http_thread.start() |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 248 | |
| tierno | 57f7bda | 2017-02-09 12:01:55 +0100 | [diff] [blame] | 249 | if 'http_admin_port' in config_dic: |
| 250 | engine2 = ovim.ovim(config_dic) |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 251 | http_thread_admin = httpserver.httpserver(engine2, 'http-admin', config_dic['http_host'], |
| 252 | config_dic['http_admin_port'], True) |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 253 | http_thread_admin.start() |
| 254 | else: |
| 255 | http_thread_admin = None |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 256 | time.sleep(1) |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 257 | logger.info('Waiting for http clients') |
| 258 | print ('openvimd ready') |
| 259 | print ('====================') |
| 260 | sys.stdout.flush() |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 261 | |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 262 | # TODO: Interactive console would be nice here instead of join or sleep |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 263 | |
| 264 | r = "" |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 265 | while True: |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 266 | if r == 'exit': |
| 267 | break |
| 268 | elif r != '': |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 269 | print "type 'exit' for terminate" |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 270 | try: |
| 271 | r = raw_input('> ') |
| 272 | except EOFError: |
| 273 | time.sleep(86400) |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 274 | |
| 275 | except (KeyboardInterrupt, SystemExit): |
| 276 | pass |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 277 | except (getopt.GetoptError, LoadConfigurationException, ovim.ovimException) as e: |
| tierno | 86b8dd1 | 2017-05-26 13:16:40 +0200 | [diff] [blame^] | 278 | logger.critical(str(e)) # will print something like "option -a not recognized" |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 279 | exit(1) |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 280 | |
| 281 | logger.info('Exiting openvimd') |
| tierno | 57f7bda | 2017-02-09 12:01:55 +0100 | [diff] [blame] | 282 | if engine: |
| 283 | engine.stop_service() |
| tierno | 56c0c28 | 2017-02-10 14:52:55 +0100 | [diff] [blame] | 284 | if http_thread: |
| 285 | http_thread.join(1) |
| 286 | if http_thread_admin: |
| 287 | http_thread_admin.join(1) |
| tierno | a693304 | 2017-05-24 16:54:33 +0200 | [diff] [blame] | 288 | logger.debug("bye!") |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 289 | exit() |