<s> '''<STR_LIT>''' <EOL> __author__ = "<STR_LIT>" <EOL> __date__ = "<STR_LIT>" <EOL> import bottle <EOL> import yaml <EOL> import json <EOL> import threading <EOL> import time <EOL> from jsonschema import validate as js_v , exceptions as js_e <EOL> from openmano_schemas import vnfd_schema_v01 , vnfd_schema_v02 , nsd_schema_v01 , nsd_schema_v02 , scenario_edit_schema , scenario_action_schema , instance_scenario_action_schema , instance_scenario_create_schema , tenant_schema , tenant_edit_schema , datacenter_schema , datacenter_edit_schema , datacenter_action_schema , datacenter_associate_schema , object_schema , netmap_new_schema , netmap_edit_schema <EOL> import nfvo <EOL> from utils import auxiliary_functions as af <EOL> global mydb <EOL> global url_base <EOL> url_base = "<STR_LIT>" <EOL> HTTP_Bad_Request = <NUM_LIT> <EOL> HTTP_Unauthorized = <NUM_LIT> <EOL> HTTP_Not_Found = <NUM_LIT> <EOL> HTTP_Forbidden = <NUM_LIT> <EOL> HTTP_Method_Not_Allowed = <NUM_LIT> <EOL> HTTP_Not_Acceptable = <NUM_LIT> <EOL> HTTP_Service_Unavailable = <NUM_LIT> <EOL> HTTP_Internal_Server_Error = <NUM_LIT> <EOL> def delete_nulls ( var ) : <EOL> if type ( var ) is dict : <EOL> for k in var . keys ( ) : <EOL> if var [ k ] is None : del var [ k ] <EOL> elif type ( var [ k ] ) is dict or type ( var [ k ] ) is list or type ( var [ k ] ) is tuple : <EOL> if delete_nulls ( var [ k ] ) : del var [ k ] <EOL> if len ( var ) == <NUM_LIT:0> : return True <EOL> elif type ( var ) is list or type ( var ) is tuple : <EOL> for k in var : <EOL> if type ( k ) is dict : delete_nulls ( k ) <EOL> if len ( var ) == <NUM_LIT:0> : return True <EOL> return False <EOL> def convert_datetime2str ( var ) : <EOL> '''<STR_LIT>''' <EOL> if type ( var ) is dict : <EOL> for k , v in var . items ( ) : <EOL> if type ( v ) is float and k in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> var [ k ] = time . strftime ( "<STR_LIT>" , time . localtime ( v ) ) <EOL> elif type ( v ) is dict or type ( v ) is list or type ( v ) is tuple : <EOL> convert_datetime2str ( v ) <EOL> if len ( var ) == <NUM_LIT:0> : return True <EOL> elif type ( var ) is list or type ( var ) is tuple : <EOL> for v in var : <EOL> convert_datetime2str ( v ) <EOL> class httpserver ( threading . Thread ) : <EOL> def __init__ ( self , db , admin = False , host = '<STR_LIT:localhost>' , port = <NUM_LIT> ) : <EOL> global mydb <EOL> threading . Thread . __init__ ( self ) <EOL> self . host = host <EOL> self . port = port <EOL> if admin == True : <EOL> self . name = "<STR_LIT>" <EOL> else : <EOL> self . name = "<STR_LIT:http>" <EOL> mydb = db <EOL> self . daemon = True <EOL> self . setDaemon ( True ) <EOL> def run ( self ) : <EOL> bottle . run ( host = self . host , port = self . port , debug = True ) <EOL> def run_bottle ( db , host_ = '<STR_LIT:localhost>' , port_ = <NUM_LIT> ) : <EOL> '''<STR_LIT>''' <EOL> global mydb <EOL> mydb = db <EOL> bottle . run ( host = host_ , port = port_ , debug = True ) <EOL> @ bottle . route ( url_base + '<STR_LIT:/>' , method = '<STR_LIT:GET>' ) <EOL> def http_get ( ) : <EOL> print <EOL> return '<STR_LIT>' <EOL> def change_keys_http2db ( data , http_db , reverse = False ) : <EOL> '''<STR_LIT>''' <EOL> if type ( data ) is tuple or type ( data ) is list : <EOL> for d in data : <EOL> change_keys_http2db ( d , http_db , reverse ) <EOL> elif type ( data ) is dict or type ( data ) is bottle . FormsDict : <EOL> if reverse : <EOL> for k , v in http_db . items ( ) : <EOL> if v in data : data [ k ] = data . pop ( v ) <EOL> else : <EOL> for k , v in http_db . items ( ) : <EOL> if k in data : data [ v ] = data . pop ( k ) <EOL> def format_out ( data ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in bottle . request . headers . get ( '<STR_LIT>' ) : <EOL> bottle . response . content_type = '<STR_LIT>' <EOL> print yaml . safe_dump ( data , explicit_start = True , indent = <NUM_LIT:4> , default_flow_style = False , tags = False , encoding = '<STR_LIT:utf-8>' , allow_unicode = True ) <EOL> return yaml . safe_dump ( data , explicit_start = True , indent = <NUM_LIT:4> , default_flow_style = False , tags = False , encoding = '<STR_LIT:utf-8>' , allow_unicode = True ) <EOL> else : <EOL> bottle . response . content_type = '<STR_LIT:application/json>' <EOL> return json . dumps ( data , indent = <NUM_LIT:4> ) + "<STR_LIT:\n>" <EOL> def format_in ( default_schema , version_fields = None , version_dict_schema = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> error_text = "<STR_LIT>" <EOL> format_type = bottle . request . headers . get ( '<STR_LIT:Content-Type>' , '<STR_LIT:application/json>' ) <EOL> if '<STR_LIT:application/json>' in format_type : <EOL> error_text = "<STR_LIT>" <EOL> client_data = json . load ( bottle . request . body ) <EOL> elif '<STR_LIT>' in format_type : <EOL> error_text = "<STR_LIT>" <EOL> client_data = yaml . load ( bottle . request . body ) <EOL> elif '<STR_LIT>' in format_type : <EOL> bottle . abort ( <NUM_LIT> , "<STR_LIT>" ) <EOL> else : <EOL> print '<STR_LIT>' + str ( format_type ) + '<STR_LIT>' <EOL> bottle . abort ( HTTP_Not_Acceptable , '<STR_LIT>' + str ( format_type ) + '<STR_LIT>' ) <EOL> return <EOL> error_text = "<STR_LIT>" <EOL> client_version = None <EOL> used_schema = None <EOL> if version_fields != None : <EOL> client_version = client_data <EOL> for field in version_fields : <EOL> if field in client_version : <EOL> client_version = client_version [ field ] <EOL> else : <EOL> client_version = None <EOL> break <EOL> if client_version == None : <EOL> used_schema = default_schema <EOL> elif version_dict_schema != None : <EOL> if client_version in version_dict_schema : <EOL> used_schema = version_dict_schema [ client_version ] <EOL> elif None in version_dict_schema : <EOL> used_schema = version_dict_schema [ None ] <EOL> if used_schema == None : <EOL> bottle . abort ( HTTP_Bad_Request , "<STR_LIT>" ) <EOL> js_v ( client_data , used_schema ) <EOL> return client_data , used_schema <EOL> except ( ValueError , yaml . YAMLError ) as exc : <EOL> error_text += str ( exc ) <EOL> print error_text <EOL> bottle . abort ( HTTP_Bad_Request , error_text ) <EOL> except js_e . ValidationError as exc : <EOL> print "<STR_LIT>" , exc . message , "<STR_LIT>" , exc . path <EOL> error_pos = "<STR_LIT>" <EOL> if len ( exc . path ) > <NUM_LIT:0> : error_pos = "<STR_LIT>" + "<STR_LIT::>" . join ( map ( json . dumps , exc . path ) ) <EOL> bottle . abort ( HTTP_Bad_Request , error_text + exc . message + error_pos ) <EOL> def filter_query_string ( qs , http2db , allowed ) : <EOL> '''<STR_LIT>''' <EOL> where = { } <EOL> limit = <NUM_LIT:100> <EOL> select = [ ] <EOL> if type ( qs ) is not bottle . FormsDict : <EOL> print '<STR_LIT>' <EOL> else : <EOL> for k in qs : <EOL> if k == '<STR_LIT>' : <EOL> select += qs . getall ( k ) <EOL> for v in select : <EOL> if v not in allowed : <EOL> bottle . abort ( HTTP_Bad_Request , "<STR_LIT>" + v + "<STR_LIT:'>" ) <EOL> elif k == '<STR_LIT>' : <EOL> try : <EOL> limit = int ( qs [ k ] ) <EOL> except : <EOL> bottle . abort ( HTTP_Bad_Request , "<STR_LIT>" + qs [ k ] + "<STR_LIT:'>" ) <EOL> else : <EOL> if k not in allowed : <EOL> bottle . abort ( HTTP_Bad_Request , "<STR_LIT>" + k + "<STR_LIT:=>" + qs [ k ] + "<STR_LIT:'>" ) <EOL> if qs [ k ] != "<STR_LIT:null>" : where [ k ] = qs [ k ] <EOL> else : where [ k ] = None <EOL> if len ( select ) == <NUM_LIT:0> : select += allowed <EOL> for i in range ( <NUM_LIT:0> , len ( select ) ) : <EOL> k = select [ i ] <EOL> if http2db and k in http2db : <EOL> select [ i ] = http2db [ k ] <EOL> if http2db : <EOL> change_keys_http2db ( where , http2db ) <EOL> print "<STR_LIT>" , select , where , limit <EOL> return select , where , limit <EOL> @ bottle . hook ( '<STR_LIT>' ) <EOL> def enable_cors ( ) : <EOL> '''<STR_LIT>''' <EOL> bottle . response . headers [ '<STR_LIT>' ] = '<STR_LIT:*>' <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_tenants ( ) : <EOL> select_ , where_ , limit_ = filter_query_string ( bottle . request . query , None , <EOL> ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT:description>' , '<STR_LIT>' ) ) <EOL> result , content = mydb . get_table ( FROM = '<STR_LIT>' , SELECT = select_ , WHERE = where_ , LIMIT = limit_ ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" , content <EOL> bottle . abort ( - result , content ) <EOL> else : <EOL> convert_datetime2str ( content ) <EOL> data = { '<STR_LIT>' : content } <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_tenant_id ( tenant_id ) : <EOL> '''<STR_LIT>''' <EOL> result , content = mydb . get_table_by_uuid_name ( '<STR_LIT>' , tenant_id , "<STR_LIT>" ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , content ) <EOL> bottle . abort ( - result , content ) <EOL> convert_datetime2str ( content ) <EOL> print content <EOL> data = { '<STR_LIT>' : content } <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_post_tenants ( ) : <EOL> '''<STR_LIT>''' <EOL> http_content , _ = format_in ( tenant_schema ) <EOL> r = af . remove_extra_items ( http_content , tenant_schema ) <EOL> if r is not None : print "<STR_LIT>" , r <EOL> result , data = nfvo . new_tenant ( mydb , http_content [ '<STR_LIT>' ] ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return http_get_tenant_id ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_edit_tenant_id ( tenant_id ) : <EOL> '''<STR_LIT>''' <EOL> http_content , _ = format_in ( tenant_edit_schema ) <EOL> r = af . remove_extra_items ( http_content , tenant_edit_schema ) <EOL> if r is not None : print "<STR_LIT>" , r <EOL> result , content = mydb . get_table_by_uuid_name ( '<STR_LIT>' , tenant_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , content ) <EOL> bottle . abort ( - result , content ) <EOL> tenant_id = content [ '<STR_LIT>' ] <EOL> where = { '<STR_LIT>' : content [ '<STR_LIT>' ] } <EOL> result , content = mydb . update_rows ( '<STR_LIT>' , http_content [ '<STR_LIT>' ] , where ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , content ) <EOL> bottle . abort ( - result , content ) <EOL> return http_get_tenant_id ( tenant_id ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_delete_tenant_id ( tenant_id ) : <EOL> '''<STR_LIT>''' <EOL> result , data = nfvo . delete_tenant ( mydb , tenant_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( { "<STR_LIT:result>" : "<STR_LIT>" + data + "<STR_LIT>" } ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_datacenters ( tenant_id ) : <EOL> if tenant_id != '<STR_LIT>' : <EOL> if not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print '<STR_LIT>' % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , '<STR_LIT>' % tenant_id ) <EOL> return <EOL> select_ , where_ , limit_ = filter_query_string ( bottle . request . query , None , <EOL> ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT:type>' , '<STR_LIT>' ) ) <EOL> if tenant_id != '<STR_LIT>' : <EOL> where_ [ '<STR_LIT>' ] = tenant_id <EOL> if '<STR_LIT>' in select_ : <EOL> select_ [ select_ . index ( '<STR_LIT>' ) ] = '<STR_LIT>' <EOL> if '<STR_LIT>' in where_ : <EOL> where_ [ '<STR_LIT>' ] = where_ . pop ( '<STR_LIT>' ) <EOL> result , content = mydb . get_table ( FROM = '<STR_LIT>' , <EOL> SELECT = select_ , WHERE = where_ , LIMIT = limit_ ) <EOL> else : <EOL> result , content = mydb . get_table ( FROM = '<STR_LIT>' , <EOL> SELECT = select_ , WHERE = where_ , LIMIT = limit_ ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" , content <EOL> bottle . abort ( - result , content ) <EOL> else : <EOL> convert_datetime2str ( content ) <EOL> data = { '<STR_LIT>' : content } <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_datacenter_id ( tenant_id , datacenter_id ) : <EOL> '''<STR_LIT>''' <EOL> if tenant_id != '<STR_LIT>' : <EOL> if not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print '<STR_LIT>' % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , '<STR_LIT>' % tenant_id ) <EOL> return <EOL> what = '<STR_LIT>' if af . check_valid_uuid ( datacenter_id ) else '<STR_LIT:name>' <EOL> where_ = { } <EOL> where_ [ what ] = datacenter_id <EOL> select_ = [ '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:type>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT>' ] <EOL> if tenant_id != '<STR_LIT>' : <EOL> select_ . append ( "<STR_LIT>" ) <EOL> where_ [ '<STR_LIT>' ] = tenant_id <EOL> from_ = '<STR_LIT>' <EOL> else : <EOL> from_ = '<STR_LIT>' <EOL> result , content = mydb . get_table ( <EOL> SELECT = select_ , <EOL> FROM = from_ , <EOL> WHERE = where_ ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , content ) <EOL> bottle . abort ( - result , content ) <EOL> elif result == <NUM_LIT:0> : <EOL> bottle . abort ( HTTP_Not_Found , "<STR_LIT>" % ( what , datacenter_id ) ) <EOL> elif result > <NUM_LIT:1> : <EOL> bottle . abort ( HTTP_Bad_Request , "<STR_LIT>" % ( what , datacenter_id ) ) <EOL> if tenant_id != '<STR_LIT>' : <EOL> result , content2 = mydb . get_table ( <EOL> SELECT = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:user>" ) , <EOL> FROM = "<STR_LIT>" , <EOL> WHERE = { "<STR_LIT>" : content [ <NUM_LIT:0> ] [ "<STR_LIT>" ] } , <EOL> ORDER_BY = ( "<STR_LIT>" , ) ) <EOL> del content [ <NUM_LIT:0> ] [ "<STR_LIT>" ] <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , content2 ) <EOL> bottle . abort ( - result , content2 ) <EOL> content [ <NUM_LIT:0> ] [ "<STR_LIT>" ] = content2 <EOL> print content <EOL> if content [ <NUM_LIT:0> ] [ '<STR_LIT>' ] != None : <EOL> try : <EOL> config_dict = yaml . load ( content [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> content [ <NUM_LIT:0> ] [ '<STR_LIT>' ] = config_dict <EOL> except Exception , e : <EOL> print "<STR_LIT>" % str ( e ) <EOL> convert_datetime2str ( content [ <NUM_LIT:0> ] ) <EOL> data = { '<STR_LIT>' : content [ <NUM_LIT:0> ] } <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_post_datacenters ( ) : <EOL> '''<STR_LIT>''' <EOL> http_content , _ = format_in ( datacenter_schema ) <EOL> r = af . remove_extra_items ( http_content , datacenter_schema ) <EOL> if r is not None : print "<STR_LIT>" , r <EOL> result , data = nfvo . new_datacenter ( mydb , http_content [ '<STR_LIT>' ] ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return http_get_datacenter_id ( '<STR_LIT>' , data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_edit_datacenter_id ( datacenter_id_name ) : <EOL> '''<STR_LIT>''' <EOL> http_content , _ = format_in ( datacenter_edit_schema ) <EOL> r = af . remove_extra_items ( http_content , datacenter_edit_schema ) <EOL> if r is not None : print "<STR_LIT>" , r <EOL> result , datacenter_id = nfvo . edit_datacenter ( mydb , datacenter_id_name , http_content [ '<STR_LIT>' ] ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , datacenter_id ) <EOL> bottle . abort ( - result , datacenter_id ) <EOL> else : <EOL> return http_get_datacenter_id ( '<STR_LIT>' , datacenter_id ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_getnetmap_datacenter_id ( tenant_id , datacenter_id , netmap_id = None ) : <EOL> '''<STR_LIT>''' <EOL> result , datacenter_dict = mydb . get_table_by_uuid_name ( '<STR_LIT>' , datacenter_id , "<STR_LIT>" ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , datacenter_dict ) <EOL> bottle . abort ( - result , datacenter_dict ) <EOL> where_ = { "<STR_LIT>" : datacenter_dict [ '<STR_LIT>' ] } <EOL> if netmap_id : <EOL> if af . check_valid_uuid ( netmap_id ) : <EOL> where_ [ "<STR_LIT>" ] = netmap_id <EOL> else : <EOL> where_ [ "<STR_LIT:name>" ] = netmap_id <EOL> result , content = mydb . get_table ( FROM = '<STR_LIT>' , <EOL> SELECT = ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:type>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT>' ) , <EOL> WHERE = where_ ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , content ) <EOL> bottle . abort ( - result , content ) <EOL> convert_datetime2str ( content ) <EOL> af . convert_str2boolean ( content , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if netmap_id and len ( content ) == <NUM_LIT:1> : <EOL> data = { '<STR_LIT>' : content [ <NUM_LIT:0> ] } <EOL> elif netmap_id and len ( content ) == <NUM_LIT:0> : <EOL> bottle . abort ( HTTP_Not_Found , "<STR_LIT>" + "<STR_LIT>" . join ( map ( lambda x : str ( x [ <NUM_LIT:0> ] ) + "<STR_LIT>" + str ( x [ <NUM_LIT:1> ] ) , where_ . iteritems ( ) ) ) ) <EOL> return <EOL> else : <EOL> data = { '<STR_LIT>' : content } <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_delnetmap_datacenter_id ( tenant_id , datacenter_id , netmap_id = None ) : <EOL> '''<STR_LIT>''' <EOL> result , datacenter_dict = mydb . get_table_by_uuid_name ( '<STR_LIT>' , datacenter_id , "<STR_LIT>" ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , datacenter_dict ) <EOL> bottle . abort ( - result , datacenter_dict ) <EOL> where_ = { "<STR_LIT>" : datacenter_dict [ '<STR_LIT>' ] } <EOL> if netmap_id : <EOL> if af . check_valid_uuid ( netmap_id ) : <EOL> where_ [ "<STR_LIT>" ] = netmap_id <EOL> else : <EOL> where_ [ "<STR_LIT:name>" ] = netmap_id <EOL> result , content = mydb . delete_row_by_dict ( FROM = '<STR_LIT>' , WHERE = where_ ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , content ) <EOL> bottle . abort ( - result , content ) <EOL> elif result == <NUM_LIT:0> and netmap_id : <EOL> bottle . abort ( HTTP_Not_Found , "<STR_LIT>" + "<STR_LIT>" . join ( map ( lambda x : str ( x [ <NUM_LIT:0> ] ) + "<STR_LIT>" + str ( x [ <NUM_LIT:1> ] ) , where_ . iteritems ( ) ) ) ) <EOL> if netmap_id : <EOL> return format_out ( { "<STR_LIT:result>" : "<STR_LIT>" % netmap_id } ) <EOL> else : <EOL> return format_out ( { "<STR_LIT:result>" : "<STR_LIT>" % result } ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_uploadnetmap_datacenter_id ( tenant_id , datacenter_id ) : <EOL> result , content = nfvo . datacenter_new_netmap ( mydb , tenant_id , datacenter_id , None ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , content ) <EOL> bottle . abort ( - result , content ) <EOL> convert_datetime2str ( content ) <EOL> af . convert_str2boolean ( content , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> print content <EOL> data = { '<STR_LIT>' : content } <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_postnetmap_datacenter_id ( tenant_id , datacenter_id ) : <EOL> '''<STR_LIT>''' <EOL> http_content , _ = format_in ( netmap_new_schema ) <EOL> r = af . remove_extra_items ( http_content , netmap_new_schema ) <EOL> if r is not None : print "<STR_LIT>" , r <EOL> result , content = nfvo . datacenter_new_netmap ( mydb , tenant_id , datacenter_id , http_content ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , content ) <EOL> bottle . abort ( - result , content ) <EOL> convert_datetime2str ( content ) <EOL> af . convert_str2boolean ( content , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> print content <EOL> data = { '<STR_LIT>' : content } <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_putnettmap_datacenter_id ( tenant_id , datacenter_id , netmap_id ) : <EOL> '''<STR_LIT>''' <EOL> http_content , _ = format_in ( netmap_edit_schema ) <EOL> r = af . remove_extra_items ( http_content , netmap_edit_schema ) <EOL> if r is not None : print "<STR_LIT>" , r <EOL> result , content = nfvo . datacenter_edit_netmap ( mydb , tenant_id , datacenter_id , netmap_id , http_content ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , content ) <EOL> bottle . abort ( - result , content ) <EOL> else : <EOL> return http_getnetmap_datacenter_id ( tenant_id , datacenter_id , netmap_id ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_action_datacenter_id ( tenant_id , datacenter_id ) : <EOL> '''<STR_LIT>''' <EOL> http_content , _ = format_in ( datacenter_action_schema ) <EOL> r = af . remove_extra_items ( http_content , datacenter_action_schema ) <EOL> if r is not None : print "<STR_LIT>" , r <EOL> result , content = nfvo . datacenter_action ( mydb , tenant_id , datacenter_id , http_content ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( result , content ) <EOL> bottle . abort ( - result , content ) <EOL> if '<STR_LIT>' in http_content : <EOL> return http_getnetmap_datacenter_id ( datacenter_id ) <EOL> else : <EOL> return format_out ( content ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_delete_datacenter_id ( datacenter_id ) : <EOL> '''<STR_LIT>''' <EOL> result , data = nfvo . delete_datacenter ( mydb , datacenter_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( { "<STR_LIT:result>" : "<STR_LIT>" + data + "<STR_LIT>" } ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_associate_datacenters ( tenant_id , datacenter_id ) : <EOL> '''<STR_LIT>''' <EOL> http_content , _ = format_in ( datacenter_associate_schema ) <EOL> r = af . remove_extra_items ( http_content , datacenter_associate_schema ) <EOL> if r != None : print "<STR_LIT>" , r <EOL> result , data = nfvo . associate_datacenter_to_tenant ( mydb , tenant_id , datacenter_id , <EOL> http_content [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) , <EOL> http_content [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) , <EOL> http_content [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) , <EOL> http_content [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> print "<STR_LIT>" , data <EOL> return http_get_datacenter_id ( tenant_id , data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_deassociate_datacenters ( tenant_id , datacenter_id ) : <EOL> '''<STR_LIT>''' <EOL> result , data = nfvo . deassociate_datacenter_to_tenant ( mydb , tenant_id , datacenter_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( { "<STR_LIT:result>" : data } ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_vim_items ( tenant_id , datacenter_id , item , name = None ) : <EOL> result , data = nfvo . vim_action_get ( mydb , tenant_id , datacenter_id , item , name ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_del_vim_items ( tenant_id , datacenter_id , item , name ) : <EOL> result , data = nfvo . vim_action_delete ( mydb , tenant_id , datacenter_id , item , name ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( { "<STR_LIT:result>" : data } ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_post_vim_items ( tenant_id , datacenter_id , item ) : <EOL> http_content , _ = format_in ( object_schema ) <EOL> result , data = nfvo . vim_action_create ( mydb , tenant_id , datacenter_id , item , http_content ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_vnfs ( tenant_id ) : <EOL> if tenant_id != "<STR_LIT>" and not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print '<STR_LIT>' % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , '<STR_LIT>' % tenant_id ) <EOL> return <EOL> select_ , where_ , limit_ = filter_query_string ( bottle . request . query , None , <EOL> ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT:description>' , '<STR_LIT>' , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> where_or = { } <EOL> if tenant_id != "<STR_LIT>" : <EOL> where_or [ "<STR_LIT>" ] = tenant_id <EOL> where_or [ "<STR_LIT>" ] = True <EOL> result , content = mydb . get_table ( FROM = '<STR_LIT>' , SELECT = select_ , WHERE = where_ , WHERE_OR = where_or , WHERE_AND_OR = "<STR_LIT>" , LIMIT = limit_ ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" , content <EOL> bottle . abort ( - result , content ) <EOL> else : <EOL> af . convert_str2boolean ( content , ( '<STR_LIT>' , ) ) <EOL> convert_datetime2str ( content ) <EOL> data = { '<STR_LIT>' : content } <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_vnf_id ( tenant_id , vnf_id ) : <EOL> '''<STR_LIT>''' <EOL> result , data = nfvo . get_vnf_id ( mydb , tenant_id , vnf_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> af . convert_str2boolean ( data , ( '<STR_LIT>' , ) ) <EOL> convert_datetime2str ( data ) <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_post_vnfs ( tenant_id ) : <EOL> '''<STR_LIT>''' <EOL> print "<STR_LIT>" <EOL> http_content , used_schema = format_in ( vnfd_schema_v01 , ( "<STR_LIT:version>" , ) , { "<STR_LIT>" : vnfd_schema_v02 } ) <EOL> r = af . remove_extra_items ( http_content , used_schema ) <EOL> if r is not None : print "<STR_LIT>" , r <EOL> result , data = nfvo . new_vnf ( mydb , tenant_id , http_content ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return http_get_vnf_id ( tenant_id , data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_delete_vnf_id ( tenant_id , vnf_id ) : <EOL> '''<STR_LIT>''' <EOL> result , data = nfvo . delete_vnf ( mydb , tenant_id , vnf_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( { "<STR_LIT:result>" : "<STR_LIT>" + data + "<STR_LIT>" } ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_hosts ( tenant_id , datacenter ) : <EOL> '''<STR_LIT>''' <EOL> global mydb <EOL> print "<STR_LIT>" + tenant_id + '<STR_LIT>' + datacenter <EOL> if datacenter == '<STR_LIT>' : <EOL> result , data = nfvo . get_hosts ( mydb , tenant_id ) <EOL> else : <EOL> result , data = nfvo . get_hosts_info ( mydb , tenant_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> convert_datetime2str ( data ) <EOL> print json . dumps ( data , indent = <NUM_LIT:4> ) <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_options_deploy ( path ) : <EOL> '''<STR_LIT>''' <EOL> bottle . response . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> bottle . response . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> bottle . response . set_header ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) <EOL> bottle . response . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> bottle . response . set_header ( '<STR_LIT>' , '<STR_LIT:*>' ) <EOL> return <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_post_deploy ( tenant_id ) : <EOL> '''<STR_LIT>''' <EOL> print "<STR_LIT>" + tenant_id <EOL> http_content , used_schema = format_in ( nsd_schema_v01 , ( "<STR_LIT>" , ) , { <NUM_LIT:2> : nsd_schema_v02 } ) <EOL> print "<STR_LIT>" , http_content <EOL> result , scenario_uuid = nfvo . new_scenario ( mydb , tenant_id , http_content ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , scenario_uuid ) <EOL> bottle . abort ( - result , scenario_uuid ) <EOL> result , data = nfvo . start_scenario ( mydb , tenant_id , scenario_uuid , http_content [ '<STR_LIT:name>' ] , http_content [ '<STR_LIT:name>' ] ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> print json . dumps ( data , indent = <NUM_LIT:4> ) <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_post_verify ( tenant_id ) : <EOL> return <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_post_scenarios ( tenant_id ) : <EOL> '''<STR_LIT>''' <EOL> print "<STR_LIT>" + tenant_id <EOL> http_content , used_schema = format_in ( nsd_schema_v01 , ( "<STR_LIT>" , ) , { <NUM_LIT:2> : nsd_schema_v02 } ) <EOL> print "<STR_LIT>" , http_content <EOL> if http_content . get ( "<STR_LIT>" ) == None : <EOL> result , data = nfvo . new_scenario ( mydb , tenant_id , http_content ) <EOL> else : <EOL> result , data = nfvo . new_scenario_v02 ( mydb , tenant_id , http_content ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return http_get_scenario_id ( tenant_id , data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_post_scenario_action ( tenant_id , scenario_id ) : <EOL> '''<STR_LIT>''' <EOL> if not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print '<STR_LIT>' % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , '<STR_LIT>' % tenant_id ) <EOL> return <EOL> http_content , _ = format_in ( scenario_action_schema ) <EOL> r = af . remove_extra_items ( http_content , scenario_action_schema ) <EOL> if r is not None : print "<STR_LIT>" , r <EOL> if "<STR_LIT:start>" in http_content : <EOL> result , data = nfvo . start_scenario ( mydb , tenant_id , scenario_id , http_content [ '<STR_LIT:start>' ] [ '<STR_LIT>' ] , http_content [ '<STR_LIT:start>' ] . get ( '<STR_LIT:description>' , http_content [ '<STR_LIT:start>' ] [ '<STR_LIT>' ] ) , <EOL> http_content [ '<STR_LIT:start>' ] . get ( '<STR_LIT>' ) ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( data ) <EOL> elif "<STR_LIT>" in http_content : <EOL> result , data = nfvo . start_scenario ( mydb , tenant_id , scenario_id , http_content [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> http_content [ '<STR_LIT>' ] . get ( '<STR_LIT:description>' , http_content [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <EOL> http_content [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( data ) <EOL> elif "<STR_LIT>" in http_content : <EOL> result , data = nfvo . start_scenario ( mydb , tenant_id , scenario_id , http_content [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> http_content [ '<STR_LIT>' ] . get ( '<STR_LIT:description>' , http_content [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <EOL> http_content [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) , startvms = False ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( data ) <EOL> elif "<STR_LIT>" in http_content : <EOL> result , data = nfvo . start_scenario ( mydb , tenant_id , scenario_id , http_content [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> http_content [ '<STR_LIT>' ] . get ( '<STR_LIT:description>' , http_content [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <EOL> http_content [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) , startvms = False ) <EOL> if result < <NUM_LIT:0> or result != <NUM_LIT:1> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> instance_id = data [ '<STR_LIT>' ] <EOL> result , message = nfvo . delete_instance ( mydb , tenant_id , instance_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , message ) <EOL> bottle . abort ( - result , message ) <EOL> else : <EOL> return format_out ( { "<STR_LIT:result>" : "<STR_LIT>" } ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_scenarios ( tenant_id ) : <EOL> '''<STR_LIT>''' <EOL> if tenant_id != "<STR_LIT>" and not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print "<STR_LIT>" % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , "<STR_LIT>" % tenant_id ) <EOL> return <EOL> s , w , l = filter_query_string ( bottle . request . query , None , ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT:description>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> where_or = { } <EOL> if tenant_id != "<STR_LIT>" : <EOL> where_or [ "<STR_LIT>" ] = tenant_id <EOL> where_or [ "<STR_LIT>" ] = True <EOL> result , data = mydb . get_table ( SELECT = s , WHERE = w , WHERE_OR = where_or , WHERE_AND_OR = "<STR_LIT>" , LIMIT = l , FROM = '<STR_LIT>' ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> convert_datetime2str ( data ) <EOL> af . convert_str2boolean ( data , ( '<STR_LIT>' , ) ) <EOL> scenarios = { '<STR_LIT>' : data } <EOL> return format_out ( scenarios ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_scenario_id ( tenant_id , scenario_id ) : <EOL> '''<STR_LIT>''' <EOL> if tenant_id != "<STR_LIT>" and not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print "<STR_LIT>" % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , "<STR_LIT>" % tenant_id ) <EOL> return <EOL> result , content = mydb . get_scenario ( scenario_id , tenant_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , content ) <EOL> bottle . abort ( - result , content ) <EOL> else : <EOL> convert_datetime2str ( content ) <EOL> data = { '<STR_LIT>' : content } <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_delete_scenario_id ( tenant_id , scenario_id ) : <EOL> '''<STR_LIT>''' <EOL> if tenant_id != "<STR_LIT>" and not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print "<STR_LIT>" % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , "<STR_LIT>" % tenant_id ) <EOL> return <EOL> result , data = mydb . delete_scenario ( scenario_id , tenant_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( { "<STR_LIT:result>" : "<STR_LIT>" + data + "<STR_LIT>" } ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_put_scenario_id ( tenant_id , scenario_id ) : <EOL> '''<STR_LIT>''' <EOL> print "<STR_LIT>" + tenant_id <EOL> http_content , _ = format_in ( scenario_edit_schema ) <EOL> print "<STR_LIT>" , http_content <EOL> result , data = nfvo . edit_scenario ( mydb , tenant_id , scenario_id , http_content ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return http_get_scenario_id ( tenant_id , data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_post_instances ( tenant_id ) : <EOL> '''<STR_LIT>''' <EOL> if not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print '<STR_LIT>' % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , '<STR_LIT>' % tenant_id ) <EOL> return <EOL> http_content , used_schema = format_in ( instance_scenario_create_schema ) <EOL> r = af . remove_extra_items ( http_content , used_schema ) <EOL> if r is not None : print "<STR_LIT>" , r <EOL> result , data = nfvo . create_instance ( mydb , tenant_id , http_content [ "<STR_LIT>" ] ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_instances ( tenant_id ) : <EOL> '''<STR_LIT>''' <EOL> if tenant_id != "<STR_LIT>" and not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print '<STR_LIT>' % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , '<STR_LIT>' % tenant_id ) <EOL> return <EOL> s , w , l = filter_query_string ( bottle . request . query , None , ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT>' ) ) <EOL> where_or = { } <EOL> if tenant_id != "<STR_LIT>" : <EOL> w [ '<STR_LIT>' ] = tenant_id <EOL> result , data = mydb . get_table ( SELECT = s , WHERE = w , LIMIT = l , FROM = '<STR_LIT>' ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> convert_datetime2str ( data ) <EOL> af . convert_str2boolean ( data , ( '<STR_LIT>' , ) ) <EOL> instances = { '<STR_LIT>' : data } <EOL> print json . dumps ( instances , indent = <NUM_LIT:4> ) <EOL> return format_out ( instances ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> def http_get_instance_id ( tenant_id , instance_id ) : <EOL> '''<STR_LIT>''' <EOL> if tenant_id != "<STR_LIT>" and not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print '<STR_LIT>' % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , '<STR_LIT>' % tenant_id ) <EOL> return <EOL> if tenant_id == "<STR_LIT>" : <EOL> tenant_id = None <EOL> result , data = mydb . get_instance_scenario ( instance_id , tenant_id , verbose = True ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> return <EOL> r , c = nfvo . refresh_instance ( mydb , tenant_id , data ) <EOL> if r < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % c <EOL> result , data = mydb . get_instance_scenario ( instance_id , tenant_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> return <EOL> convert_datetime2str ( data ) <EOL> print json . dumps ( data , indent = <NUM_LIT:4> ) <EOL> return format_out ( data ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> def http_delete_instance_id ( tenant_id , instance_id ) : <EOL> '''<STR_LIT>''' <EOL> if tenant_id != "<STR_LIT>" and not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print '<STR_LIT>' % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , '<STR_LIT>' % tenant_id ) <EOL> return <EOL> if tenant_id == "<STR_LIT>" : <EOL> tenant_id = None <EOL> result , message = nfvo . delete_instance ( mydb , tenant_id , instance_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , message ) <EOL> bottle . abort ( - result , message ) <EOL> else : <EOL> return format_out ( { "<STR_LIT:result>" : message } ) <EOL> @ bottle . route ( url_base + '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> def http_post_instance_scenario_action ( tenant_id , instance_id ) : <EOL> '''<STR_LIT>''' <EOL> if not nfvo . check_tenant ( mydb , tenant_id ) : <EOL> print '<STR_LIT>' % tenant_id <EOL> bottle . abort ( HTTP_Not_Found , '<STR_LIT>' % tenant_id ) <EOL> return <EOL> http_content , _ = format_in ( instance_scenario_action_schema ) <EOL> r = af . remove_extra_items ( http_content , instance_scenario_action_schema ) <EOL> if r is not None : print "<STR_LIT>" , r <EOL> print "<STR_LIT>" , http_content <EOL> result , data = mydb . get_instance_scenario ( instance_id , tenant_id ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> instance_id = data [ "<STR_LIT>" ] <EOL> result , data = nfvo . instance_action ( mydb , tenant_id , instance_id , http_content ) <EOL> if result < <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( - result , data ) <EOL> bottle . abort ( - result , data ) <EOL> else : <EOL> return format_out ( data ) <EOL> @ bottle . error ( <NUM_LIT> ) <EOL> @ bottle . error ( <NUM_LIT> ) <EOL> @ bottle . error ( <NUM_LIT> ) <EOL> @ bottle . error ( <NUM_LIT> ) <EOL> @ bottle . error ( <NUM_LIT> ) <EOL> @ bottle . error ( <NUM_LIT> ) <EOL> @ bottle . error ( <NUM_LIT> ) <EOL> @ bottle . error ( <NUM_LIT> ) <EOL> @ bottle . error ( <NUM_LIT> ) <EOL> def error400 ( error ) : <EOL> e = { "<STR_LIT:error>" : { "<STR_LIT:code>" : error . status_code , "<STR_LIT:type>" : error . status , "<STR_LIT:description>" : error . body } } <EOL> bottle . response . headers [ '<STR_LIT>' ] = '<STR_LIT:*>' <EOL> return format_out ( e ) </s>
