Ejemplo n.º 1
0
def vnfs_internal():
    code, nfs_response = nfsapi.get_vnfd_list()

    if code != 200:
        response = jsonify(detail="NFS GET vnfds request failed, code:%s" % code)
        response.status_code = 404
        return response
    else:
        return Response(dumps(nfs_response['vnfds']), mimetype='application/json', status=200)
Ejemplo n.º 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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def vnfs():
    vnfds = []

    code, nfs_response = nfsapi.get_vnfd_list()

    if code != 200:
        response = jsonify(detail="NFS GET vnfds request failed, code:%s" % code)
        response.status_code = 404
        return response
    else:

        if has_perm('vnfs.view_all_vnfs'):
            return Response(dumps(nfs_response['vnfds']), mimetype='application/json', status=200)
        elif has_perm('vnfs.view_own_vnfs'):
            for vnfd in nfs_response['vnfds']:
                if vnfd['provider_id'] == request.user['user_id']:
                    vnfds.append(vnfd)
            return Response(dumps(vnfds), mimetype='application/json', status=200)