Commit c3dd4099 by Kálmán Viktor

occi: delete VM

parent 78c30ada
...@@ -306,6 +306,11 @@ class Compute(Resource): ...@@ -306,6 +306,11 @@ class Compute(Resource):
user = User.objects.get(username="test") user = User.objects.get(username="test")
getattr(self.instance, operation).async(user=user) getattr(self.instance, operation).async(user=user)
def delete(self):
# TODO
user = User.objects.get(username="test")
self.instance.destroy(user=user)
class OsTemplate(Mixin): class OsTemplate(Mixin):
def __init__(self, template): def __init__(self, template):
......
...@@ -28,7 +28,7 @@ urlpatterns = patterns( ...@@ -28,7 +28,7 @@ urlpatterns = patterns(
url(r'^-/$', QueryInterface.as_view(), name="occi.query"), url(r'^-/$', QueryInterface.as_view(), name="occi.query"),
url(r'^compute/$', ComputeInterface.as_view(), name="occi.compute"), url(r'^compute/$', ComputeInterface.as_view(), name="occi.compute"),
url(r'^os_tpl/$', OsTplInterface.as_view(), name="occi.os_tpl"), url(r'^os_tpl/$', OsTplInterface.as_view(), name="occi.os_tpl"),
url(r'^vm/(?P<pk>\d+)/$', VmInterface.as_view(), name="occi.vm"), url(r'^vm/(?P<pk>\d+)/?$', VmInterface.as_view(), name="occi.vm"),
url(r'^storage/$', StorageInterface.as_view(), name="occi.storage"), url(r'^storage/$', StorageInterface.as_view(), name="occi.storage"),
url(r'^disk/(?P<pk>\d+)/$', DiskInterface.as_view(), name="occi.disk"), url(r'^disk/(?P<pk>\d+)/$', DiskInterface.as_view(), name="occi.disk"),
......
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.generic import View, DetailView from django.views.generic import View, DetailView
...@@ -97,6 +98,10 @@ class ComputeInterface(View): ...@@ -97,6 +98,10 @@ class ComputeInterface(View):
class VmInterface(DetailView): class VmInterface(DetailView):
model = Instance model = Instance
def get_object(self):
return get_object_or_404(Instance.objects.filter(destroyed_at=None),
pk=self.kwargs['pk'])
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
vm = self.get_object() vm = self.get_object()
c = Compute(instance=vm) c = Compute(instance=vm)
...@@ -113,6 +118,12 @@ class VmInterface(DetailView): ...@@ -113,6 +118,12 @@ class VmInterface(DetailView):
Compute(instance=vm).trigger_action(data) Compute(instance=vm).trigger_action(data)
return HttpResponse() return HttpResponse()
def delete(self, request, *args, **kwargs):
vm = self.get_object()
Compute(instance=vm).delete()
return HttpResponse()
@method_decorator(csrf_exempt) # decorator on post method doesn't work @method_decorator(csrf_exempt) # decorator on post method doesn't work
def dispatch(self, *args, **kwargs): def dispatch(self, *args, **kwargs):
return super(VmInterface, self).dispatch(*args, **kwargs) return super(VmInterface, self).dispatch(*args, **kwargs)
......
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