Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
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
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
32 deletions
+54
-32
circle/dashboard/forms.py
+35
-14
circle/dashboard/static/dashboard/vm-create.js
+2
-0
circle/dashboard/templates/dashboard/_vm-create-2.html
+2
-2
circle/dashboard/views.py
+15
-16
No files found.
circle/dashboard/forms.py
View file @
c766e690
...
@@ -143,25 +143,46 @@ class VmCustomizeForm(forms.Form):
...
@@ -143,25 +143,46 @@ class VmCustomizeForm(forms.Form):
self
.
template
=
kwargs
.
pop
(
"template"
,
None
)
self
.
template
=
kwargs
.
pop
(
"template"
,
None
)
super
(
VmCustomizeForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
VmCustomizeForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
# set displayed disk and network list
if
self
.
user
.
has_perm
(
"vm_set_resouces"
):
self
.
fields
[
'disks'
]
.
queryset
=
self
.
template
.
disks
.
all
()
self
.
allowed_fields
=
tuple
(
self
.
fields
.
keys
())
self
.
fields
[
'networks'
]
.
queryset
=
Vlan
.
get_objects_with_level
(
# set displayed disk and network list
'user'
,
self
.
user
)
self
.
fields
[
'disks'
]
.
queryset
=
self
.
template
.
disks
.
all
()
self
.
fields
[
'networks'
]
.
queryset
=
Vlan
.
get_objects_with_level
(
# set initial for disk and network list
'user'
,
self
.
user
)
self
.
initial
[
'disks'
]
=
self
.
template
.
disks
.
all
()
self
.
initial
[
'networks'
]
=
InterfaceTemplate
.
objects
.
filter
(
# set initial for disk and network list
template
=
self
.
template
)
.
values_list
(
"vlan"
,
flat
=
True
)
self
.
initial
[
'disks'
]
=
self
.
template
.
disks
.
all
()
self
.
initial
[
'networks'
]
=
InterfaceTemplate
.
objects
.
filter
(
template
=
self
.
template
)
.
values_list
(
"vlan"
,
flat
=
True
)
# set initial for resources
self
.
initial
[
'cpu_priority'
]
=
self
.
template
.
priority
self
.
initial
[
'cpu_count'
]
=
self
.
template
.
num_cores
self
.
initial
[
'ram_size'
]
=
self
.
template
.
ram_size
# set initial for resources
else
:
self
.
initial
[
'cpu_priority'
]
=
self
.
template
.
priority
self
.
allowed_fields
=
(
"name"
,
"template"
,
"customized"
,
)
self
.
initial
[
'cpu_count'
]
=
self
.
template
.
num_cores
self
.
initial
[
'ram_size'
]
=
self
.
template
.
ram_size
# initial name and template pk
# initial name and template pk
self
.
initial
[
'name'
]
=
self
.
template
.
name
self
.
initial
[
'name'
]
=
self
.
template
.
name
self
.
initial
[
'template'
]
=
self
.
template
.
pk
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
):
class
GroupCreateForm
(
forms
.
ModelForm
):
...
...
circle/dashboard/static/dashboard/vm-create.js
View file @
c766e690
...
@@ -222,6 +222,8 @@ function vmCustomizeLoaded() {
...
@@ -222,6 +222,8 @@ function vmCustomizeLoaded() {
$
(
this
).
find
(
"i"
).
prop
(
"class"
,
"fa fa-spinner fa-spin"
);
$
(
this
).
find
(
"i"
).
prop
(
"class"
,
"fa fa-spinner fa-spin"
);
if
(
$
(
"#create-modal"
))
return
true
;
$
.
ajax
({
$
.
ajax
({
url
:
'/dashboard/vm/create/'
,
url
:
'/dashboard/vm/create/'
,
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)},
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)},
...
...
circle/dashboard/templates/dashboard/_vm-create-2.html
View file @
c766e690
...
@@ -3,10 +3,11 @@
...
@@ -3,10 +3,11 @@
{% load sizefieldtags %}
{% load sizefieldtags %}
{% include "display-form-errors.html" with form=vm_create_form %}
{% include "display-form-errors.html" with form=vm_create_form %}
<form
method=
"POST"
>
<form
method=
"POST"
action=
"{% url "
dashboard
.
views
.
vm-create
"
%}"
>
{% csrf_token %}
{% csrf_token %}
{{ vm_create_form.template }}
{{ vm_create_form.template }}
{{ vm_create_form.customized }}
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"col-sm-12"
>
...
@@ -23,7 +24,6 @@
...
@@ -23,7 +24,6 @@
</div>
</div>
{% if perms.vm.set_resources %}
{% if perms.vm.set_resources %}
{{ vm_create_form.customized }}
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-sm-10"
>
<div
class=
"col-sm-10"
>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
...
...
circle/dashboard/views.py
View file @
c766e690
...
@@ -2157,8 +2157,6 @@ class VmCreate(LoginRequiredMixin, TemplateView):
...
@@ -2157,8 +2157,6 @@ class VmCreate(LoginRequiredMixin, TemplateView):
raise
PermissionDenied
()
raise
PermissionDenied
()
args
=
{
"template"
:
template
,
"owner"
:
user
}
args
=
{
"template"
:
template
,
"owner"
:
user
}
if
"name"
in
request
.
POST
:
args
[
"name"
]
=
request
.
POST
.
get
(
"name"
)
instances
=
[
Instance
.
create_from_template
(
**
args
)]
instances
=
[
Instance
.
create_from_template
(
**
args
)]
return
self
.
__deploy
(
request
,
instances
)
return
self
.
__deploy
(
request
,
instances
)
...
@@ -2179,30 +2177,31 @@ class VmCreate(LoginRequiredMixin, TemplateView):
...
@@ -2179,30 +2177,31 @@ class VmCreate(LoginRequiredMixin, TemplateView):
if
not
template
.
has_level
(
user
,
'user'
):
if
not
template
.
has_level
(
user
,
'user'
):
raise
PermissionDenied
()
raise
PermissionDenied
()
ikwargs
=
{
'name'
:
post
[
'name'
],
'template'
:
template
,
'owner'
:
user
,
}
amount
=
post
.
get
(
"amount"
,
1
)
if
request
.
user
.
has_perm
(
'vm.set_resources'
):
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'
],
}
networks
=
[
InterfaceTemplate
(
vlan
=
l
,
managed
=
l
.
managed
)
networks
=
[
InterfaceTemplate
(
vlan
=
l
,
managed
=
l
.
managed
)
for
l
in
post
[
'networks'
]]
for
l
in
post
[
'networks'
]]
ikwargs
.
update
({
ikwargs
.
update
({
'template'
:
template
,
'num_cores'
:
post
[
'cpu_count'
],
'owner'
:
user
,
'ram_size'
:
post
[
'ram_size'
],
'priority'
:
post
[
'cpu_priority'
],
'max_ram_size'
:
post
[
'ram_size'
],
'networks'
:
networks
,
'networks'
:
networks
,
'disks'
:
list
(
template
.
disks
.
all
()),
'disks'
:
list
(
template
.
disks
.
all
()),
})
})
amount
=
post
[
'amount'
]
instances
=
Instance
.
mass_create_from_template
(
amount
=
amount
,
**
ikwargs
)
return
self
.
__deploy
(
request
,
instances
)
else
:
else
:
raise
PermissionDenied
()
pass
instances
=
Instance
.
mass_create_from_template
(
amount
=
amount
,
**
ikwargs
)
return
self
.
__deploy
(
request
,
instances
)
def
__deploy
(
self
,
request
,
instances
,
*
args
,
**
kwargs
):
def
__deploy
(
self
,
request
,
instances
,
*
args
,
**
kwargs
):
for
i
in
instances
:
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