Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
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
1dc6857e
authored
Mar 25, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: create multiple vms
parent
d88fddf7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
19 deletions
+50
-19
circle/dashboard/forms.py
+17
-6
circle/dashboard/static/dashboard/vm-create.js
+6
-2
circle/dashboard/views.py
+27
-11
No files found.
circle/dashboard/forms.py
View file @
1dc6857e
...
@@ -33,6 +33,7 @@ class VmCustomizeForm(forms.Form):
...
@@ -33,6 +33,7 @@ class VmCustomizeForm(forms.Form):
cpu_priority
=
forms
.
IntegerField
()
cpu_priority
=
forms
.
IntegerField
()
cpu_count
=
forms
.
IntegerField
()
cpu_count
=
forms
.
IntegerField
()
ram_size
=
forms
.
IntegerField
()
ram_size
=
forms
.
IntegerField
()
amount
=
forms
.
IntegerField
(
min_value
=
0
,
initial
=
1
)
disks
=
forms
.
ModelMultipleChoiceField
(
disks
=
forms
.
ModelMultipleChoiceField
(
queryset
=
None
,
required
=
True
)
queryset
=
None
,
required
=
True
)
...
@@ -68,12 +69,21 @@ class VmCustomizeForm(forms.Form):
...
@@ -68,12 +69,21 @@ class VmCustomizeForm(forms.Form):
self
.
initial
[
'template'
]
=
self
.
template
.
pk
self
.
initial
[
'template'
]
=
self
.
template
.
pk
self
.
initial
[
'customized'
]
=
self
.
template
.
pk
self
.
initial
[
'customized'
]
=
self
.
template
.
pk
# set widget for amount
self
.
fields
[
'amount'
]
.
widget
=
NumberInput
()
self
.
helper
=
FormHelper
(
self
)
self
.
helper
=
FormHelper
(
self
)
self
.
helper
.
form_show_labels
=
False
# don't show labels for the sliders
self
.
helper
.
form_show_labels
=
True
self
.
fields
[
'cpu_count'
]
.
label
=
""
self
.
fields
[
'ram_size'
]
.
label
=
""
self
.
fields
[
'cpu_priority'
]
.
label
=
""
self
.
helper
.
layout
=
Layout
(
self
.
helper
.
layout
=
Layout
(
Field
(
"template"
,
type
=
"hidden"
),
Field
(
"template"
,
type
=
"hidden"
),
Field
(
"customized"
,
type
=
"hidden"
),
Field
(
"customized"
,
type
=
"hidden"
),
Div
(
# buttons
Div
(
Div
(
Div
(
AnyTag
(
# tip: don't try to use Button class
AnyTag
(
# tip: don't try to use Button class
"button"
,
"button"
,
...
@@ -84,16 +94,17 @@ class VmCustomizeForm(forms.Form):
...
@@ -84,16 +94,17 @@ class VmCustomizeForm(forms.Form):
HTML
(
" Start"
),
HTML
(
" Start"
),
css_id
=
"vm-create-customized-start"
,
css_id
=
"vm-create-customized-start"
,
css_class
=
"btn btn-success"
,
css_class
=
"btn btn-success"
,
style
=
"float: right; margin-top: 24px;"
,
),
),
css_class
=
"col-sm-11 text-right"
,
Field
(
"name"
,
style
=
"max-width: 350px;"
),
css_class
=
"col-sm-12"
,
),
),
css_class
=
"row"
,
css_class
=
"row"
,
),
),
Div
(
Div
(
Div
(
Div
(
Field
(
"
name
"
),
Field
(
"
amount"
,
min
=
"1"
,
style
=
"max-width: 60px;
"
),
css_class
=
"col-sm-
5
"
,
css_class
=
"col-sm-
10
"
,
),
),
css_class
=
"row"
,
css_class
=
"row"
,
),
),
...
...
circle/dashboard/static/dashboard/vm-create.js
View file @
1dc6857e
...
@@ -14,7 +14,6 @@ function vmCreateLoaded() {
...
@@ -14,7 +14,6 @@ function vmCreateLoaded() {
$
(
".customize-vm"
).
click
(
function
()
{
$
(
".customize-vm"
).
click
(
function
()
{
var
template
=
$
(
this
).
data
(
"template-pk"
);
var
template
=
$
(
this
).
data
(
"template-pk"
);
console
.
log
(
template
);
$
.
get
(
"/dashboard/vm/create/?template="
+
template
,
function
(
data
)
{
$
.
get
(
"/dashboard/vm/create/?template="
+
template
,
function
(
data
)
{
var
r
=
$
(
'#create-modal'
);
r
.
next
(
'div'
).
remove
();
r
.
remove
();
var
r
=
$
(
'#create-modal'
);
r
.
next
(
'div'
).
remove
();
r
.
remove
();
...
@@ -251,8 +250,13 @@ function vmCustomizeLoaded() {
...
@@ -251,8 +250,13 @@ function vmCustomizeLoaded() {
type
:
'POST'
,
type
:
'POST'
,
data
:
$
(
'form'
).
serialize
(),
data
:
$
(
'form'
).
serialize
(),
success
:
function
(
data
,
textStatus
,
xhr
)
{
success
:
function
(
data
,
textStatus
,
xhr
)
{
console
.
log
(
data
);
if
(
data
.
redirect
)
{
if
(
data
.
redirect
)
{
window
.
location
.
replace
(
data
.
redirect
+
'#activity'
);
/* it won't redirect to the same page */
if
(
window
.
location
.
pathname
==
data
.
redirect
)
{
window
.
location
.
reload
();
}
window
.
location
.
href
=
data
.
redirect
+
'#activity'
;
}
}
else
{
else
{
var
r
=
$
(
'#create-modal'
);
r
.
next
(
'div'
).
remove
();
r
.
remove
();
var
r
=
$
(
'#create-modal'
);
r
.
next
(
'div'
).
remove
();
r
.
remove
();
...
...
circle/dashboard/views.py
View file @
1dc6857e
...
@@ -1100,9 +1100,9 @@ class VmCreate(LoginRequiredMixin, TemplateView):
...
@@ -1100,9 +1100,9 @@ class VmCreate(LoginRequiredMixin, TemplateView):
if
not
template
.
has_level
(
request
.
user
,
'user'
):
if
not
template
.
has_level
(
request
.
user
,
'user'
):
raise
PermissionDenied
()
raise
PermissionDenied
()
inst
=
Instance
.
create_from_template
(
inst
ances
=
[
Instance
.
create_from_template
(
template
=
template
,
owner
=
user
)
template
=
template
,
owner
=
user
)
]
return
self
.
__deploy
(
request
,
inst
)
return
self
.
__deploy
(
request
,
inst
ances
)
def
__create_customized
(
self
,
request
,
*
args
,
**
kwargs
):
def
__create_customized
(
self
,
request
,
*
args
,
**
kwargs
):
user
=
request
.
user
user
=
request
.
user
...
@@ -1131,17 +1131,33 @@ class VmCreate(LoginRequiredMixin, TemplateView):
...
@@ -1131,17 +1131,33 @@ class VmCreate(LoginRequiredMixin, TemplateView):
networks
=
[
InterfaceTemplate
(
vlan
=
l
,
managed
=
l
.
managed
)
networks
=
[
InterfaceTemplate
(
vlan
=
l
,
managed
=
l
.
managed
)
for
l
in
post
[
'networks'
]]
for
l
in
post
[
'networks'
]]
disks
=
post
[
'disks'
]
disks
=
post
[
'disks'
]
inst
=
Instance
.
create_from_template
(
template
=
template
,
owner
=
user
,
networks
=
networks
,
ikwargs
.
update
({
disks
=
disks
,
**
ikwargs
)
'template'
:
template
,
return
self
.
__deploy
(
request
,
inst
)
'owner'
:
user
,
'networks'
:
networks
,
'disks'
:
disks
,
})
amount
=
post
[
'amount'
]
instances
=
Instance
.
mass_create_from_template
(
amount
=
amount
,
**
ikwargs
)
return
self
.
__deploy
(
request
,
instances
)
else
:
else
:
raise
PermissionDenied
()
raise
PermissionDenied
()
def
__deploy
(
self
,
request
,
instance
,
*
args
,
**
kwargs
):
def
__deploy
(
self
,
request
,
instances
,
*
args
,
**
kwargs
):
instance
.
deploy_async
(
user
=
request
.
user
)
for
i
in
instances
:
messages
.
success
(
request
,
_
(
'VM successfully created!'
))
i
.
deploy_async
(
user
=
request
.
user
)
path
=
instance
.
get_absolute_url
()
if
len
(
instances
)
>
1
:
messages
.
success
(
request
,
_
(
"Successfully created
%
d VMs!"
%
len
(
instances
)))
path
=
reverse
(
"dashboard.index"
)
else
:
messages
.
success
(
request
,
_
(
"VM successfully created!"
))
path
=
instances
[
0
]
.
get_absolute_url
()
if
request
.
is_ajax
():
if
request
.
is_ajax
():
return
HttpResponse
(
json
.
dumps
({
'redirect'
:
path
}),
return
HttpResponse
(
json
.
dumps
({
'redirect'
:
path
}),
content_type
=
"application/json"
)
content_type
=
"application/json"
)
...
...
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