def _do_post(self, host, port, cmd, mimeType, data, pars): start = time.time() res = ngamsHttpUtils.httpPost(host, port, cmd, data, mimeType, pars=pars, timeout=self.timeout, auth=self.basic_auth) delta = time.time() - start logger.info("Successfully completed command %s in %.3f [s]", cmd, delta) return res
def notifyRegistrationService(srvObj, svrStatus='online'): """ to notify the ngas registration service that I am online now svrStatus = online|offline """ parDicOnline = ngamsPlugInApi.\ parseRawPlugInPars(srvObj.getCfg().getOnlinePlugInPars()) if (parDicOnline.has_key("regsvr_host")): if (svrStatus == "online"): errTag = "NGAMS_ER_ONLINE_PLUGIN" else: errTag = "NGAMS_ER_OFFLINE_PLUGIN" regsvr_host = parDicOnline["regsvr_host"] regsvr_port = parDicOnline["regsvr_port"] regsvr_path = parDicOnline["regsvr_path"] host_name = getHostName() host_port = srvObj.getCfg().getPortNo() body = urllib.urlencode({ 'ngas_host': host_name, 'ngas_port': host_port, 'status': svrStatus }) hdrs = {"Accept": "text/plain"} resp = ngamsHttpUtils.httpPost( regsvr_host, regsvr_port, regsvr_path, body, mimeType='application/x-www-form-urlencoded', hdrs=hdrs, timeout=10) with contextlib.closing(resp): if resp.status != 200: errMsg = "Problem notifying registration service! Error " + resp.reason errMsg = genLog(errTag, [errMsg]) logger.error(errMsg) #raise Exception, errMsg else: logger.debug("Successfully notified registration service: %s", svrStatus) logger.info(resp.read()) return