1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 16:28:11 +00:00

Correctly show the host in templates

Fix #157
This commit is contained in:
Julien Duponchelle 2015-04-23 14:31:36 +02:00
parent 3680c40e23
commit 6b862b8397
2 changed files with 11 additions and 9 deletions

View File

@ -30,10 +30,11 @@ renderer = jinja2.Environment(loader=jinja2.PackageLoader('gns3server', 'templat
class Response(aiohttp.web.Response):
def __init__(self, route=None, output_schema=None, headers={}, **kwargs):
def __init__(self, request=None, route=None, output_schema=None, headers={}, **kwargs):
self._route = route
self._output_schema = output_schema
self._request = request
headers['X-Route'] = self._route
headers['Server'] = "Python/{0[0]}.{0[1]} GNS3/{1}".format(sys.version_info, __version__)
super().__init__(headers=headers, **kwargs)
@ -70,6 +71,7 @@ class Response(aiohttp.web.Response):
"""
template = renderer.get_template(template_filename)
kwargs["gns3_version"] = __version__
kwargs["gns3_host"] = self._request.host
self.html(template.render(**kwargs))
def json(self, answer):

View File

@ -120,7 +120,7 @@ class Route(object):
# Non API call
if api_version is None:
response = Response(route=route, output_schema=output_schema)
response = Response(request=request, route=route, output_schema=output_schema)
yield from func(request, response)
return response
@ -136,34 +136,34 @@ class Route(object):
f.write("\n")
except OSError as e:
log.warn("Could not write to the record file {}: {}".format(record_file, e))
response = Response(route=route, output_schema=output_schema)
response = Response(request=request, route=route, output_schema=output_schema)
yield from func(request, response)
except aiohttp.web.HTTPBadRequest as e:
response = Response(route=route)
response = Response(request=request, route=route)
response.set_status(e.status)
response.json({"message": e.text, "status": e.status, "path": route, "request": request.json})
except aiohttp.web.HTTPException as e:
response = Response(route=route)
response = Response(request=request, route=route)
response.set_status(e.status)
response.json({"message": e.text, "status": e.status})
except VMError as e:
log.error("VM error detected: {type}".format(type=type(e)), exc_info=1)
response = Response(route=route)
response = Response(request=request, route=route)
response.set_status(409)
response.json({"message": str(e), "status": 409})
except asyncio.futures.CancelledError as e:
log.error("Request canceled")
response = Response(route=route)
response = Response(request=request, route=route)
response.set_status(408)
response.json({"message": "Request canceled", "status": 408})
except aiohttp.ClientDisconnectedError:
log.error("Client disconnected")
response = Response(route=route)
response = Response(request=request, route=route)
response.set_status(408)
response.json({"message": "Client disconnected", "status": 408})
except Exception as e:
log.error("Uncaught exception detected: {type}".format(type=type(e)), exc_info=1)
response = Response(route=route)
response = Response(request=request, route=route)
response.set_status(500)
CrashReport.instance().capture_exception(request)
exc_type, exc_value, exc_tb = sys.exc_info()