Commit 006ce344 by Bach Dániel

vm: add context support (BootUrl)

parent aea8a13b
......@@ -17,4 +17,5 @@ urlpatterns = patterns(
url(r'^admin/', include(admin.site.urls)),
url(r'^network/', include('network.urls')),
url(r'^dashboard/', include('dashboard.urls')),
url(r'^vm-api/', include('vm.urls')),
)
......@@ -17,6 +17,7 @@ from .tasks import local_tasks, vm_tasks, net_tasks
from common.models import ActivityModel, activitycontextimpl
from firewall.models import Vlan, Host
from storage.models import Disk
from django.core import signing
logger = logging.getLogger(__name__)
......@@ -510,6 +511,7 @@ class Instance(VirtualMachineDescModel, TimeStampedModel):
'passwd': '',
'port': self.vnc_port
},
'boot_token': signing.dumps(self.id, salt='activate'),
'raw_data': "" if not self.raw_data else self.raw_data
}
......
from django.conf.urls import patterns, url
from .views import BootUrl
urlpatterns = patterns(
'',
url(r'^b/(?P<token>.*)/$', BootUrl.as_view()),
)
# Create your views here.
from django.views.generic.base import View
from django.http import HttpResponse
from django.core import signing
from django.shortcuts import get_object_or_404
from vm.models import Instance
from datetime import datetime
class BootUrl(View):
def get(self, 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")
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