コード例 #1
0
def create_vnf():
    vnfd = request.get_json()

    if vnfd is None:
        response = jsonify(detail="Empty Request body.")
        response.status_code = 404
        return response

    # append some extra fields
    vnfd['provider_id'] = request.user['user_id']
    vnfd['provider'] = request.user['company_name']
    vnfd['created_at'] = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ')
    vnfd['modified_at'] = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ')

    #rename vdus to vdu
    if 'vdus' in vnfd:
        vnfd['vdu'] = vnfd['vdus']
        del vnfd['vdus']

    code, nfs_response = nfsapi.upload_vnfd(vnfd)
    print code, nfs_response
    if code != 201:
        response = jsonify(detail="NFS POST request failed, code:%s" % code, nfs_error=nfs_response)
        response.status_code = 404
        return response

    code, nfs_vnfd = nfsapi.get_vnfd(nfs_response['vnfd_id'])

    # SLA TEMPLATE GENERATION
    try:
        createVNFDSLATemplate(nfs_vnfd)
    except:
        print("VNF SLA template exception error")

    return Response(dumps(nfs_vnfd), mimetype='application/json', status=201)
コード例 #2
0
def init_sample_data():
    with app.app_context():
        # remove all vnfds from the nfstore
        code, v = nfsapi.get_vnfd_list()
        for vnfd in v['vnfds']:
            print nfsapi.delete_vnfd(vnfd['id'])

        # remove all images from the nfstore
        # code, v = nfsapi.get_images_list()
        # for i in v['files']:
        #     print nfsapi.delete_image(i['name'])

        temp_file_path = os.path.join(UPLOAD_FOLDER, 'sample-pfsense.img')
        nfs_image = nfsimages.NFSImage(4, 'pfsense.img')
        nfs_image.upload(temp_file_path, '2345094b3b92832abb35162a61f6aa03',
                         'raw')

        json_data = open(
            os.path.join(os.path.join(BASE_DIR, 'templates'),
                         'vnfd0.json')).read()
        code, nfs_response = nfsapi.upload_vnfd(json_data)

        code, nfs_vnfd = nfsapi.get_vnfd(nfs_response['vnfd_id'])
        nfs_vnfd['_id'] = nfs_response['vnfd_id']
        vnfd_id = mongo.db.vnfds.insert(nfs_vnfd)

        # SLA TEMPLATE GENERATION
        try:
            createVNFDSLATemplate(nfs_vnfd)
        except:
            print("VNF SLA template exception error")

        nfs_image = nfsimages.NFSImage(5, 'pfsense.img')
        nfs_image.upload(temp_file_path, '2345094b3b92832abb35162a61f6aa03',
                         'raw')

        json_data = open(
            os.path.join(os.path.join(BASE_DIR, 'templates'),
                         'vnfd1.json')).read()
        code, nfs_response = nfsapi.upload_vnfd(json_data)

        code, nfs_vnfd = nfsapi.get_vnfd(nfs_response['vnfd_id'])
        nfs_vnfd['_id'] = nfs_response['vnfd_id']
        vnfd_id = mongo.db.vnfds.insert(nfs_vnfd)

        # SLA TEMPLATE GENERATION
        try:
            createVNFDSLATemplate(nfs_vnfd)
        except:
            print("VNF SLA template exception error")

        return Response("OK", mimetype='application/json', status=200)
コード例 #3
0
ファイル: app.py プロジェクト: yan0s/Marketplace
def init_sample_data():
    with app.app_context():
        # remove all vnfds from the nfstore
        code, v = nfsapi.get_vnfd_list()
        for vnfd in v['vnfds']:
            print nfsapi.delete_vnfd(vnfd['id'])

        # remove all images from the nfstore
        # code, v = nfsapi.get_images_list()
        # for i in v['files']:
        #     print nfsapi.delete_image(i['name'])

        temp_file_path = os.path.join(UPLOAD_FOLDER, 'sample-pfsense.img')
        nfs_image = nfsimages.NFSImage(4, 'pfsense.img')
        nfs_image.upload(temp_file_path, '2345094b3b92832abb35162a61f6aa03', 'raw')

        json_data = open(os.path.join(os.path.join(BASE_DIR, 'templates'), 'vnfd0.json')).read()
        code, nfs_response = nfsapi.upload_vnfd(json_data)

        code, nfs_vnfd = nfsapi.get_vnfd(nfs_response['vnfd_id'])
        nfs_vnfd['_id'] = nfs_response['vnfd_id']
        vnfd_id = mongo.db.vnfds.insert(nfs_vnfd)

        # SLA TEMPLATE GENERATION
        try:
            createVNFDSLATemplate(nfs_vnfd)
        except:
            print("VNF SLA template exception error")

        nfs_image = nfsimages.NFSImage(5, 'pfsense.img')
        nfs_image.upload(temp_file_path, '2345094b3b92832abb35162a61f6aa03', 'raw')

        json_data = open(os.path.join(os.path.join(BASE_DIR, 'templates'), 'vnfd1.json')).read()
        code, nfs_response = nfsapi.upload_vnfd(json_data)

        code, nfs_vnfd = nfsapi.get_vnfd(nfs_response['vnfd_id'])
        nfs_vnfd['_id'] = nfs_response['vnfd_id']
        vnfd_id = mongo.db.vnfds.insert(nfs_vnfd)

        # SLA TEMPLATE GENERATION
        try:
            createVNFDSLATemplate(nfs_vnfd)
        except:
            print("VNF SLA template exception error")

        return Response("OK", mimetype='application/json', status=200)