Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
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
c766e690
authored
Sep 08, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue-267' into 'master'
Fix vm customization dialog's error handling Closes #267
parents
06018f2d
f4539967
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
15 deletions
+37
-15
circle/dashboard/forms.py
+22
-1
circle/dashboard/static/dashboard/vm-create.js
+2
-0
circle/dashboard/templates/dashboard/_vm-create-2.html
+2
-2
circle/dashboard/views.py
+11
-12
No files found.
circle/dashboard/forms.py
View file @
c766e690
...
...
@@ -143,6 +143,8 @@ class VmCustomizeForm(forms.Form):
self
.
template
=
kwargs
.
pop
(
"template"
,
None
)
super
(
VmCustomizeForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
if
self
.
user
.
has_perm
(
"vm_set_resouces"
):
self
.
allowed_fields
=
tuple
(
self
.
fields
.
keys
())
# set displayed disk and network list
self
.
fields
[
'disks'
]
.
queryset
=
self
.
template
.
disks
.
all
()
self
.
fields
[
'networks'
]
.
queryset
=
Vlan
.
get_objects_with_level
(
...
...
@@ -158,10 +160,29 @@ class VmCustomizeForm(forms.Form):
self
.
initial
[
'cpu_count'
]
=
self
.
template
.
num_cores
self
.
initial
[
'ram_size'
]
=
self
.
template
.
ram_size
else
:
self
.
allowed_fields
=
(
"name"
,
"template"
,
"customized"
,
)
# initial name and template pk
self
.
initial
[
'name'
]
=
self
.
template
.
name
self
.
initial
[
'template'
]
=
self
.
template
.
pk
self
.
initial
[
'customized'
]
=
self
.
template
.
pk
self
.
initial
[
'customized'
]
=
True
def
_clean_fields
(
self
):
for
name
,
field
in
self
.
fields
.
items
():
if
name
in
self
.
allowed_fields
:
value
=
field
.
widget
.
value_from_datadict
(
self
.
data
,
self
.
files
,
self
.
add_prefix
(
name
))
try
:
value
=
field
.
clean
(
value
)
self
.
cleaned_data
[
name
]
=
value
if
hasattr
(
self
,
'clean_
%
s'
%
name
):
value
=
getattr
(
self
,
'clean_
%
s'
%
name
)()
self
.
cleaned_data
[
name
]
=
value
except
ValidationError
as
e
:
self
.
_errors
[
name
]
=
self
.
error_class
(
e
.
messages
)
if
name
in
self
.
cleaned_data
:
del
self
.
cleaned_data
[
name
]
class
GroupCreateForm
(
forms
.
ModelForm
):
...
...
circle/dashboard/static/dashboard/vm-create.js
View file @
c766e690
...
...
@@ -222,6 +222,8 @@ function vmCustomizeLoaded() {
$
(
this
).
find
(
"i"
).
prop
(
"class"
,
"fa fa-spinner fa-spin"
);
if
(
$
(
"#create-modal"
))
return
true
;
$
.
ajax
({
url
:
'/dashboard/vm/create/'
,
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)},
...
...
circle/dashboard/templates/dashboard/_vm-create-2.html
View file @
c766e690
...
...
@@ -3,10 +3,11 @@
{% load sizefieldtags %}
{% include "display-form-errors.html" with form=vm_create_form %}
<form
method=
"POST"
>
<form
method=
"POST"
action=
"{% url "
dashboard
.
views
.
vm-create
"
%}"
>
{% csrf_token %}
{{ vm_create_form.template }}
{{ vm_create_form.customized }}
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
...
...
@@ -23,7 +24,6 @@
</div>
{% if perms.vm.set_resources %}
{{ vm_create_form.customized }}
<div
class=
"row"
>
<div
class=
"col-sm-10"
>
<div
class=
"form-group"
>
...
...
circle/dashboard/views.py
View file @
c766e690
...
...
@@ -2157,8 +2157,6 @@ class VmCreate(LoginRequiredMixin, TemplateView):
raise
PermissionDenied
()
args
=
{
"template"
:
template
,
"owner"
:
user
}
if
"name"
in
request
.
POST
:
args
[
"name"
]
=
request
.
POST
.
get
(
"name"
)
instances
=
[
Instance
.
create_from_template
(
**
args
)]
return
self
.
__deploy
(
request
,
instances
)
...
...
@@ -2179,30 +2177,31 @@ class VmCreate(LoginRequiredMixin, TemplateView):
if
not
template
.
has_level
(
user
,
'user'
):
raise
PermissionDenied
()
if
request
.
user
.
has_perm
(
'vm.set_resources'
):
ikwargs
=
{
'name'
:
post
[
'name'
],
'num_cores'
:
post
[
'cpu_count'
],
'ram_size'
:
post
[
'ram_size'
],
'priority'
:
post
[
'cpu_priority'
],
'max_ram_size'
:
post
[
'ram_size'
],
'template'
:
template
,
'owner'
:
user
,
}
amount
=
post
.
get
(
"amount"
,
1
)
if
request
.
user
.
has_perm
(
'vm.set_resources'
):
networks
=
[
InterfaceTemplate
(
vlan
=
l
,
managed
=
l
.
managed
)
for
l
in
post
[
'networks'
]]
ikwargs
.
update
({
'template'
:
template
,
'owner'
:
user
,
'num_cores'
:
post
[
'cpu_count'
],
'ram_size'
:
post
[
'ram_size'
],
'priority'
:
post
[
'cpu_priority'
],
'max_ram_size'
:
post
[
'ram_size'
],
'networks'
:
networks
,
'disks'
:
list
(
template
.
disks
.
all
()),
})
amount
=
post
[
'amount'
]
else
:
pass
instances
=
Instance
.
mass_create_from_template
(
amount
=
amount
,
**
ikwargs
)
return
self
.
__deploy
(
request
,
instances
)
else
:
raise
PermissionDenied
()
def
__deploy
(
self
,
request
,
instances
,
*
args
,
**
kwargs
):
for
i
in
instances
:
...
...
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