Commit aff6d0b0 by Őry Máté

one: reimplement boot token functionality

parent d23686e0
......@@ -42,4 +42,5 @@ urlpatterns = patterns('',
url(r'^ajax/vm/status/(?P<iid>\d+)$', 'one.views.vm_ajax_instance_status', name='vm_ajax_instance_status'),
url(r'^language/(?P<lang>[-A-Za-z]+)/$', 'school.views.language', name='language'),
url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
url(r'^b/(?P<token>.*)/$', 'one.views.boot_token', name='boot_token'),
)
......@@ -127,6 +127,19 @@ def vm_ajax_instance_status(request, iid):
inst.update_state()
return HttpResponse(json.dumps({'booting': not inst.active_since, 'state': inst.state}))
def boot_token(request, token):
try:
id = signing.loads(token, salt='activate')
except:
return HttpResponse("Invalid token.")
inst = get_object_or_404(Instance, id=id)
if inst.active_since:
return HttpResponse("Already booted?")
else:
inst.active_since = datetime.now()
inst.save()
return HttpResponse("KTHXBYE")
class VmPortAddView(View):
def post(self, request, iid, *args, **kwargs):
try:
......@@ -217,11 +230,4 @@ def vm_restart(request, iid, *args, **kwargs):
messages.error(request, _('Failed to restart virtual machine.'))
return redirect('/')
def vm_active(request, token):
id = signing.loads(token, salt='activate', max_age=300)
vm = get_object_or_404(Instance, id=id)
vm.active_since = datetime.now()
vm.save()
return HttpResponse("Ok.", content_type="text/plain")
# vim: et sw=4 ai fenc=utf8 smarttab :
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment