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_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)
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)
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) af.convert_str2boolean(data, ('public',)) convert_datetime2str(data) return format_out(data)
def http_uploadnetmap_datacenter_id(tenant_id, datacenter_id): result, content = nfvo.datacenter_new_netmap(mydb, tenant_id, datacenter_id, None) if result < 0: print "http_postnetmap_datacenter_id error %d %s" % (result, content) bottle.abort(-result, content) convert_datetime2str(content) af.convert_str2boolean(content, ('shared', 'multipoint') ) print content data={'netmaps' : content} return format_out(data)
def http_postnetmap_datacenter_id(tenant_id, datacenter_id): '''creates a new netmap''' #parse input data http_content,_ = format_in( netmap_new_schema ) r = af.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) af.convert_str2boolean(content, ('shared', 'multipoint') ) print content data={'netmaps' : content} return format_out(data)
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)
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)
def http_getnetwork_datacenter_id(datacenter_id): '''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) #change_keys_http2db(content, http2db_tenant, reverse=True) result, content =mydb.get_table(FROM='datacenter_nets', SELECT=('name','vim_net_id as uuid','type','multipoint','shared','description', 'created_at'), WHERE={"datacenter_id":datacenter_dict['uuid']} ) 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') ) print content data={'networks' : content} return format_out(data)
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)
def http_getnetwork_datacenter_id(datacenter_id): """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) # change_keys_http2db(content, http2db_tenant, reverse=True) result, content = mydb.get_table( FROM="datacenter_nets", SELECT=("name", "vim_net_id as uuid", "type", "multipoint", "shared", "description", "created_at"), WHERE={"datacenter_id": datacenter_dict["uuid"]}, ) 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")) print content data = {"networks": content} return format_out(data)
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) af.convert_str2boolean(data, ('public',) ) scenarios={'scenarios':data} #print json.dumps(scenarios, indent=4) return format_out(scenarios)
def http_get_vnf_id(tenant_id,vnf_id): '''get vnf details, can use both uuid or name''' #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 #obtain data result, content = mydb.get_table_by_uuid_name('vnfs', vnf_id, "VNF") if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) vnf_id=content["uuid"] filter_keys = ('uuid','name','description','path','physical','public', "created_at") filtered_content = dict( (k,v) for k,v in content.iteritems() if k in filter_keys ) #change_keys_http2db(filtered_content, http2db_vnf, reverse=True) af.convert_str2boolean(filtered_content, ('physical','public',)) convert_datetime2str(filtered_content) data={'vnf' : filtered_content} #GET VM result,content = mydb.get_table(FROM='vnfs join vms on vnfs.uuid=vms.vnf_id', SELECT=('vms.uuid as uuid','vms.name as name', 'vms.description as description'), WHERE={'vnfs.uuid': vnf_id} ) if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) elif result==0: print "http_get_vnf_id vnf '%s' not found" % vnf_id bottle.abort(HTTP_Not_Found, "vnf %s not found" % vnf_id) data['vnf']['VNFC'] = content #GET NET result,content = mydb.get_table(FROM='vnfs join nets on vnfs.uuid=nets.vnf_id', SELECT=('nets.uuid as uuid','nets.name as name','nets.description as description', 'nets.type as type', 'nets.multipoint as multipoint'), WHERE={'vnfs.uuid': vnf_id} ) print content if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) else: if result==0: data['vnf']['nets'] = [] else: data['vnf']['nets'] = content #GET Interfaces result,content = mydb.get_table(FROM='vnfs join vms on vnfs.uuid=vms.vnf_id join interfaces on vms.uuid=interfaces.vm_id',\ SELECT=('interfaces.uuid as uuid','interfaces.external_name as external_name', 'vms.name as vm_name', 'interfaces.vm_id as vm_id', \ 'interfaces.internal_name as internal_name', 'interfaces.type as type', 'interfaces.vpci as vpci','interfaces.bw as bw'),\ WHERE={'vnfs.uuid': vnf_id}, WHERE_NOTNULL=('interfaces.external_name',) ) print content if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) else: if result==0: data['vnf']['external-connections'] = [] else: data['vnf']['external-connections'] = content return format_out(data)
def http_get_vnf_id(tenant_id,vnf_id): '''get vnf details, can use both uuid or name''' #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 #obtain data result, content = mydb.get_table_by_uuid_name('vnfs', vnf_id, "VNF") if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) vnf_id=content["uuid"] filter_keys = ('uuid','name','description','path','physical','public', "created_at") filtered_content = dict( (k,v) for k,v in content.iteritems() if k in filter_keys ) #change_keys_http2db(filtered_content, http2db_vnf, reverse=True) af.convert_str2boolean(filtered_content, ('physical','public',)) convert_datetime2str(filtered_content) data={'vnf' : filtered_content} #GET VM result,content = mydb.get_table(FROM='vnfs join vms on vnfs.uuid=vms.vnf_id', SELECT=('vms.uuid as uuid','vim_flavor_id','vim_image_id','vms.name as name', 'vms.description as description'), WHERE={'vnfs.uuid': vnf_id} ) if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) elif result==0: print "http_get_vnf_id vnf '%s' not found" % vnf_id bottle.abort(HTTP_Not_Found, "vnf %s not found" % vnf_id) data['vnf']['VNFC'] = content #GET NET result,content = mydb.get_table(FROM='vnfs join nets on vnfs.uuid=nets.vnf_id', SELECT=('nets.uuid as uuid','nets.name as name','nets.description as description', 'nets.type as type', 'nets.multipoint as multipoint'), WHERE={'vnfs.uuid': vnf_id} ) print content if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) else: if result==0: data['vnf']['nets'] = [] else: data['vnf']['nets'] = content #GET Interfaces result,content = mydb.get_table(FROM='vnfs join vms on vnfs.uuid=vms.vnf_id join interfaces on vms.uuid=interfaces.vm_id',\ SELECT=('interfaces.uuid as uuid','interfaces.external_name as external_name', 'vms.name as vm_name', 'interfaces.vm_id as vm_id', \ 'interfaces.internal_name as internal_name', 'interfaces.type as type', 'interfaces.vpci as vpci','interfaces.bw as bw'),\ WHERE={'vnfs.uuid': vnf_id}, WHERE_NOTNULL=('interfaces.external_name',) ) print content if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) else: if result==0: data['vnf']['external-connections'] = [] else: data['vnf']['external-connections'] = content return format_out(data)
def http_get_vnf_id(tenant_id, vnf_id): """get vnf details, can use both uuid or name""" # 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 # obtain data result, content = mydb.get_table_by_uuid_name("vnfs", vnf_id, "VNF") if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) vnf_id = content["uuid"] filter_keys = ("uuid", "name", "description", "path", "physical", "public", "created_at") filtered_content = dict((k, v) for k, v in content.iteritems() if k in filter_keys) # change_keys_http2db(filtered_content, http2db_vnf, reverse=True) af.convert_str2boolean(filtered_content, ("physical", "public")) convert_datetime2str(filtered_content) data = {"vnf": filtered_content} # GET VM result, content = mydb.get_table( FROM="vnfs join vms on vnfs.uuid=vms.vnf_id", SELECT=("vms.uuid as uuid", "vms.name as name", "vms.description as description"), WHERE={"vnfs.uuid": vnf_id}, ) if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) elif result == 0: print "http_get_vnf_id vnf '%s' not found" % vnf_id bottle.abort(HTTP_Not_Found, "vnf %s not found" % vnf_id) data["vnf"]["VNFC"] = content # GET NET result, content = mydb.get_table( FROM="vnfs join nets on vnfs.uuid=nets.vnf_id", SELECT=( "nets.uuid as uuid", "nets.name as name", "nets.description as description", "nets.type as type", "nets.multipoint as multipoint", ), WHERE={"vnfs.uuid": vnf_id}, ) print content if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) else: if result == 0: data["vnf"]["nets"] = [] else: data["vnf"]["nets"] = content # GET Interfaces result, content = mydb.get_table( FROM="vnfs join vms on vnfs.uuid=vms.vnf_id join interfaces on vms.uuid=interfaces.vm_id", SELECT=( "interfaces.uuid as uuid", "interfaces.external_name as external_name", "vms.name as vm_name", "interfaces.vm_id as vm_id", "interfaces.internal_name as internal_name", "interfaces.type as type", "interfaces.vpci as vpci", "interfaces.bw as bw", ), WHERE={"vnfs.uuid": vnf_id}, WHERE_NOTNULL=("interfaces.external_name",), ) print content if result < 0: print "http_get_vnf_id error %d %s" % (result, content) bottle.abort(-result, content) else: if result == 0: data["vnf"]["external-connections"] = [] else: data["vnf"]["external-connections"] = content return format_out(data)