Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
50e5a41d
authored
Jul 30, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: validate user input for resources
parent
c44710dd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
19 deletions
+49
-19
circle/dashboard/forms.py
+16
-8
circle/dashboard/static/dashboard/vm-details.js
+5
-1
circle/dashboard/views.py
+28
-10
No files found.
circle/dashboard/forms.py
View file @
50e5a41d
...
...
@@ -85,21 +85,25 @@ class VmCustomizeForm(forms.Form):
'required'
:
""
,
}))
cpu_count
=
forms
.
Cha
rField
(
widget
=
forms
.
NumberInput
(
attrs
=
{
cpu_count
=
forms
.
Intege
rField
(
widget
=
forms
.
NumberInput
(
attrs
=
{
'class'
:
"form-control input-tags cpu-count-input"
,
'min'
:
1
,
'max'
:
10
,
'required'
:
""
,
}))
}),
min_value
=
1
,
max_value
=
10
,
)
ram_size
=
forms
.
Cha
rField
(
widget
=
forms
.
TextInput
(
attrs
=
{
ram_size
=
forms
.
Intege
rField
(
widget
=
forms
.
TextInput
(
attrs
=
{
'class'
:
"form-control input-tags ram-input"
,
'min'
:
128
,
'pattern'
:
"
\
d+"
,
'max'
:
MAX_NODE_RAM
,
'step'
:
128
,
'required'
:
""
,
}))
}),
min_value
=
128
,
max_value
=
MAX_NODE_RAM
,
)
cpu_priority
=
forms
.
ChoiceField
(
priority_choices
,
widget
=
forms
.
Select
(
attrs
=
{
...
...
@@ -1134,20 +1138,24 @@ class GroupPermissionForm(forms.ModelForm):
class
VmResourcesForm
(
forms
.
ModelForm
):
num_cores
=
forms
.
Cha
rField
(
widget
=
forms
.
NumberInput
(
attrs
=
{
num_cores
=
forms
.
Intege
rField
(
widget
=
forms
.
NumberInput
(
attrs
=
{
'class'
:
"form-control input-tags cpu-count-input"
,
'min'
:
1
,
'max'
:
10
,
'required'
:
""
,
}))
}),
min_value
=
1
,
max_value
=
10
,
)
ram_size
=
forms
.
Cha
rField
(
widget
=
forms
.
NumberInput
(
attrs
=
{
ram_size
=
forms
.
Intege
rField
(
widget
=
forms
.
NumberInput
(
attrs
=
{
'class'
:
"form-control input-tags ram-input"
,
'min'
:
128
,
'max'
:
MAX_NODE_RAM
,
'step'
:
128
,
'required'
:
""
,
}))
}),
min_value
=
128
,
max_value
=
MAX_NODE_RAM
,
)
priority
=
forms
.
ChoiceField
(
priority_choices
,
widget
=
forms
.
Select
(
attrs
=
{
'class'
:
"form-control input-tags cpu-priority-input"
,
...
...
circle/dashboard/static/dashboard/vm-details.js
View file @
50e5a41d
...
...
@@ -43,8 +43,12 @@ $(function() {
url
:
"/dashboard/vm/"
+
vm
+
"/op/resources_change/"
,
data
:
$
(
'#vm-details-resources-form'
).
serialize
(),
success
:
function
(
data
,
textStatus
,
xhr
)
{
if
(
data
.
success
)
{
$
(
'a[href="#activity"]'
).
trigger
(
"click"
);
}
else
{
addMessage
(
data
.
messages
.
join
(
"<br />"
),
"danger"
);
}
$
(
"#vm-details-resources-save i"
).
removeClass
(
'fa-refresh fa-spin'
).
addClass
(
"fa-floppy-o"
);
$
(
'a[href="#activity"]'
).
trigger
(
"click"
);
},
error
:
function
(
xhr
,
textStatus
,
error
)
{
$
(
"#vm-details-resources-save i"
).
removeClass
(
'fa-refresh fa-spin'
).
addClass
(
"fa-floppy-o"
);
...
...
circle/dashboard/views.py
View file @
50e5a41d
...
...
@@ -765,17 +765,35 @@ class VmResourcesChangeView(VmOperationView):
if
extra
is
None
:
extra
=
{}
resources
=
{
'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
)
instance
=
get_object_or_404
(
Instance
,
pk
=
kwargs
[
'pk'
])
return
super
(
VmResourcesChangeView
,
self
)
.
post
(
request
,
extra
,
*
args
,
**
kwargs
)
form
=
VmResourcesForm
(
request
.
POST
,
instance
=
instance
)
if
not
form
.
is_valid
():
for
f
in
form
.
errors
:
messages
.
error
(
request
,
"<strong>
%
s</strong>:
%
s"
%
(
f
,
form
.
errors
[
f
]
.
as_text
()
))
if
request
.
is_ajax
():
# this is not too nice
store
=
messages
.
get_messages
(
request
)
store
.
used
=
True
return
HttpResponse
(
json
.
dumps
({
'success'
:
False
,
'messages'
:
[
unicode
(
m
)
for
m
in
store
]}),
content_type
=
"application=json"
)
else
:
return
redirect
(
instance
.
get_absolute_url
()
+
"#resources"
)
else
:
resources
=
{
'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
)
return
super
(
VmResourcesChangeView
,
self
)
.
post
(
request
,
extra
,
*
args
,
**
kwargs
)
class
TokenOperationView
(
OperationView
):
...
...
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