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:
parent
b7457a4362
commit
4d08f956fb
2 changed files with 21 additions and 3 deletions
|
@ -14,4 +14,6 @@ urlpatterns = [
|
||||||
views.guess_clone_name, name='guess_clone_name'),
|
views.guess_clone_name, name='guess_clone_name'),
|
||||||
url(r'^check_instance/(?P<vname>[\w\-\.]+)/$',
|
url(r'^check_instance/(?P<vname>[\w\-\.]+)/$',
|
||||||
views.check_instance, name='check_instance'),
|
views.check_instance, name='check_instance'),
|
||||||
|
url(r'^sshkeys/(?P<vname>[\w\-\.]+)/$',
|
||||||
|
views.sshkeys, name='sshkeys'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -807,7 +807,7 @@ def guess_mac_address(request, vname):
|
||||||
if name_found and "hardware ethernet" in line:
|
if name_found and "hardware ethernet" in line:
|
||||||
data['mac'] = line.split(' ')[-1].strip().strip(';')
|
data['mac'] = line.split(' ')[-1].strip().strip(';')
|
||||||
break
|
break
|
||||||
return HttpResponse(json.dumps(data));
|
return HttpResponse(json.dumps(data))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def guess_clone_name(request):
|
def guess_clone_name(request):
|
||||||
|
@ -823,7 +823,7 @@ def guess_clone_name(request):
|
||||||
hostname = fqdn.split('.')[0]
|
hostname = fqdn.split('.')[0]
|
||||||
if hostname.startswith(prefix) and hostname not in instance_names:
|
if hostname.startswith(prefix) and hostname not in instance_names:
|
||||||
return HttpResponse(json.dumps({'name': hostname}))
|
return HttpResponse(json.dumps({'name': hostname}))
|
||||||
return HttpResponse(json.dumps({}));
|
return HttpResponse(json.dumps({}))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def check_instance(request, vname):
|
def check_instance(request, vname):
|
||||||
|
@ -831,4 +831,20 @@ def check_instance(request, vname):
|
||||||
data = { 'vname': vname, 'exists': False }
|
data = { 'vname': vname, 'exists': False }
|
||||||
if check_instance:
|
if check_instance:
|
||||||
data['exists'] = True
|
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))
|
||||||
|
|
Loading…
Reference in a new issue