Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
216378f7
authored
Jul 29, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: working new sliders
parent
7211cc96
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
31 deletions
+73
-31
circle/circle/settings/base.py
+2
-0
circle/dashboard/forms.py
+32
-1
circle/dashboard/static/dashboard/dashboard.js
+15
-13
circle/dashboard/templates/dashboard/vm-detail/resources.html
+16
-10
circle/dashboard/views.py
+8
-7
No files found.
circle/circle/settings/base.py
View file @
216378f7
...
...
@@ -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
)
circle/dashboard/forms.py
View file @
216378f7
...
...
@@ -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'
,
)
circle/dashboard/static/dashboard/dashboard.js
View file @
216378f7
...
...
@@ -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"
);
}
...
...
circle/dashboard/templates/dashboard/vm-detail/resources.html
View file @
216378f7
...
...
@@ -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>
...
...
circle/dashboard/views.py
View file @
216378f7
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment