Example #1
0
def http_post_ns_action(tenant_id, ns_id):
    '''take an action over a ns'''
    #check valid tenant_id
    if not nfvo.check_tenant(mydb, tenant_id): 
        print 'httpserver.http_post_ns_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( ns_action_schema )
    r = af.remove_extra_items(http_content, ns_action_schema)
    if r is not None: print "http_post_ns_action: Warning: remove extra items ", r
    
    if "start" in http_content:
        result, data = nfvo.start_ns(mydb, tenant_id, ns_id, http_content['start']['instance_name'], \
                    http_content['start'].get('description',http_content['start']['instance_name']),
                    http_content['start'].get('network') )
        if result < 0:
            print "http_post_ns_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_ns(mydb, tenant_id, ns_id, http_content['deploy']['instance_name'],
                    http_content['deploy'].get('description',http_content['deploy']['instance_name']),
                    http_content['deploy'].get('network') )
        if result < 0:
            print "http_post_ns_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_ns(mydb, tenant_id, ns_id, http_content['reserve']['instance_name'],
                    http_content['reserve'].get('description',http_content['reserve']['instance_name']),
                    http_content['reserve'].get('network'),  startvms=False )
        if result < 0:
            print "http_post_ns_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_ns(mydb, tenant_id, ns_id, http_content['verify']['instance_name'],
                    http_content['verify'].get('description',http_content['verify']['instance_name']),
                    http_content['verify'].get('network'), startvms=False )
        if result < 0 or result!=1:
            print "http_post_ns_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_ns_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"})
Example #2
0
def http_post_deploy(tenant_id):
    '''post topology deploy.'''
    print "http_post_deploy by tenant " + tenant_id 

    http_content, used_schema = format_in( nsd_schema_v01, ("version",), {"v0.2": nsd_schema_v02})
    #r = af.remove_extra_items(http_content, used_schema)
    #if r is not None: print "http_post_deploy: Warning: remove extra items ", r
    print "http_post_deploy input: ",  http_content
    
    result, ns_uuid = nfvo.new_ns(mydb, tenant_id, http_content)
    if result < 0:
        print "http_post_deploy error creating the ns %d %s" % (-result, ns_uuid)
        bottle.abort(-result, ns_uuid)

    result, data = nfvo.start_ns(mydb, tenant_id, ns_uuid, http_content['name'], http_content['name'])
    if result < 0:
        print "http_post_deploy error launching the ns %d %s" % (-result, data)
        bottle.abort(-result, data)
    else:
        print json.dumps(data, indent=4)
        return format_out(data)