Exemplo n.º 1
0
def buildApp(aid,appHost,language):
    "生成一个应用"
    #请求应用服务器生成应用
    
    #根据轮转算法选择服务器
    dao=db.execute("select count(*) from paas_app")
    r=objToDict(dao.first())
    dao.close()
    
    num=r['count(*)'] % len(config.REMOTE_SERVER_PHP)
    data={'language':language,'appHost':config.REMOTE_SERVER_PHP[num],'aid':str(aid)}
    result=urlPostWithToken(config.REMOTE_SERVER_PHP[num],"/servlet/buildApp",data)
    
    #在主服务器生成反向代理配置文件
    obj=json.loads(result)
    if obj['result'] == "ok":
        buildMainServerConfig(aid,appHost,obj['remoteSocket'])
        #把远程服务器地址写入数据库
        sql="update paas_app set remoteServer = '%s' ,remoteSocket = '%s' where id = %d"%(config.REMOTE_SERVER_PHP[num],obj['remoteSocket'],aid)
        dao=db.execute(sql)
        dao.close()
        
        return True
    else:
        return False
Exemplo n.º 2
0
def buildApp(aid, appHost, language):
    "生成一个应用"
    #请求应用服务器生成应用

    #根据轮转算法选择服务器
    dao = db.execute("select count(*) from paas_app")
    r = objToDict(dao.first())
    dao.close()

    num = r['count(*)'] % len(config.REMOTE_SERVER_PHP)
    data = {
        'language': language,
        'appHost': config.REMOTE_SERVER_PHP[num],
        'aid': str(aid)
    }
    result = urlPostWithToken(config.REMOTE_SERVER_PHP[num],
                              "/servlet/buildApp", data)

    #在主服务器生成反向代理配置文件
    obj = json.loads(result)
    if obj['result'] == "ok":
        buildMainServerConfig(aid, appHost, obj['remoteSocket'])
        #把远程服务器地址写入数据库
        sql = "update paas_app set remoteServer = '%s' ,remoteSocket = '%s' where id = %d" % (
            config.REMOTE_SERVER_PHP[num], obj['remoteSocket'], aid)
        dao = db.execute(sql)
        dao.close()

        return True
    else:
        return False
Exemplo n.º 3
0
def editApp():
    "编辑应用"
    aid = request.args.get("id", None)

    sql = "select * from paas_app where id = %s limit 1" % (sqlDeal(aid))
    dao = db.execute(sql)
    g.obj = objToDict(dao.first())
    dao.close()

    if request.method == "GET":
        g.add = False

        sql = "select * from paas_account where status != 3"
        dao = db.execute(sql)
        g.users = map(objToDict, dao.fetchall())
        dao.close()

        return render_template("admin/addApp.html")
    else:

        uid = request.form.get("uid", None)
        title = request.form.get("title", None)
        description = request.form.get("description", None)
        host = request.form.get("host", None)
        gitUrl = request.form.get("gitUrl", None)
        #处理git地址,防止注入恶意代码
        gitUrl = gitUrl.replace(" ", "")

        args = map(sqlDeal, [uid, title, description, host, gitUrl, aid])

        sql = "update paas_app set uid = '%s',title='%s',description='%s',host='%s',gitUrl='%s' where id = %s" % tuple(
            args)
        dao = db.execute(sql)
        dao.close()

        #修改配置文件,防止修改域名后nginx配置文件不一致
        obj = g.obj
        webApp.buildMainServerConfig(obj['id'], obj['host'],
                                     obj['remoteSocket'])

        return redirect("/admin/appManager")
Exemplo n.º 4
0
Arquivo: admin.py Projeto: vipsql/paas
def editApp():
    "编辑应用"
    aid=request.args.get("id",None)
    
    sql="select * from paas_app where id = %s limit 1"%(sqlDeal(aid))
    dao=db.execute(sql)
    g.obj=objToDict(dao.first())
    dao.close()
    
    if request.method == "GET":
        g.add=False
        
        sql="select * from paas_account where status != 3"
        dao=db.execute(sql)
        g.users=map(objToDict,dao.fetchall())
        dao.close()
        
        return render_template("admin/addApp.html")
    else:
        
        uid=request.form.get("uid",None)
        title=request.form.get("title",None)
        description=request.form.get("description",None)
        host=request.form.get("host",None)
        gitUrl=request.form.get("gitUrl",None)
        #处理git地址,防止注入恶意代码
        gitUrl=gitUrl.replace(" ","")
        
        args=map(sqlDeal,[uid,title,description,host,gitUrl,aid])
        
        sql="update paas_app set uid = '%s',title='%s',description='%s',host='%s',gitUrl='%s' where id = %s"%tuple(args)
        dao=db.execute(sql)
        dao.close()
        
        #修改配置文件,防止修改域名后nginx配置文件不一致
        obj=g.obj
        webApp.buildMainServerConfig(obj['id'],obj['host'],obj['remoteSocket'])
        
        return redirect("/admin/appManager")