#!-*-coding:utf-8-*-#/usr/bin/python# #参数4个: Platform name Area code (secondary service) port (main service) domain name (main service) import sysreload (SYS) # reload to invoke Setdefaultencod ing method sys.setdefaultencoding (' Utf-8 ') # set ' utf-8 ' Import mysqldbimport houtai_dbnameimport commandsimport paramikodef Server_zoneid (): #result = "" Global conn,plname Try:cur = conn.cursor (cursorclass=mysqldb.cursors.dictcursor) conn.select_db (' H5_houtai ') sql= "select Ip,zoneid,gameport from ServerInfo WHERE pf=\ '%s\ ' and ZoneID =%s;"% (plname,z Oneid) cur.execute (SQL) Result=cur.fetchone () domain=result.get (' IP ') print domain Id=int (result.get (' ZoneID ')) print ID #gport =result.get (' Gameport ') #print gport #print hostname user= ' root ' pkey_file = '/root/.ssh/id_rsa ' Key=paramiko. Rsakey.from_private_key_file (pkey_file) cmd= ' echo '%s=jdbc:mysql://%s:3306/xmxy_bnxy_%s&jygsuser&jy_ GAME89XOK23CM4KCMHHJSKB ">>/usr/jyserver/%s/server/config/dbs.properties '% (zoneid,domain,zoneid,port) # The number of DBS configurations is written to the main service catalog DBS S=paramiko. Sshclient () #调用paramiko模块下的sshclient () S.loAd_system_host_keys () #加载本地的known_hosts文件, the file is a record attached to each other when the other party gives the host key. I=s.load_system_host_keys () S.set_missing_host_key_policy (Paramiko) is checked for each connection. Autoaddpolicy ()) S.connect (hostname,22,user,pkey=key,timeout=5) stdin,stdout,stderr=s.exec_command (cmd) cmd_ Result=stdout.read (), Stderr.read () print Cmd_result #for line in Cmd_result: # print line #print result #for line in Resul T: #print (Line,result[line]) #print "values:%s"% result.values () cur.close () conn.close () except mysqldb.error,e: #pri NT "MYSQLDB error%d:%s"% (E.args[0],e.args[1]) print EIF __name__== "__main__": plname=sys.argv[1] zoneid=sys.argv[2] Po RT=SYS.ARGV[3] hostname=sys.argv[4] #with open ("/usr/jyserver/%s/server/config/dbs.properties"% str (port)) as F: # Print F.read (). Strip ("") Conn=mysqldb.connect (host= ' xxx ', user= ' xxx ', passwd= ' xxx ', port=3306,charset= ' UTF8 ') server _zoneid ()
Main Service DBS Add sub-service DBS configuration