Пример #1
0
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
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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
Пример #6
0
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
Пример #7
0
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
Пример #8
0
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
Пример #9
0
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
Пример #10
0
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
Пример #11
0
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
Пример #12
0
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