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)
def http_getnetmap_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_getnetwork_datacenter_id error %d %s" % (result, datacenter_dict) bottle.abort(-result, datacenter_dict) where_= {"datacenter_id":datacenter_dict['uuid']} if netmap_id: if af.check_valid_uuid(netmap_id): where_["uuid"] = netmap_id else: where_["name"] = netmap_id result, content =mydb.get_table(FROM='datacenter_nets', SELECT=('name','vim_net_id as vim_id', 'uuid', 'type','multipoint','shared','description', 'created_at'), WHERE=where_ ) if result < 0: print "http_getnetwork_datacenter_id error %d %s" % (result, content) bottle.abort(-result, content) convert_datetime2str(content) af.convert_str2boolean(content, ('shared', 'multipoint') ) if netmap_id and len(content)==1: data={'netmap' : content[0]} elif netmap_id and len(content)==0: bottle.abort(HTTP_Not_Found, "No netmap found with " + " and ".join(map(lambda x: str(x[0])+": "+str(x[1]), where_.iteritems())) ) return else: data={'netmaps' : content} return format_out(data)
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)
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': 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 = yaml.load(content[0]['config']) content[0]['config'] = config_dict except Exception, e: print "Exception '%s' while trying to load config information" % str( e)
def http_get_network_id(tenant_id, network_id): '''get network 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_network_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(network_id) else 'name' where_={} where_[what] = network_id select_=('uuid', 'name','vim_url', 'vim_url_admin', 'type', 'config', 'description', 'd.created_at as created_at') if tenant_id != 'any': where_['td.nfvo_tenant_id']= tenant_id from_='networks as d join tenants_networks as td on d.uuid=td.network_id' else: from_='networks as d' result, content = mydb.get_table( SELECT=select_, FROM=from_, WHERE=where_) if result < 0: print "http_get_network_id error %d %s" % (result, content) bottle.abort(-result, content) elif result==0: bottle.abort( HTTP_Not_Found, "No network found for tenant with %s '%s'" %(what, network_id) ) elif result>1: bottle.abort( HTTP_Bad_Request, "More than one network found for tenant with %s '%s'" %(what, network_id) ) 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)
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 if tenant_id != 'any': where['td.nfvo_tenant_id']= tenant_id result, content = mydb.get_table( SELECT=('uuid', 'name','vim_url', 'vim_url_admin', 'd.created_at as created_at'), FROM='datacenters as d join tenants_datacenters as td on d.uuid=td.datacenter_id', WHERE=where) else: result, content = mydb.get_table( SELECT=('uuid', 'name','vim_url', 'vim_url_admin', 'created_at'), FROM='datacenters', 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 #change_keys_http2db(content, http2db_datacenter, reverse=True) convert_datetime2str(content[0]) data={'datacenter' : content[0]} return format_out(data)
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 af.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})