From 4d08f956fb8af591feed1b69df6c40e7d1655a5c Mon Sep 17 00:00:00 2001 From: "Ing. Jan KRCMAR" Date: Thu, 11 May 2017 10:46:39 +0200 Subject: [PATCH] add /instance/sshkeys/ endpoint for retrieving instance owners ssh keys --- instances/urls.py | 2 ++ instances/views.py | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/instances/urls.py b/instances/urls.py index e8f263b..dfba916 100644 --- a/instances/urls.py +++ b/instances/urls.py @@ -14,4 +14,6 @@ urlpatterns = [ views.guess_clone_name, name='guess_clone_name'), url(r'^check_instance/(?P[\w\-\.]+)/$', views.check_instance, name='check_instance'), + url(r'^sshkeys/(?P[\w\-\.]+)/$', + views.sshkeys, name='sshkeys'), ] diff --git a/instances/views.py b/instances/views.py index e098788..a746763 100644 --- a/instances/views.py +++ b/instances/views.py @@ -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))