本文整理汇总了Python中bottle.error方法的典型用法代码示例。如果您正苦于以下问题:Python bottle.error方法的具体用法?Python bottle.error怎么用?Python bottle.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle
的用法示例。
在下文中一共展示了bottle.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: http_delete_host_id
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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
#
示例2: http_delete_flavor_id
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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
示例3: http_post_images
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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
示例4: http_delete_image_id
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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
示例5: http_get_networks
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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)
示例6: http_clear_openflow_rules
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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)
示例7: http_get_port_id
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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)
示例8: http_edit_tenant_id
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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)
示例9: http_delnetmap_datacenter_id
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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})
示例10: http_postnetmap_datacenter_id
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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)
示例11: http_action_datacenter_id
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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)
示例12: http_associate_datacenters
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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)
示例13: http_get_hosts
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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)
示例14: http_post_scenarios
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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)
示例15: http_get_scenarios
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import error [as 别名]
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)