コード例 #1
0
ファイル: memcached.py プロジェクト: mingshi/memcached-cloud
def memcached_do_add() :
    result = {}
    if not request.form.has_key('ip') :
        result['status'] = 'no ip address'
    elif not request.form.has_key('version') :
        result['status'] = 'no version selected'
    elif not request.form.has_key('port') :
        result['status'] = 'no port inputed'
    elif not request.form.has_key('memory') :
        result['status'] = 'no memory inputed'
    elif not request.form.has_key('group') :
        result['status'] = 'no group selected'
    else :
        ip = request.form['ip'].strip().encode('utf8')
        version = request.form['version']
        port = str(request.form['port'].strip())
        memory = str(request.form['memory'].strip())
        group = str(request.form['group'])
        param = request.form['param'].strip().encode('utf8')
        isstart = str(request.form['isstart'])
        _memcached = db_session.query(Memcacheds).filter_by(ip = ip,port = port).first()
        if not _memcached :
            if not param :
                data = os.popen("bash -l /var/www/memcache_cloud/memcached_add.sh " + ip + " " + version + " " + port + " " + memory + " " + isstart).read()
            else :
                data = os.popen("bash -l /var/www/memcache_cloud/memcached_add.sh " + ip + " " + version + " " + port + " " + memory + " " + isstart + " '" + param + "'").read()
            result['status'] = data
            if (isstart == "1" and data == "add success\n") or isstart == "0" :
                memcache = Memcacheds(ip=ip, port=port, memory=memory, status=1, group_id=group, version=version, parameters=param)
                db_session.add(memcache)
                db_session.commit()
        else :
            result['status'] = 'the memcached is already added'
    return json.dumps(result)
コード例 #2
0
ファイル: group.py プロジェクト: mingshi/memcached-cloud
def group_do_add() :
    result = {}

    if not request.form.has_key('name') :
        result['status'] = 'error'
        result['message'] = 'please input name'
    else :
        name = request.form['name']
        count = db_session.query(Groups).filter_by(name = name).count()
        if (count > 0) :
            result['status'] = 'error'
            result['message'] = 'group ' + name + ' is existed!'
        else :
            group = Groups(name)
            db_session.add(group)
            db_session.commit()
            result['status'] = 'ok'
            result['message'] = 'add successed. group id is ' + str(group.id)

    return json.dumps(result)
コード例 #3
0
ファイル: log.py プロジェクト: mingshi/memcached-cloud
     filehandler.close()
     if int(current_get) >= int(old_get) :
         process_get = int(current_get) - int(old_get)
         process_hit = int(current_hit) - int(old_hit)
     else :
         process_get = int(current_get)
         process_hit = int(current_hit)
     if process_get == 0 :
         hit_rank = 0
     else :
         hit_rank = "%.2f" % (float(process_hit) / float(process_get))
         hit_rank = float(hit_rank) * 100
         hit_rank = "%.0f" % hit_rank
     nowtime = int(time.time())
     log = Logs(num=hit_rank,get=process_get,hit=process_hit,log_type=1,time=nowtime,m_id=mid)
     db_session.add(log)
     db_session.commit()
     this_data = str(current_get) + ' ' + str(current_hit)
     fw = open(log_file,'w')
     fw.write(this_data)
     fw.close()
 else :
     process_get = int(current_get)
     process_hit = int(current_hit)
     if process_get == 0 :
         hit_rank = 0
     else :
         hit_rank = "%.2f" % (float(process_hit) / float(process_get))
         hit_rank = float(hit_rank) * 100
         hit_rank = "%.0f" % hit_rank
     nowtime = int(time.time())