def getServerWip(interIp): get_outip_from_zichan = arg.gameOption("get_outip_from_zichan",type="bool",default=False) iplist = [] if not get_outip_from_zichan: sshobj = ssh.ssh(interIp.strip()) cmd = "/sbin/ifconfig -a | grep 'inet addr'|cut -d':' -f2|cut -d' ' -f1" status,r,stderr = sshobj.cmd(cmd) if status == 0: for ip in r.split("\n"): if re.search(r"^(10\.|192\.168|172\.1[6-9]\.|172\.2[0-9]\.|172\.3[01]\.|169\.254\.|127\.)",ip) or ip.strip() == "": continue else: iplist.append(ip.strip()) if len(iplist) == 0: #status,r1,stderr = sshobj.cmd("curl -s ip.cn | awk '{print $2}' | sed 's/[^0-9\\.]*\\(.*\\)/\\1/g'") status,r1,stderr = sshobj.cmd("curl -s ipip.net | awk '{print $2}' | sed 's/[^0-9\\.]*\\(.*\\)/\\1/g'") if check.checkIp(r1) : iplist.append(r1.strip()) else: print "[%s] out:%serr:%s"%(cmd,out,err) else: hsot = arg.mainOption("zichan_host") user = arg.mainOption("zichan_user") pwd = arg.mainOption("zichan_pwd") port = arg.mainOption("zichan_port",type="int") db = arg.mainOption("zichan_db") my = mysql.mysql(hsot,user,pwd,db,port) mylist = my.query("select asset_outip.ip,isp from asset_inip join asset_outip on asset_outip.did = asset_inip.did and asset_inip.ip = '%s'"%interIp) for i in mylist: if i[1].strip() == "电信": iplist.insert(0,i[0].strip()) else: iplist.append(i[0].strip()) pass return iplist
def getRecoverServerList(backstageDB,headTag,partnersType,backstageIp,serverName): if check.checkIp(serverName): ipType='ip' else: ipType='Name' filecheck(backstageIp) servers = mycmd(ip=backstageIp,cmd="python /app/opbin/allinone/serverlistOnServer.py 'getRecoverServer' '%s' '%s' '%s' '%s' '%s'"%(backstageDB,headTag,partnersType,ipType,serverName)) return json.loads(servers)
def validate(self, value): Parameter.validate(self, value) # special case - dhcp if value.lower() == pdesc.IP_DHCP.lower(): return if not check.checkIp(value): parts = value.split("/") if len(parts) != 2: raise Exception("Invalid IPv4 or CIDR notation") ip, cidr = parts if not check.checkIp(ip): raise Exception("%s is not a valid IPv4 address" % ip) if not check.checkCidr(cidr): raise Exception("%s is not a valid subnet mask number" % cidr)
def reset(cleartime, starttime, server): if check.nullCheck(cleartime): raise Exception("清档时间不能为空") if check.nullCheck(starttime): raise Exception("开服时间不能为空") if check.nullCheck(server): raise Exception("游戏服不能为空") if not check.checkDatetime(cleartime): raise Exception("清档时间格式不正确") if not check.checkDatetime(starttime): raise Exception("开服时间格式不正确") backstageIp = gameOption("backstage") backstageDb = gameOption("backstage_db") head_tag = gameOption("backstage_tag") ismobile = gameOption("is_mobile", type="bool") if ismobile: partnersType = 2 else: partnersType = 1 serverinfo = serverlist.serverInfo(backstageDb, head_tag, partnersType, "main", backstageIp, server) if not serverinfo["result"]: raise Exception("获取游戏服在后台的信息失败!msg:%s" % serverinfo["msg"]) ip = serverinfo["ip"] if not check.checkIp(ip): raise Exception("获取游戏服ip失败!ip:%s" % ip) global sshobj sshobj = ssh.ssh(ip) players = cmd( "pandora %s_%s -e 'select count(1) from player' | grep -v count" % (state.game, server)).strip() if players != "": if int(players) > 0: print "WARNNING: 当前角色数为%s" % players servertime = cmd("date +'%Y-%m-%d %H:%M:%S'").strip() print "servertime:", servertime servertime_datetime = datetime.datetime.strptime(servertime, "%Y-%m-%d %H:%M:%S") cleartime_datetime = datetime.datetime.strptime(cleartime, '%Y-%m-%d %H:%M:%S') if servertime_datetime + datetime.timedelta( minutes=1) > cleartime_datetime: raise Exception("服务器时间大于了清档时间,清档失败!服务器时间为:%s,清档时间提交为:%s" % (servertime, cleartime)) clearshell = gameOption("clear_script") print clearshell cmd("mkdir -p /app/opbin/%s/allinone/shell/" % state.game) sshobj.put("%s/../shell/%s" % (os.path.abspath(os.path.dirname(__file__)), clearshell), remote_path="/app/opbin/%s/allinone/shell/" % state.game) tmpfile = "/tmp/crontab_%s" % datetime.datetime.now().strftime( "%Y%m%d_%H%M%S") try: cmd("crontab -l > %s" % tmpfile) except Exception, e1: if str(e1).find("no crontab for astd") < 0: raise e1
def reset(cleartime,starttime,server): if check.nullCheck(cleartime): raise Exception("清档时间不能为空") if check.nullCheck(starttime): raise Exception("开服时间不能为空") if check.nullCheck(server): raise Exception("游戏服不能为空") if not check.checkDatetime(cleartime): raise Exception("清档时间格式不正确") if not check.checkDatetime(starttime): raise Exception("开服时间格式不正确") backstageIp = gameOption("backstage") backstageDb = gameOption("backstage_db") head_tag = gameOption("backstage_tag") ismobile = gameOption("is_mobile",type="bool") if ismobile: partnersType = 2 else: partnersType = 1 serverinfo = serverlist.serverInfo(backstageDb,head_tag,partnersType,"main",backstageIp,server) if not serverinfo["result"]: raise Exception("获取游戏服在后台的信息失败!msg:%s"%serverinfo["msg"]) ip = serverinfo["ip"] if not check.checkIp(ip): raise Exception("获取游戏服ip失败!ip:%s"%ip) global sshobj sshobj = ssh.ssh(ip) players = cmd("pandora %s_%s -e 'select count(1) from player' | grep -v count"%(state.game,server)).strip() if players != "": if int(players) > 0: print "WARNNING: 当前角色数为%s"%players servertime = cmd("date +'%Y-%m-%d %H:%M:%S'").strip() print "servertime:",servertime servertime_datetime = datetime.datetime.strptime(servertime,"%Y-%m-%d %H:%M:%S") cleartime_datetime = datetime.datetime.strptime(cleartime,'%Y-%m-%d %H:%M:%S') if servertime_datetime + datetime.timedelta(minutes=1) > cleartime_datetime : raise Exception("服务器时间大于了清档时间,清档失败!服务器时间为:%s,清档时间提交为:%s"%(servertime,cleartime)) clearshell = gameOption("clear_script") print clearshell cmd("mkdir -p /app/opbin/%s/allinone/shell/"%state.game) sshobj.put("%s/../shell/%s"%(os.path.abspath(os.path.dirname(__file__)),clearshell),remote_path="/app/opbin/%s/allinone/shell/"%state.game) tmpfile = "/tmp/crontab_%s"%datetime.datetime.now().strftime("%Y%m%d_%H%M%S") try: cmd("crontab -l > %s"%tmpfile) except Exception,e1: if str(e1).find("no crontab for astd") < 0: raise e1
def getserverlist(ServerFile=None,ServerList=None,ExecludeServerList=None,StartDate=None,EndDate=None,UniqueServer=None): if ServerFile != None or ServerList != None or ExecludeServerList != None or StartDate != None or EndDate != None or UniqueServer != None: #print ServerFile,ServerList,ExecludeServerList,StartDate,EndDate,UniqueServer pass else: ServerFile = state.options.serverfile ServerList = state.options.serverlist ExecludeServerList = state.options.excludeServerlist StartDate = state.options.startdate EndDate = state.options.enddate UniqueServer = state.options.uniqserver slist = [] if not check.nullCheck(ServerFile): for i in open(ServerFile).readlines(): if i.strip() != "": if i.find("@") > 0: s = i.split("@") servername = s[0].strip() ip = s[1].strip() else: servername = i.strip() if check.checkIp(i.strip()): ip = i.strip() else: ip = state.game + "_" + i.strip() if not check.nullCheck( ServerList ): if not re.match(r"^%s$"%ServerList,servername): continue if not check.nullCheck(ExecludeServerList): if re.match("^%s$"%ExecludeServerList,servername): continue slist.append([servername,ip]) else: if gameOption("is_mobile",type="bool"): partnersType = 2 else: partnersType = 1 slist = serverlist.serverRange(gameOption("backstage_db"),gameOption("backstage_tag"),partnersType,"main",gameOption("backstage"),StartDate,EndDate,ServerList,ExecludeServerList) #print StartDate,EndDate,ServerList,ExecludeServerList serverlist_tag = [ i.strip() for i in gameOption("serverlist_tag",default="").split(",") if i.strip() != "" ] for tag in serverlist_tag: slist += serverlist.serverRange(gameOption("backstage_db"), tag, partnersType,"main",gameOption("backstage"),StartDate,EndDate,ServerList,ExecludeServerList) if UniqueServer: return list(set(i[1].strip() for i in slist)) else: return slist
def getServerWip(interIp): get_outip_from_zichan = arg.gameOption("get_outip_from_zichan", type="bool", default=False) iplist = [] if not get_outip_from_zichan: sshobj = ssh.ssh(interIp.strip()) cmd = "/sbin/ifconfig -a | grep 'inet addr'|cut -d':' -f2|cut -d' ' -f1" status, r, stderr = sshobj.cmd(cmd) if status == 0: for ip in r.split("\n"): if re.search( r"^(10\.|192\.168|172\.1[6-9]\.|172\.2[0-9]\.|172\.3[01]\.|169\.254\.|127\.)", ip) or ip.strip() == "": continue else: iplist.append(ip.strip()) if len(iplist) == 0: #status,r1,stderr = sshobj.cmd("curl -s ip.cn | awk '{print $2}' | sed 's/[^0-9\\.]*\\(.*\\)/\\1/g'") status, r1, stderr = sshobj.cmd( "curl -s ipip.net | awk '{print $2}' | sed 's/[^0-9\\.]*\\(.*\\)/\\1/g'" ) if check.checkIp(r1): iplist.append(r1.strip()) else: print "[%s] out:%serr:%s" % (cmd, out, err) else: hsot = arg.mainOption("zichan_host") user = arg.mainOption("zichan_user") pwd = arg.mainOption("zichan_pwd") port = arg.mainOption("zichan_port", type="int") db = arg.mainOption("zichan_db") my = mysql.mysql(hsot, user, pwd, db, port) mylist = my.query( "select asset_outip.ip,isp from asset_inip join asset_outip on asset_outip.did = asset_inip.did and asset_inip.ip = '%s'" % interIp) for i in mylist: if i[1].strip() == "电信": iplist.insert(0, i[0].strip()) else: iplist.append(i[0].strip()) pass return iplist
def init(self): curdir = os.path.dirname(os.path.abspath(__file__)) self.curdir = curdir logdir = curdir +"/../logs" if not os.path.exists(logdir): os.makedirs(logdir) game = self.game servername = self.servername ip = self.ip cleartime = self.cleartime language = self.language nowstring = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', #filename='%s/deploy_%s_%s_%s.log'%(os.path.abspath(logdir),game,servername,nowstring), #filename='%s/deploy_%s_%s.log'%(os.path.abspath(logdir),game,servername), #filemode='a' ) logging.info("开始部署游戏...") print "详细日志为:%s/deploy_%s_%s.log"%(os.path.abspath(logdir),game,servername) sys.stdout.flush() self.html = mailhtml.mailhtml("%s_%s_deploy.html"%(game,servername),"%s_%s游戏服部署"%(game,servername)) self.email_address = gameOption("email_address") self.mail_title = "[%s][%s]游戏服部署"%(game,servername) #参数校验 self.yx,self.quhao = self.servername.split("_") self.statusCheck(check.checkIp(ip),"ip:%s不合法"%ip) self.html.add("服务器ip",ip) self.statusCheck(check.checkServer(servername),"游戏名称:%s 不合法"%servername) self.html.add("游戏名称",servername) self.statusCheck(check.checkDatetime(cleartime),"清档时间:%s 不合法"%cleartime) self.htmlStatus = True try: logging.info("%s建立ssh连接..."%ip) self.ssh = ssh.ssh(ip) logging.info("%s建立ssh连接完毕!"%ip) self.clientrootdir = mainOption("clientrootdir").replace("${game}",game) self.rootdir = mainOption("rootdir").replace("${game}",game) #后台相关信息 self.backstage = gameOption("backstage") self.backstage_db = gameOption("backstage_db") self.backstage_tag = gameOption("backstage_tag",default="") self.backstage_interface_url = gameOption("backstage_interface_url") self.backstage_header = gameOption("backstage_header") self.have_backstage_interface = gameOption("have_backstage_interface",type="bool") #游戏服务器需要下载资源的地址信息 self.www_ip = gameOption("www_ip") self.www_port = gameOption("www_port",default="80") self.www_header = gameOption("www_header") #是否为海外 self.is_oversea = gameOption("is_oversea",type="bool") #是否为手游 if gameOption("is_mobile",type="bool"): self.is_mobile = "mobile" self.partnersType = 2 else: self.is_mobile = "web" self.partnersType = 1 #建库sql self.innit_sql = self.game + "_"+ self.language+"_init" + ".sql" #判断是否检查游戏服存在与否,主要用于没有后台时的布服 if not self.skipcheck: serverExistsJson = serverlist.serverExists(self.backstage_db,self.backstage_tag,self.partnersType,servername,self.backstage) if serverExistsJson["result"]: self.statusCheck(False,"游戏已经存在,请确认") self.time_zone = gameOption("time_zone",default="+8") delta_hours = 8 - int(self.time_zone) self.starttime = (datetime.datetime.strptime(cleartime,"%Y-%m-%d %H:%M:%S") + datetime.timedelta(hours=delta_hours) + datetime.timedelta(minutes=30)).strftime("%Y-%m-%d %H:%M:%S") self.html.add("开服时间(北京+8区)",self.starttime) self.html.add("清档时间(服务器%s区)"%self.time_zone,cleartime) #www是老模式(www)还是新模式(www_ly_id) self.www_dir_type = gameOption("www_dir_type",default="new") #布服脚本 self.deploy_script = gameOption("deploy_script") #布服特殊脚本 self.deploy_special_script = gameOption("deploy_special_script") #清档脚本 self.clear_script = gameOption("clear_script") #是否添加ast域名解析 self.add_dns = gameOption("add_dns",type="bool") #是否需要联运解析域名 self.lianyun_add_dns = gameOption("lianyun_add_dns",type="bool") #后台游戏域名,后续会替换server_url self.web_url = gameOption("web_url") #布服公共包目录 self.template_tar_dir = gameOption("template_tar_dir") self.template_exclude_dir = gameOption("template_exclude_dir") #是否需要部署大混服 self.big_mix_server = gameOption("big_mix_server",type="bool") #dns解析使用的game self.dns_game = gameOption("dns_game",default=self.game) logging.info("变量初始化完毕") except Exception,e1: self.statusCheck(False,str(e1))
def init(self): curdir = os.path.dirname(os.path.abspath(__file__)) self.curdir = curdir logdir = curdir + "/../logs" if not os.path.exists(logdir): os.makedirs(logdir) game = self.game servername = self.servername ip = self.ip cleartime = self.cleartime language = self.language nowstring = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") logging.basicConfig( level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', #filename='%s/deploy_%s_%s_%s.log'%(os.path.abspath(logdir),game,servername,nowstring), filename='%s/deploy_%s_%s.log' % (os.path.abspath(logdir), game, servername), filemode='a') logging.info("开始部署游戏...") print "详细日志为:%s/deploy_%s_%s.log" % (os.path.abspath(logdir), game, servername) self.html = mailhtml.mailhtml("%s_%s_deploy.html" % (game, servername), "%s_%s游戏服部署" % (game, servername)) self.email_address = gameOption("email_address") self.mail_title = "[%s][%s]游戏服部署" % (game, servername) #参数校验 self.yx, self.quhao = self.servername.split("_") self.statusCheck(check.checkIp(ip), "ip:%s不合法" % ip) self.html.add("服务器ip", ip) self.statusCheck(check.checkServer(servername), "游戏名称:%s 不合法" % servername) self.html.add("游戏名称", servername) self.statusCheck(check.checkDatetime(cleartime), "清档时间:%s 不合法" % cleartime) self.htmlStatus = True try: logging.info("%s建立ssh连接..." % ip) self.ssh = ssh.ssh(ip) logging.info("%s建立ssh连接完毕!" % ip) self.clientrootdir = mainOption("clientrootdir").replace( "${game}", game) self.rootdir = mainOption("rootdir").replace("${game}", game) #后台相关信息 self.backstage = gameOption("backstage") self.backstage_db = gameOption("backstage_db") self.backstage_tag = gameOption("backstage_tag") self.backstage_interface_url = gameOption( "backstage_interface_url") self.backstage_header = gameOption("backstage_header") self.have_backstage_interface = gameOption( "have_backstage_interface", type="bool") #游戏服务器需要下载资源的地址信息 self.www_ip = gameOption("www_ip") self.www_port = gameOption("www_port") self.www_header = gameOption("www_header") #是否为海外 self.is_oversea = gameOption("is_oversea", type="bool") #是否为手游 if gameOption("is_mobile", type="bool"): self.is_mobile = "mobile" self.partnersType = 2 else: self.is_mobile = "web" self.partnersType = 1 #建库sql self.innit_sql = self.game + "_" + self.language + "_init" + ".sql" #判断是否检查游戏服存在与否,主要用于没有后台时的布服 if not self.skipcheck: serverExistsJson = serverlist.serverExists( self.backstage_db, self.backstage_tag, self.partnersType, servername, self.backstage) if serverExistsJson["result"]: self.statusCheck(False, "游戏已经存在,请确认") time_zone = gameOption("time_zone") delta_hours = 8 - int(time_zone) self.starttime = ( datetime.datetime.strptime(cleartime, "%Y-%m-%d %H:%M:%S") - datetime.timedelta(hours=delta_hours) + datetime.timedelta(minutes=30)).strftime("%Y-%m-%d %H:%M:%S") self.html.add("开服时间(北京+8区)", self.starttime) self.html.add("清档时间(服务器%s区)" % time_zone, cleartime) #www是老模式(www)还是新模式(www_ly_id) self.www_dir_type = gameOption("www_dir_type") #布服脚本 self.deploy_script = gameOption("deploy_script") #清档脚本 self.clear_script = gameOption("clear_script") #是否添加ast域名解析 self.add_dns = gameOption("add_dns", type="bool") #是否需要联运解析域名 self.lianyun_add_dns = gameOption("lianyun_add_dns", type="bool") #后台游戏域名,后续会替换server_url self.web_url = gameOption("web_url") #布服公共包目录 self.template_tar_dir = gameOption("template_tar_dir") self.template_exclude_dir = gameOption("template_exclude_dir") #是否需要部署大混服 self.big_mix_server = gameOption("big_mix_server", type="bool") logging.info("变量初始化完毕") except Exception, e1: self.statusCheck(False, str(e1))
def init(self): curdir = os.path.dirname(os.path.abspath(__file__)) self.curdir = curdir logdir = curdir +"/../logs" if not os.path.exists(logdir): os.makedirs(logdir) game = self.game servername = self.servername ip = self.ip #cleartime = self.cleartime language = self.language nowstring = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filename='%s/recover_%s_%s.log'%(os.path.abspath(logdir),game,servername), filemode='a') logging.info("开始恢复游戏...") print "详细日志为:%s/recover_%s_%s.log"%(os.path.abspath(logdir),game,servername) #参数校验 self.statusCheck(check.checkIp(ip),"ip:%s不合法"%ip) #if check.checkServer(servername): # ipType='oneserver' #elif check.checkIp(servername): # ipType='ip' #else: # self.statusCheck(check.checkIp(servername),"恢复服务器参数:%s不合法,要么是iP要么是具体的游戏主服"%servername) try: logging.info("%s建立ssh连接..."%ip) self.ssh = ssh.ssh(ip) logging.info("%s建立ssh连接完毕!"%ip) self.clientrootdir = mainOption("clientrootdir").replace("${game}",game) self.rootdir = mainOption("rootdir").replace("${game}",game) #后台相关信息 self.backstage = gameOption("backstage") self.backstage_db = gameOption("backstage_db") self.backstage_tag = gameOption("backstage_tag") self.backstage_interface_url = gameOption("backstage_interface_url") self.backstage_header = gameOption("backstage_header") self.have_backstage_interface = gameOption("have_backstage_interface",type="bool") #游戏服务器需要下载资源的地址信息 self.www_ip = gameOption("www_ip") self.www_port = gameOption("www_port") self.www_header = gameOption("www_header") #下载备份sql的hadoop路径 self.ftppath = gameOption("FTP_PATH") #是否为海外 self.is_oversea = gameOption("is_oversea",type="bool") #是否为手游 if gameOption("is_mobile",type="bool"): self.is_mobile = "mobile" self.partnersType = 2 else: self.is_mobile = "web" self.partnersType = 1 #建库sql self.innit_sql = self.game + "_"+ self.language+"_init" + ".sql" time_zone = gameOption("time_zone") self.delta_hours = 8 - int(time_zone) #self.starttime = (datetime.datetime.strptime(cleartime,"%Y-%m-%d %H:%M:%S") - datetime.timedelta(hours=delta_hours) + datetime.timedelta(minutes=30)).strftime("%Y-%m-%d %H:%M:%S") #self.cleartime = (datetime.datetime.strptime(starttime,"%Y-%m-%d %H:%M:%S") + datetime.timedelta(hours=delta_hours) - datetime.timedelta(minutes=30)).strftime("%Y-%m-%d %H:%M:%S") #www是老模式(www)还是新模式(www_ly_id) self.www_dir_type = gameOption("www_dir_type") #恢复脚本 self.deploy_script = gameOption("deploy_script") #混服部署脚本 self.mix_deploy_script = gameOption("mix_deploy_script") #执行特殊脚本 self.deploy_special_script = gameOption("deploy_special_script") #清档脚本 self.clear_script = gameOption("clear_script") #是否添加ast域名解析 self.add_dns = gameOption("add_dns",type="bool") #是否需要联运解析域名 self.lianyun_add_dns = gameOption("lianyun_add_dns",type="bool") #后台游戏域名,后续会替换server_url self.web_url = gameOption("web_url") #布服公共包目录 self.template_tar_dir = gameOption("template_tar_dir") self.template_exclude_dir = gameOption("template_exclude_dir") #是否需要部署大混服 self.big_mix_server = gameOption("big_mix_server",type="bool") #dns game self.dns_game = gameOption("dns_game",default=self.game) logging.info("变量初始化完毕") except Exception,e1: self.statusCheck(False,str(e1))
def init(self): self.mainserverYx, self.mainserverQuhao = self.mainserver.split("_") self.htmlStatus = True curdir = os.path.dirname(os.path.abspath(__file__)) self.curdir = curdir logdir = curdir + "/../logs" if not os.path.exists(logdir): os.makedirs(logdir) game = self.game servername = self.servername language = self.language nowstring = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filename='%s/mix_%s_%s.log' % (os.path.abspath(logdir), game, self.mainserver), filemode='a') logging.info("开始部署游戏...") self.html = mailhtml.mailhtml( "mix_%s_%s_%s_deploy.html" % (game, self.mainserver, nowstring), "%s_%s游戏混服部署" % (game, self.mainserver)) self.rootDir = mainOption("rootdir").replace("${game}", game) self.email_address = gameOption("email_address") self.mail_title = "[%s][%s]游戏服部署" % (game, servername) self.html.add("游戏混服名称", servername.replace(",", "<br>")) self.htmlStatus = True try: self.clientrootdir = getOption(mainConfig, "main", "clientrootdir").replace( "${game}", game) self.rootdir = getOption(mainConfig, "main", "rootdir").replace("${game}", game) #是否为大混服 self.bigmix = gameOption("big_mix_server", type="bool") if self.bigmix: self.html.add("混服类型", "大混服") else: self.html.add("混服类型", "混服") #参数校验 self.sList = [ i.strip() for i in self.servername.split(",") if i.strip() != "" ] if self.bigmix: for i in self.sList: self.statusCheck(check.checkServer(i), "游戏名称:%s 不合法" % i) else: self.statusCheck(check.checkServer(self.servername), "游戏名称:%s 不合法" % self.servername) #后台相关信息 self.backstage = gameOption("backstage") self.backstage_db = gameOption("backstage_db") self.backstage_tag = gameOption("backstage_tag") self.backstage_interface_url = gameOption( "backstage_interface_url") self.backstage_header = gameOption("backstage_header") self.have_backstage_interface = gameOption( "have_backstage_interface", type="bool") #游戏服务器需要下载资源的地址信息 self.www_ip = gameOption("www_ip") self.www_port = gameOption("www_port") self.www_header = gameOption("www_header") #是否为海外 self.is_oversea = gameOption("is_oversea", type="bool") #是否为手游 if gameOption("is_mobile", type="bool"): self.partnersType = 2 self.is_mobile = "mobile" else: self.is_mobile = "web" self.partnersType = 1 if self.skipcheck: serverExistsJson = json.loads( serverlist.serverListExists(self.backstage_db, self.backstage_tag, self.partnersType, servername, self.backstage)) if serverExistsJson["result"]: self.statusCheck(False, "游戏已经存在,请确认") #获取主服的信息 #print self.backstage_db,self.backstage_tag,self.partnersType,"main",self.backstage,self.mainserver serverinfo = serverlist.serverInfo(self.backstage_db, self.backstage_tag, self.partnersType, "main", self.backstage, self.mainserver) logging.info(serverinfo) if not serverinfo["result"]: self.statusCheck(False, "主服信息获取失败,err:%s" % serverinfo["msg"]) self.ip = serverinfo["ip"] self.statusCheck(check.checkIp(self.ip), "ip:%s不合法" % self.ip) self.starttime = serverinfo["starttime"] self.statusCheck(check.checkDatetime(self.starttime), "开服时间:%s 不合法" % self.starttime) self.mainserver_web_url = serverinfo["web_url"] self.html.add("服务器ip", self.ip) logging.info("%s建立ssh连接..." % self.ip) self.ssh = ssh.ssh(self.ip) logging.info("%s建立ssh连接完毕!" % self.ip) time_zone = gameOption("time_zone") delta_hours = 8 - int(time_zone) self.cleartime = ( datetime.datetime.strptime(self.starttime, "%Y-%m-%d %H:%M:%S") + datetime.timedelta(hours=delta_hours) - datetime.timedelta(minutes=30)).strftime("%Y-%m-%d %H:%M:%S") self.html.add("开服时间(北京+8区)", self.starttime) self.html.add("清档时间(服务器%s区)" % time_zone, self.cleartime) #www是老模式(www)还是新模式(www_ly_id) self.www_dir_type = gameOption("www_dir_type") #是否添加ast域名解析 self.add_dns = gameOption("add_dns", type="bool") #是否需要联运解析域名 self.lianyun_add_dns = gameOption("lianyun_add_dns", type="bool") #后台游戏域名,后续会替换server_url self.web_url = gameOption("web_url") #混服部署脚本 self.mix_deploy_script = gameOption("mix_deploy_script") logging.info("变量初始化完毕") except Exception, e1: self.statusCheck(False, str(e1))
def init(self): self.mainserverYx,self.mainserverQuhao = self.mainserver.split("_") self.htmlStatus = True curdir = os.path.dirname(os.path.abspath(__file__)) self.curdir = curdir logdir = curdir +"/../logs" if not os.path.exists(logdir): os.makedirs(logdir) game = self.game servername = self.servername language = self.language nowstring = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filename='%s/mix_%s_%s.log'%(os.path.abspath(logdir),game,self.mainserver), filemode='a') logging.info("开始部署游戏...") self.html = mailhtml.mailhtml("mix_%s_%s_%s_deploy.html"%(game,self.mainserver,nowstring),"%s_%s游戏混服部署"%(game,self.mainserver)) mainConfig = config.getConfig("main") gameConfig = config.getConfig(game) mainConfig = config.getConfig("main") self.rootDir = mainConfig.get("main","rootdir").replace("${game}",game) self.email_address = getOption(gameConfig,language,"email_address") self.mail_title = "[%s][%s]游戏服部署"%(game,servername) self.html.add("游戏混服名称",servername.replace(",","<br>")) self.htmlStatus = True try: self.clientrootdir = getOption(mainConfig,"main","clientrootdir").replace("${game}",game) self.rootdir = getOption(mainConfig,"main","rootdir").replace("${game}",game) #是否为大混服 self.bigmix = getOption(gameConfig,language,"big_mix_server",type = "bool") if self.bigmix: self.html.add("混服类型","大混服") else: self.html.add("混服类型","混服") #参数校验 self.sList = [ i.strip() for i in self.servername.split(",") if i.strip() != "" ] if self.bigmix: for i in self.sList: self.statusCheck(check.checkServer(i),"游戏名称:%s 不合法"%i) else: self.statusCheck(check.checkServer(self.servername),"游戏名称:%s 不合法"%self.servername) #后台相关信息 self.backstage = getOption(gameConfig,language,"backstage") self.backstage_db = getOption(gameConfig,language,"backstage_db") self.backstage_tag = getOption(gameConfig,language,"backstage_tag") self.backstage_interface_url = getOption(gameConfig,language,"backstage_interface_url") self.backstage_header = getOption(gameConfig,language,"backstage_header") self.have_backstage_interface = getOption(gameConfig,language,"have_backstage_interface",type="bool") #游戏服务器需要下载资源的地址信息 self.www_ip = getOption(gameConfig,language,"www_ip") self.www_port = getOption(gameConfig,language,"www_port") self.www_header = getOption(gameConfig,language,"www_header") #是否为海外 self.is_oversea = getOption(gameConfig,language,"is_oversea",type="bool") #是否为手游 if getOption(gameConfig,language,"is_mobile",type="bool"): self.partnersType = 2 self.is_mobile = "mobile" else: self.is_mobile = "web" self.partnersType = 1 if self.skipcheck: serverExistsJson = json.loads(serverlist.serverListExists(self.backstage_db,self.backstage_tag,self.partnersType,servername,self.backstage)) if serverExistsJson["result"]: self.statusCheck(False,"游戏已经存在,请确认") #获取主服的信息 #print self.backstage_db,self.backstage_tag,self.partnersType,"main",self.backstage,self.mainserver serverinfo = serverlist.serverInfo(self.backstage_db,self.backstage_tag,self.partnersType,"main",self.backstage,self.mainserver) logging.info(serverinfo) if not serverinfo["result"]: self.statusCheck(False,"主服信息获取失败,err:%s"%serverinfo["msg"]) self.ip = serverinfo["ip"] self.statusCheck(check.checkIp(self.ip),"ip:%s不合法"%self.ip) self.starttime = serverinfo["starttime"] self.statusCheck(check.checkDatetime(self.starttime),"开服时间:%s 不合法"%self.starttime) self.mainserver_web_url = serverinfo["web_url"] self.html.add("服务器ip",self.ip) logging.info("%s建立ssh连接..."%self.ip) self.ssh = ssh.ssh(self.ip) logging.info("%s建立ssh连接完毕!"%self.ip) time_zone = getOption(gameConfig,language,"time_zone") delta_hours = 8 - int(time_zone) self.cleartime = (datetime.datetime.strptime(self.starttime,"%Y-%m-%d %H:%M:%S") + datetime.timedelta(hours=delta_hours) - datetime.timedelta(minutes=30)).strftime("%Y-%m-%d %H:%M:%S") self.html.add("开服时间(北京+8区)",self.starttime) self.html.add("清档时间(服务器%s区)"%time_zone,self.cleartime) #www是老模式(www)还是新模式(www_ly_id) self.www_dir_type = getOption(gameConfig,language,"www_dir_type") #是否添加ast域名解析 self.add_dns = getOption(gameConfig,language,"add_dns",type="bool") #是否需要联运解析域名 self.lianyun_add_dns = getOption(gameConfig,language,"lianyun_add_dns",type="bool") #后台游戏域名,后续会替换server_url self.web_url = getOption(gameConfig,language,"web_url") #混服部署脚本 self.mix_deploy_script = getOption(gameConfig,language,"mix_deploy_script") logging.info("变量初始化完毕") except Exception,e1: self.statusCheck(False,str(e1))
def init(self): curdir = os.path.dirname(os.path.abspath(__file__)) self.curdir = curdir logdir = curdir + "/../logs" if not os.path.exists(logdir): os.makedirs(logdir) game = self.game servername = self.servername ip = self.ip language = self.language nowstring = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filename='%s/recover_%s_%s.log' % (os.path.abspath(logdir), game, servername), filemode='a') logging.info("开始恢复游戏...") print "详细日志为:%s/recover_%s_%s.log" % (os.path.abspath(logdir), game, servername) #参数校验 self.statusCheck(check.checkIp(ip), "ip:%s不合法" % ip) try: logging.info("%s建立ssh连接..." % ip) self.ssh = ssh.ssh(ip) logging.info("%s建立ssh连接完毕!" % ip) self.clientrootdir = mainOption("clientrootdir").replace( "${game}", game) self.rootdir = mainOption("rootdir").replace("${game}", game) #后台相关信息 self.backstage = gameOption("backstage") self.backstage_db = gameOption("backstage_db") self.backstage_tag = gameOption("backstage_tag") self.backstage_interface_url = gameOption( "backstage_interface_url") self.backstage_header = gameOption("backstage_header") self.have_backstage_interface = gameOption( "have_backstage_interface", type="bool") #游戏服务器需要下载资源的地址信息 self.www_ip = gameOption("www_ip") self.www_port = gameOption("www_port") self.www_header = gameOption("www_header") #下载备份sql的hadoop路径 self.ftppath = gameOption("FTP_PATH") #是否为海外 self.is_oversea = gameOption("is_oversea", type="bool") #是否为手游 if gameOption("is_mobile", type="bool"): self.is_mobile = "mobile" self.partnersType = 2 else: self.is_mobile = "web" self.partnersType = 1 #建库sql self.innit_sql = self.game + "_" + self.language + "_init" + ".sql" time_zone = gameOption("time_zone") self.delta_hours = 8 - int(time_zone) #www是老模式(www)还是新模式(www_ly_id) self.www_dir_type = gameOption("www_dir_type") #恢复脚本 self.deploy_script = gameOption("deploy_script") #混服部署脚本 self.mix_deploy_script = gameOption("mix_deploy_script") #执行特殊脚本 self.deploy_special_script = gameOption("deploy_special_script") #清档脚本 self.clear_script = gameOption("clear_script") #是否添加ast域名解析 self.add_dns = gameOption("add_dns", type="bool") #是否需要联运解析域名 self.lianyun_add_dns = gameOption("lianyun_add_dns", type="bool") #后台游戏域名,后续会替换server_url self.web_url = gameOption("web_url") #布服公共包目录 self.template_tar_dir = gameOption("template_tar_dir") self.template_exclude_dir = gameOption("template_exclude_dir") #是否需要部署大混服 self.big_mix_server = gameOption("big_mix_server", type="bool") logging.info("变量初始化完毕") except Exception, e1: self.statusCheck(False, str(e1))
def validate(self, value): Parameter.validate(self, value) if not check.checkIp(value): raise Exception("Invalid IPv4 address")
def validate(self, value): Parameter.validate(self, value) if not (check.checkDomain(value) or check.checkIp(value)): raise Exception("Invalid host or IP")
def getserverlist(ServerFile=None, ServerList=None, ExecludeServerList=None, StartDate=None, EndDate=None, UniqueServer=None): if ServerFile != None or ServerList != None or ExecludeServerList != None or StartDate != None or EndDate != None or UniqueServer != None: #print ServerFile,ServerList,ExecludeServerList,StartDate,EndDate,UniqueServer pass else: ServerFile = state.options.serverfile ServerList = state.options.serverlist ExecludeServerList = state.options.excludeServerlist StartDate = state.options.startdate EndDate = state.options.enddate UniqueServer = state.options.uniqserver slist = [] if not check.nullCheck(ServerFile): for i in open(ServerFile).readlines(): if i.strip() != "": if i.find("@") > 0: s = i.split("@") servername = s[0].strip() ip = s[1].strip() else: servername = i.strip() if check.checkIp(i.strip()): ip = i.strip() else: ip = state.game + "_" + i.strip() if not check.nullCheck(ServerList): if not re.match(r"^%s$" % ServerList, servername): continue if not check.nullCheck(ExecludeServerList): if re.match("^%s$" % ExecludeServerList, servername): continue slist.append([servername, ip]) else: if gameOption("is_mobile", type="bool"): partnersType = 2 else: partnersType = 1 slist = serverlist.serverRange(gameOption("backstage_db"), gameOption("backstage_tag"), partnersType, "main", gameOption("backstage"), StartDate, EndDate, ServerList, ExecludeServerList) #print StartDate,EndDate,ServerList,ExecludeServerList serverlist_tag = [ i.strip() for i in gameOption("serverlist_tag", default="").split(",") if i.strip() != "" ] for tag in serverlist_tag: slist += serverlist.serverRange(gameOption("backstage_db"), tag, partnersType, "main", gameOption("backstage"), StartDate, EndDate, ServerList, ExecludeServerList) if UniqueServer: return list(set(i[1].strip() for i in slist)) else: return slist