1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

show vdi url on access tab. some typo and convention fix. gethostbyaddr exception mitigated.

This commit is contained in:
catborise 2018-09-05 09:30:08 +03:00
parent cb5b0c1ecb
commit 0f7a110535
2 changed files with 20 additions and 5 deletions

View file

@ -7,13 +7,15 @@ from libvirt import libvirtError
import json
import socket
OS_VERSIONS = [ 'latest', '' ]
OS_VERSIONS = ['latest', '']
OS_UUID = "iid-dswebvirtcloud"
def os_index(request):
response = '\n'.join(OS_VERSIONS)
return HttpResponse(response)
def os_metadata_json(request, version):
"""
:param request:
@ -27,9 +29,10 @@ def os_metadata_json(request, version):
response = { 'uuid': OS_UUID, 'hostname': hostname }
return HttpResponse(json.dumps(response))
else:
err = 'Invalid version: %s' % version
err = 'Invalid version: {}'.format(version)
raise Http404(err)
def os_userdata(request, version):
"""
:param request:
@ -51,9 +54,10 @@ def os_userdata(request, version):
return render(request, 'user_data', locals())
else:
err = 'Invalid version: %s' % version
err = 'Invalid version: {}'.format(version)
raise Http404(err)
def get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
@ -62,10 +66,15 @@ def get_client_ip(request):
ip = request.META.get('REMOTE_ADDR')
return ip
def get_hostname_by_ip(ip):
addrs = socket.gethostbyaddr(ip)
try:
addrs = socket.gethostbyaddr(ip)
except Exception:
addrs = [ip,]
return addrs[0]
def get_vdi_url(request, vname):
instance = Instance.objects.get(name=vname)
compute = instance.compute