Allow instance of only networks without scenario
[osm/RO.git] / osm_ro / httpserver.py
index 083bac1..374676e 100644 (file)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 ##
-# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U.
 # This file is part of openmano
 # All Rights Reserved.
 #
@@ -248,7 +248,7 @@ def format_in(default_schema, version_fields=None, version_dict_schema=None, con
             
         js_v(client_data, used_schema)
         return client_data, used_schema
-    except (ValueError, yaml.YAMLError) as exc:
+    except (TypeError, ValueError, yaml.YAMLError) as exc:
         error_text += str(exc)
         logger.error(error_text) 
         bottle.abort(HTTP_Bad_Request, error_text)
@@ -330,6 +330,8 @@ def http_get_tenants():
         convert_datetime2str(tenants)
         data={'tenants' : tenants}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -347,12 +349,19 @@ def http_get_tenant_id(tenant_id):
         from_ = 'nfvo_tenants'
         select_, where_, limit_ = filter_query_string(bottle.request.query, None,
                                                       ('uuid', 'name', 'description', 'created_at'))
-        where_['uuid'] = tenant_id
+        what = 'uuid' if utils.check_valid_uuid(tenant_id) else 'name'
+        where_[what] = tenant_id
         tenants = mydb.get_rows(FROM=from_, SELECT=select_,WHERE=where_)
         #change_keys_http2db(content, http2db_tenant, reverse=True)
-        convert_datetime2str(tenants)
-        data = {'tenant' : tenants[0]}
+        if len(tenants) == 0:
+            bottle.abort(HTTP_Not_Found, "No tenant found with {}='{}'".format(what, tenant_id))
+        elif len(tenants) > 1:
+            bottle.abort(HTTP_Bad_Request, "More than one tenant found with {}='{}'".format(what, tenant_id))
+        convert_datetime2str(tenants[0])
+        data = {'tenant': tenants[0]}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -373,6 +382,8 @@ def http_post_tenants():
     try: 
         data = nfvo.new_tenant(mydb, http_content['tenant'])
         return http_get_tenant_id(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -399,6 +410,8 @@ def http_edit_tenant_id(tenant_id):
         where={'uuid': tenant['uuid']}
         mydb.update_rows('nfvo_tenants', http_content['tenant'], where)
         return http_get_tenant_id(tenant_id)
+    except bottle.HTTPError:
+        raise
     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))
@@ -414,6 +427,8 @@ def http_delete_tenant_id(tenant_id):
     try:
         data = nfvo.delete_tenant(mydb, tenant_id)
         return format_out({"result":"tenant " + data + " deleted"})
+    except bottle.HTTPError:
+        raise
     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))
@@ -446,6 +461,8 @@ def http_get_datacenters(tenant_id):
         convert_datetime2str(datacenters)
         data={'datacenters' : datacenters}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -454,6 +471,54 @@ def http_get_datacenters(tenant_id):
         bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
 
 
+@bottle.route(url_base + '/<tenant_id>/vim_accounts', method='GET')
+@bottle.route(url_base + '/<tenant_id>/vim_accounts/<vim_account_id>', method='GET')
+def http_get_vim_account(tenant_id, vim_account_id=None):
+    '''get vim_account list/details, '''
+    logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+    try:
+        select_ = ('uuid', 'name', 'dt.datacenter_id as vim_id', 'vim_tenant_name', 'vim_tenant_id', 'user', 'config',
+                   'dt.created_at as created_at', 'passwd')
+        where_ = {'nfvo_tenant_id': tenant_id}
+        if vim_account_id:
+            where_['dt.uuid'] = vim_account_id
+        from_ = 'tenants_datacenters as td join datacenter_tenants as dt on dt.uuid=td.datacenter_tenant_id'
+        vim_accounts = mydb.get_rows(SELECT=select_, FROM=from_, WHERE=where_)
+
+        if len(vim_accounts) == 0 and vim_account_id:
+            bottle.abort(HTTP_Not_Found, "No vim_account found for tenant {} and id '{}'".format(tenant_id,
+                                                                                                 vim_account_id))
+        for vim_account in vim_accounts:
+                if vim_account["passwd"]:
+                    vim_account["passwd"] = "******"
+                if vim_account['config'] != None:
+                    try:
+                        config_dict = yaml.load(vim_account['config'])
+                        vim_account['config'] = config_dict
+                        if vim_account['config'].get('admin_password'):
+                            vim_account['config']['admin_password'] = "******"
+                        if vim_account['config'].get('vcenter_password'):
+                            vim_account['config']['vcenter_password'] = "******"
+                        if vim_account['config'].get('nsx_password'):
+                            vim_account['config']['nsx_password'] = "******"
+                    except Exception as e:
+                        logger.error("Exception '%s' while trying to load config information", str(e))
+        # change_keys_http2db(content, http2db_datacenter, reverse=True)
+        #convert_datetime2str(vim_account)
+        if vim_account_id:
+            return format_out({"datacenter": vim_accounts[0]})
+        else:
+            return format_out({"datacenters": vim_accounts})
+    except bottle.HTTPError:
+        raise
+    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 + '/<tenant_id>/datacenters/<datacenter_id>', method='GET')
 def http_get_datacenter_id(tenant_id, datacenter_id):
     '''get datacenter details, can use both uuid or name'''
