Example #1
0
    def post(self):
        rev = self.request.arguments
        if self.request.remote_ip != dbtxSSL['ctrSrvAddr']:  ## 远程IP不是控制端IP,退出
            saveLog.warning("%s is a Non-authoritative IP." % self.request.remote_ip)
            self.write('2')
            return
        saveLog.info("Start receive parameters from %s" % self.request.remote_ip)
        revTime, revIP, revKey, revAct, sPlat, sID = rev['rTimes'], rev['istIP'], rev['sPKI_KEY'], rev['rAct'], rev['sPlat'], rev['sID']
        ## 对接收到的数据一一解密,然后储存到一个列表
        deRevList = [(lambda x:decode(''.join(x))) (x) for x in (revTime, revIP, revKey, revAct, sPlat, sID)]
        revTime, revIP, revKey, revAct, sPlat, sID = deRevList[0], deRevList[1], deRevList[2], deRevList[3], deRevList[4], deRevList[5]
        localeKey = str(dbtxSSL['INTER_KEY']) + str(revTime)  ## 交换key与接收到的时间戮,组装成本地key
        if localeKey == revKey and revAct.upper() == "INSTALL":  ## 对比接收到的key与本地key是否一致
            saveLog.info("INSTALL, Found matching key.")
            if revIP not in getLocalIp():  ## 对比接收到的IP与本地IP是否一致
                saveLog.error("Receive error IP:%s" % revIP)
                self.write('3')
                return
            srvFlag = sPlat+"_"+sID
            for gSrv in os.listdir("/opt/dbtx/"):
                if gSrv == srvFlag:  ## 如果"/opt/dbtx/"目录下存在该服区,退出安装
                    saveLog.warning("Already exist this agent and sid: %s" % srvFlag)
                    self.write('5')
                    return
            saveLog.info("Starting installation------%s" % srvFlag)
            ## 开始回传安装状态到运维后台, 1为已安装,2为未安装,3为正在安装,4为安装失败
            opUrl = "http://%s/op_center/dbtx/dbtx_new_server_update.php" % dbtxSSL['ctrSrvAddr']
            bgData = "sPlat=%s&sServs=%s&sIP=%s&iStatus=%d" % (sPlat, sID, revIP, 3)
            postToWeb(opUrl, bgData)  ## 回传到运维后台,修改装服状态为"正在安装"
            try:
                runCmd("bash /data/sh/opTmpKey.sh install")  ## 安装装服用的临时key
##                runCmd("cd /root/AutoMatic/%s;bash dbtx_install_game.sh &" % srvFlag)  ## 开始装服
                os.system("cd /root/AutoMatic/%s;bash dbtx_install_game.sh &" % srvFlag)  ## 开始装服
            except Exception,err:  ## 有异常, 安装失败
                runCmd("bash /data/sh/opTmpKey.sh delete")  ## 删除临时key
                saveLog.warning("installation error occured, %s" % str(err))
                errData = "sPlat=%s&sServs=%s&sIP=%s&iStatus=%d" % (sPlat, sID, revIP, 4)
                postToWeb(opUrl, errData)  ## 回传到运维后台,修改装服状态为"安装失败"
                self.write('4')
            else:  ## 无异常, 安装完成
##                saveLog.info("%s's installation complete." % srvFlag)
##                resData = "sPlat=%s&sServs=%s&sIP=%s&iStatus=%d" % (sPlat, sID, revIP, 1)
##                postToWeb(opUrl, resData)  ## 回传到运维后台,修改装服状态为"已装"
##                runCmd("bash /data/sh/opTmpKey.sh delete")  ## 删除临时key
                self.write('1')
Example #2
0
##                runCmd("cd /root/AutoMatic/%s;bash dbtx_install_game.sh &" % srvFlag)  ## 开始装服
                os.system("cd /root/AutoMatic/%s;bash dbtx_install_game.sh &" % srvFlag)  ## 开始装服
            except Exception,err:  ## 有异常, 安装失败
                runCmd("bash /data/sh/opTmpKey.sh delete")  ## 删除临时key
                saveLog.warning("installation error occured, %s" % str(err))
                errData = "sPlat=%s&sServs=%s&sIP=%s&iStatus=%d" % (sPlat, sID, revIP, 4)
                postToWeb(opUrl, errData)  ## 回传到运维后台,修改装服状态为"安装失败"
                self.write('4')
            else:  ## 无异常, 安装完成
##                saveLog.info("%s's installation complete." % srvFlag)
##                resData = "sPlat=%s&sServs=%s&sIP=%s&iStatus=%d" % (sPlat, sID, revIP, 1)
##                postToWeb(opUrl, resData)  ## 回传到运维后台,修改装服状态为"已装"
##                runCmd("bash /data/sh/opTmpKey.sh delete")  ## 删除临时key
                self.write('1')
        else:
            saveLog.warning("Invalid key string.")
            self.write('0')  ## 返回0,  表示key没有匹配上

class MergHandler(tornado.web.RequestHandler):
    '''处理合服'''
    pass

class CancelHandler(tornado.web.RequestHandler):
    '''处理 操作撤消'''
    pass

class MigrationHandler(tornado.web.RequestHandler):
    '''处理切机'''
    pass