Python bottle.error() Examples
The following are 30
code examples of bottle.error().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bottle
, or try the search function
.
Example #1
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_post_images(tenant_id): '''insert a image into the database, and attach to tenant.''' my = config_dic['http_threads'][ threading.current_thread().name ] #check valid tenant_id result,content = check_valid_tenant(my, tenant_id) if result != 0: bottle.abort(result, content) http_content = format_in(image_new_schema) r = remove_extra_items(http_content, image_new_schema) if r is not None: print "http_post_images: Warning: remove extra items ", r change_keys_http2db(http_content['image'], http2db_image) metadata_dict = http_content['image'].pop('metadata', None) if metadata_dict is not None: http_content['image']['metadata'] = json.dumps(metadata_dict) #insert in data base result, content = my.db.new_image(http_content['image'], tenant_id) if result >= 0: return http_get_image_id(tenant_id, content) else: print "http_post_images error %d %s" % (result, content) bottle.abort(-result, content) return
Example #2
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_post_instances(tenant_id): '''take an action over a scenario''' #check valid tenant_id if not nfvo.check_tenant(mydb, tenant_id): print 'httpserver.http_post_scenario_action() tenant %s not found' % tenant_id bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id) return #parse input data http_content,used_schema = format_in( instance_scenario_create_schema) r = utils.remove_extra_items(http_content, used_schema) if r is not None: print "http_post_instances: Warning: remove extra items ", r result, data = nfvo.create_instance(mydb, tenant_id, http_content["instance"]) if result < 0: print "http_post_instances start error %d: %s" % (-result, data) bottle.abort(-result, data) else: return format_out(data) # # INSTANCES #
Example #3
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_get_instances(tenant_id): '''get instance list''' #check valid tenant_id if tenant_id != "any" and not nfvo.check_tenant(mydb, tenant_id): print 'httpserver.http_get_instances() tenant %s not found' % tenant_id bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id) return #obtain data s,w,l=filter_query_string(bottle.request.query, None, ('uuid', 'name', 'scenario_id', 'tenant_id', 'description', 'created_at')) where_or={} if tenant_id != "any": w['tenant_id'] = tenant_id result, data = mydb.get_table(SELECT=s, WHERE=w, LIMIT=l, FROM='instance_scenarios') if result < 0: print "http_get_instances error %d %s" % (-result, data) bottle.abort(-result, data) else: convert_datetime2str(data) utils.convert_str2boolean(data, ('public',) ) instances={'instances':data} print json.dumps(instances, indent=4) return format_out(instances)
Example #4
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_get_scenarios(tenant_id): '''get scenarios list''' #check valid tenant_id if tenant_id != "any" and not nfvo.check_tenant(mydb, tenant_id): print "httpserver.http_get_scenarios() tenant '%s' not found" % tenant_id bottle.abort(HTTP_Not_Found, "Tenant '%s' not found" % tenant_id) return #obtain data s,w,l=filter_query_string(bottle.request.query, None, ('uuid', 'name', 'description', 'tenant_id', 'created_at', 'public')) where_or={} if tenant_id != "any": where_or["tenant_id"] = tenant_id where_or["public"] = True result, data = mydb.get_table(SELECT=s, WHERE=w, WHERE_OR=where_or, WHERE_AND_OR="AND", LIMIT=l, FROM='scenarios') if result < 0: print "http_get_scenarios error %d %s" % (-result, data) bottle.abort(-result, data) else: convert_datetime2str(data) utils.convert_str2boolean(data, ('public',) ) scenarios={'scenarios':data} #print json.dumps(scenarios, indent=4) return format_out(scenarios)
Example #5
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_get_port_id(port_id): my = config_dic['http_threads'][ threading.current_thread().name ] #obtain data result, content = my.db.get_table(WHERE={'uuid': port_id}, FROM='ports') if result < 0: print "http_get_ports error", result, content bottle.abort(-result, content) elif result==0: print "http_get_ports port '%s' not found" % str(port_id) bottle.abort(HTTP_Not_Found, 'port %s not found' % port_id) else: convert_boolean(content, ('admin_state_up',) ) delete_nulls(content) change_keys_http2db(content, http2db_port, reverse=True) data={'port' : content[0]} return format_out(data)
Example #6
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_clear_openflow_rules(): '''To make actions over the net. The action is to delete ALL openflow rules ''' my = config_dic['http_threads'][ threading.current_thread().name ] if not my.admin: bottle.abort(HTTP_Unauthorized, "Needed admin privileges") return #ignore input data r,c = config_dic['of_thread'].insert_task("clear-all") if r < 0: print "http_delete_openflow_id error while launching openflow rules" bottle.abort(HTTP_Internal_Server_Error, c) return data={'result' : " Clearing openflow rules in process"} return format_out(data)
Example #7
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_delete_instance_id(tenant_id, instance_id): '''delete instance from VIM and from database, can use both uuid or name''' #check valid tenant_id if tenant_id != "any" and not nfvo.check_tenant(mydb, tenant_id): print 'httpserver.http_delete_instance_id() tenant %s not found' % tenant_id bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id) return if tenant_id == "any": tenant_id = None #obtain data result, message = nfvo.delete_instance(mydb, tenant_id,instance_id) if result < 0: print "http_delete_instance_id error %d %s" % (-result, message) bottle.abort(-result, message) else: #print json.dumps(data, indent=4) return format_out({"result":message})
Example #8
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_post_instance_scenario_action(tenant_id, instance_id): '''take an action over a scenario instance''' #check valid tenant_id if not nfvo.check_tenant(mydb, tenant_id): print 'httpserver.http_post_instance_scenario_action() tenant %s not found' % tenant_id bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id) return #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 print "http_post_instance_scenario_action input: ", http_content #obtain data result, data = mydb.get_instance_scenario(instance_id, tenant_id) if result < 0: print "http_get_instance_id error %d %s" % (-result, data) bottle.abort(-result, data) instance_id = data["uuid"] result, data = nfvo.instance_action(mydb, tenant_id, instance_id, http_content) if result < 0: print "http_post_scenario_action error %d: %s" % (-result, data) bottle.abort(-result, data) else: return format_out(data)
Example #9
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_get_networks(): my = config_dic['http_threads'][ threading.current_thread().name ] #obtain data select_,where_,limit_ = filter_query_string(bottle.request.query, http2db_network, ('id','name','tenant_id','type', 'shared','provider:vlan','status','last_error','admin_state_up','provider:physical') ) #TODO temporally remove tenant_id if "tenant_id" in where_: del where_["tenant_id"] result, content = my.db.get_table(SELECT=select_, FROM='nets', WHERE=where_, LIMIT=limit_) if result < 0: print "http_get_networks error %d %s" % (result, content) bottle.abort(-result, content) else: convert_boolean(content, ('shared', 'admin_state_up', 'enable_dhcp') ) delete_nulls(content) change_keys_http2db(content, http2db_network, reverse=True) data={'networks' : content} return format_out(data)
Example #10
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_post_scenarios(tenant_id): '''add a scenario into the catalogue. Creates the scenario and its internal structure in the OPENMANO DB''' print "http_post_scenarios by tenant " + tenant_id http_content, used_schema = format_in( nsd_schema_v01, ("schema_version",), {2: nsd_schema_v02}) #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 if http_content.get("schema_version") == None: result, data = nfvo.new_scenario(mydb, tenant_id, http_content) else: result, data = nfvo.new_scenario_v02(mydb, tenant_id, http_content) if result < 0: print "http_post_scenarios error %d %s" % (-result, data) bottle.abort(-result, data) else: #print json.dumps(data, indent=4) #return format_out(data) return http_get_scenario_id(tenant_id,data)
Example #11
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_delnetmap_datacenter_id(tenant_id, datacenter_id, netmap_id=None): '''get datacenter networks, can use both uuid or name''' #obtain data result, datacenter_dict = mydb.get_table_by_uuid_name('datacenters', datacenter_id, "datacenter") if result < 0: print "http_delnetmap_datacenter_id error %d %s" % (result, datacenter_dict) bottle.abort(-result, datacenter_dict) where_= {"datacenter_id":datacenter_dict['uuid']} if netmap_id: if utils.check_valid_uuid(netmap_id): where_["uuid"] = netmap_id else: where_["name"] = netmap_id #change_keys_http2db(content, http2db_tenant, reverse=True) result, content =mydb.delete_row_by_dict(FROM='datacenter_nets', WHERE= where_) if result < 0: print "http_delnetmap_datacenter_id error %d %s" % (result, content) bottle.abort(-result, content) elif result == 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" % result})
Example #12
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_delete_image_id(tenant_id, image_id): '''Deletes the image_id of a tenant. IT removes from tenants_images table.''' my = config_dic['http_threads'][ threading.current_thread().name ] #check valid tenant_id result,content = check_valid_tenant(my, tenant_id) if result != 0: bottle.abort(result, content) result, content = my.db.delete_image_flavor('image', image_id, tenant_id) if result == 0: bottle.abort(HTTP_Not_Found, content) elif result >0: data={'result' : content} return format_out(data) else: print "http_delete_image_id error",result, content bottle.abort(-result, content) return
Example #13
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_get_hosts(tenant_id, datacenter): '''get the tidvim host hopology from the vim.''' global mydb print "http_get_hosts received by tenant " + tenant_id + ' datacenter ' + datacenter if datacenter == 'treeview': result, data = nfvo.get_hosts(mydb, tenant_id) else: #openmano-gui is using a hardcoded value for the datacenter result, data = nfvo.get_hosts_info(mydb, tenant_id) #, datacenter) if result < 0: print "http_post_vnfs error %d %s" % (-result, data) bottle.abort(-result, data) else: convert_datetime2str(data) print json.dumps(data, indent=4) return format_out(data)
Example #14
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_postnetmap_datacenter_id(tenant_id, datacenter_id): '''creates a new netmap''' #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_action_datacenter_id: Warning: remove extra items ", r #obtain data, check that only one exist result, content = nfvo.datacenter_new_netmap(mydb, tenant_id, datacenter_id, http_content) if result < 0: print "http_postnetmap_datacenter_id error %d %s" % (result, content) bottle.abort(-result, content) convert_datetime2str(content) utils.convert_str2boolean(content, ('shared', 'multipoint') ) print content data={'netmaps' : content} return format_out(data)
Example #15
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_delete_flavor_id(tenant_id, flavor_id): '''Deletes the flavor_id of a tenant. IT removes from tenants_flavors table.''' my = config_dic['http_threads'][ threading.current_thread().name ] #check valid tenant_id result,content = check_valid_tenant(my, tenant_id) if result != 0: bottle.abort(result, content) return result, content = my.db.delete_image_flavor('flavor', flavor_id, tenant_id) if result == 0: bottle.abort(HTTP_Not_Found, content) elif result >0: data={'result' : content} return format_out(data) else: print "http_delete_flavor_id error",result, content bottle.abort(-result, content) return
Example #16
Source File: main.py From rxivist with GNU Affero General Public License v3.0 | 6 votes |
def get_distros(entity, metric): if entity not in ["paper", "author"]: bottle.response.status = 404 return {"error": f"Unknown entity: expected 'paper' or 'author'; got '{entity}'"} if metric not in ["downloads"]: bottle.response.status = 404 return {"error": f"Unknown entity: expected 'downloads'; got '{metric}'"} try: results, averages = endpoints.get_distribution(entity, metric, connection) except Exception as e: bottle.response.status = 500 return {"error": f"Server error – {e}"} return { "histogram": [{"bucket_min": x[0], "count": x[1]} for x in results], "averages": { "mean": averages["mean"], "median": averages["median"] } }
Example #17
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_action_datacenter_id(tenant_id, datacenter_id): '''perform an action over datacenter, can use both uuid or name''' #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 #obtain data, check that only one exist result, content = nfvo.datacenter_action(mydb, tenant_id, datacenter_id, http_content) if result < 0: print "http_action_datacenter_id error %d %s" % (result, content) bottle.abort(-result, content) if 'net-update' in http_content: return http_getnetmap_datacenter_id(datacenter_id) else: return format_out(content)
Example #18
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_edit_tenant_id(tenant_id): '''edit tenant details, can use both uuid or name''' #parse input data 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 #obtain data, check that only one exist result, content = mydb.get_table_by_uuid_name('nfvo_tenants', tenant_id) if result < 0: print "http_edit_tenant_id error %d %s" % (result, content) bottle.abort(-result, content) #edit data tenant_id = content['uuid'] where={'uuid': content['uuid']} result, content = mydb.update_rows('nfvo_tenants', http_content['tenant'], where) if result < 0: print "http_edit_tenant_id error %d %s" % (result, content) bottle.abort(-result, content) return http_get_tenant_id(tenant_id)
Example #19
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_delete_host_id(host_id): my = config_dic['http_threads'][ threading.current_thread().name ] #check permissions if not my.admin: bottle.abort(HTTP_Unauthorized, "Needed admin privileges") result, content = my.db.delete_row('hosts', host_id) if result == 0: bottle.abort(HTTP_Not_Found, content) elif result >0: #terminate thread if host_id in config_dic['host_threads']: config_dic['host_threads'][host_id].insert_task("exit") #return data data={'result' : content} return format_out(data) else: print "http_delete_host_id error",result, content bottle.abort(-result, content) return # # TENANTS #
Example #20
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_associate_datacenters(tenant_id, datacenter_id): '''associate an existing datacenter to a this tenant. ''' #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 result, data = 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') ) if result < 0: print "http_associate_datacenters error %d %s" % (-result, data) bottle.abort(-result, data) else: print "http_associate_datacenters data" , data return http_get_datacenter_id(tenant_id, data)
Example #21
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_get_scenario_id(tenant_id, scenario_id): '''get scenario details, can use both uuid or name''' #check valid tenant_id if tenant_id != "any" and not nfvo.check_tenant(mydb, tenant_id): print "httpserver.http_get_scenario_id() tenant '%s' not found" % tenant_id bottle.abort(HTTP_Not_Found, "Tenant '%s' not found" % tenant_id) return #obtain data result, content = mydb.get_scenario(scenario_id, tenant_id) if result < 0: print "http_get_scenario_id error %d %s" % (-result, content) bottle.abort(-result, content) else: #print json.dumps(content, indent=4) convert_datetime2str(content) data={'scenario' : content} return format_out(data)
Example #22
Source File: main.py From rxivist with GNU Affero General Public License v3.0 | 5 votes |
def error404(error): bottle.response.set_header("Content-Type", "application/json") return "{\"error\": \"unrecognized URL\"}" # - SERVER -
Example #23
Source File: detector_webapp.py From pipeline with BSD 3-Clause "New" or "Revised" License | 5 votes |
def error_handler_500(error): log.error(error.exception) return repr(error.exception)
Example #24
Source File: server.py From maloja with GNU General Public License v3.0 | 5 votes |
def customerror(error): code = int(str(error).split(",")[0][1:]) if os.path.exists(pthjoin(WEBFOLDER,"errors",str(code) + ".pyhp")): return pyhpfile(pthjoin(WEBFOLDER,"errors",str(code) + ".pyhp"),{"errorcode":code}) else: return pyhpfile(pthjoin(WEBFOLDER,"errors","generic.pyhp"),{"errorcode":code})
Example #25
Source File: main.py From rxivist with GNU Affero General Public License v3.0 | 5 votes |
def get_category_list(): try: category_list = endpoints.get_categories(connection) except Exception as e: bottle.response.status = 500 return {"error": f"Server error – {e}"} return { "results": category_list } # stat distributions endpoint
Example #26
Source File: httpserver.py From openmano with Apache License 2.0 | 5 votes |
def http_get_vnf_id(tenant_id,vnf_id): '''get vnf details, can use both uuid or name''' result, data = nfvo.get_vnf_id(mydb,tenant_id,vnf_id) if result < 0: print "http_post_vnfs error %d %s" % (-result, data) bottle.abort(-result, data) utils.convert_str2boolean(data, ('public',)) convert_datetime2str(data) return format_out(data)
Example #27
Source File: webserver.py From pagan with GNU General Public License v2.0 | 5 votes |
def error404(code): """handle error 404 """ return template('{{code}} Avatar not found. You may use this:', code=code)
Example #28
Source File: httpserver.py From openmano with Apache License 2.0 | 5 votes |
def http_delete_vnf_id(tenant_id,vnf_id): '''delete a vnf from database, and images and flavors in VIM when appropriate, can use both uuid or name''' #check valid tenant_id and deletes the vnf, including images, result, data = nfvo.delete_vnf(mydb,tenant_id,vnf_id) if result < 0: print "http_delete_vnf_id error %d %s" % (-result, data) bottle.abort(-result, data) else: #print json.dumps(data, indent=4) return format_out({"result":"VNF " + data + " deleted"}) #@bottle.route(url_base + '/<tenant_id>/hosts/topology', method='GET') #@bottle.route(url_base + '/<tenant_id>/physicalview/Madrid-Alcantara', method='GET')
Example #29
Source File: httpserver.py From openmano with Apache License 2.0 | 5 votes |
def http_post_vnfs(tenant_id): '''insert a vnf into the catalogue. Creates the flavor and images in the VIM, and creates the VNF and its internal structure in the OPENMANO DB''' print "Parsing the YAML file of the VNF" #parse input data http_content, used_schema = format_in( vnfd_schema_v01, ("version",), {"v0.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 result, data = nfvo.new_vnf(mydb,tenant_id,http_content) if result < 0: print "http_post_vnfs error %d %s" % (-result, data) bottle.abort(-result, data) else: return http_get_vnf_id(tenant_id,data)
Example #30
Source File: serve.py From metadoc with MIT License | 5 votes |
def error404(error): return json.dumps({'code': 404,'message': 'url param is missing.'})