1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 15:15:22 +00:00

add /instance/sshkeys/ endpoint for retrieving instance owners ssh keys

This commit is contained in:
Ing. Jan KRCMAR 2017-05-11 10:46:39 +02:00
parent b7457a4362
commit 4d08f956fb
2 changed files with 21 additions and 3 deletions

View file

@ -14,4 +14,6 @@ urlpatterns = [
views.guess_clone_name, name='guess_clone_name'),
url(r'^check_instance/(?P<vname>[\w\-\.]+)/$',
views.check_instance, name='check_instance'),
url(r'^sshkeys/(?P<vname>[\w\-\.]+)/$',
views.sshkeys, name='sshkeys'),
]

View file

@ -807,7 +807,7 @@ def guess_mac_address(request, vname):
if name_found and "hardware ethernet" in line:
data['mac'] = line.split(' ')[-1].strip().strip(';')
break
return HttpResponse(json.dumps(data));
return HttpResponse(json.dumps(data))
@login_required
def guess_clone_name(request):
@ -823,7 +823,7 @@ def guess_clone_name(request):
hostname = fqdn.split('.')[0]
if hostname.startswith(prefix) and hostname not in instance_names:
return HttpResponse(json.dumps({'name': hostname}))
return HttpResponse(json.dumps({}));
return HttpResponse(json.dumps({}))
@login_required
def check_instance(request, vname):
@ -831,4 +831,20 @@ def check_instance(request, vname):
data = { 'vname': vname, 'exists': False }
if check_instance:
data['exists'] = True
return HttpResponse(json.dumps(data));
return HttpResponse(json.dumps(data))
def sshkeys(request, vname):
"""
:param request:
:param vm:
:return:
"""
instance_keys = []
userinstances = UserInstance.objects.filter(instance__name=vname)
for ui in userinstances:
keys = UserSSHKey.objects.filter(user=ui.user)
for k in keys:
instance_keys.append(k.keypublic)
return HttpResponse(json.dumps(instance_keys))