Beispiel #1
0
def delete_vnf(vnfd_id):

    vnfd = mongo.db.vnfds.find_one({'_id': vnfd_id})

    if vnfd != None:
        if not has_perm('vnfs.delete_all_vnfs') and not (has_perm('vnfs.delete_own_vnfs') and vnfd['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:
        response = jsonify(detail="VNFD not found.")
        response.status_code = 404
        return response

    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

    success = mongo.db.vnfds.remove({'_id': vnfd_id})

    if success:
        return Response(mimetype='application/json', status=204)
    else:
        response = jsonify(detail="VNFD not found.")
        response.status_code = 404
        return response
Beispiel #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)
Beispiel #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)