Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
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)
    instance_id = data["uuid"]
    
    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)
Esempio n. 5
0
def http_get_instance_id(tenant_id, instance_id):
    '''get instances details, can use both uuid or name'''
    #check valid tenant_id
    if tenant_id != "any" and 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
    if tenant_id == "any":
        tenant_id = None
  
    #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)
Esempio n. 6
0
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','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)
Esempio n. 7
0
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)
Esempio n. 8
0
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)
Esempio n. 9
0
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)
Esempio n. 10
0
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)
Esempio n. 11
0
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)
Esempio n. 12
0
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"})
Esempio n. 13
0
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"})
Esempio n. 14
0
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)
Esempio n. 15
0
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 utils.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)
Esempio n. 16
0
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})
Esempio n. 17
0
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"})
Esempio n. 18
0
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"})
Esempio n. 19
0
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})
Esempio n. 20
0
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)
Esempio n. 21
0
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)
Esempio n. 22
0
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)
Esempio n. 23
0
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 = utils.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)
Esempio n. 24
0
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)
Esempio n. 25
0
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)
Esempio n. 26
0
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)
Esempio n. 27
0
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)
Esempio n. 28
0
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)
Esempio n. 29
0
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)
Esempio n. 30
0
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)
Esempio n. 31
0
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)
    if result < 0:
        print "http_get_instance_id error %d %s" % (-result, data)
        bottle.abort(-result, data)
        return


#     OLD:
#     qs = bottle.request.query
#     if type(qs) is not bottle.FormsDict:
#         print '!!!!!!!!!!!!!!invalid query string not a dictionary'
#         bottle.abort(HTTP_Internal_Server_Error, "ttpserver.http_get_instance_id(): unexpected query string")
#     else:
#         print "Query: %s" %qs.dict
#         if 'refresh' in qs and qs.get('refresh')=="yes":
#             print "REFRESH: %s" %qs.get('refresh')
#             #refresh the instance
#             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
#         else:
#             print "NO REFRESH"

    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
    print json.dumps(data, indent=4)
    return format_out(data)
Esempio n. 32
0
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)
    if result < 0:
        print "http_get_instance_id error %d %s" % (-result, data)
        bottle.abort(-result, data)
        return
    
#     OLD:
#     qs = bottle.request.query
#     if type(qs) is not bottle.FormsDict:
#         print '!!!!!!!!!!!!!!invalid query string not a dictionary'
#         bottle.abort(HTTP_Internal_Server_Error, "ttpserver.http_get_instance_id(): unexpected query string")
#     else:
#         print "Query: %s" %qs.dict
#         if 'refresh' in qs and qs.get('refresh')=="yes":
#             print "REFRESH: %s" %qs.get('refresh')
#             #refresh the instance
#             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
#         else:
#             print "NO REFRESH"

    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
    print json.dumps(data, indent=4)
    return format_out(data)
Esempio n. 33
0
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)
Esempio n. 34
0
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)
Esempio n. 35
0
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)