Commit bf49a963 by Karsa Zoltán István

add disk to rest api

parent 5485381c
......@@ -2,20 +2,25 @@ from rest_framework.renderers import JSONRenderer
from rest_framework import serializers
from vm.models import InstanceTemplate, Lease
from storage.models import Disk
class InstanceTemplateSerializer(serializers.ModelSerializer):
class Meta:
model = InstanceTemplate
resource_name = 'template'
fields = [ 'id', 'name', 'description', 'parent', 'owner', 'access_method', 'boot_menu',
'lease', 'raw_data', 'cloud_init', 'ci_meta_data', 'ci_user_data', 'system',
'has_agent', 'num_cores', 'ram_size', 'max_ram_size', 'arch', 'priority']
'has_agent', 'num_cores', 'ram_size', 'max_ram_size', 'arch', 'priority', 'disks']
class LeaseSerializer(serializers.ModelSerializer):
class Meta:
model = Lease
resource_name = 'lease'
fields = [ 'id', 'name', 'suspend_interval_seconds', 'delete_interval_seconds']
class DiskSerializer(serializers.ModelSerializer):
class Meta:
model = Disk
fields = ['id', 'name', 'filename', 'datastore', 'type', 'bus', 'size', 'base',
'dev_num', 'destroyed', 'ci_disk', 'is_ready']
\ No newline at end of file
......@@ -53,8 +53,8 @@ from .views import (
TransferInstanceOwnershipView, TransferInstanceOwnershipConfirmView,
TransferTemplateOwnershipView, TransferTemplateOwnershipConfirmView,
OpenSearchDescriptionView,
NodeActivityView,
UserList, TemplateREST, LeaseREST,
NodeActivityView,
UserList, TemplateREST, LeaseREST, DiskRest,
StorageDetail, DiskDetail,
MessageList, MessageDetail, MessageCreate, MessageDelete,
EnableTwoFactorView, DisableTwoFactorView,
......@@ -68,6 +68,7 @@ urlpatterns = [
path('acpi/vm/', iac_vm_list),
path('acpi/template/', TemplateREST.as_view()),
path('acpi/lease/', LeaseREST.as_view()),
path('acpi/disk/', DiskRest.as_view()),
url(r'^$', IndexView.as_view(), name="dashboard.index"),
url(r"^profile/list/$", UserList.as_view(),
name="dashboard.views.user-list"),
......
......@@ -21,14 +21,21 @@ from django.urls import reverse
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
from django.views.generic import UpdateView
from django.http import JsonResponse
from braces.views import SuperuserRequiredMixin
from sizefield.utils import filesizeformat
from rest_framework.authentication import TokenAuthentication, BasicAuthentication
from rest_framework.permissions import IsAdminUser
from rest_framework.views import APIView
from rest_framework.parsers import JSONParser
from common.models import WorkerNotFound
from storage.models import DataStore, Disk
from ..tables import DiskListTable
from ..forms import DataStoreForm, DiskForm
from dashboard.serializers import DiskSerializer
class StorageDetail(SuperuserRequiredMixin, UpdateView):
......@@ -138,3 +145,21 @@ class DiskDetail(SuperuserRequiredMixin, UpdateView):
def form_valid(self, form):
pass
class DiskRest(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
def get(self, request, format=None):
templates = Disk.objects.all()
serializer = DiskSerializer(templates, many=True)
return JsonResponse({ 'disks': serializer.data}, safe=False)
def post(self, request, format=None):
data = JSONParser().parse(request)
serializer = DiskSerializer(data=data)
if serializer.is_valid():
serializer.save()
return JsonResponse(serializer.data, status=201)
return JsonResponse(serializer.errors, status=400)
\ No newline at end of file
......@@ -61,7 +61,6 @@ from dashboard.serializers import InstanceTemplateSerializer, LeaseSerializer
from rest_framework.authentication import TokenAuthentication, BasicAuthentication
from rest_framework.permissions import IsAdminUser
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.parsers import JSONParser
try:
......
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