<s> '''<STR_LIT>''' <EOL> __author__ = "<STR_LIT>" <EOL> __date__ = "<STR_LIT>" <EOL> __version__ = "<STR_LIT>" <EOL> version_date = "<STR_LIT>" <EOL> database_version = "<STR_LIT>" <EOL> import httpserver <EOL> import time <EOL> import os <EOL> import sys <EOL> import getopt <EOL> import yaml <EOL> import nfvo_db <EOL> from jsonschema import validate as js_v , exceptions as js_e <EOL> from utils import auxiliary_functions as af <EOL> from openmano_schemas import config_schema <EOL> import nfvo <EOL> global global_config <EOL> def load_configuration ( configuration_file ) : <EOL> default_tokens = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : '<STR_LIT:localhost>' } <EOL> try : <EOL> if not os . path . isfile ( configuration_file ) : <EOL> return ( False , "<STR_LIT>" + configuration_file + "<STR_LIT>" ) <EOL> ( return_status , code ) = af . read_file ( configuration_file ) <EOL> if not return_status : <EOL> return ( return_status , "<STR_LIT>" + configuration_file + "<STR_LIT>" + code ) <EOL> try : <EOL> config = yaml . load ( code ) <EOL> except yaml . YAMLError , exc : <EOL> error_pos = "<STR_LIT>" <EOL> if hasattr ( exc , '<STR_LIT>' ) : <EOL> mark = exc . problem_mark <EOL> error_pos = "<STR_LIT>" % ( mark . line + <NUM_LIT:1> , mark . column + <NUM_LIT:1> ) <EOL> return ( False , "<STR_LIT>" + configuration_file + "<STR_LIT:'>" + error_pos + "<STR_LIT>" ) <EOL> try : <EOL> js_v ( config , config_schema ) <EOL> except js_e . ValidationError , exc : <EOL> error_pos = "<STR_LIT>" <EOL> if len ( exc . path ) > <NUM_LIT:0> : error_pos = "<STR_LIT>" + "<STR_LIT::>" . join ( map ( str , exc . path ) ) + "<STR_LIT:'>" <EOL> return False , "<STR_LIT>" + configuration_file + "<STR_LIT:'>" + error_pos + "<STR_LIT>" + exc . message <EOL> for k , v in default_tokens . items ( ) : <EOL> if k not in config : config [ k ] = v <EOL> except Exception , e : <EOL> return ( False , "<STR_LIT>" + configuration_file + "<STR_LIT>" + str ( e ) ) <EOL> return ( True , config ) <EOL> def console_port_iterator ( ) : <EOL> '''<STR_LIT>''' <EOL> index = <NUM_LIT:0> <EOL> while index < len ( global_config [ "<STR_LIT>" ] ) : <EOL> port = global_config [ "<STR_LIT>" ] [ index ] <EOL> if type ( port ) is int : <EOL> yield port <EOL> else : <EOL> port2 = port [ "<STR_LIT>" ] <EOL> while port2 <= port [ "<STR_LIT:to>" ] : <EOL> print "<STR_LIT>" , port , port2 <EOL> yield port2 <EOL> port2 += <NUM_LIT:1> <EOL> index += <NUM_LIT:1> <EOL> def usage ( ) : <EOL> print "<STR_LIT>" , sys . argv [ <NUM_LIT:0> ] , "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> return <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> try : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:version>" , "<STR_LIT:port>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> except getopt . GetoptError as err : <EOL> print "<STR_LIT>" , err <EOL> usage ( ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> port = None <EOL> port_admin = None <EOL> config_file = '<STR_LIT>' <EOL> vnf_repository = None <EOL> for o , a in opts : <EOL> if o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> print "<STR_LIT>" , __version__ , version_date <EOL> print "<STR_LIT>" <EOL> sys . exit ( ) <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> usage ( ) <EOL> sys . exit ( ) <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> vnf_repository = a <EOL> elif o in ( "<STR_LIT:-c>" , "<STR_LIT>" ) : <EOL> config_file = a <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> port = a <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> port_admin = a <EOL> else : <EOL> assert False , "<STR_LIT>" <EOL> try : <EOL> r , global_config = load_configuration ( config_file ) <EOL> if not r : <EOL> print global_config <EOL> exit ( - <NUM_LIT:1> ) <EOL> if port is not None : global_config [ '<STR_LIT>' ] = port <EOL> if port_admin is not None : global_config [ '<STR_LIT>' ] = port_admin <EOL> if vnf_repository is not None : <EOL> global_config [ '<STR_LIT>' ] = vnf_repository <EOL> else : <EOL> if not '<STR_LIT>' in global_config : <EOL> print os . getcwd ( ) <EOL> global_config [ '<STR_LIT>' ] = os . getcwd ( ) + '<STR_LIT>' <EOL> if not os . path . exists ( global_config [ '<STR_LIT>' ] ) : <EOL> print "<STR_LIT>" % global_config [ '<STR_LIT>' ] <EOL> try : <EOL> os . makedirs ( global_config [ '<STR_LIT>' ] ) <EOL> except Exception , e : <EOL> print "<STR_LIT>" % ( e . args [ <NUM_LIT:1> ] , config_file ) <EOL> exit ( - <NUM_LIT:1> ) <EOL> global_config [ "<STR_LIT>" ] = console_port_iterator <EOL> global_config [ "<STR_LIT>" ] = { } <EOL> global_config [ "<STR_LIT>" ] = { } <EOL> mydb = nfvo_db . nfvo_db ( ) ; <EOL> if mydb . connect ( global_config [ '<STR_LIT>' ] , global_config [ '<STR_LIT>' ] , global_config [ '<STR_LIT>' ] , global_config [ '<STR_LIT>' ] ) == - <NUM_LIT:1> : <EOL> print "<STR_LIT>" , global_config [ '<STR_LIT>' ] , "<STR_LIT>" , global_config [ '<STR_LIT>' ] , "<STR_LIT:@>" , global_config [ '<STR_LIT>' ] <EOL> exit ( - <NUM_LIT:1> ) <EOL> r = mydb . get_db_version ( ) <EOL> if r [ <NUM_LIT:0> ] < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % database_version <EOL> exit ( - <NUM_LIT:1> ) <EOL> elif r [ <NUM_LIT:1> ] != database_version : <EOL> print "<STR_LIT>" % ( r [ <NUM_LIT:1> ] , database_version ) <EOL> exit ( - <NUM_LIT:1> ) <EOL> nfvo . global_config = global_config <EOL> httpthread = httpserver . httpserver ( mydb , False , global_config [ '<STR_LIT>' ] , global_config [ '<STR_LIT>' ] ) <EOL> httpthread . start ( ) <EOL> if '<STR_LIT>' in global_config : <EOL> httpthreadadmin = httpserver . httpserver ( mydb , True , global_config [ '<STR_LIT>' ] , global_config [ '<STR_LIT>' ] ) <EOL> httpthreadadmin . start ( ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> time . sleep ( <NUM_LIT:20> ) <EOL> sys . stdout . flush ( ) <EOL> while True : <EOL> time . sleep ( <NUM_LIT> ) <EOL> for thread in global_config [ "<STR_LIT>" ] : <EOL> thread . terminate = True <EOL> except ( KeyboardInterrupt , SystemExit ) : <EOL> print '<STR_LIT>' <EOL> exit ( ) </s>
