Commit 216378f7 by Kálmán Viktor

dashboard: working new sliders

parent 7211cc96
......@@ -449,3 +449,5 @@ else:
SESSION_COOKIE_NAME = "csessid%x" % (((getnode() // 139) ^
(getnode() % 983)) & 0xffff)
MAX_NODE_RAM = get_env_variable("MAX_NODE_RAM", 1024)
......@@ -51,7 +51,7 @@ from vm.models import (
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.contrib.auth.models import Permission
from .models import Profile, GroupProfile
from circle.settings.base import LANGUAGES
from circle.settings.base import LANGUAGES, MAX_NODE_RAM
from django.utils.translation import string_concat
......@@ -1279,3 +1279,34 @@ class GroupPermissionForm(forms.ModelForm):
helper.add_input(Submit("submit", _("Save"),
css_class="btn btn-success", ))
return helper
priority_choices = (
(10, _("idle")),
(30, _("normal")),
(80, _("server")),
(100, _("realtime")),
)
class VmResourcesForm(forms.ModelForm):
num_cores = forms.CharField(widget=forms.NumberInput(attrs={
'class': "form-control input-tags cpu-count-input",
'min': 1,
'max': 10,
'required': "",
}))
ram_size = forms.CharField(widget=forms.NumberInput(attrs={
'class': "form-control input-tags ram-input",
'min': 128,
'max': MAX_NODE_RAM,
'step': 128,
'required': "",
}))
priority = forms.ChoiceField(priority_choices, widget=forms.Select(attrs={
'class': "form-control input-tags cpu-priority-input",
}))
class Meta:
model = Instance
fields = ('num_cores', 'priority', 'ram_size', )
......@@ -431,25 +431,28 @@ function compareVmByFav(a, b) {
return a.pk < b.pk ? -1 : 1;
}
$(document).on('shown.bs.tab', 'a[href="#resources"]', function (e) {
$(".cpu-priority-input").trigger("change");
$(".cpu-count-input, .ram-input").trigger("input");
})
function addSliderMiscs() {
// set max values based on inputs
var cpu_count_range = "0, " + $(".cpu-count-input").prop("max");
var ram_range = "0, " + $(".ram-input").prop("max");
$(".cpu-count-slider").data("slider-range", cpu_count_range);
$(".ram-slider").data("slider-range", ram_range);
$(".vm-slider").simpleSlider();
$(".cpu-priority-slider").bind("slider:changed", function (event, data) {
value = data.value + 0;
switch(value) {
case 30: type = 1; break;
case 80: type = 2; break;
case 100: type = 3; break;
default: type = 0;
}
var value = data.value + 0;
$(".cpu-priority-input option:eq(" + type + ")").attr("selected", "selected");
$('.cpu-priority-input option[value="' + value + '"]').attr("selected", "selected");
});
var ram_fire = false;
$(".cpu-priority-input").change(function() {
var val = $(":selected", $(this)).val();
var slider_value = [10, 30, 80, 100][val]
$(".cpu-priority-slider").simpleSlider("setValue", slider_value);
$(".cpu-priority-slider").simpleSlider("setValue", val);
});
$(".cpu-count-slider").bind("slider:changed", function (event, data) {
......@@ -463,6 +466,7 @@ function addSliderMiscs() {
});
var ram_fire = false;
$(".ram-slider").bind("slider:changed", function (event, data) {
if(ram_fire) {
ram_fire = false;
......@@ -478,8 +482,6 @@ function addSliderMiscs() {
ram_fire = true;
$(".ram-slider").simpleSlider("setValue", parseInt(val));
});
$(".cpu-priority-input").trigger("change");
$(".cpu-count-input, .ram-input").trigger("input");
}
......
......@@ -3,9 +3,10 @@
{% load crispy_forms_tags %}
<hr />
<div class="vm-resources-sliders">
<form method="POST" action="{{ op.resources_change.get_url }}">
{% csrf_token %}
<div class="row">
<div class="col-sm-3" style="font-weight: bold;">
<i class="fa fa-trophy"></i> {% trans "CPU priority" %}
......@@ -17,19 +18,13 @@
</div>
<div class="col-sm-3">
<div class="input-group">
<select type="text" class="form-control input-tags cpu-priority-input">
<option value="0">idle</option>
<option value="1">normal</option>
<option value="2">server</option>
<option value="3">realtime</option>
</select>
{{ resources_form.priority }}
<span class="input-group-addon input-tags">
<i class="fa fa-question" title="yo"></i>
</span>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3" style="font-weight: bold;">
<i class="fa fa-cogs"></i> {% trans "CPU count" %}
......@@ -41,7 +36,7 @@
</div>
<div class="col-sm-3">
<div class="input-group">
<input type="number" min="1" max="10" value="1" class="form-control input-tags cpu-count-input"/>
{{ resources_form.num_cores }}
<span class="input-group-addon input-tags">
<i class="fa fa-question" title="yo"></i>
</span>
......@@ -60,7 +55,7 @@
</div>
<div class="col-sm-3">
<div class="input-group">
<input type="text" class="form-control input-tags ram-input" value="512"/>
{{ resources_form.ram_size }}
<span class="input-group-addon input-tags">
MiB
</span>
......@@ -70,6 +65,17 @@
</div>
</div>
</div>
{% if can_change_resources %}
<button type="submit" class="btn btn-success btn-sm change-resources-button" id="vm-details-resources-savea"
data-vm="{{ instance.pk }}"
{% if not op.resources_change %}disabled{% endif %}>
<i class="fa fa-floppy-o"></i> {% trans "Save resources" %}
</button>
<span class="change-resources-help"
{% if op.resources_change %}style="display: none;"{% endif %}
>{% trans "Stop your VM to change resources." %}</span>
{% endif %}
</form>
</div>
......
......@@ -61,7 +61,8 @@ from .forms import (
UserCreationForm, GroupProfileUpdateForm, UnsubscribeForm,
VmSaveForm, UserKeyForm, VmRenewForm,
CirclePasswordChangeForm, VmCreateDiskForm, VmDownloadDiskForm,
TraitsForm, RawDataForm, GroupPermissionForm, AclUserAddForm
TraitsForm, RawDataForm, GroupPermissionForm, AclUserAddForm,
VmResourcesForm,
)
from .tables import (
......@@ -291,6 +292,8 @@ class VmDetailView(CheckedDetailView):
context['ipv6_port'] = instance.get_connect_port(use_ipv6=True)
# resources forms
context['resources_form'] = VmResourcesForm(instance=instance)
if self.request.user.is_superuser:
context['traits_form'] = TraitsForm(instance=instance)
context['raw_data_form'] = RawDataForm(instance=instance)
......@@ -317,8 +320,6 @@ class VmDetailView(CheckedDetailView):
return v(request)
raise Http404()
raise Http404()
def __change_password(self, request):
self.object = self.get_object()
if not self.object.has_level(request.user, 'owner'):
......@@ -719,10 +720,10 @@ class VmResourcesChangeView(VmOperationView):
extra = {}
resources = {
'num_cores': "cpu-count",
'priority': "cpu-priority",
'ram_size': "ram-size",
"max_ram_size": "ram-size", # TODO
'num_cores': "num_cores",
'priority': "priority",
'ram_size': "ram_size",
"max_ram_size": "ram_size", # TODO
}
for k, v in resources.iteritems():
extra[k] = request.POST.get(v)
......
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