Python bottle.abort() Examples
The following are 30
code examples of bottle.abort().
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: restapi.py From lokun-record with GNU Affero General Public License v3.0 | 7 votes |
def vpn_report(name): keyinfo= key_auth() user = model.User.get(name) if not 'dl' in request.forms: abort(400, "Must include dl") dl = int(request.forms['dl']) if dl < 0: abort(400, "dl must be >= 0") user.dl_left = user.dl_left - dl if user.dl_left < 0: logger.email("dl_finished: " + ",".join(user.username, user.sub_end)) user.save() log("Report for a user recieved (user disconnected from {0})".format(keyinfo.name)) return {} #---------- # /nodes/ #----------
Example #2
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 #3
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 #4
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 #5
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_put_tenant_id(tenant_id): '''update a tenant into the database.''' my = config_dic['http_threads'][ threading.current_thread().name ] #parse input data http_content = format_in( tenant_edit_schema ) r = remove_extra_items(http_content, tenant_edit_schema) if r is not None: print "http_put_tenant_id: Warning: remove extra items ", r change_keys_http2db(http_content['tenant'], http2db_tenant) #insert in data base result, content = my.db.update_rows('tenants', http_content['tenant'], WHERE={'uuid': tenant_id}, log=True ) if result >= 0: return http_get_tenant_id(tenant_id) else: bottle.abort(-result, content) return
Example #6
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_post_tenants(): '''insert a tenant into the database.''' my = config_dic['http_threads'][ threading.current_thread().name ] #parse input data http_content = format_in( tenant_new_schema ) r = remove_extra_items(http_content, tenant_new_schema) if r is not None: print "http_post_tenants: Warning: remove extra items ", r change_keys_http2db(http_content['tenant'], http2db_tenant) #insert in data base result, content = my.db.new_tenant(http_content['tenant']) if result >= 0: return http_get_tenant_id(content) else: bottle.abort(-result, content) return
Example #7
Source File: restapi.py From lokun-record with GNU Affero General Public License v3.0 | 6 votes |
def getallnodes(): key_auth() transform = lambda nl: [dict(node) for node in nl] if not request.params.filter or request.params.filter == "all": return {'data': transform(model.NodeList.get()) } elif request.params.filter == "best": return {'data': transform(model.NodeList.best()) } elif request.params.filter == "alive": return {'data': transform(model.NodeList.best()) } elif request.params.filter == "down": return {'data': transform(model.NodeList.down()) } elif request.params.fitler == "disabled": return {'data': transform(model.NodeList.disabled()) } else: abort(400, "Invalid filter")
Example #8
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_get_hosts(): select_,where_,limit_ = filter_query_string(bottle.request.query, http2db_host, ('id','name','description','status','admin_state_up') ) myself = config_dic['http_threads'][ threading.current_thread().name ] result, content = myself.db.get_table(FROM='hosts', SELECT=select_, WHERE=where_, LIMIT=limit_) if result < 0: print "http_get_hosts Error", content bottle.abort(-result, content) else: convert_boolean(content, ('admin_state_up',) ) change_keys_http2db(content, http2db_host, reverse=True) for row in content: row['links'] = ( {'href': myself.url_preffix + '/hosts/' + str(row['id']), 'rel': 'bookmark'}, ) data={'hosts' : content} return format_out(data)
Example #9
Source File: restapi.py From lokun-record with GNU Affero General Public License v3.0 | 6 votes |
def dalpay(): # Since deciding to create lokun-billing, this got a # bit.. hacky. try: passwd = request.forms["SilentPostPassword"] if not sec.compare(passwd, config.dalpay_passwd): log("DalPay: Invalid SilentPostPassword") abort(401, "Unauthorized") message = request.forms["user1"] dalpay = DalPay.read(message, key=config.dalpay_key) cardtype = request.forms["pay_type"] fees = calculate_fees(cardtype, dalpay.amount) model.Deposit.new(dalpay.username, dalpay.amount, cardtype, vsk=25.5, fees=fees, deposit=True) logger.email("DalPay: {0},{1}".format(dalpay.username, dalpay.amount)) return config.dalpay_return except ValueError as ve: logger.email("DalPay: " + str(ve)) # Do i need to log something more? BK 22.03.2014 return "<!-- error: {0} -->".format(str(ve))
Example #10
Source File: app.py From ivre with GNU General Public License v3.0 | 6 votes |
def parse_form(): categories = request.forms.get("categories") categories = (set(categories.split(',')) if categories else set()) source = request.forms.get("source") if not source: utils.LOGGER.critical("source is mandatory") abort(400, "ERROR: source is mandatory\n") files = request.files.getall("result") if config.WEB_PUBLIC_SRV: if webutils.get_user() is None: utils.LOGGER.critical("username is mandatory on public instances") abort(400, "ERROR: username is mandatory on public instances") if request.forms.get('public') == 'on': categories.add('Shared') user = webutils.get_anonymized_user() categories.add(user) source = "%s-%s" % (user, source) return (request.forms.get('referer'), source, categories, files)
Example #11
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 #12
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 #13
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 #14
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 #15
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 #16
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_get_network_id(network_id): my = config_dic['http_threads'][ threading.current_thread().name ] #obtain data where_ = bottle.request.query where_['uuid'] = network_id result, content = my.db.get_table(FROM='nets', WHERE=where_, LIMIT=100) if result < 0: print "http_get_networks_id error %d %s" % (result, content) bottle.abort(-result, content) elif result==0: print "http_get_networks_id network '%s' not found" % network_id bottle.abort(HTTP_Not_Found, 'network %s not found' % network_id) else: convert_boolean(content, ('shared', 'admin_state_up', 'enale_dhcp') ) change_keys_http2db(content, http2db_network, reverse=True) #get ports result, ports = my.db.get_table(FROM='ports', SELECT=('uuid as port_id',), WHERE={'net_id': network_id}, LIMIT=100) if len(ports) > 0: content[0]['ports'] = ports delete_nulls(content[0]) data={'network' : content[0]} return format_out(data)
Example #17
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_get_openflow_id(network_id): '''To obtain the list of openflow rules of a network ''' my = config_dic['http_threads'][ threading.current_thread().name ] #ignore input data if network_id=='all': where_={} else: where_={"net_id": network_id} result, content = my.db.get_table(SELECT=("name","net_id","priority","vlan_id","ingress_port","src_mac","dst_mac","actions"), WHERE=where_, FROM='of_flows') if result < 0: bottle.abort(-result, content) return data={'openflow-rules' : content} return format_out(data)
Example #18
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_put_scenario_id(tenant_id, scenario_id): '''edit an existing scenario id''' print "http_put_scenarios by tenant " + tenant_id http_content,_ = format_in( scenario_edit_schema ) #r = utils.remove_extra_items(http_content, scenario_edit_schema) #if r is not None: print "http_put_scenario_id: Warning: remove extra items ", r print "http_put_scenario_id input: ", http_content result, data = nfvo.edit_scenario(mydb, tenant_id, scenario_id, http_content) if result < 0: print "http_put_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 #19
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 #20
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_get_ports(): #obtain data my = config_dic['http_threads'][ threading.current_thread().name ] select_,where_,limit_ = filter_query_string(bottle.request.query, http2db_port, ('id','name','tenant_id','network_id','vpci','mac_address','device_owner','device_id', 'binding:switch_port','binding:vlan','bandwidth','status','admin_state_up','ip_address') ) #result, content = my.db.get_ports(where_) result, content = my.db.get_table(SELECT=select_, WHERE=where_, FROM='ports',LIMIT=limit_) if result < 0: print "http_get_ports Error", result, content bottle.abort(-result, content) return else: convert_boolean(content, ('admin_state_up',) ) delete_nulls(content) change_keys_http2db(content, http2db_port, reverse=True) data={'ports' : content} return format_out(data)
Example #21
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 #22
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 #23
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 #24
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_post_deploy(tenant_id): '''post topology deploy.''' print "http_post_deploy 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_deploy: Warning: remove extra items ", r print "http_post_deploy input: ", http_content result, scenario_uuid = nfvo.new_scenario(mydb, tenant_id, http_content) if result < 0: print "http_post_deploy error creating the scenario %d %s" % (-result, scenario_uuid) bottle.abort(-result, scenario_uuid) result, data = nfvo.start_scenario(mydb, tenant_id, scenario_uuid, http_content['name'], http_content['name']) if result < 0: print "http_post_deploy error launching the scenario %d %s" % (-result, data) bottle.abort(-result, data) else: print json.dumps(data, indent=4) return format_out(data)
Example #25
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 #26
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 #27
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 #28
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 #29
Source File: httpserver.py From openmano with Apache License 2.0 | 6 votes |
def http_post_server_action(tenant_id, server_id): '''take an action over a server''' 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 http_content = format_in( server_action_schema ) #r = remove_extra_items(http_content, server_action_schema) #if r is not None: print "http_post_server_action: Warning: remove extra items ", r return http_server_action(server_id, tenant_id, http_content) # # NETWORKS #
Example #30
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)