X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=openmanod.py;h=6df29d116b50820d23c5262783d19335f81f9f5b;hb=1f3a67138592443a8bd68ab936e071cb5bccda55;hp=dbd7737e8f8d6a6a4b8f5fbed13708d9b111d6b3;hpb=205d102de8f7d0bc69aacd323ef2386e71276da6;p=osm%2FRO.git diff --git a/openmanod.py b/openmanod.py index dbd7737e..6df29d11 100755 --- a/openmanod.py +++ b/openmanod.py @@ -33,9 +33,9 @@ It loads the configuration file and launches the http_server thread that will li ''' __author__="Alfonso Tierno, Gerardo Garcia, Pablo Montes" __date__ ="$26-aug-2014 11:09:29$" -__version__="0.4.44-r482" -version_date="Jul 2016" -database_version="0.11" #expected database schema version +__version__="0.4.60-r503" +version_date="Sep 2016" +database_version="0.15" #expected database schema version import httpserver import time @@ -59,10 +59,9 @@ class LoadConfigurationException(Exception): def load_configuration(configuration_file): default_tokens ={'http_port':9090, 'http_host':'localhost', + 'http_console_proxy': True, + 'http_console_host': None, 'log_level': 'DEBUG', - 'log_level_db': 'ERROR', - 'log_level_vimconn': 'DEBUG', - 'log_level_nfvo': 'DEBUG', 'log_socket_port': 9022, } try: @@ -123,9 +122,9 @@ def usage(): print( " -p|--port [port_number]: changes port number and overrides the port number in the configuration file (default: 9090)") print( " -P|--adminport [port_number]: changes admin port number and overrides the port number in the configuration file (default: 9095)") #print( " -V|--vnf-repository: changes the path of the vnf-repository and overrides the path in the configuration file") - print( " --log-socket-host: send logs to this host") - print( " --log-socket-port: send logs using this port (default: 9022)") - print( " --log-file: send logs to this file") + print( " --log-socket-host HOST: send logs to this host") + print( " --log-socket-port PORT: send logs using this port (default: 9022)") + print( " --log-file FILE: send logs to this file") return if __name__=="__main__": @@ -147,7 +146,7 @@ if __name__=="__main__": # Read parameters and configuration file try: #load parameters and configuration - opts, args = getopt.getopt(sys.argv[1:], "hvc:V:p:P:", ["config", "help", "version", "port", "vnf-repository", "adminport", "log-socket-host=", "log-socket-port=", "log-file="]) + opts, args = getopt.getopt(sys.argv[1:], "hvc:V:p:P:", ["config=", "help", "version", "port=", "vnf-repository=", "adminport=", "log-socket-host=", "log-socket-port=", "log-file="]) port=None port_admin = None config_file = 'openmanod.cfg' @@ -174,7 +173,7 @@ if __name__=="__main__": port_admin = a elif o == "--log-socket-port": log_socket_port = a - elif o == "--log-socket-port": + elif o == "--log-socket-host": log_socket_host = a elif o == "--log-file": log_file = a @@ -211,6 +210,10 @@ if __name__=="__main__": global_config["console_port_iterator"] = console_port_iterator global_config["console_thread"]={} global_config["console_ports"]={} + if not global_config["http_console_host"]: + global_config["http_console_host"] = global_config["http_host"] + if global_config["http_host"]=="0.0.0.0": + global_config["http_console_host"] = socket.gethostname() #Configure logging STEP 2 if "log_host" in global_config: @@ -225,16 +228,35 @@ if __name__=="__main__": file_handler= logging.handlers.RotatingFileHandler(global_config["log_file"], maxBytes=100e6, backupCount=9, delay=0) file_handler.setFormatter(log_formatter_simple) logger.addHandler(file_handler) - logger.debug("moving logs to '%s'", global_config["log_file"]) - #remove initial strema handler + #logger.debug("moving logs to '%s'", global_config["log_file"]) + #remove initial stream handler logging.root.removeHandler(logging.root.handlers[0]) + print ("logging on '{}'".format(global_config["log_file"])) except IOError as e: raise LoadConfigurationException("Cannot open logging file '{}': {}. Check folder exist and permissions".format(global_config["log_file"], str(e)) ) #logging.basicConfig(level = getattr(logging, global_config.get('log_level',"debug"))) logger.setLevel(getattr(logging, global_config['log_level'])) + logger.critical("Starting openmano server command: '%s'", sys.argv[0]) + + for log_module in ("nfvo", "http", "vim", "db"): + log_level_module = "log_level_" + log_module + log_file_module = "log_file_" + log_module + logger_module = logging.getLogger('openmano.' + log_module) + if log_level_module in global_config: + logger_module.setLevel(global_config[log_level_module]) + if log_file_module in global_config: + try: + file_handler= logging.handlers.RotatingFileHandler(global_config[log_file_module], maxBytes=100e6, backupCount=9, delay=0) + file_handler.setFormatter(log_formatter_simple) + logger_module.addHandler(file_handler) + except IOError as e: + raise LoadConfigurationException("Cannot open logging file '{}': {}. Check folder exist and permissions".format(global_config[log_file_module], str(e)) ) + global_config["logger_"+log_module] = logger_module + #httpserver.logger = global_config["logger_http"] + #nfvo.logger = global_config["logger_nfvo"] # Initialize DB connection - mydb = nfvo_db.nfvo_db(log_level=global_config["log_level_db"]); + mydb = nfvo_db.nfvo_db(); if mydb.connect(global_config['db_host'], global_config['db_user'], global_config['db_passwd'], global_config['db_name']) == -1: logger.critical("Cannot connect to database %s at %s@%s", global_config['db_name'], global_config['db_user'], global_config['db_host']) exit(-1)