- #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
+ logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+ try:
+ if tenant_id != 'any':
+ #check valid tenant_id
+ nfvo.check_tenant(mydb, tenant_id)
+ #obtain data
+ 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', '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
+ from_='datacenters as d join tenants_datacenters as td on d.uuid=td.datacenter_id'
+ else:
+ from_='datacenters as d'
+ datacenters = mydb.get_rows(
+ SELECT=select_,
+ FROM=from_,
+ WHERE=where_)
+
+ if len(datacenters)==0:
+ bottle.abort( HTTP_Not_Found, "No datacenter found for tenant with {} '{}'".format(what, datacenter_id) )
+ elif len(datacenters)>1:
+ bottle.abort( HTTP_Bad_Request, "More than one datacenter found for tenant with {} '{}'".format(what, datacenter_id) )
+ datacenter = datacenters[0]
+ if tenant_id != 'any':
+ #get vim tenant info
+ vim_tenants = mydb.get_rows(
+ 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 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)
+ data={'datacenter' : datacenter}
+ return format_out(data)
+ 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))