@@ -524,6 +589,8 @@ def http_get_datacenter_id(tenant_id, datacenter_id):
         convert_datetime2str(datacenter)
         data={'datacenter' : datacenter}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -544,6 +611,8 @@ def http_post_datacenters():
     try:
         data = nfvo.new_datacenter(mydb, http_content['datacenter'])
         return http_get_datacenter_id('any', data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -565,6 +634,8 @@ def http_edit_datacenter_id(datacenter_id_name):
     try:
         datacenter_id = nfvo.edit_datacenter(mydb, datacenter_id_name, http_content['datacenter'])
         return http_get_datacenter_id('any', datacenter_id)
+    except bottle.HTTPError:
+        raise
     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))
@@ -584,6 +655,8 @@ def http_post_sdn_controller(tenant_id):
 
         data = nfvo.sdn_controller_create(mydb, tenant_id, http_content['sdn_controller'])
         return format_out({"sdn_controller": nfvo.sdn_controller_list(mydb, tenant_id, data)})
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_sdn_controller error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -607,6 +680,8 @@ def http_put_sdn_controller_update(tenant_id, controller_id):
         data = nfvo.sdn_controller_update(mydb, tenant_id, controller_id, http_content['sdn_controller'])
         return format_out({"sdn_controller": nfvo.sdn_controller_list(mydb, tenant_id, controller_id)})
 
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_sdn_controller error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -622,6 +697,8 @@ def http_get_sdn_controller(tenant_id):
 
         data = {'sdn_controllers': nfvo.sdn_controller_list(mydb, tenant_id)}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_sdn_controller error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -636,6 +713,8 @@ def http_get_sdn_controller_id(tenant_id, controller_id):
         logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
         data = nfvo.sdn_controller_list(mydb, tenant_id, controller_id)
         return format_out({"sdn_controllers": data})
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_sdn_controller_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -650,6 +729,8 @@ def http_delete_sdn_controller_id(tenant_id, controller_id):
         logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
         data = nfvo.sdn_controller_delete(mydb, tenant_id, controller_id)
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_delete_sdn_controller_id error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -669,6 +750,8 @@ def http_post_datacenter_sdn_port_mapping(tenant_id, datacenter_id):
     try:
         data = nfvo.datacenter_sdn_port_mapping_set(mydb, tenant_id, datacenter_id, http_content['sdn_port_mapping'])
         return format_out({"sdn_port_mapping": data})
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_datacenter_sdn_port_mapping error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -684,6 +767,8 @@ def http_get_datacenter_sdn_port_mapping(tenant_id, datacenter_id):
 
         data = nfvo.datacenter_sdn_port_mapping_list(mydb, tenant_id, datacenter_id)
         return format_out({"sdn_port_mapping": data})
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_datacenter_sdn_port_mapping error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -698,6 +783,8 @@ def http_delete_datacenter_sdn_port_mapping(tenant_id, datacenter_id):
         logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
         data = nfvo.datacenter_sdn_port_mapping_delete(mydb, tenant_id, datacenter_id)
         return format_out({"result": data})
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_delete_datacenter_sdn_port_mapping error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -733,6 +820,8 @@ def http_getnetmap_datacenter_id(tenant_id, datacenter_id, netmap_id=None):
         else:
             data={'netmaps' : netmaps}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -757,12 +846,14 @@ def http_delnetmap_datacenter_id(tenant_id, datacenter_id, netmap_id=None):
                 where_["name"] = netmap_id
         #change_keys_http2db(content, http2db_tenant, reverse=True)
         deleted = mydb.delete_row(FROM='datacenter_nets', WHERE= where_) 
-        if deleted == 0 and netmap_id :
+        if deleted == 0 and netmap_id:
             bottle.abort(HTTP_Not_Found, "No netmap found with " + " and ".join(map(lambda x: str(x[0])+": "+str(x[1]), where_.iteritems())) )
         if netmap_id:
             return format_out({"result": "netmap %s deleted" % netmap_id})
         else:
             return format_out({"result": "%d netmap deleted" % deleted})
