Commit 909f6f1c by Kálmán Viktor

dashboard: set resources in vm detail

parent 91763ce1
$(function() { $(function() {
if($('.timeline .activity:first i:first').hasClass('icon-spin')) if($('.timeline .activity:first i:first').hasClass('icon-spin'))
checkNewActivity(); checkNewActivity();
/* save resources */
$('#vm-details-resources-save').click(function() {
$('i.icon-save', this).removeClass("icon-save").addClass("icon-refresh icon-spin");
$.ajax({
type: 'POST',
url: location.href,
data: $('#vm-details-resources-form').serialize(),
success: function(data, textStatus, xhr) {
addMessage(data['message'], 'success');
$("#vm-details-resources-save i").removeClass('icon-refresh icon-spin').addClass("icon-save");
},
error: function(xhr, textStatus, error) {
$("#vm-details-resources-save i").removeClass('icon-refresh icon-spin').addClass("icon-save");
addMessage("Eww, something is wrong", 'danger');
if (xhr.status == 500) {
// alert("uhuhuhuhuhuh");
} else {
// alert("unknown error");
}
}
});
return false;
});
}); });
function checkNewActivity() { function checkNewActivity() {
......
{% load i18n %}
<form id="vm-details-resources-form" method="POST" action="">
{% csrf_token %}
<p class="row"> <p class="row">
<div class="col-sm-3"> <div class="col-sm-3">
<label for="vm-cpu-priority-slider"><i class="icon-trophy"></i> CPU priority</label> <label for="vm-cpu-priority-slider"><i class="icon-trophy"></i> {% trans "CPU priority" %}</label>
</div> </div>
<div class="col-sm-9"> <div class="col-sm-9">
<input name="cpu-priority" type="text" id="vm-cpu-priority-slider" class="vm-slider" value="{{ instance.priority }}" data-slider-min="0" data-slider-max="100" data-slider-step="1" data-slider-value="{{ instance.priority }}" data-slider-orientation="horizontal" data-slider-handle="square" data-slider-tooltip="hide"/> <input name="cpu-priority" type="text" id="vm-cpu-priority-slider" class="vm-slider" value="{{ instance.priority }}" data-slider-min="0" data-slider-max="100" data-slider-step="1" data-slider-value="{{ instance.priority }}" data-slider-orientation="horizontal" data-slider-handle="square" data-slider-tooltip="hide"/>
...@@ -10,7 +13,7 @@ ...@@ -10,7 +13,7 @@
<p class="row"> <p class="row">
<div class="col-sm-3"> <div class="col-sm-3">
<label for="cpu-count-slider"><i class="icon-cogs"></i> CPU count</label> <label for="cpu-count-slider"><i class="icon-cogs"></i> {% trans "CPU count" %}</label>
</div> </div>
<div class="col-sm-9"> <div class="col-sm-9">
<input name="cpu-count" type="text" id="vm-cpu-count-slider" class="vm-slider" value=" {{ instance.num_cores }}" data-slider-min="0" data-slider-max="8" data-slider-step="1" data-slider-value="{{ instance.num_cores }}" data-slider-orientation="horizontal" data-slider-handle="square" data-slider-tooltip="hide"/> <input name="cpu-count" type="text" id="vm-cpu-count-slider" class="vm-slider" value=" {{ instance.num_cores }}" data-slider-min="0" data-slider-max="8" data-slider-step="1" data-slider-value="{{ instance.num_cores }}" data-slider-orientation="horizontal" data-slider-handle="square" data-slider-tooltip="hide"/>
...@@ -20,13 +23,19 @@ ...@@ -20,13 +23,19 @@
<p class="row"> <p class="row">
<div class="col-sm-3"> <div class="col-sm-3">
<label for="ram-slider"><i class="icon-ticket"></i> RAM amount</label> <label for="ram-slider"><i class="icon-ticket"></i> {% trans "RAM amount" %}</label>
</div> </div>
<div class="col-sm-9"> <div class="col-sm-9">
<input name="ram-size" type="text" id="vm-ram-size-slider" class="vm-slider" value="{{ instance.ram_size }}" data-slider-min="128" data-slider-max="4096" data-slider-step="128" data-slider-value="{{ instance.ram_size }}" data-slider-orientation="horizontal" data-slider-handle="square" data-slider-tooltip="hide"/> MiB <input name="ram-size" type="text" id="vm-ram-size-slider" class="vm-slider" value="{{ instance.ram_size }}" data-slider-min="128" data-slider-max="4096" data-slider-step="128" data-slider-value="{{ instance.ram_size }}" data-slider-orientation="horizontal" data-slider-handle="square" data-slider-tooltip="hide"/> MiB
</div> </div>
</p> </p>
<p class="row">
<div class="col-sm-12">
<button type="submit" class="btn btn-success btn-sm" id="vm-details-resources-save"><i class="icon-save"></i> {% trans "Save resources" %}</button>
</div>
</p>
</form>
{% block extra_js %} {% block extra_js %}
<style> <style>
label {padding-top: 6px;} label {padding-top: 6px;}
......
...@@ -99,6 +99,35 @@ class VmDetailView(CheckedDetailView): ...@@ -99,6 +99,35 @@ class VmDetailView(CheckedDetailView):
context['acl'] = get_acl_data(instance) context['acl'] = get_acl_data(instance)
return context return context
def post(self, request, *args, **kwargs):
if (request.POST.get('ram-size') and request.POST.get('cpu-count')
and request.POST.get('cpu-priority')):
return self.__set_resources(request)
def __set_resources(self, request):
self.object = self.get_object()
if not self.object.has_level(request.user, 'owner'):
raise PermissionDenied()
resources = {
'num_cores': request.POST.get('cpu-count'),
'ram_size': request.POST.get('ram-size'),
'priority': request.POST.get('cpu-priority')
}
Instance.objects.filter(pk=self.object.pk).update(**resources)
success_message = _("Resources successfully updated!")
if request.is_ajax():
response = {'message': success_message}
return HttpResponse(
json.dumps(response),
content_type="application/json"
)
else:
messages.success(request, success_message)
return redirect(reverse_lazy("dashboard.views.detail",
kwargs={'pk': self.object.pk}))
class AclUpdateView(View, SingleObjectMixin): class AclUpdateView(View, SingleObjectMixin):
......
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