Merge "v0.4.61 fixed 37 Deploying multisite get properly the information from sites...
[osm/RO.git] / httpserver.py
index 680fddf..cd40882 100644 (file)
@@ -38,8 +38,8 @@ import logging
 
 from jsonschema import validate as js_v, exceptions as js_e
 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, \
+                            nsd_schema_v01, nsd_schema_v02, nsd_schema_v03, scenario_edit_schema, \
+                            scenario_action_schema, instance_scenario_action_schema, instance_scenario_create_schema_v01, \
                             tenant_schema, tenant_edit_schema,\
                             datacenter_schema, datacenter_edit_schema, datacenter_action_schema, datacenter_associate_schema,\
                             object_schema, netmap_new_schema, netmap_edit_schema
@@ -52,6 +52,7 @@ global mydb
 global url_base
 global logger
 url_base="/openmano"
+logger = None
 
 HTTP_Bad_Request =          400
 HTTP_Unauthorized =         401 
@@ -112,7 +113,8 @@ class httpserver(threading.Thread):
         global mydb
         global logger
         #initialization
-        logger = logging.getLogger('openmano.http')
+        if not logger:
+            logger = logging.getLogger('openmano.http')
         threading.Thread.__init__(self)
         self.host = host
         self.port = port   #Port where the listen service must be started
@@ -141,7 +143,7 @@ def run_bottle(db, host_='localhost', port_=9090):
 
 @bottle.route(url_base + '/', method='GET')
 def http_get():
-    print 
+    #print 
     return 'works' #TODO: to be completed
 
 #
@@ -170,7 +172,7 @@ def change_keys_http2db(data, http_db, reverse=False):
 
 def format_out(data):
     '''return string of dictionary data according to requested json, yaml, xml. By default json'''
-    logger.debug(yaml.safe_dump(data, explicit_start=True, indent=4, default_flow_style=False, tags=False, encoding='utf-8', allow_unicode=True) )
+    logger.debug("OUT: " + yaml.safe_dump(data, explicit_start=True, indent=4, default_flow_style=False, tags=False, encoding='utf-8', allow_unicode=True) )
     if 'application/yaml' in bottle.request.headers.get('Accept'):
         bottle.response.content_type='application/yaml'
         return yaml.safe_dump(data, explicit_start=True, indent=4, default_flow_style=False, tags=False, encoding='utf-8', allow_unicode=True) #, canonical=True, default_style='"'
@@ -205,13 +207,14 @@ def format_in(default_schema, version_fields=None, version_dict_schema=None):
         elif 'application/xml' in format_type:
             bottle.abort(501, "Content-Type: application/xml not supported yet.")
         else:
-            print 'Content-Type ' + str(format_type) + ' not supported.'
+            logger.warning('Content-Type ' + str(format_type) + ' not supported.')
             bottle.abort(HTTP_Not_Acceptable, 'Content-Type ' + str(format_type) + ' not supported.')
             return
         #if client_data == None:
         #    bottle.abort(HTTP_Bad_Request, "Content error, empty")
         #    return
 
+        logger.debug('IN: %s', yaml.safe_dump(client_data, explicit_start=True, indent=4, default_flow_style=False, tags=False, encoding='utf-8', allow_unicode=True) )
         #look for the client provider version
         error_text = "Invalid content "
         client_version = None
@@ -238,10 +241,10 @@ def format_in(default_schema, version_fields=None, version_dict_schema=None):
         return client_data, used_schema
     except (ValueError, yaml.YAMLError) as exc:
         error_text += str(exc)
-        print error_text 
+        logger.error(error_text) 
         bottle.abort(HTTP_Bad_Request, error_text)
     except js_e.ValidationError as exc:
-        print "validate_in error, jsonschema exception ", exc.message, "at", exc.path
+        logger.error("validate_in error, jsonschema exception at '%s' '%s' ", str(exc.path), str(exc.message))
         error_pos = ""
         if len(exc.path)>0: error_pos=" at " + ":".join(map(json.dumps, exc.path))
         bottle.abort(HTTP_Bad_Request, error_text + exc.message + error_pos)
