def urlWeather(request): postalCode = request.pathDict['postalCode'] host_url = "http://{}/weather/{}/forecast".format(request.host, postalCode) cliResp = requests.request( method=request.method, url=host_url, headers={key: value for (key, value) in request.headers if key != 'Host'}, data=request.body, allow_redirects=False) if cliResp.status_code != 200: return HttpResponse.errorResponse(cliResp.status_code, "Message") logging.info(cliResp.text) response = HttpResponse.okResponse() response.headers.append(("Cache-Control", "private")) response.addContentLengthHeader(len(cliResp.text)) response.addContentTypeHeader("application/xml; charset=utf-8") response.addServerHeader() response.addRequestContextHeader() response.addAccessControlHeader() response.addDateHeader() response.body = cliResp.text return response
def makeSystemsResponse(): response = HttpResponse.okResponse() response.headers.append(("Cache-Control", "private")) response.headers.append(("Etag", "\"0180958508d7b88afdc6a55c\"")) response.addServerHeader() response.addRequestContextHeader() response.addAccessControlHeader() response.addDateHeader() response.addContentLengthHeader(0) return response
def makeSystemsNotificationsResponse(): response = HttpResponse.okResponse() response.headers.append(("Cache-Control", "private")) response.addContentTypeHeader("application/xml; charset=utf-8") response.addServerHeader() response.addRequestContextHeader() response.addAccessControlHeader() response.addDateHeader() response.addContentLengthHeader(0) return response
def urlAlive(request): response = HttpResponse.okResponse() response.headers.append(("Cache-Control", "private, no-transform")) response.addContentLengthHeader(5) response.addContentTypeHeader("text/plain; charset=utf-8") response.addServerHeader() response.addRequestContextHeader() response.addAccessControlHeader() response.addDateHeader() response.body = "alive" return response
def makeApiResponse(code, message, body, contentType=None): if code == 200: response = HttpResponse.okResponse() else: response = HttpResponse.errorResponse(code, message) if body: response.addContentLengthHeader(len(body)) response.addContentTypeHeader(contentType) response.body = body response.addDateHeader() return response
def makeSystemsConfigResponse(xmlBodyStr): response = HttpResponse.okResponse() response.headers.append(("Cache-Control", "private")) response.addContentLengthHeader(len(xmlBodyStr)) response.addContentTypeHeader("application/xml; charset=utf-8") response.headers.append(("Etag", "\"00de388808d7b88cd8f146a1\"")) response.addServerHeader() response.addRequestContextHeader() response.addAccessControlHeader() response.addDateHeader() response.body = xmlBodyStr return response
def urlManifest(request): global responseManifest response = HttpResponse.okResponse() response.headers.append(("Cache-Control", "no-store,no-cache")) response.headers.append(("Pragma", "no-cache")) response.addContentLengthHeader(len(responseManifest)) response.addContentTypeHeader("application/xml") response.addRequestContextHeader() # Set-cookie header response.addDateHeader() response.body = responseManifest return response
def urlSystemsProfile(request): xmlBodyStr = request.bodyDict["data"][0] logging.debug(" SN={}".format(request.pathDict["serialNumber"])) logging.debug(" body={}".format(xmlBodyStr)) response = HttpResponse.okResponse() response.headers.append(("Cache-Control", "private")) response.addServerHeader() response.addRequestContextHeader() response.addAccessControlHeader() response.addDateHeader() response.addContentLengthHeader(0) return response
def urlSystemsUtilityEvents(request): logging.debug(" SN={}".format(request.pathDict["serialNumber"])) utilityXMLStr = '<utility_events version="1.42" xmlns:atom="http://www.w3.org/2005/Atom"/>' response = HttpResponse.okResponse() response.headers.append(("Cache-Control", "private")) response.addContentLengthHeader(len(utilityXMLStr)) response.addContentTypeHeader("application/xml; charset=utf-8") response.addServerHeader() response.addRequestContextHeader() response.addAccessControlHeader() response.addDateHeader() response.body = utilityXMLStr return response
def urlTime(request): utc = datetime.utcnow() strDate = utc.strftime("%Y-%m-%dT%H:%M:%SZ") timeXmlStr = '<time version="1.42" xmlns:atom="http://www.w3.org/2005/Atom"><atom:link rel="self" href="http://www.api.ing.carrier.com/time/"/><utc>' timeXmlStr += strDate timeXmlStr += '</utc></time>' response = HttpResponse.okResponse() response.headers.append(("Cache-Control", "private")) response.addContentLengthHeader(len(timeXmlStr)) response.addContentTypeHeader("application/xml; charset=utf-8") response.addServerHeader() response.addRequestContextHeader() response.addAccessControlHeader() response.addDateHeader() response.body = timeXmlStr return response
def urlRelNodes(request): hostAndPath = request.pathDict['hostAndPath'] logging.info("Fetch http://{}".format(hostAndPath)) bodyStr = "Returned from python server" response = HttpResponse.okResponse() response.headers.append(("Cache-Control", "no-store,no-cache")) response.headers.append(("Pragma", "no-cache")) response.addContentLengthHeader(len(bodyStr)) response.addContentTypeHeader("text/plain") response.addRequestContextHeader() response.headers.append(("X-Content-CRC", "1278")) response.headers.append(("X-Current-Page", "http://{}".format(hostAndPath))) # Cookie response.addDateHeader() response.body = bodyStr return response
def makeSystemsStatusResponse(request, serverHasChanges, configHasChanges): serialNumber = request.pathDict["serialNumber"] statusRoot = ET.Element("status") statusRoot.set("version", "1.42") statusRoot.set("xmlns:atom", "http://www.w3.org/2005/Atom") atomLink = ET.Element("atom:link") atomLink.set("rel", "self") atomLink.set( "href", "http://www.api.ing.carrier.com/systems/" + serialNumber + "/status") statusRoot.append(atomLink) atomLink = ET.Element("atom:link") atomLink.set("rel", "http://www.api.ing.carrier.com/rels/system") atomLink.set("href", "http://www.api.ing.carrier.com/systems/" + serialNumber) statusRoot.append(atomLink) tsEl = ET.Element("timestamp") tsEl.text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") statusRoot.append(tsEl) el = ET.Element("pingRate") el.text = "10" statusRoot.append(el) el = ET.Element("iduStatusPingRate") el.text = "93600" statusRoot.append(el) el = ET.Element("iduFaultsPingRate") el.text = "86400" statusRoot.append(el) el = ET.Element("oduStatusPingRate") el.text = "90000" statusRoot.append(el) el = ET.Element("oduFaultsPingRate") el.text = "82800" statusRoot.append(el) el = ET.Element("historyPingRate") el.text = "75600" statusRoot.append(el) el = ET.Element("equipEventsPingRate") el.text = "79200" statusRoot.append(el) el = ET.Element("rootCausePingRate") el.text = "72000" statusRoot.append(el) el = ET.Element("serverHasChanges") if serverHasChanges: el.text = "true" else: el.text = "false" statusRoot.append(el) el = ET.Element("configHasChanges") if configHasChanges: el.text = "true" else: el.text = "false" statusRoot.append(el) el = ET.Element("dealerHasChanges") el.text = "false" statusRoot.append(el) el = ET.Element("dealerLogoHasChanges") el.text = "false" statusRoot.append(el) el = ET.Element("oduConfigHasChanges") el.text = "false" statusRoot.append(el) el = ET.Element("iduConfigHasChanges") el.text = "false" statusRoot.append(el) el = ET.Element("utilityEventsHasChanges") el.text = "false" statusRoot.append(el) el = ET.Element("sensorConfigHasChanges") el.text = "false" statusRoot.append(el) el = ET.Element("sensorProfileHasChanges") el.text = "false" statusRoot.append(el) el = ET.Element("sensorDiagnosticHasChanges") el.text = "false" statusRoot.append(el) xmlBodyStr = ET.tostring(statusRoot, "utf-8") response = HttpResponse.okResponse() response.headers.append(("Cache-Control", "private")) response.addContentLengthHeader(len(xmlBodyStr)) response.addContentTypeHeader("application/xml; charset=utf-8") response.addServerHeader() response.addRequestContextHeader() response.addAccessControlHeader() response.addDateHeader() response.body = xmlBodyStr return response