Commit 66b3e551 by Karsa Zoltán István

update models and views for stats

parent 6277a2eb
...@@ -94,6 +94,28 @@ class VmSaveForm(OperationForm): ...@@ -94,6 +94,28 @@ class VmSaveForm(OperationForm):
help_text=_('Backing file location')) help_text=_('Backing file location'))
overlay_path = forms.ModelChoiceField(queryset=None, initial=0, empty_label=None, overlay_path = forms.ModelChoiceField(queryset=None, initial=0, empty_label=None,
help_text=_('Overlay image dir')) help_text=_('Overlay image dir'))
cache_size = forms.CharField(
widget=FileSizeWidget, initial=(1 << 20), label=_('Metadata cache size'),
help_text=_('Backing file metadata cache size, '
'like KB, MB'))
cluster_size = forms.CharField(
widget=FileSizeWidget, initial=(1 << 16), label=_('Cluster size'),
help_text=_('Backing file disk cluster (block) size, '
'like KB'))
def clean_cache_size(self):
size_in_kbytes = self.cleaned_data.get("cache_size")
if not size_in_kbytes.isdigit() and len(size_in_kbytes) > 0:
raise forms.ValidationError(_("Invalid format, you can use "
" KB or MB!"))
return int(size_in_kbytes) / 1024
def clean_cluster_size(self):
size_in_kbytes = self.cleaned_data.get("cluster_size")
if not size_in_kbytes.isdigit() and len(size_in_kbytes) > 0:
raise forms.ValidationError(_("Invalid format, you can use "
" KB or MB!"))
return int(size_in_kbytes) / 1024
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
default = kwargs.pop('default', None) default = kwargs.pop('default', None)
......
...@@ -45,7 +45,7 @@ class NodeSerializer(serializers.ModelSerializer): ...@@ -45,7 +45,7 @@ class NodeSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Node model = Node
fields = [ 'id', 'name', 'priority', 'host', 'enabled', 'schedule_enabled', fields = [ 'id', 'name', 'priority', 'host', 'enabled', 'schedule_enabled',
'traits', 'overcommit', 'ram_weight', 'cpu_weight', 'time_stamp' ] 'traits', 'overcommit', 'ram_weight', 'cpu_weight', 'time_stamp', 'allocated_ram', 'ram_size', 'num_cores']
class InstanceTemplateSerializer(serializers.ModelSerializer): class InstanceTemplateSerializer(serializers.ModelSerializer):
......
...@@ -70,7 +70,7 @@ from .views import ( ...@@ -70,7 +70,7 @@ from .views import (
RescheduleView, GroupImportView, GroupExportView, RescheduleView, GroupImportView, GroupExportView,
VariableREST, GetVariableREST, HotplugMemSetREST, HotplugVCPUSetREST VariableREST, GetVariableREST, HotplugMemSetREST, HotplugVCPUSetREST
) )
from .views.node import node_ops, NodeREST, GetNodeREST 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
urlpatterns = [ urlpatterns = [
...@@ -88,6 +88,7 @@ urlpatterns = [ ...@@ -88,6 +88,7 @@ urlpatterns = [
path('acpi/var/<int:pk>/', GetVariableREST.as_view(), name='variable-detail'), path('acpi/var/<int:pk>/', GetVariableREST.as_view(), name='variable-detail'),
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/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()),
......
...@@ -30,6 +30,7 @@ from django.shortcuts import redirect ...@@ -30,6 +30,7 @@ from django.shortcuts import redirect
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.views.generic import DetailView, TemplateView, View from django.views.generic import DetailView, TemplateView, View
from rest_framework.response import Response
from rest_framework import status from rest_framework import status
from rest_framework.views import APIView from rest_framework.views import APIView
...@@ -81,6 +82,21 @@ class GetNodeREST(APIView): ...@@ -81,6 +82,21 @@ class GetNodeREST(APIView):
return JsonResponse(serializer.data, safe=False) return JsonResponse(serializer.data, safe=False)
class GetNodeRESTSum(APIView):
permission_classes = []
def get(self, request, format=None):
nodes = Node.objects.filter(enabled=True, schedule_enabled=True)
cpu_core = 0
max_memory = 0
for i in nodes:
cpu_core = cpu_core + i.info['core_num']()
max_memory = max_memory + i.info['ram_size']
return Response(
{"core_num": cpu_core, "max_ram": max_memory}
)
def get_operations(instance, user): def get_operations(instance, user):
ops = [] ops = []
for k, v in list(node_ops.items()): for k, v in list(node_ops.items()):
......
...@@ -339,8 +339,8 @@ class Disk(TimeStampedModel): ...@@ -339,8 +339,8 @@ class Disk(TimeStampedModel):
new_type = type_mapping[self.type] new_type = type_mapping[self.type]
return Disk.create(base=self, datastore=self.datastore if datastore is None else datastore, return Disk.create(base=self, datastore=self.datastore if datastore is None else datastore,
name=self.name, size=self.size, name=self.name, size=self.size, cache_size = self.cache_size,
type=new_type, dev_num=self.dev_num) type=new_type, dev_num=self.dev_num, cluster_size = self.cluster_size)
def get_vmdisk_desc(self): def get_vmdisk_desc(self):
"""Serialize disk object to the vmdriver. """Serialize disk object to the vmdriver.
...@@ -367,7 +367,7 @@ class Disk(TimeStampedModel): ...@@ -367,7 +367,7 @@ class Disk(TimeStampedModel):
'base_name': self.base.filename if self.base else None, 'base_name': self.base.filename if self.base else None,
'type': 'snapshot' if self.base else 'normal', 'type': 'snapshot' if self.base else 'normal',
'base_dir': self.base.datastore.path if self.base else None, 'base_dir': self.base.datastore.path if self.base else None,
'cluster_size': self.cluster_size 'cluster_size': self.cluster_size,
} }
def get_remote_queue_name(self, queue_id='storage', priority=None, def get_remote_queue_name(self, queue_id='storage', priority=None,
...@@ -568,7 +568,7 @@ class Disk(TimeStampedModel): ...@@ -568,7 +568,7 @@ class Disk(TimeStampedModel):
args=[self.datastore.path, self.filename], args=[self.datastore.path, self.filename],
queue=queue_name).get(timeout=timeout) queue=queue_name).get(timeout=timeout)
def save_as(self, task=None, user=None, task_uuid=None, datastore=None, timeout=300): def save_as(self, task=None, user=None, task_uuid=None, datastore=None, timeout=300, cache_size = 1024, cluster_size=64):
"""Save VM as template. """Save VM as template.
Based on disk type: Based on disk type:
...@@ -602,7 +602,7 @@ class Disk(TimeStampedModel): ...@@ -602,7 +602,7 @@ class Disk(TimeStampedModel):
disk = Disk.create(datastore=datastore, disk = Disk.create(datastore=datastore,
base=new_base, base=new_base,
name=self.name, size=self.size, name=self.name, size=self.size,
type=new_type, dev_num=self.dev_num) type=new_type, dev_num=self.dev_num, cluster_size=cluster_size, cache_size=cache_size)
queue_name = self.get_remote_queue_name("storage", priority="slow") queue_name = self.get_remote_queue_name("storage", priority="slow")
remote = storage_tasks.merge.apply_async(kwargs={ remote = storage_tasks.merge.apply_async(kwargs={
......
...@@ -895,12 +895,14 @@ class SaveAsTemplateOperation(InstanceOperation): ...@@ -895,12 +895,14 @@ class SaveAsTemplateOperation(InstanceOperation):
params.update(kwargs) params.update(kwargs)
params.pop("parent_activity", None) params.pop("parent_activity", None)
cache_size = params.pop('cache_size', 1024)
cluster_size = params.pop('cluster_size', 64)
from storage.models import Disk from storage.models import Disk
def __try_save_disk(disk, datastore): def __try_save_disk(disk, datastore):
try: try:
return disk.save_as(task, datastore=datastore) return disk.save_as(task, datastore=datastore, cache_size=cache_size, cluster_size=cluster_size)
except Disk.WrongDiskTypeError: except Disk.WrongDiskTypeError:
return disk return disk
......
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