+    except bottle.HTTPError:
+        raise
     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))
@@ -780,6 +871,8 @@ def http_uploadnetmap_datacenter_id(tenant_id, datacenter_id):
         utils.convert_str2boolean(netmaps, ('shared', 'multipoint') )
         data={'netmaps' : netmaps}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -804,6 +897,8 @@ def http_postnetmap_datacenter_id(tenant_id, datacenter_id):
         utils.convert_str2boolean(netmaps, ('shared', 'multipoint') )
         data={'netmaps' : netmaps}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -826,6 +921,8 @@ def http_putnettmap_datacenter_id(tenant_id, datacenter_id, netmap_id):
     try:
         nfvo.datacenter_edit_netmap(mydb, tenant_id, datacenter_id, netmap_id, http_content)
         return http_getnetmap_datacenter_id(tenant_id, datacenter_id, netmap_id)
+    except bottle.HTTPError:
+        raise
     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))
@@ -850,6 +947,8 @@ def http_action_datacenter_id(tenant_id, datacenter_id):
             return http_getnetmap_datacenter_id(datacenter_id)
         else:
             return format_out(result)
+    except bottle.HTTPError:
+        raise
     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))
@@ -866,6 +965,8 @@ def http_delete_datacenter_id( datacenter_id):
     try:
         data = nfvo.delete_datacenter(mydb, datacenter_id)
         return format_out({"result":"datacenter '" + data + "' deleted"})
+    except bottle.HTTPError:
+        raise
     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))
@@ -875,7 +976,8 @@ def http_delete_datacenter_id( datacenter_id):
 
 
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>', method='POST')
-def http_associate_datacenters(tenant_id, datacenter_id):
+@bottle.route(url_base + '/<tenant_id>/vim_accounts', method='POST')
+def http_associate_datacenters(tenant_id, datacenter_id=None):
     '''associate an existing datacenter to a this tenant. '''
     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
     #parse input data
@@ -884,14 +986,11 @@ def http_associate_datacenters(tenant_id, datacenter_id):
     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'),
-                                    http_content['datacenter'].get('vim_tenant_name'),
-                                    http_content['datacenter'].get('vim_username'),
-                                    http_content['datacenter'].get('vim_password'),
-                                    http_content['datacenter'].get('config')
-        )
-        return http_get_datacenter_id(tenant_id, id_)
+        vim_account_id = nfvo.create_vim_account(mydb, tenant_id, datacenter_id,
+                                                             **http_content['datacenter'])
+        return http_get_vim_account(tenant_id, vim_account_id)
+    except bottle.HTTPError:
+        raise
     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))
@@ -899,38 +998,40 @@ def http_associate_datacenters(tenant_id, datacenter_id):
         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_accounts/<vim_account_id>', method='PUT')
 @bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>', method='PUT')
-def http_associate_datacenters_edit(tenant_id, datacenter_id):
+def http_vim_account_edit(tenant_id, vim_account_id=None, datacenter_id=None):
     '''associate an existing datacenter to a this tenant. '''
     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
     #parse input data
-    http_content,_ = format_in( datacenter_associate_schema )
+    http_content,_ = format_in(datacenter_associate_schema)
     r = utils.remove_extra_items(http_content, datacenter_associate_schema)
     if r:
         logger.debug("Remove received extra items %s", str(r))
     try:
-        id_ = nfvo.edit_datacenter_to_tenant(mydb, tenant_id, datacenter_id,
-                                    http_content['datacenter'].get('vim_tenant'),
-                                    http_content['datacenter'].get('vim_tenant_name'),
-                                    http_content['datacenter'].get('vim_username'),
-                                    http_content['datacenter'].get('vim_password'),
-                                    http_content['datacenter'].get('config')
-        )
-        return http_get_datacenter_id(tenant_id, id_)
+        vim_account_id = nfvo.edit_vim_account(mydb, tenant_id, vim_account_id, datacenter_id=datacenter_id,
+                                               **http_content['datacenter'])
+        return http_get_vim_account(tenant_id, vim_account_id)
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
-        logger.error("http_associate_datacenters_edit error {}: {}".format(e.http_code, str(e)))
+        logger.error("http_vim_account_edit 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):
+@bottle.route(url_base + '/<tenant_id>/vim_accounts/<vim_account_id>', method='DELETE')
+def http_deassociate_datacenters(tenant_id, datacenter_id=None, vim_account_id=None):
     '''deassociate an existing datacenter to a this tenant. '''
     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
     try:
-        data = nfvo.deassociate_datacenter_to_tenant(mydb, tenant_id, datacenter_id)
+        data = nfvo.delete_vim_account(mydb, tenant_id, vim_account_id, datacenter_id)
         return format_out({"result": data})
+    except bottle.HTTPError:
+        raise
     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))
