예제 #1
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)
예제 #2
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)
예제 #3
0
def delete_vnf(vnfd_id):

    code, nfs_response = nfsapi.get_vnfd(vnfd_id)

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

        if not has_perm('vnfs.delete_all_vnfs') and not (
                has_perm('vnfs.delete_own_vnfs')
                and nfs_response['provider_id'] == request.user['user_id']):
            response = jsonify(
                detail="You do not have permission to perform this action.")
            response.status_code = 401
            return response
        else:
            code, nfs_response = nfsapi.delete_vnfd(vnfd_id)

            if code != 204:
                response = jsonify(
                    detail="NFS DELETE request failed, code:%s" % code)
                response.status_code = 404
                return response
            else:
                return Response(mimetype='application/json', status=204)
예제 #4
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)
예제 #5
0
def get_vnfd_yaml_file(vnfd_id):
    code, nfs_response = nfsapi.get_vnfd(vnfd_id)

    if code != 200:
        response = jsonify(detail="NFS GET VNFD request failed, code:%s" % code)
        response.status_code = 404
        return response
    else:
        return Response(yaml.safe_dump(nfs_response, default_flow_style=False), mimetype='text/yaml', status=200)
예제 #6
0
def get_vnfd_file(vnfd_id):
    code, nfs_response = nfsapi.get_vnfd(vnfd_id)

    if code != 200:
        response = jsonify(detail="NFS GET VNFD request failed, code:%s" % code)
        response.status_code = 404
        return response
    else:
        return Response(dumps(nfs_response), mimetype='application/json', status=200)
예제 #7
0
파일: app.py 프로젝트: T-NOVA/Marketplace
def get_vnf(vnfd_id):
    code, nfs_response = nfsapi.get_vnfd(vnfd_id)

    if code != 200:
        response = jsonify(detail="NFS GET VNFD request failed, code:%s" % code)
        response.status_code = 404
        return response
    else:
        if has_perm('vnfs.view_all_vnfs') or (has_perm('vnfs.view_own_vnfs') and nfs_response['provider_id'] == request.user['user_id']):
            return Response(dumps(nfs_response), mimetype='application/json', status=200)
        else:
            response = jsonify(detail="You do not have permission to perform this action.")
            response.status_code = 401
            return response