本文整理汇总了Python中nfvo.check_tenant函数的典型用法代码示例。如果您正苦于以下问题:Python check_tenant函数的具体用法?Python check_tenant怎么用?Python check_tenant使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_tenant函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: http_get_datacenter_id
def http_get_datacenter_id(tenant_id, datacenter_id):
"""get datacenter details, can use both uuid or name"""
# check valid tenant_id
if tenant_id != "any":
if not nfvo.check_tenant(mydb, tenant_id):
print "httpserver.http_get_datacenter_id () tenant %s not found" % tenant_id
bottle.abort(HTTP_Not_Found, "Tenant %s not found" % tenant_id)
return
# obtain data
what = "uuid" if af.check_valid_uuid(datacenter_id) else "name"
where_ = {}
where_[what] = datacenter_id
select_ = ("uuid", "name", "vim_url", "vim_url_admin", "type", "config", "d.created_at as created_at")
if tenant_id != "any":
where_["td.nfvo_tenant_id"] = tenant_id
from_ = "datacenters as d join tenants_datacenters as td on d.uuid=td.datacenter_id"
else:
from_ = "datacenters as d"
result, content = mydb.get_table(SELECT=select_, FROM=from_, WHERE=where_)
if result < 0:
print "http_get_datacenter_id error %d %s" % (result, content)
bottle.abort(-result, content)
elif result == 0:
bottle.abort(HTTP_Not_Found, "No datacenter found for tenant with %s '%s'" % (what, datacenter_id))
elif result > 1:
bottle.abort(HTTP_Bad_Request, "More than one datacenter found for tenant with %s '%s'" % (what, datacenter_id))
print content
if content[0]["config"] != None:
try:
config_dict = json.loads(content[0]["config"])
content[0]["config"] = config_dict
except Exception, e:
print "Exception '%s' while trying to load config information" % str(e)
示例2: http_post_instance_scenario_action
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 = af.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)
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)
示例3: http_get_datacenters
def http_get_datacenters(tenant_id):
# check valid tenant_id
if tenant_id != "any":
if not nfvo.check_tenant(mydb, tenant_id):
print "httpserver.http_get_datacenters () tenant %s not found" % tenant_id
bottle.abort(HTTP_Not_Found, "Tenant %s not found" % tenant_id)
return
select_, where_, limit_ = filter_query_string(
bottle.request.query, None, ("uuid", "name", "vim_url", "type", "created_at")
)
if tenant_id != "any":
where_["nfvo_tenant_id"] = tenant_id
if "created_at" in select_:
select_[select_.index("created_at")] = "d.created_at as created_at"
if "created_at" in where_:
where_["d.created_at"] = where_.pop("created_at")
result, content = mydb.get_table(
FROM="datacenters as d join tenants_datacenters as td on d.uuid=td.datacenter_id",
SELECT=select_,
WHERE=where_,
LIMIT=limit_,
)
else:
result, content = mydb.get_table(FROM="datacenters", SELECT=select_, WHERE=where_, LIMIT=limit_)
if result < 0:
print "http_get_datacenters Error", content
bottle.abort(-result, content)
else:
# change_keys_http2db(content, http2db_tenant, reverse=True)
convert_datetime2str(content)
data = {"datacenters": content}
return format_out(data)
示例4: http_get_instance_id
def http_get_instance_id(tenant_id, instance_id):
'''get instances details, can use both uuid or name'''
#check valid tenant_id
if not nfvo.check_tenant(mydb, tenant_id):
print 'httpserver.http_get_instance_id() tenant %s not found' % tenant_id
bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id)
return
#obtain data (first time is only to check that the instance exists)
result, data = mydb.get_instance_scenario(instance_id, tenant_id, verbose=True)
if result < 0:
print "http_get_instance_id error %d %s" % (-result, data)
bottle.abort(-result, data)
return
r,c = nfvo.refresh_instance(mydb, tenant_id, data)
if r<0:
print "WARNING: nfvo.refresh_instance couldn't refresh the status of the instance: %s" %c
#obtain data with results upated
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)
return
convert_datetime2str(data)
print json.dumps(data, indent=4)
return format_out(data)
示例5: http_get_datacenters
def http_get_datacenters(tenant_id):
#check valid tenant_id
if tenant_id != 'any':
if not nfvo.check_tenant(mydb, tenant_id):
print 'httpserver.http_get_datacenters () tenant %s not found' % tenant_id
bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id)
return
select_,where_,limit_ = filter_query_string(bottle.request.query, None,
('uuid','name','vim_url','type','created_at') )
if tenant_id != 'any':
where_['nfvo_tenant_id'] = tenant_id
if 'created_at' in select_:
select_[ select_.index('created_at') ] = 'd.created_at as created_at'
if 'created_at' in where_:
where_['d.created_at'] = where_.pop('created_at')
result, content = mydb.get_table(FROM='datacenters as d join tenants_datacenters as td on d.uuid=td.datacenter_id',
SELECT=select_,WHERE=where_,LIMIT=limit_)
else:
result, content = mydb.get_table(FROM='datacenters',
SELECT=select_,WHERE=where_,LIMIT=limit_)
if result < 0:
print "http_get_datacenters Error", content
bottle.abort(-result, content)
else:
#change_keys_http2db(content, http2db_tenant, reverse=True)
convert_datetime2str(content)
data={'datacenters' : content}
return format_out(data)
示例6: http_get_instance_id
def http_get_instance_id(tenant_id, instance_id):
'''get instances details, can use both uuid or name'''
#check valid tenant_id
if 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
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)
return
# print "Query: %s", bottle.request.query
# refresh=True
# if refresh:
# r,c = nfvo.refresh_instance(mydb, tenant_id, data, datacenter=None, vim_tenant=None)
# if r<0:
# print "WARNING: nfvo.refresh_instance had a problem: %s" %c
# #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)
# return
print json.dumps(data, indent=4)
return format_out(data)
示例7: http_post_scenario_action
def http_post_scenario_action(tenant_id, scenario_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,_ = format_in( scenario_action_schema )
r = af.remove_extra_items(http_content, scenario_action_schema)
if r is not None: print "http_post_scenario_action: Warning: remove extra items ", r
if "start" in http_content:
result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['start']['instance_name'], \
http_content['start'].get('description',http_content['start']['instance_name']),
http_content['start'].get('datacenter') )
if result < 0:
print "http_post_scenario_action start error %d: %s" % (-result, data)
bottle.abort(-result, data)
else:
return format_out(data)
elif "deploy" in http_content: #Equivalent to start
result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['deploy']['instance_name'],
http_content['deploy'].get('description',http_content['deploy']['instance_name']),
http_content['deploy'].get('datacenter') )
if result < 0:
print "http_post_scenario_action deploy error %d: %s" % (-result, data)
bottle.abort(-result, data)
else:
return format_out(data)
elif "reserve" in http_content: #Reserve resources
result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['reserve']['instance_name'],
http_content['reserve'].get('description',http_content['reserve']['instance_name']),
http_content['reserve'].get('datacenter'), startvms=False )
if result < 0:
print "http_post_scenario_action reserve error %d: %s" % (-result, data)
bottle.abort(-result, data)
else:
return format_out(data)
elif "verify" in http_content: #Equivalent to start and then delete
result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['verify']['instance_name'],
http_content['verify'].get('description',http_content['verify']['instance_name']),
http_content['verify'].get('datacenter'), startvms=False )
if result < 0 or result!=1:
print "http_post_scenario_action verify error during start %d: %s" % (-result, data)
bottle.abort(-result, data)
instance_id = data['uuid']
result, message = nfvo.delete_instance(mydb, tenant_id,instance_id)
if result < 0:
print "http_post_scenario_action verify error during start delete_instance_id %d %s" % (-result, message)
bottle.abort(-result, message)
else:
#print json.dumps(data, indent=4)
return format_out({"result":"Verify OK"})
示例8: http_get_datacenter_id
def http_get_datacenter_id(tenant_id, datacenter_id):
'''get datacenter details, can use both uuid or name'''
#check valid tenant_id
if tenant_id != 'any':
if not nfvo.check_tenant(mydb, tenant_id):
print 'httpserver.http_get_datacenter_id () tenant %s not found' % tenant_id
bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id)
return
#obtain data
what = 'uuid' if af.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']
if tenant_id != 'any':
select_.append("datacenter_tenant_id")
where_['td.nfvo_tenant_id']= tenant_id
from_='datacenters as d join tenants_datacenters as td on d.uuid=td.datacenter_id'
else:
from_='datacenters as d'
result, content = mydb.get_table(
SELECT=select_,
FROM=from_,
WHERE=where_)
if result < 0:
print "http_get_datacenter_id error %d %s" % (result, content)
bottle.abort(-result, content)
elif result==0:
bottle.abort( HTTP_Not_Found, "No datacenter found for tenant with %s '%s'" %(what, datacenter_id) )
elif result>1:
bottle.abort( HTTP_Bad_Request, "More than one datacenter found for tenant with %s '%s'" %(what, datacenter_id) )
if tenant_id != 'any':
#get vim tenant info
result, content2 = mydb.get_table(
SELECT=("vim_tenant_name", "vim_tenant_id", "user"),
FROM="datacenter_tenants",
WHERE={"uuid": content[0]["datacenter_tenant_id"]},
ORDER_BY=("created", ) )
del content[0]["datacenter_tenant_id"]
if result < 0:
print "http_get_datacenter_id vim_tenant_info error %d %s" % (result, content2)
bottle.abort(-result, content2)
content[0]["vim_tenants"] = content2
print content
if content[0]['config'] != None:
try:
config_dict = yaml.load(content[0]['config'])
content[0]['config'] = config_dict
except Exception, e:
print "Exception '%s' while trying to load config information" % str(e)
示例9: http_delete_instance_id
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 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
#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})
示例10: http_delete_scenario_id
def http_delete_scenario_id(tenant_id, scenario_id):
'''delete a scenario from database, can use both uuid or name'''
#check valid tenant_id
if not nfvo.check_tenant(mydb, tenant_id):
print 'httpserver.http_delete_scenario_id() tenant %s not found' % tenant_id
bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id)
return
#obtain data
result, data = mydb.delete_scenario(scenario_id, tenant_id)
if result < 0:
print "http_delete_scenario_id error %d %s" % (-result, data)
bottle.abort(-result, data)
else:
#print json.dumps(data, indent=4)
return format_out({"result":"Scenario " + data + " deleted"})
示例11: http_get_scenario_id
def http_get_scenario_id(tenant_id, scenario_id):
'''get scenario details, can use both uuid or name'''
#check valid tenant_id
if 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)
data={'scenario' : content}
return format_out(data)
示例12: http_post_instances
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 = af.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)
示例13: http_get_vnfs
def http_get_vnfs(tenant_id):
#check valid tenant_id
if not nfvo.check_tenant(mydb, tenant_id):
print 'httpserver.http_get_vnf_id() tenant %s not found' % tenant_id
bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id)
return
select_,where_,limit_ = filter_query_string(bottle.request.query, None,
('uuid','name','description','path','physical','public', "created_at") )
result, content = mydb.get_table(FROM='vnfs', SELECT=select_,WHERE=where_,LIMIT=limit_)
if result < 0:
print "http_get_vnfs Error", content
bottle.abort(-result, content)
else:
#change_keys_http2db(content, http2db_vnf, reverse=True)
af.convert_str2boolean(content, ('physical','public',))
convert_datetime2str(content)
data={'vnfs' : content}
return format_out(data)
示例14: http_get_instances
def http_get_instances(tenant_id):
'''get instance list'''
#check valid tenant_id
if 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', 'description', 'created_at'))
w['nfvo_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:
af.convert_datetime2str(data)
af.convert_str2boolean(data, ('public',) )
instances={'instances':data}
print json.dumps(instances, indent=4)
return format_out(instances)
示例15: http_get_scenarios
def http_get_scenarios(tenant_id):
"""get scenarios list"""
# check valid tenant_id
if 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", "created_at", "public"))
w["nfvo_tenant_id"] = tenant_id
result, data = mydb.get_table(SELECT=s, WHERE=w, LIMIT=l, FROM="scenarios")
if result < 0:
print "http_get_scenarios error %d %s" % (-result, data)
bottle.abort(-result, data)
else:
af.convert_datetime2str(data)
af.convert_str2boolean(data, ("public",))
scenarios = {"scenarios": data}
print json.dumps(scenarios, indent=4)
return format_out(scenarios)