def __registerService(self, exip, ports): from libs.syslog import slog slog.warn("%s:%s register to %s with %s" % (exip, ", ".join([str(p) for p in ports]), self.regServer, self.regName)) if self.regServer is not None: from server.cclient import curlCservice curlCservice(self.regServer, 'CServiceTool/RegistServer', hostport="%s:%s" % (exip, ports[0]), serverName=self.regName)
def addProxy(self, mockaddr, info, proxy, timeMark=None): curlCservice(mockaddr, 'LogHttpProxy/reloadProxyConfig', isCheckResp=True, proxyConfig=proxy) return self.dapi.saveInfData("LogHttpProxy.reloadProxyConfig", info, {'proxyConfig': proxy}, timeMark=timeMark)
def deleteUrlMock(self, mockaddr, timeMark, url, isdelete): curlCservice(mockaddr, 'LogHttpProxy/addUrlMock', isCheckResp=True, url=url, param="", resp="", isdelete="true") if isdelete == "true": return self.dapi.deleteInfData("LogHttpProxy.addUrlMock", timeMark) else: mock = self.dapi.getInfData("LogHttpProxy.addUrlMock", {'t': timeMark}) mock[0]['a']['isdelete'] = 'true'
def __registerService(self, exip, ports, initMethods): from libs.syslog import slog slog.warn( "%s:%s register to %s with %s" % (exip, ", ".join([str(p) for p in ports]), self.regServer, self.regName)) import time time.sleep(1) if self.regServer != "": from server.cclient import curlCservice curlCservice(self.regServer, 'CServiceTool/registServer', hostport="%s:%s" % (exip, ports[0]), serverName=self.regName, initMethods=initMethods)
def doInfRequest(self, hostPort, infName, requestArgs, replaceProp=None, isHostName=False): infPath = infName.replace(".", "/") requestArgs = toJsonObj(requestArgs) if replaceProp is not None and replaceProp != "" and requestArgs != "": try: for argName in requestArgs.keys(): if replaceProp.__contains__(argName): originVal = requestArgs[argName] requestArgs[argName] = self.replaceValues.TryGet( originVal, originVal) requestArgs = requestArgs.__str__(0, True) except: pass return curlCservice( self._getServerAddress(hostPort) if isHostName else hostPort, infPath, isCheckResp=True, **requestArgs)
def packageCode(self, module, branch='trunk', svnPath="", codeIp=""): config = ObjOperation.tryGetVal(self.getModuleInfo(), module, {}) packageName = "%s-%s-%s" % (module, branch, time.strftime("%Y%m%d-%H%M")) pkFile = '%s/%s.tar' % (pkFolder, packageName) if os.path.exists(pkFile): return 0, packageName # package code path = ObjOperation.tryGetVal(config, branch, svnPath) if path == "": path = ObjOperation.tryGetVal(config, "trunk", svnPath) resp = curlCservice(pkHost, "PackageTool/packageToLocalFolder", isCheckResp=True, curlHeader={"host": pkHostName}, path=path, module=module, branch=branch, packageName=packageName, toFolder=ObjOperation.tryGetVal( config, "deployFolder", module)) plog.info(resp) # down load code downloadPkCmd = 'wget %s/file/%s_tar --header="Host: %s" -q -O %s > /dev/null' % ( pkHost, packageName, pkHostName, pkFile) os.system(downloadPkCmd) try: resp = curlCservice(pkHost, "PackageTool/deletePackage", isCheckResp=True, curlHeader={"host": pkHostName}, packageName=packageName) except Exception as ex: return ex # check package if os.path.exists(pkFile): fsize = os.path.getsize(pkFile) if fsize < 20480: os.system("rm -rf %s" % pkFile) else: fsize = -1 return fsize, packageName
def addUrlMock(self, mockaddr, info, mockurl, mockparam, mockresp, timeMark=None): curlCservice(mockaddr, 'LogHttpProxy/addUrlMock', isCheckResp=True, url=mockurl, param=mockparam, resp=mockresp) return self.dapi.saveInfData("LogHttpProxy.addUrlMock", info, { 'url': mockurl, 'resp': mockresp, 'param': mockparam, "isdelete": "false" }, timeMark=timeMark)
def __executeSql__(self, sqlStr, isSelect=True, isFethall=True, isCommit=True, dbName=None): import base64 return curlCservice(self.host, None, urlPath=self.path, isCheckResp=True, base64Sql=base64.encodestring(sqlStr), dbName=dbName, dbconfig=self.dbconfig)
def __executeSql__(self, sqlStr, isSelect=True, isFethall=True, isCommit=True, dbName=None): return curlCservice(self.host, self.path, isCheckResp=True, passwd=self.passwd, sqlStr=sqlStr, isSelect=isSelect, isFethall=isFethall, isCommit=isCommit, dbName=dbName)
def getService(self, hostPort): return curlCservice(hostPort, "param", isGetInfo=True, connTimeout=1)
def _callServer(self, aname, **args): return curlCservice(self.serverhost, self.serverpath, isCheckResp=True, passwd=self.serverauth, aname=aname, **args)