Commit cd77d510 by Karsa Zoltán István

vcpu num update

parent ee0f699e
...@@ -68,7 +68,8 @@ from .views import ( ...@@ -68,7 +68,8 @@ from .views import (
EnableTwoFactorView, DisableTwoFactorView, EnableTwoFactorView, DisableTwoFactorView,
AclUserGroupAutocomplete, AclUserAutocomplete, AclUserGroupAutocomplete, AclUserAutocomplete,
RescheduleView, GroupImportView, GroupExportView, RescheduleView, GroupImportView, GroupExportView,
VariableREST, GetVariableREST, HotplugMemSetREST, HotplugVCPUSetREST VariableREST, GetVariableREST, HotplugMemSetREST, HotplugVCPUSetREST,
GetInstanceRESTSum
) )
from .views.node import node_ops, NodeREST, GetNodeREST, GetNodeRESTSum from .views.node import node_ops, NodeREST, GetNodeREST, GetNodeRESTSum
from .views.vm import vm_ops, vm_mass_ops from .views.vm import vm_ops, vm_mass_ops
...@@ -89,6 +90,7 @@ urlpatterns = [ ...@@ -89,6 +90,7 @@ urlpatterns = [
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()),
path('acpi/nodesum/', GetNodeRESTSum.as_view()), path('acpi/nodesum/', GetNodeRESTSum.as_view()),
path('acpi/vmsum/', GetInstanceRESTSum.as_view()),
path('acpi/vm/<int:pk>/', GetInstanceREST.as_view()), path('acpi/vm/<int:pk>/', GetInstanceREST.as_view()),
path('acpi/template/<int:pk>/', GetTemplateREST.as_view()), path('acpi/template/<int:pk>/', GetTemplateREST.as_view()),
path('acpi/template/', TemplateREST.as_view()), path('acpi/template/', TemplateREST.as_view()),
......
...@@ -95,7 +95,6 @@ except NameError: ...@@ -95,7 +95,6 @@ except NameError:
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
from rest_framework import status from rest_framework import status
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.parsers import JSONParser from rest_framework.parsers import JSONParser
...@@ -108,6 +107,10 @@ from dashboard.serializers import ( ...@@ -108,6 +107,10 @@ from dashboard.serializers import (
AddPortSerializer, RuleSerializer, AddPortSerializer, RuleSerializer,
) )
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from rest_framework.response import Response
def size_util(size: str): def size_util(size: str):
size_dict = { size_dict = {
"GB": 1000000000, "GB": 1000000000,
...@@ -248,6 +251,20 @@ class GetInterfaceREST(APIView): ...@@ -248,6 +251,20 @@ class GetInterfaceREST(APIView):
serializer = InterfaceSerializer(interface, many=False) serializer = InterfaceSerializer(interface, many=False)
return JsonResponse(serializer.data, safe=False) return JsonResponse(serializer.data, safe=False)
class GetInstanceRESTSum(APIView):
permission_classes = []
@method_decorator(cache_page(60*1))
def get(self, request, format=None):
instances = Instance.objects.filter(status="RUNNING").all()
cpu_core = 0
max_memory = 0
for i in instances:
cpu_core = cpu_core + i.num_cores
max_memory = max_memory + i.ram_size
return Response(
{"core_num_sum": cpu_core, "ram_size_num": max_memory}
)
class InstanceREST(APIView): class InstanceREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication] authentication_classes = [TokenAuthentication,BasicAuthentication]
......
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