Commit 355ad49c by Karsa Zoltán István

fix bugs

parent 8a880eb5
......@@ -128,6 +128,9 @@ class DestroyDiskSerializer(serializers.Serializer):
class Meta:
extra_kwargs = {'instance': {'required': False, 'allow_null': True}}
class AddPortSerializer(serializers.Serializer):
port_type = serializers.CharField(max_length=5)
port_number = serializers.IntegerField()
class VMDeploySerializer(serializers.Serializer):
node = serializers.IntegerField(required=False)
......
......@@ -60,7 +60,7 @@ from .views import (
GetLeaseREST, GetDiskRest, DeployInstanceREST, CreateDiskREST,
VlanREST, ResizeDiskREST, GetVlanREST, DestroyDiskREST,
StorageDetail, DiskDetail, UserREST, GroupREST,
InstanceActivityREST, GetInstanceActivityREST,
InstanceActivityREST, GetInstanceActivityREST, GetGroupREST, GetUserREST,
SleepInstanceREST, WakeUpInstanceREST, DownloadPersistentDiskREST,
CreatePersistentDiskREST, GetStorageActivityREST,
MessageList, MessageDetail, MessageCreate, MessageDelete,
......@@ -78,7 +78,9 @@ urlpatterns = [
path('acpi/vmact/', InstanceActivityREST.as_view()),
path('acpi/vmact/<int:pk>/', GetInstanceActivityREST.as_view()),
path('acpi/user/', UserREST.as_view()),
path('acpi/user/<int:pk>/', GetUserREST.as_view()),
path('acpi/group/', GroupREST.as_view()),
path('acpi/group/<int:pk>/', GetGroupREST.as_view()),
path('acpi/vm/', InstanceREST.as_view()),
path('acpi/node/', NodeREST.as_view()),
path('acpi/node/<int:pk>/', GetNodeREST.as_view()),
......
......@@ -80,6 +80,16 @@ class GroupREST(APIView):
return JsonResponse(serializer.data, safe=False)
class GetGroupREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
def get(self, request, pk, format=None):
groups = Group.objects.get(pk=pk)
serializer = GroupSerializer(groups, many=False)
return JsonResponse(serializer.data, safe=False)
class GroupCodeMixin(object):
@classmethod
......
......@@ -91,6 +91,15 @@ class UserREST(APIView):
serializer = UserSerializer(users, many=True)
return JsonResponse(serializer.data, safe=False)
class GetUserREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
def get(self, request, pk, format=None):
users = User.objects.get(pk=pk)
serializer = UserSerializer(users, many=False)
return JsonResponse(serializer.data, safe=False)
def set_session_expiry(request, user):
if user.is_superuser:
messages.info(request, _("You've logged in with an administrator "
......
......@@ -49,7 +49,7 @@ from braces.views import SuperuserRequiredMixin, LoginRequiredMixin
from storage.tasks import storage_tasks
from vm.tasks.local_tasks import abortable_async_downloaddisk_operation
from vm.operations import (DeployOperation, DestroyOperation, DownloadDiskOperation, ShutdownOperation, RenewOperation,
ResizeDiskOperation, RemoveDiskOperation, SleepOperation, WakeUpOperation
ResizeDiskOperation, RemoveDiskOperation, SleepOperation, WakeUpOperation, AddPortOperation,
)
from common.models import (
......@@ -105,6 +105,7 @@ from rest_framework.permissions import IsAdminUser
from dashboard.serializers import (
DiskSerializer, InstanceSerializer, InterfaceSerializer, CreateDiskSerializer, DownloadDiskSerializer,
VMDeploySerializer, VlanSerializer, ResizeDiskSerializer, InstanceActivitySerializer, DestroyDiskSerializer, StorageActivitySerializer,
AddPortSerializer,
)
def size_util(size: str):
......@@ -216,6 +217,9 @@ class InstanceREST(APIView):
def post(self, request, format=None):
data = JSONParser().parse(request)
data['pw'] = pwgen()
req_deploy = False
if 'status' in data:
req_deploy = data['status'] == "RUNNING"
data['status'] = 'STOPPED'
if 'owner' not in data:
data['owner'] = request.user.id
......@@ -242,12 +246,17 @@ class InstanceREST(APIView):
Interface.create(instance=inst, vlan=net.vlan,
owner=inst.owner, managed=net.managed,
base_activity=act)
if 'create_disk' in data:
inst.create_disk(size=data['create_disk']['size'], user=inst.owner,
name=data['create_disk']['name'], activity=None)
if 'download_disk' in data:
inst.download_disk(user=inst.owner, name=data['download_disk']['name'])
if 'disks' in data:
import string
devnums = list(string.ascii_lowercase)
for l in data['disks']:
disk = Disk.objects.get(pk=int(l))
disk.dev_num = devnums.pop(0)
disk.save()
if req_deploy:
DeployOperation(inst).call(node=None, user=inst.owner)
return JsonResponse(serializer.data, status=201)
return JsonResponse(serializer.errors, status=400)
......@@ -298,7 +307,21 @@ class DeployInstanceREST(APIView):
DeployOperation(instance).call(node=None, user=instance.owner)
serializer = InstanceSerializer(instance, many=False)
return JsonResponse(serializer.data, safe=False)
return JsonResponse(deploy.errors, status=201)
return JsonResponse(deploy.errors, status=400)
class AddPortREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
def post(self, request, pk, format=None):
instance = Instance.objects.get(pk=pk)
data = JSONParser().parse(request)
addport = AddPortSerializer(data=data)
if addport.is_valid():
AddPortOperation(instance).call(port=int(data['port_number']), proto=str(data['port_type']))
return JsonResponse({}, status=201)
return JsonResponse(addport.errors, status=400)
class SleepInstanceREST(APIView):
......
......@@ -71,6 +71,6 @@ def abortable_async_downloaddisk_operation(task, activity_pk, url, name):
activity.disk = disk
activity.succeeded = True
activity.finished = timezone.now()
#activity.finished = timezone.now()
activity.save()
return
\ No newline at end of file
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