예제 #1
0
 def Add(self, host, port, user, passwd, sd, ris=''):
     """添加一个服务
     @param host,port,user,passwd,分别对应db的地址:端口:用户:密码
     @param sd str: 这个db的描述
     @param ris str: 即推荐的inception的地址:端口,例如127.0.0.1:6669,端口默认6669
     """
     res = dict(msg=None, code=1)
     if ris:
         ihost, iport = ris.split(":") if ":" in ris else (ris, 6669)
         if not ip_check(ihost) or not number_check(iport):
             res.update(msg="Invaild ris")
             return res
     if sd and host and port and user and passwd:
         if " " in passwd or "%" in passwd:
             res.update(msg="Password has spaces or %")
             return res
         if number_check(port):
             sql = "INSERT INTO incetops_db (sd,host,port,user,passwd,ris,ctime) VALUES(%s,%s,%s,%s,%s,%s,%s)"
             try:
                 self.mysql.insert(sql, sd, host, port, user,
                                   self.Encrypt(passwd), ris,
                                   get_current_timestamp())
             except IntegrityError:
                 res.update(msg="DB connection already exists")
             except Exception, e:
                 logger.error(e, exc_info=True)
                 res.update(msg="System exception")
             else:
                 res.update(code=0)
         else:
             res.update(msg="Invaild db port")
예제 #2
0
 def Add(self, connect, sd):
     """添加一个服务
     @param connect str: 地址:端口,例如127.0.0.1:6669,端口默认6669可以省略
     @param sd str: 这个连接的描述
     """
     res = dict(msg=None, code=1)
     if sd and connect:
         host, port = connect.split(":") if ":" in connect else (connect, 6669)
         if ip_check(host) and number_check(port):
             sql = "INSERT INTO incetops_inception (sd,host,port,ctime) VALUES(%s,%s,%s,%s)"
             try:
                 self.mysql.insert(sql, sd, host, port, get_current_timestamp())
             except IntegrityError:
                 res.update(msg="Inception connection already exists")
             except Exception,e:
                 logger.error(e, exc_info=True)
                 res.update(msg="System exception")
             else:
                 res.update(code=0)
         else:
             res.update(msg="Invaild connect")