예제 #1
0
파일: ports.py 프로젝트: yunw/MyTechTest
 def getFreePort(self, appName, porttype):
     #host=['0.0.0.0','127.0.0.1', '10.25.23.165']
     hosts = self.find_all_ip()
     cf = ConfigParser.ConfigParser()
     realpath = os.path.split(os.path.realpath(sys.argv[0]))[0]
     cf.read(realpath + '/script/ports.properties')
     cf.sections()
     minPort = cf.get("portRange", "minPort")
     maxPort = cf.get("portRange", "maxPort")
     lock = threading.Lock()
     db = dbOps()
     dbPath = db.getDbFilePath()
     p = db.fetchFreePort(appName, porttype)
     if p is not None:
         return p
     if lock.acquire():
         for port in range(int(minPort), int(maxPort)):
             cnt = 0
             for h in hosts:
                 try:
                     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                     s.bind((h, port))
                     s.close()
                     cnt = cnt + 1
                 except:
                     break
             if (cnt == len(hosts)):
                 whitePorts = cf.get('whitePorts', 'ports')
                 wps = whitePorts.split(',')
                 isWhite = False
                 for p in wps:
                     if (int(p) == port):
                         isWhite = True
                         break
                 if (isWhite == False):
                     sql = 'INSERT INTO ports values(?,?,?)'
                     data = [
                         (port, appName, porttype),
                     ]
                     res = db.save(sql, data)
                     if (res == 0):
                         return port
         lock.release()
예제 #2
0
 def saveDeployData(self):        
     db = dbOps()
     
     stage = getattr(self,'stage')
     appName = getattr(self,'appName')
     appVersion = getattr(self,'appVersion')
     appPath = getattr(self,'appPath')
     accessURL = getattr(self,'accessURL')
     dubboAddress = getattr(self,'dubboAddress')
     debugPort = getattr(self,'debugPort')
     tcpPort = getattr(self,'tcpPort')
     udpPort = getattr(self,'udpPort')
     result = getattr(self,'result')
     
     sql = 'INSERT INTO TB_DEPLOY_K8S (STAGE,APP_NAME,APP_VERSION,APP_PATH,ACCESS_URL,DUBBO_ADDRESS,DEBUG_PORT,TCP_PORT,UDP_PORT,RESULT) VALUES(?,?,?,?,?,?,?,?,?,?)'
     data = [(stage,appName,appVersion,appPath,accessURL,dubboAddress,debugPort,tcpPort,udpPort,result),]
     res = db.save(sql, data)
     if (res == 0):
         return 0
예제 #3
0
파일: ports.py 프로젝트: yinsl/MyTechTest
 def getFreePort(self,appName,porttype):
     #host=['0.0.0.0','127.0.0.1', '10.25.23.165']
     hosts = self.find_all_ip()
     cf = ConfigParser.ConfigParser() 
     realpath = os.path.split( os.path.realpath( sys.argv[0] ) )[0] 
     cf.read(realpath + '/script/ports.properties')
     cf.sections()
     minPort = cf.get("portRange", "minPort")
     maxPort = cf.get("portRange", "maxPort")
     lock = threading.Lock()
     db = dbOps()
     dbPath =  db.getDbFilePath()
     p = db.fetchFreePort(appName,porttype)
     if p is not None:
         return p
     if lock.acquire():
         for port in range(int(minPort), int(maxPort)):
             cnt = 0
             for h in hosts:
                 try:
                     s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                     s.bind((h,port))
                     s.close()
                     cnt= cnt+1
                 except:
                     break
             if (cnt == len(hosts)):
                 whitePorts=cf.get('whitePorts', 'ports')
                 wps = whitePorts.split(',')
                 isWhite = False
                 for p in wps:
                     if (int(p) == port):
                         isWhite = True
                         break
                 if (isWhite == False):
                     sql='INSERT INTO ports values(?,?,?)'
                     data=[(port,appName,porttype),]
                     res = db.save(sql, data)
                     if (res == 0):
                         return port
         lock.release()
예제 #4
0
    def saveDeployData(self):
        db = dbOps()

        stage = getattr(self, 'stage')
        appName = getattr(self, 'appName')
        appVersion = getattr(self, 'appVersion')
        appPath = getattr(self, 'appPath')
        accessURL = getattr(self, 'accessURL')
        dubboAddress = getattr(self, 'dubboAddress')
        debugPort = getattr(self, 'debugPort')
        tcpPort = getattr(self, 'tcpPort')
        udpPort = getattr(self, 'udpPort')
        result = getattr(self, 'result')

        sql = 'INSERT INTO TB_DEPLOY_K8S (STAGE,APP_NAME,APP_VERSION,APP_PATH,ACCESS_URL,DUBBO_ADDRESS,DEBUG_PORT,TCP_PORT,UDP_PORT,RESULT) VALUES(?,?,?,?,?,?,?,?,?,?)'
        data = [
            (stage, appName, appVersion, appPath, accessURL, dubboAddress,
             debugPort, tcpPort, udpPort, result),
        ]
        res = db.save(sql, data)
        if (res == 0):
            return 0