Commit 00680aec by Karsa Zoltán István

rest api hotplug

parent 1c898e2e
......@@ -68,7 +68,7 @@ from .views import (
EnableTwoFactorView, DisableTwoFactorView,
AclUserGroupAutocomplete, AclUserAutocomplete,
RescheduleView, GroupImportView, GroupExportView,
VariableREST, GetVariableREST,
VariableREST, GetVariableREST, HotplugMemSetREST, HotplugVCPUSetREST
)
from .views.node import node_ops, NodeREST, GetNodeREST
from .views.vm import vm_ops, vm_mass_ops
......@@ -102,6 +102,8 @@ urlpatterns = [
path('acpi/interface/<int:pk>/', GetInterfaceREST.as_view()),
path('acpi/ftusers/', InstanceFTforUsersREST.as_view()),
path('acpi/ftusersid/', InstanceFTforUsersIdREST.as_view()),
path('acpi/vm/<int:pk>/hotplugmem/', HotplugVCPUSetREST.as_view()),
path('acpi/vm/<int:pk>/hotplugvcpu/', HotplugMemSetREST.as_view()),
path('acpi/vm/<int:pk>/downloaddisk/', DownloadDiskREST.as_view()),
path('acpi/vm/<int:vm_id>/port/<int:vlan_id>/', SetupPortREST.as_view()),
path('acpi/vm/<int:vm_id>/rules/<int:vlan_id>/', RulesREST.as_view()),
......
......@@ -188,6 +188,34 @@ class GetVlanREST(APIView):
return JsonResponse(serializer.data, safe=False)
class HotplugMemSetREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
def put(self, request, pk, format=None):
instance = Instance.objects.get(pk=pk)
data = JSONParser().parse(request)
ram_size = int(data["ram_size"])
instance.hotplug_mem(user=request.user, memory=ram_size)
instance.ram_size = ram_size
instance.save()
serializer = InstanceSerializer(instance)
return JsonResponse(serializer.data, status=201)
class HotplugVCPUSetREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
def put(self, request, pk, format=None):
instance = Instance.objects.get(pk=pk)
data = JSONParser().parse(request)
num_cores = int(data["num_cores"])
instance.hotplug_mem(user=request.user, vcpu=num_cores)
instance.num_cores = num_cores
instance.save()
serializer = InstanceSerializer(instance)
return JsonResponse(serializer.data, status=201)
class InterfaceREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser]
......
......@@ -1457,6 +1457,27 @@ class ScreenshotOperation(RemoteInstanceOperation):
@register_operation
class HotPlugMem(RemoteInstanceOperation):
id = 'hotplug_mem'
name = _("hotplug_mem")
description = _("")
acl_level = "owner"
required_perms = ()
accept_states = ('RUNNING',)
task = vm_tasks.hotplug_memset
@register_operation
class HotPlugVCPU(RemoteInstanceOperation):
id = 'hotplug_vcpu'
name = _("hotplug_vcpu")
description = _("")
acl_level = "owner"
required_perms = ()
accept_states = ('RUNNING',)
task = vm_tasks.hotplug_vcpuset
@register_operation
class RecoverOperation(InstanceOperation):
id = 'recover'
name = _("recover")
......
......@@ -186,3 +186,11 @@ def get_node_metrics(params):
@celery.task(name='vmdriver.screenshot')
def screenshot(params):
pass
@celery.task(name='vmdriver.hotplug_memset')
def hotplug_memset(name, memory):
pass
@celery.task(name='vmdriver.hotplug_vcpuset')
def hotplug_vcpuset(name, vcpu):
pass
\ No newline at end of file
import sys
import libvirt
domName = 'cloud-9'
conn = None
try:
conn = libvirt.open("qemu:///system")
except libvirt.libvirtError as e:
print(repr(e), file=sys.stderr)
exit(1)
dom = conn.lookupByID(7)
if dom == None:
print('Failed to find the domain '+domName, file=sys.stderr)
exit(1)
dom.setVcpus(4)
conn.close()
exit(0)
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