X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=httpserver.py;h=a0216e12f2f209853703f77e240bf54565b57291;hb=06e6c396413630640cafae3488442a0869f1642d;hp=d9d6cc8520a02478facbf3475e1abd839156da23;hpb=efd80c982df1301bf4bdaaf8c8ae78919a03964f;p=osm%2FRO.git diff --git a/httpserver.py b/httpserver.py index d9d6cc85..a0216e12 100644 --- a/httpserver.py +++ b/httpserver.py @@ -321,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/', method='GET') def http_get_tenant_id(tenant_id): @@ -336,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(): @@ -352,6 +360,10 @@ def http_post_tenants(): 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/', method='PUT') def http_edit_tenant_id(tenant_id): @@ -374,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/', method='DELETE') def http_delete_tenant_id(tenant_id): @@ -385,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 + '//datacenters', method='GET') def http_get_datacenters(tenant_id): @@ -414,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 + '//datacenters/', method='GET') def http_get_datacenter_id(tenant_id, datacenter_id): @@ -427,7 +450,7 @@ def http_get_datacenter_id(tenant_id, datacenter_id): what = 'uuid' if utils.check_valid_uuid(datacenter_id) else 'name' where_={} where_[what] = datacenter_id - select_=['uuid', 'name','vim_url', 'vim_url_admin', 'type', 'config', 'description', 'd.created_at as created_at'] + select_=['uuid', 'name','vim_url', 'vim_url_admin', 'type', 'd.config as config', 'description', 'd.created_at as created_at'] if tenant_id != 'any': select_.append("datacenter_tenant_id") where_['td.nfvo_tenant_id']= tenant_id @@ -447,18 +470,27 @@ def http_get_datacenter_id(tenant_id, datacenter_id): if tenant_id != 'any': #get vim tenant info vim_tenants = mydb.get_rows( - SELECT=("vim_tenant_name", "vim_tenant_id", "user"), + SELECT=("vim_tenant_name", "vim_tenant_id", "user", "passwd", "config"), FROM="datacenter_tenants", WHERE={"uuid": datacenters[0]["datacenter_tenant_id"]}, ORDER_BY=("created", ) ) del datacenter["datacenter_tenant_id"] datacenter["vim_tenants"] = vim_tenants - + for vim_tenant in vim_tenants: + if vim_tenant["passwd"]: + vim_tenant["passwd"] = "******" + if vim_tenant['config'] != None: + try: + config_dict = yaml.load(vim_tenant['config']) + vim_tenant['config'] = config_dict + except Exception as e: + logger.error("Exception '%s' while trying to load config information", str(e)) + if datacenter['config'] != None: try: config_dict = yaml.load(datacenter['config']) datacenter['config'] = config_dict - except Exception, e: + 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(datacenter) @@ -467,6 +499,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(): @@ -483,6 +519,10 @@ def http_post_datacenters(): 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/', method='PUT') def http_edit_datacenter_id(datacenter_id_name): @@ -500,6 +540,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 + '//datacenters//networks', method='GET') #deprecated @bottle.route(url_base + '//datacenters//netmaps', method='GET') @@ -532,6 +576,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 + '//datacenters//netmaps', method='DELETE') @bottle.route(url_base + '//datacenters//netmaps/', method='DELETE') @@ -558,6 +606,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 + '//datacenters//netmaps/upload', method='POST') @@ -572,6 +623,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 + '//datacenters//netmaps', method='POST') def http_postnetmap_datacenter_id(tenant_id, datacenter_id): @@ -592,6 +647,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 + '//datacenters//netmaps/', method='PUT') def http_putnettmap_datacenter_id(tenant_id, datacenter_id, netmap_id): @@ -610,6 +669,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 + '//datacenters//action', method='POST') @@ -631,6 +693,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/', method='DELETE') @@ -644,6 +709,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 + '//datacenters/', method='POST') def http_associate_datacenters(tenant_id, datacenter_id): @@ -659,12 +728,17 @@ def http_associate_datacenters(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('vim_password'), + http_content['datacenter'].get('config') + ) return http_get_datacenter_id(tenant_id, 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 + '//datacenters/', method='DELETE') def http_deassociate_datacenters(tenant_id, datacenter_id): @@ -676,6 +750,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 + '//vim//', method='GET') @bottle.route(url_base + '//vim///', method='GET') @@ -687,6 +765,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 + '//vim///', method='DELETE') def http_del_vim_items(tenant_id, datacenter_id, item, name): @@ -697,6 +779,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 + '//vim//', 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) @@ -707,6 +794,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 + '//vnfs', method='GET') def http_get_vnfs(tenant_id): @@ -730,6 +821,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 + '//vnfs/', method='GET') def http_get_vnf_id(tenant_id,vnf_id): @@ -743,6 +838,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 + '//vnfs', method='POST') def http_post_vnfs(tenant_id): @@ -766,6 +865,10 @@ def http_post_vnfs(tenant_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 + '//vnfs/', method='DELETE') def http_delete_vnf_id(tenant_id,vnf_id): @@ -779,6 +882,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 + '//hosts/topology', method='GET') #@bottle.route(url_base + '//physicalview/Madrid-Alcantara', method='GET') @@ -804,6 +911,9 @@ def http_get_hosts(tenant_id, datacenter): 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)) + 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 + '/', method='OPTIONS') @@ -836,6 +946,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 + '//topology/verify', method='POST') def http_post_verify(tenant_id): @@ -861,9 +975,9 @@ def http_post_scenarios(tenant_id): if used_schema == nsd_schema_v01: scenario_id = nfvo.new_scenario(mydb, tenant_id, http_content) elif used_schema == nsd_schema_v02: - scenario_id = nfvo.new_scenario_v02(mydb, tenant_id, http_content) + scenario_id = nfvo.new_scenario_v02(mydb, tenant_id, http_content, "0.2") elif used_schema == nsd_schema_v03: - scenario_id = nfvo.new_scenario_v03(mydb, tenant_id, http_content) + scenario_id = nfvo.new_scenario_v02(mydb, tenant_id, http_content, "0.3") else: logger.warning('Unexpected schema_version: %s', http_content.get("schema_version")) bottle.abort(HTTP_Bad_Request, "Invalid schema version") @@ -873,19 +987,23 @@ def http_post_scenarios(tenant_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 + '//scenarios//action', method='POST') def http_post_scenario_action(tenant_id, scenario_id): '''take an action over a scenario''' logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url) - #check valid tenant_id + # parse input data + http_content, _ = format_in(scenario_action_schema) + r = utils.remove_extra_items(http_content, scenario_action_schema) + if r: + logger.debug("Remove received extra items %s", str(r)) try: - nfvo.check_tenant(mydb, tenant_id) - #parse input data - http_content,_ = format_in( scenario_action_schema ) - r = utils.remove_extra_items(http_content, scenario_action_schema) - if r: - logger.debug("Remove received extra items %s", str(r)) + # check valid tenant_id + nfvo.check_tenant(mydb, tenant_id) 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']), @@ -911,6 +1029,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 + '//scenarios', method='GET') def http_get_scenarios(tenant_id): @@ -935,6 +1057,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 + '//scenarios/', method='GET') def http_get_scenario_id(tenant_id, scenario_id): @@ -952,14 +1078,19 @@ 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 + '//scenarios/', method='DELETE') def http_delete_scenario_id(tenant_id, scenario_id): '''delete a scenario from database, 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) + nfvo.check_tenant(mydb, tenant_id) #obtain data data = mydb.delete_scenario(scenario_id, tenant_id) #print json.dumps(data, indent=4) @@ -967,6 +1098,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 + '//scenarios/', method='PUT') @@ -985,25 +1119,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 + '//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) + # parse input data + 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: + logger.warning("http_post_instances: Warning: remove extra items %s", str(r)) 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_v01) - r = utils.remove_extra_items(http_content, used_schema) - 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 @@ -1027,6 +1167,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 + '//instances/', method='GET') def http_get_instance_id(tenant_id, instance_id): @@ -1052,6 +1196,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 + '//instances/', method='DELETE') def http_delete_instance_id(tenant_id, instance_id): @@ -1069,21 +1217,25 @@ 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 + '//instances//action', method='POST') def http_post_instance_scenario_action(tenant_id, instance_id): '''take an action over a scenario instance''' logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url) + # parse input data + http_content, _ = format_in(instance_scenario_action_schema) + r = utils.remove_extra_items(http_content, instance_scenario_action_schema) + if r: + logger.debug("Remove received extra items %s", str(r)) try: #check valid tenant_id if tenant_id != "any": nfvo.check_tenant(mydb, tenant_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: - 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) @@ -1094,6 +1246,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)