@@ -318,6 +321,10 @@ def http_get_tenants():
     except db_base_Exception as e:
         logger.error("http_get_tenants error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/tenants/<tenant_id>', method='GET')
 def http_get_tenant_id(tenant_id):
@@ -333,6 +340,10 @@ def http_get_tenant_id(tenant_id):
     except db_base_Exception as e:
         logger.error("http_get_tenant_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/tenants', method='POST')
 def http_post_tenants():
@@ -341,13 +352,18 @@ def http_post_tenants():
     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
     http_content,_ = format_in( tenant_schema )
     r = utils.remove_extra_items(http_content, tenant_schema)
-    if r is not None: print "http_post_tenants: Warning: remove extra items ", r
+    if r:
+        logger.debug("Remove received extra items %s", str(r))
     try: 
         data = nfvo.new_tenant(mydb, http_content['tenant'])
         return http_get_tenant_id(data)
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_tenants error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/tenants/<tenant_id>', method='PUT')
 def http_edit_tenant_id(tenant_id):
@@ -356,7 +372,8 @@ def http_edit_tenant_id(tenant_id):
     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
     http_content,_ = format_in( tenant_edit_schema )
     r = utils.remove_extra_items(http_content, tenant_edit_schema)
-    if r is not None: print "http_edit_tenant_id: Warning: remove extra items ", r
+    if r:
+        logger.debug("Remove received extra items %s", str(r))
     
     #obtain data, check that only one exist
     try: 
@@ -369,6 +386,10 @@ def http_edit_tenant_id(tenant_id):
     except db_base_Exception as e:
         logger.error("http_edit_tenant_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/tenants/<tenant_id>', method='DELETE')
 def http_delete_tenant_id(tenant_id):
@@ -380,7 +401,10 @@ def http_delete_tenant_id(tenant_id):
     except db_base_Exception as e:
         logger.error("http_delete_tenant_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
-    
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/datacenters', method='GET')
 def http_get_datacenters(tenant_id):
@@ -409,6 +433,10 @@ def http_get_datacenters(tenant_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_datacenters error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>', method='GET')
 def http_get_datacenter_id(tenant_id, datacenter_id):
@@ -454,7 +482,7 @@ def http_get_datacenter_id(tenant_id, datacenter_id):
                 config_dict = yaml.load(datacenter['config'])
                 datacenter['config'] = config_dict
             except Exception, e:
-                print "Exception '%s' while trying to load config information" % str(e)
+                logger.error("Exception '%s' while trying to load config information", str(e))
         #change_keys_http2db(content, http2db_datacenter, reverse=True)
         convert_datetime2str(datacenter)
         data={'datacenter' : datacenter}
@@ -462,6 +490,10 @@ def http_get_datacenter_id(tenant_id, datacenter_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_datacenter_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/datacenters', method='POST')
 def http_post_datacenters():
@@ -470,13 +502,18 @@ def http_post_datacenters():
     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
     http_content,_ = format_in( datacenter_schema )
     r = utils.remove_extra_items(http_content, datacenter_schema)
-    if r is not None: print "http_post_datacenters: Warning: remove extra items ", r
+    if r:
+        logger.debug("Remove received extra items %s", str(r))
     try:
         data = nfvo.new_datacenter(mydb, http_content['datacenter'])
         return http_get_datacenter_id('any', data)
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_datacenters error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/datacenters/<datacenter_id_name>', method='PUT')
 def http_edit_datacenter_id(datacenter_id_name):
@@ -485,7 +522,8 @@ def http_edit_datacenter_id(datacenter_id_name):
     #parse input data
     http_content,_ = format_in( datacenter_edit_schema )
     r = utils.remove_extra_items(http_content, datacenter_edit_schema)
-    if r is not None: print "http_edit_datacenter_id: Warning: remove extra items ", r
+    if r:
+        logger.debug("Remove received extra items %s", str(r))
     
     try:
         datacenter_id = nfvo.edit_datacenter(mydb, datacenter_id_name, http_content['datacenter'])
@@ -493,6 +531,10 @@ def http_edit_datacenter_id(datacenter_id_name):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_edit_datacenter_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>/networks', method='GET')  #deprecated
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>/netmaps', method='GET')
@@ -525,6 +567,10 @@ def http_getnetmap_datacenter_id(tenant_id, datacenter_id, netmap_id=None):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_getnetwork_datacenter_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>/netmaps', method='DELETE')
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>/netmaps/<netmap_id>', method='DELETE')
@@ -551,6 +597,9 @@ def http_delnetmap_datacenter_id(tenant_id, datacenter_id, netmap_id=None):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_delnetmap_datacenter_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
 
 
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>/netmaps/upload', method='POST')
@@ -565,6 +614,10 @@ def http_uploadnetmap_datacenter_id(tenant_id, datacenter_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_uploadnetmap_datacenter_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>/netmaps', method='POST')
 def http_postnetmap_datacenter_id(tenant_id, datacenter_id):
@@ -573,8 +626,8 @@ def http_postnetmap_datacenter_id(tenant_id, datacenter_id):
     #parse input data
     http_content,_ = format_in( netmap_new_schema )
     r = utils.remove_extra_items(http_content, netmap_new_schema)
-    if r is not None: print "http_postnetmap_datacenter_id: Warning: remove extra items ", r
-    
+    if r:
+        logger.debug("Remove received extra items %s", str(r))
     try:
         #obtain data, check that only one exist
         netmaps = nfvo.datacenter_new_netmap(mydb, tenant_id, datacenter_id, http_content)
@@ -585,6 +638,10 @@ def http_postnetmap_datacenter_id(tenant_id, datacenter_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_postnetmap_datacenter_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>/netmaps/<netmap_id>', method='PUT')
 def http_putnettmap_datacenter_id(tenant_id, datacenter_id, netmap_id):
@@ -593,7 +650,8 @@ def http_putnettmap_datacenter_id(tenant_id, datacenter_id, netmap_id):
     #parse input data
     http_content,_ = format_in( netmap_edit_schema )
     r = utils.remove_extra_items(http_content, netmap_edit_schema)
-    if r is not None: print "http_putnettmap_datacenter_id: Warning: remove extra items ", r
+    if r:
+        logger.debug("Remove received extra items %s", str(r))
     
     #obtain data, check that only one exist
     try:
@@ -602,6 +660,9 @@ def http_putnettmap_datacenter_id(tenant_id, datacenter_id, netmap_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_putnettmap_datacenter_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
     
 
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>/action', method='POST')
@@ -611,8 +672,8 @@ def http_action_datacenter_id(tenant_id, datacenter_id):
     #parse input data
     http_content,_ = format_in( datacenter_action_schema )
     r = utils.remove_extra_items(http_content, datacenter_action_schema)
-    if r is not None: print "http_action_datacenter_id: Warning: remove extra items ", r
-    
+    if r:
+        logger.debug("Remove received extra items %s", str(r))
     try:
         #obtain data, check that only one exist
         result = nfvo.datacenter_action(mydb, tenant_id, datacenter_id, http_content)
@@ -623,6 +684,9 @@ def http_action_datacenter_id(tenant_id, datacenter_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_action_datacenter_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
 
 
 @bottle.route(url_base + '/datacenters/<datacenter_id>', method='DELETE')
@@ -636,6 +700,10 @@ def http_delete_datacenter_id( datacenter_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_delete_datacenter_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>', method='POST')
 def http_associate_datacenters(tenant_id, datacenter_id):
@@ -644,7 +712,8 @@ def http_associate_datacenters(tenant_id, datacenter_id):
     #parse input data
     http_content,_ = format_in( datacenter_associate_schema )
     r = utils.remove_extra_items(http_content, datacenter_associate_schema)
-    if r != None: print "http_associate_datacenters: Warning: remove extra items ", r
+    if r:
+        logger.debug("Remove received extra items %s", str(r))
     try:
         id_ = nfvo.associate_datacenter_to_tenant(mydb, tenant_id, datacenter_id, 
                                     http_content['datacenter'].get('vim_tenant'),
@@ -656,6 +725,10 @@ def http_associate_datacenters(tenant_id, datacenter_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_associate_datacenters error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>', method='DELETE')
 def http_deassociate_datacenters(tenant_id, datacenter_id):
@@ -667,6 +740,10 @@ def http_deassociate_datacenters(tenant_id, datacenter_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_deassociate_datacenters error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
        
 @bottle.route(url_base + '/<tenant_id>/vim/<datacenter_id>/<item>', method='GET')
 @bottle.route(url_base + '/<tenant_id>/vim/<datacenter_id>/<item>/<name>', method='GET')
@@ -678,6 +755,10 @@ def http_get_vim_items(tenant_id, datacenter_id, item, name=None):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_vim_items error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/vim/<datacenter_id>/<item>/<name>', method='DELETE')
 def http_del_vim_items(tenant_id, datacenter_id, item, name):
@@ -688,6 +769,11 @@ def http_del_vim_items(tenant_id, datacenter_id, item, name):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_del_vim_items error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
+
 @bottle.route(url_base + '/<tenant_id>/vim/<datacenter_id>/<item>', method='POST')
 def http_post_vim_items(tenant_id, datacenter_id, item):
     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
@@ -698,6 +784,10 @@ def http_post_vim_items(tenant_id, datacenter_id, item):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_vim_items error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/vnfs', method='GET')
 def http_get_vnfs(tenant_id):
@@ -721,6 +811,10 @@ def http_get_vnfs(tenant_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_vnfs error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/vnfs/<vnf_id>', method='GET')
 def http_get_vnf_id(tenant_id,vnf_id):
@@ -734,6 +828,10 @@ def http_get_vnf_id(tenant_id,vnf_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_vnf_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/vnfs', method='POST')
 def http_post_vnfs(tenant_id):
@@ -741,15 +839,26 @@ def http_post_vnfs(tenant_id):
     #print "Parsing the YAML file of the VNF"
     #parse input data
     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
-    http_content, used_schema = format_in( vnfd_schema_v01, ("version",), {"v0.2": vnfd_schema_v02})
+    http_content, used_schema = format_in( vnfd_schema_v01, ("schema_version",), {"0.2": vnfd_schema_v02})
     r = utils.remove_extra_items(http_content, used_schema)
-    if r is not None: print "http_post_vnfs: Warning: remove extra items ", r
+    if r:
+        logger.debug("Remove received extra items %s", str(r))
     try:
-        vnf_id = nfvo.new_vnf(mydb,tenant_id,http_content)
+        if used_schema == vnfd_schema_v01:
+            vnf_id = nfvo.new_vnf(mydb,tenant_id,http_content)
+        elif used_schema == vnfd_schema_v02:
+            vnf_id = nfvo.new_vnf_v02(mydb,tenant_id,http_content)
+        else:
+            logger.warning('Unexpected schema_version: %s', http_content.get("schema_version"))
+            bottle.abort(HTTP_Bad_Request, "Invalid schema version")
         return http_get_vnf_id(tenant_id, vnf_id)
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_vnfs error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
             
 @bottle.route(url_base + '/<tenant_id>/vnfs/<vnf_id>', method='DELETE')
 def http_delete_vnf_id(tenant_id,vnf_id):
@@ -763,6 +872,10 @@ def http_delete_vnf_id(tenant_id,vnf_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_delete_vnf_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 #@bottle.route(url_base + '/<tenant_id>/hosts/topology', method='GET')
 #@bottle.route(url_base + '/<tenant_id>/physicalview/Madrid-Alcantara', method='GET')
@@ -779,15 +892,18 @@ def http_get_hosts(tenant_id, datacenter):
             result, data = nfvo.get_hosts_info(mydb, tenant_id) #, datacenter)
         
         if result < 0:
-            print "http_post_vnfs error %d %s" % (-result, data)
+            #print "http_get_hosts error %d %s" % (-result, data)
             bottle.abort(-result, data)
         else:
             convert_datetime2str(data)
-            print json.dumps(data, indent=4)
+            #print json.dumps(data, indent=4)
             return format_out(data)
     except (nfvo.NfvoException, db_base_Exception) as e:
-        logger.error("http_post_vnfs error {}: {}".format(e.http_code, str(e)))
+        logger.error("http_get_hosts error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
 
 
 @bottle.route(url_base + '/<path:path>', method='OPTIONS')
@@ -820,6 +936,10 @@ def http_post_deploy(tenant_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_deploy error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/topology/verify', method='POST')
 def http_post_verify(tenant_id):
@@ -837,21 +957,30 @@ def http_post_verify(tenant_id):
 def http_post_scenarios(tenant_id):
     '''add a scenario into the catalogue. Creates the scenario and its internal structure in the OPENMANO DB'''
     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
-    http_content, used_schema = format_in( nsd_schema_v01, ("schema_version",), {2: nsd_schema_v02})
+    http_content, used_schema = format_in( nsd_schema_v01, ("schema_version",), {2: nsd_schema_v02, "0.3": nsd_schema_v03})
     #r = utils.remove_extra_items(http_content, used_schema)
     #if r is not None: print "http_post_scenarios: Warning: remove extra items ", r
     #print "http_post_scenarios input: ",  http_content
     try:
-        if http_content.get("schema_version") == None:
+        if used_schema == nsd_schema_v01:
             scenario_id = nfvo.new_scenario(mydb, tenant_id, http_content)
-        else:
+        elif used_schema == nsd_schema_v02:
             scenario_id = nfvo.new_scenario_v02(mydb, tenant_id, http_content)
+        elif used_schema == nsd_schema_v03:
+            scenario_id = nfvo.new_scenario_v03(mydb, tenant_id, http_content)
+        else:
+            logger.warning('Unexpected schema_version: %s', http_content.get("schema_version"))
+            bottle.abort(HTTP_Bad_Request, "Invalid schema version")
         #print json.dumps(data, indent=4)
         #return format_out(data)
         return http_get_scenario_id(tenant_id, scenario_id)
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_scenarios error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/scenarios/<scenario_id>/action', method='POST')
 def http_post_scenario_action(tenant_id, scenario_id):
@@ -863,7 +992,8 @@ def http_post_scenario_action(tenant_id, scenario_id):
         #parse input data
         http_content,_ = format_in( scenario_action_schema )
         r = utils.remove_extra_items(http_content, scenario_action_schema)
-        if r is not None: print "http_post_scenario_action: Warning: remove extra items ", r
+        if r:
+            logger.debug("Remove received extra items %s", str(r))
         if "start" in http_content:
             data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['start']['instance_name'], \
                         http_content['start'].get('description',http_content['start']['instance_name']),
@@ -889,6 +1019,10 @@ def http_post_scenario_action(tenant_id, scenario_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_scenario_action error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/scenarios', method='GET')
 def http_get_scenarios(tenant_id):
@@ -913,6 +1047,10 @@ def http_get_scenarios(tenant_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_scenarios error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/scenarios/<scenario_id>', method='GET')
 def http_get_scenario_id(tenant_id, scenario_id):
@@ -930,6 +1068,10 @@ def http_get_scenario_id(tenant_id, scenario_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_scenarios error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/scenarios/<scenario_id>', method='DELETE')
 def http_delete_scenario_id(tenant_id, scenario_id):
@@ -945,6 +1087,9 @@ def http_delete_scenario_id(tenant_id, scenario_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_delete_scenario_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
 
 
 @bottle.route(url_base + '/<tenant_id>/scenarios/<scenario_id>', method='PUT')
@@ -963,24 +1108,31 @@ def http_put_scenario_id(tenant_id, scenario_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_put_scenario_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
 
 @bottle.route(url_base + '/<tenant_id>/instances', method='POST')
 def http_post_instances(tenant_id):
-    '''take an action over a scenario'''
+    '''create an instance-scenario'''
     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
     try:
         #check valid tenant_id
         if tenant_id != "any":
             nfvo.check_tenant(mydb, tenant_id) 
         #parse input data
-        http_content,used_schema = format_in( instance_scenario_create_schema)
+        http_content,used_schema = format_in( instance_scenario_create_schema_v01)
         r = utils.remove_extra_items(http_content, used_schema)
-        if r is not None: print "http_post_instances: Warning: remove extra items ", r
+        if r is not None:
+            logger.warning("http_post_instances: Warning: remove extra items %s", str(r))
         data = nfvo.create_instance(mydb, tenant_id, http_content["instance"])
         return format_out(data)
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_instances error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
 
 #
 # INSTANCES
@@ -1004,6 +1156,10 @@ def http_get_instances(tenant_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_instances error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/instances/<instance_id>', method='GET')
 def http_get_instance_id(tenant_id, instance_id):
@@ -1029,6 +1185,10 @@ def http_get_instance_id(tenant_id, instance_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_instance_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/instances/<instance_id>', method='DELETE')
 def http_delete_instance_id(tenant_id, instance_id):
@@ -1046,6 +1206,10 @@ def http_delete_instance_id(tenant_id, instance_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_delete_instance_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
 
 @bottle.route(url_base + '/<tenant_id>/instances/<instance_id>/action', method='POST')
 def http_post_instance_scenario_action(tenant_id, instance_id):
@@ -1059,7 +1223,8 @@ def http_post_instance_scenario_action(tenant_id, instance_id):
         #parse input data
         http_content,_ = format_in( instance_scenario_action_schema )
         r = utils.remove_extra_items(http_content, instance_scenario_action_schema)
-        if r is not None: print "http_post_instance_scenario_action: Warning: remove extra items ", r
+        if r:
+            logger.debug("Remove received extra items %s", str(r))
         #print "http_post_instance_scenario_action input: ", http_content
         #obtain data
         instance = mydb.get_instance_scenario(instance_id, tenant_id)
@@ -1070,6 +1235,9 @@ def http_post_instance_scenario_action(tenant_id, instance_id):
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_instance_scenario_action error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
+    except Exception as e:
+        logger.error("Unexpected exception: ", exc_info=True)
+        bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
 
 
 @bottle.error(400)