Commit 355ad49c by Karsa Zoltán István

fix bugs

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