Пример #1
0
 def get_server_id(self, server_name):
     try:
         db = Mysql.connect('ywshow')
         sql = "SELECT f_serverid serverid FROM `mo_config` WHERE f_servername=%s "
         res = db.query(sql, [server_name])
         if not res:
             print 'the server_name not find !'
         return res[0]['serverid']
     except:
         print 'some error in get_server_id: %s' % traceback.format_exc()
Пример #2
0
 def handDb(self, server_id, data):
     try:
         host = get_ip_address()
         db = Mysql.connect('ywshow')
         ret = db.execute(
             "insert into mo_server (f_serverid,f_data,f_serverip,f_instime) values(%s,%s,%s,now())",
             [server_id, JsonUtil.write(data), host])
         if not ret:
             print 'insert faild !'
         self.upExtend(server_id, host)
     except:
         print 'some error in handDb: %s' % traceback.format_exc()
Пример #3
0
 def upExtend(self, serverid, host):
     try:
         db = Mysql.connect('ywshow')
         res = db.query(
             "select f_serverip serverip from mo_extend where f_serverid=%s",
             [serverid])
         if not res:
             db.execute(
                 "insert into mo_extend (f_serverid,f_serverip) values ( %s, %s )",
                 [serverid, host])
         else:
             sip = res[0]['serverip'].split(',')
             if host not in sip:
                 sip.append(host)
                 sip = ','.join(sip)
                 db.execute(
                     "update mo_extend set f_serverip=%s where f_serverid=%s",
                     [sip, serverid])
     except:
         print 'some error in handDb: %s' % traceback.format_exc()