Esempio n. 1
0
def save_flowtable(request, *args, **kwargs):
    flowtable = redis.Redis(db=15)
    flowtable_name = request.GET['flowtable']
    flowtable_new = "/tmp/" + uuid4().hex # request.POST['new_table']
    hashtable = flowtable_name + ".hash"
    N = flowtable.llen(flowtable_name)
    outflow = OrderedDict()
    for entry in flowtable.lrange(flowtable_name, 0, N):
        fqpatch = cPickle.loads(entry)

        if flowtable_name in request.session and fqpatch in request.session[flowtable_name]:
            outflow[fqpatch] = flowtableio.loadReceivers(request.session[flowtable_name])
        else:
            outflow[fqpatch] = flowtableio.loadReceivers(flowtable.hget(hashtable, entry))

    flowtableio.writeFlowtable(outflow, flowtable_new)
    rsp = HttpResponse(open(flowtable_new), mimetype='application/octet-stream')
    rsp['Content-Disposition'] = 'filename="flowtable.txt"'
    return rsp