Commit 28bda55b by Karsa Zoltán István

create disk for vm

parent aba1160b
...@@ -55,3 +55,8 @@ class VlanSerializer(serializers.ModelSerializer): ...@@ -55,3 +55,8 @@ class VlanSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Vlan model = Vlan
fields = ['id', 'vid', 'name', 'description', 'comment', 'domain'] fields = ['id', 'vid', 'name', 'description', 'comment', 'domain']
class CreateDiskSerializer(serializers.Serializer):
size = serializers.IntegerField()
name = serializers.CharField(max_length=100)
\ No newline at end of file
...@@ -56,6 +56,7 @@ from .views import ( ...@@ -56,6 +56,7 @@ from .views import (
NodeActivityView, NodeActivityView,
UserList, TemplateREST, LeaseREST, DiskRest, InstanceREST, UserList, TemplateREST, LeaseREST, DiskRest, InstanceREST,
InterfaceREST, InstanceFromTemplateREST, InstanceFTforUsersREST, InterfaceREST, InstanceFromTemplateREST, InstanceFTforUsersREST,
DownloadDiskREST,
StorageDetail, DiskDetail, StorageDetail, DiskDetail,
MessageList, MessageDetail, MessageCreate, MessageDelete, MessageList, MessageDetail, MessageCreate, MessageDelete,
EnableTwoFactorView, DisableTwoFactorView, EnableTwoFactorView, DisableTwoFactorView,
...@@ -73,6 +74,7 @@ urlpatterns = [ ...@@ -73,6 +74,7 @@ urlpatterns = [
path('acpi/disk/', DiskRest.as_view()), path('acpi/disk/', DiskRest.as_view()),
path('acpi/interface/', InterfaceREST.as_view()), path('acpi/interface/', InterfaceREST.as_view()),
path('acpi/ftusers/', InstanceFTforUsersREST.as_view()), path('acpi/ftusers/', InstanceFTforUsersREST.as_view()),
path('acpi/vm/<int:pk>/createdisk/', DownloadDiskREST.as_view()),
url(r'^$', IndexView.as_view(), name="dashboard.index"), url(r'^$', IndexView.as_view(), name="dashboard.index"),
url(r"^profile/list/$", UserList.as_view(), url(r"^profile/list/$", UserList.as_view(),
name="dashboard.views.user-list"), name="dashboard.views.user-list"),
......
...@@ -94,7 +94,7 @@ from rest_framework.parsers import JSONParser ...@@ -94,7 +94,7 @@ from rest_framework.parsers import JSONParser
from rest_framework.authentication import TokenAuthentication, BasicAuthentication from rest_framework.authentication import TokenAuthentication, BasicAuthentication
from rest_framework.permissions import IsAdminUser from rest_framework.permissions import IsAdminUser
from dashboard.serializers import InstanceSerializer, InterfaceSerializer from dashboard.serializers import InstanceSerializer, InterfaceSerializer, CreateDiskSerializer
class InterfaceREST(APIView): class InterfaceREST(APIView):
...@@ -145,12 +145,42 @@ class InstanceREST(APIView): ...@@ -145,12 +145,42 @@ class InstanceREST(APIView):
base_activity=act) base_activity=act)
if 'create_disk' in data: if 'create_disk' in data:
inst.create_disk(size=data['createdisk']['size'], user=inst.owner, inst.create_disk(size=data['create_disk']['size'], user=inst.owner,
name=data['createdisk']['name'], activity=None) name=data['create_disk']['name'], activity=None)
if 'download_disk' in data:
inst.download_disk(user=inst.owner, name=data['download_disk']['name'])
return JsonResponse(serializer.data, status=201) return JsonResponse(serializer.data, status=201)
return JsonResponse(serializer.errors, status=400) return JsonResponse(serializer.errors, status=400)
class DownloadDiskREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
def post(self, request, pk, format=None):
data = JSONParser().parse(request)
serializer = CreateDiskSerializer(data=data)
if serializer.is_valid():
vm_id = pk
disk_size = int(data['size'])
disk_name = str(data['name'])
instance = Instance.objects.get(pk=vm_id)
instance.create_disk(size=disk_size, user=instance.owner,
name=disk_name, activity=None)
ret = InstanceSerializer(instance, many=False)
return JsonResponse(ret.data, status=201)
return JsonResponse(serializer.errors, status=400)
class StateOperationREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
def post(self, request, pk, format=None):
pass
return JsonResponse(status=400)
class VmDetailVncTokenView(CheckedDetailView): class VmDetailVncTokenView(CheckedDetailView):
template_name = "dashboard/vm-detail.html" template_name = "dashboard/vm-detail.html"
model = Instance model = Instance
......
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