@@ -945,6 +1046,8 @@ def http_post_vim_net_sdn_attach(tenant_id, datacenter_id, network_id):
     try:
         data = nfvo.vim_net_sdn_attach(mydb, tenant_id, datacenter_id, network_id, http_content)
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_vim_net_sdn_attach error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -959,6 +1062,8 @@ def http_delete_vim_net_sdn_detach(tenant_id, datacenter_id, network_id, port_id
     try:
         data = nfvo.vim_net_sdn_detach(mydb, tenant_id, datacenter_id, network_id, port_id)
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_delete_vim_net_sdn_detach error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -973,6 +1078,8 @@ def http_get_vim_items(tenant_id, datacenter_id, item, name=None):
     try:
         data = nfvo.vim_action_get(mydb, tenant_id, datacenter_id, item, name)
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -987,6 +1094,8 @@ def http_del_vim_items(tenant_id, datacenter_id, item, name):
     try:
         data = nfvo.vim_action_delete(mydb, tenant_id, datacenter_id, item, name)
         return format_out({"result":data})
+    except bottle.HTTPError:
+        raise
     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))
@@ -1002,6 +1111,8 @@ def http_post_vim_items(tenant_id, datacenter_id, item):
     try:
         data = nfvo.vim_action_create(mydb, tenant_id, datacenter_id, item, http_content)
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1019,16 +1130,16 @@ def http_get_vnfs(tenant_id):
             nfvo.check_tenant(mydb, tenant_id)
         select_,where_,limit_ = filter_query_string(bottle.request.query, None,
                 ('uuid', 'name', 'osm_id', 'description', 'public', "tenant_id", "created_at") )
-        where_or = {}
         if tenant_id != "any":
-            where_or["tenant_id"] = tenant_id
-            where_or["public"] = True
-        vnfs = mydb.get_rows(FROM='vnfs', SELECT=select_,WHERE=where_,WHERE_OR=where_or, WHERE_AND_OR="AND",LIMIT=limit_)
-        #change_keys_http2db(content, http2db_vnf, reverse=True)
+            where_["OR"]={"tenant_id": tenant_id, "public": True}
+        vnfs = mydb.get_rows(FROM='vnfs', SELECT=select_, WHERE=where_, LIMIT=limit_)
+        # change_keys_http2db(content, http2db_vnf, reverse=True)
         utils.convert_str2boolean(vnfs, ('public',))
         convert_datetime2str(vnfs)
-        data={'vnfs' : vnfs}
+        data={'vnfs': vnfs}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1046,6 +1157,8 @@ def http_get_vnf_id(tenant_id,vnf_id):
         utils.convert_str2boolean(vnf, ('public',))
         convert_datetime2str(vnf)
         return format_out(vnf)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1076,6 +1189,8 @@ def http_post_vnfs(tenant_id):
             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 bottle.HTTPError:
+        raise
     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))
@@ -1102,6 +1217,8 @@ def http_post_vnfs_v3(tenant_id):
             convert_datetime2str(vnf)
             vnfd_list.append(vnf["vnf"])
         return format_out({"vnfd": vnfd_list})
+    except bottle.HTTPError:
+        raise
     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))
@@ -1118,6 +1235,8 @@ def http_delete_vnf_id(tenant_id, vnf_id):
         data = nfvo.delete_vnf(mydb,tenant_id,vnf_id)
         #print json.dumps(data, indent=4)
         return format_out({"result":"VNF " + data + " deleted"})
+    except bottle.HTTPError:
+        raise
     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))
@@ -1147,6 +1266,8 @@ def http_get_hosts(tenant_id, datacenter):
             convert_datetime2str(data)
             #print json.dumps(data, indent=4)
             return format_out(data)
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_hosts error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -1182,6 +1303,8 @@ def http_post_deploy(tenant_id):
         instance = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['name'], http_content['name'])
         #print json.dumps(data, indent=4)
         return format_out(instance)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1223,6 +1346,8 @@ def http_post_scenarios(tenant_id):
         #print json.dumps(data, indent=4)
         #return format_out(data)
         return http_get_scenario_id(tenant_id, scenario_id)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1248,6 +1373,8 @@ def http_post_nsds_v3(tenant_id):
             nsd_list.append(scenario)
         data = {'nsd': nsd_list}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_post_nsds_v3 error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))
