Commit 39db4eb2 by Karsa Zoltán István

template deploy

parent 355ad49c
......@@ -31,7 +31,7 @@ class GroupSerializer(serializers.ModelSerializer):
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'username', 'email', 'is_staff', 'groups')
fields = ('id', 'username', 'email', 'is_staff', 'groups', 'is_superuser', 'first_name', 'last_name')
class NodeSerializer(serializers.ModelSerializer):
......@@ -121,6 +121,9 @@ class DownloadDiskSerializer(serializers.Serializer):
url = serializers.CharField(max_length=500)
name = serializers.CharField(max_length=100)
class CreateTemplateSerializer(serializers.Serializer):
name = serializers.CharField(max_length=100)
class DestroyDiskSerializer(serializers.Serializer):
disk = serializers.IntegerField()
instance = serializers.IntegerField(required=False)
......
......@@ -59,10 +59,10 @@ from .views import (
DownloadDiskREST, GetInstanceREST, GetInterfaceREST, ShutdownInstanceREST,
GetLeaseREST, GetDiskRest, DeployInstanceREST, CreateDiskREST,
VlanREST, ResizeDiskREST, GetVlanREST, DestroyDiskREST,
StorageDetail, DiskDetail, UserREST, GroupREST,
StorageDetail, DiskDetail, UserREST, GroupREST, CreateTemplateREST,
InstanceActivityREST, GetInstanceActivityREST, GetGroupREST, GetUserREST,
SleepInstanceREST, WakeUpInstanceREST, DownloadPersistentDiskREST,
CreatePersistentDiskREST, GetStorageActivityREST,
CreatePersistentDiskREST, GetStorageActivityREST, GetTemplateREST,
MessageList, MessageDetail, MessageCreate, MessageDelete,
EnableTwoFactorView, DisableTwoFactorView,
AclUserGroupAutocomplete, AclUserAutocomplete,
......@@ -85,6 +85,7 @@ urlpatterns = [
path('acpi/node/', NodeREST.as_view()),
path('acpi/node/<int:pk>/', GetNodeREST.as_view()),
path('acpi/vm/<int:pk>/', GetInstanceREST.as_view()),
path('acpi/template/<int:pk>/', GetTemplateREST.as_view()),
path('acpi/template/', TemplateREST.as_view()),
path('acpi/ft/', InstanceFromTemplateREST.as_view()),
path('acpi/lease/', LeaseREST.as_view()),
......@@ -104,6 +105,7 @@ urlpatterns = [
path('acpi/vm/<int:pk>/wakeup/', WakeUpInstanceREST.as_view()),
path('acpi/vm/<int:pk>/resizedisk/', ResizeDiskREST.as_view()),
path('acpi/vm/<int:pk>/destroydisk/', DestroyDiskREST.as_view()),
path('acpi/vm/<int:pk>/saveastemplate/', CreateTemplateREST.as_view()),
url(r'^$', IndexView.as_view(), name="dashboard.index"),
url(r"^profile/list/$", UserList.as_view(),
name="dashboard.views.user-list"),
......
......@@ -211,6 +211,18 @@ class TemplateREST(APIView):
return JsonResponse(serializer.data, status=201)
return JsonResponse(serializer.errors, status=400)
class GetTemplateREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
def get(self, request, pk, format=None):
templates = InstanceTemplate.objects.get(pk=pk)
serializer = InstanceTemplateSerializer(templates, many=False)
return JsonResponse(serializer.data, safe=False)
def delete(self, request, pk, format=None):
return JsonResponse(status=400)
class InstanceFromTemplateREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
......
......@@ -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, AddPortOperation,
ResizeDiskOperation, RemoveDiskOperation, SleepOperation, WakeUpOperation, AddPortOperation, SaveAsTemplateOperation,
)
from common.models import (
......@@ -103,7 +103,7 @@ from rest_framework.authentication import TokenAuthentication, BasicAuthenticati
from rest_framework.permissions import IsAdminUser
from dashboard.serializers import (
DiskSerializer, InstanceSerializer, InterfaceSerializer, CreateDiskSerializer, DownloadDiskSerializer,
CreateTemplateSerializer, DiskSerializer, InstanceSerializer, InterfaceSerializer, CreateDiskSerializer, DownloadDiskSerializer,
VMDeploySerializer, VlanSerializer, ResizeDiskSerializer, InstanceActivitySerializer, DestroyDiskSerializer, StorageActivitySerializer,
AddPortSerializer,
)
......@@ -219,6 +219,7 @@ class InstanceREST(APIView):
data['pw'] = pwgen()
req_deploy = False
if 'status' in data:
logger.debug(' vm-status: ' + data['status'])
req_deploy = data['status'] == "RUNNING"
data['status'] = 'STOPPED'
if 'owner' not in data:
......@@ -257,6 +258,7 @@ class InstanceREST(APIView):
if req_deploy:
DeployOperation(inst).call(node=None, user=inst.owner)
return JsonResponse(serializer.data, status=201)
return JsonResponse(serializer.errors, status=400)
......@@ -375,6 +377,23 @@ class DownloadDiskREST(APIView):
return JsonResponse(serializer.data, status=201)
return JsonResponse(serializer.errors, status=400)
class CreateTemplateREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
def post(self, request, pk, format=None):
data = JSONParser().parse(request)
serializer = CreateTemplateSerializer(data=data)
if serializer.is_valid():
vm_id = pk
template_name = str(data['name'])
instance = Instance.objects.get(pk=vm_id)
SaveAsTemplateOperation(instance)._async(name=template_name, user=instance.owner)
act = instance.get_latest_activity_in_progress()
serializer = InstanceActivitySerializer(act, many=False)
return JsonResponse(serializer.data, status=201)
return JsonResponse(serializer.errors, status=400)
class CreateDiskREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
......
......@@ -36,7 +36,7 @@ from django.urls import reverse
from django.db.models import Q
from django.utils import timezone
from django.utils.translation import ugettext as _, ugettext_noop
from re import search
from re import search, template
from sizefield.utils import filesizeformat
from common.models import (
......@@ -929,8 +929,8 @@ class SaveAsTemplateOperation(InstanceOperation):
raise
else:
return create_readable(
ugettext_noop("New template: %(template)s"),
template=reverse('dashboard.views.template-detail',
ugettext_noop("New template: %(template)s (%(template_id)s)"),
template_id=tmpl.id, template=reverse('dashboard.views.template-detail',
kwargs={'pk': tmpl.pk}))
......
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