@@ -1290,6 +1417,8 @@ def http_post_scenario_action(tenant_id, scenario_id):
             instance_id = data['uuid']
             nfvo.delete_instance(mydb, tenant_id,instance_id)
             return format_out({"result":"Verify OK"})
+    except bottle.HTTPError:
+        raise
     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))
@@ -1309,16 +1438,16 @@ def http_get_scenarios(tenant_id):
         #obtain data
         s,w,l=filter_query_string(bottle.request.query, None,
                                   ('uuid', 'name', 'osm_id', 'description', 'tenant_id', 'created_at', 'public'))
-        where_or={}
         if tenant_id != "any":
-            where_or["tenant_id"] = tenant_id
-            where_or["public"] = True
-        scenarios = mydb.get_rows(SELECT=s, WHERE=w, WHERE_OR=where_or, WHERE_AND_OR="AND", LIMIT=l, FROM='scenarios')
+            w["OR"] = {"tenant_id": tenant_id, "public": True}
+        scenarios = mydb.get_rows(SELECT=s, WHERE=w, LIMIT=l, FROM='scenarios')
         convert_datetime2str(scenarios)
         utils.convert_str2boolean(scenarios, ('public',) )
         data={'scenarios':scenarios}
         #print json.dumps(scenarios, indent=4)
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1340,6 +1469,8 @@ def http_get_scenario_id(tenant_id, scenario_id):
         convert_datetime2str(scenario)
         data={'scenario' : scenario}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1360,6 +1491,8 @@ def http_delete_scenario_id(tenant_id, scenario_id):
         data = mydb.delete_scenario(scenario_id, tenant_id)
         #print json.dumps(data, indent=4)
         return format_out({"result":"scenario " + data + " deleted"})
+    except bottle.HTTPError:
+        raise
     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))
@@ -1381,6 +1514,8 @@ def http_put_scenario_id(tenant_id, scenario_id):
         #print json.dumps(data, indent=4)
         #return format_out(data)
         return http_get_scenario_id(tenant_id, scenario_id)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1403,6 +1538,8 @@ def http_post_instances(tenant_id):
             nfvo.check_tenant(mydb, tenant_id) 
         data = nfvo.create_instance(mydb, tenant_id, http_content["instance"])
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1429,6 +1566,8 @@ def http_get_instances(tenant_id):
         utils.convert_str2boolean(instances, ('public',) )
         data={'instances':instances}
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1442,19 +1581,15 @@ def http_get_instance_id(tenant_id, instance_id):
     '''get instances details, can use both uuid or name'''
     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) 
         if tenant_id == "any":
             tenant_id = None
-        #obtain data (first time is only to check that the instance exists)
-        instance_dict = mydb.get_instance_scenario(instance_id, tenant_id, verbose=True)
-        try:
-            nfvo.refresh_instance(mydb, tenant_id, instance_dict)
-        except (nfvo.NfvoException, db_base_Exception) as e:
-            logger.warn("nfvo.refresh_instance couldn't refresh the status of the instance: %s" % str(e))
-        # obtain data with results upated
-        instance = mydb.get_instance_scenario(instance_id, tenant_id)
+
+        instance = nfvo.get_instance_id(mydb, tenant_id, instance_id)
+
         # Workaround to SO, convert vnfs:vms:interfaces:ip_address from ";" separated list to report the first value
         for vnf in instance.get("vnfs", ()):
             for vm in vnf.get("vms", ()):
@@ -1466,6 +1601,8 @@ def http_get_instance_id(tenant_id, instance_id):
         convert_datetime2str(instance)
         # print json.dumps(instance, indent=4)
         return format_out(instance)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1487,6 +1624,8 @@ def http_delete_instance_id(tenant_id, instance_id):
         #obtain data
         message = nfvo.delete_instance(mydb, tenant_id,instance_id)
         return format_out({"result":message})
+    except bottle.HTTPError:
+        raise
     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))
@@ -1521,6 +1660,8 @@ def http_post_instance_scenario_action(tenant_id, instance_id):
         
         data = nfvo.instance_action(mydb, tenant_id, instance_id, http_content)
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     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))
@@ -1545,6 +1686,8 @@ def http_get_instance_scenario_action(tenant_id, instance_id, action_id=None):
             nfvo.check_tenant(mydb, tenant_id)
         data = nfvo.instance_action_get(mydb, tenant_id, instance_id, action_id)
         return format_out(data)
+    except bottle.HTTPError:
+        raise
     except (nfvo.NfvoException, db_base_Exception) as e:
         logger.error("http_get_instance_scenario_action error {}: {}".format(e.http_code, str(e)))
         bottle.abort(e.http_code, str(e))