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
e0ab1b77
authored
Dec 09, 2013
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: vm create with django forms
parent
ab541167
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
153 deletions
+42
-153
circle/dashboard/forms.py
+0
-0
circle/dashboard/static/dashboard/dashboard.css
+20
-1
circle/dashboard/templates/crispy_forms/anytag.html
+4
-0
circle/dashboard/templates/dashboard/vm-create.html
+4
-144
circle/dashboard/views.py
+14
-8
No files found.
circle/dashboard/forms.py
0 → 100644
View file @
e0ab1b77
This diff is collapsed.
Click to expand it.
circle/dashboard/static/dashboard/dashboard.css
View file @
e0ab1b77
...
...
@@ -207,4 +207,23 @@ body {
/* port add buttons */
.vm-details-network-port-add
.input-group-addon
,
.vm-details-network-port-add
.input-group-btn
{
width
:
inherit
;
}
}
/* vm-create */
a
.hover-black
{
color
:
white
;
}
.hover-black
:hover
{
color
:
black
/*#d9534f*/
;
text-decoration
:
none
;
}
.no-js-hidden
{
display
:
none
;
}
#vm-create-network-addcheckbox-managed
{
-webkit-transform
:
scale
(
1.3
,
1.3
);
margin-top
:
4px
;
}
/* --- */
circle/dashboard/templates/crispy_forms/anytag.html
0 → 100644
View file @
e0ab1b77
<
{{
tag
.
tag
}}
{%
if
tag
.
css_id
%}
id=
"{{ tag.css_id }}"
{%
endif
%}
{%
if
tag
.
css_class
%}
class=
"{{ tag.css_class }}"
{%
endif
%}
{{
tag
.
flat_attrs
|
safe
}}
>
{{ fields|safe }}
</
{{
tag
.tag
}}
>
circle/dashboard/templates/dashboard/vm-create.html
View file @
e0ab1b77
{% load crispy_forms_tags %}
<style>
.row
{
margin-bottom
:
15px
;
}
</style>
<form
method=
"POST"
action=
"/dashboard/vm/create/"
>
{% csrf_token %}
<div
class=
"row"
>
<div
class=
"col-sm-10"
>
<select
class=
"select form-control"
id=
"vm-create-template-select"
name=
"template-pk"
>
<option
value=
"-1"
>
Choose a VM template
</option>
{% for template in templates %}
<option
value=
"{{ template.pk }}"
>
{{ template.name}}
</option>
{% endfor %}
</select>
</div>
</div>
<div
class=
"row"
>
<div
class=
"col-sm-5"
>
<a
class=
"btn btn-info vm-create-advanced-btn"
>
Advanced
<i
class=
"vm-create-advanced-icon icon-caret-down"
></i></a>
</div>
<div
class=
"col-sm-5 text-right"
>
<button
id=
"vm-create-submit"
type=
"submit"
class=
"btn btn-success "
><i
class=
"icon-play"
></i>
Start
</button>
</div>
</div>
<div
class=
"vm-create-advanced"
>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<h2>
Resources
</h2>
</div>
<p
class=
"row"
>
<div
class=
"col-sm-3"
>
<label
for=
"vm-cpu-priority-slider"
><i
class=
"icon-trophy"
></i>
CPU priority
</label>
</div>
<div
class=
"col-sm-9"
>
<input
name=
"cpu-priority"
type=
"text"
id=
"vm-cpu-priority-slider"
class=
"vm-slider"
value=
"20"
data-slider-min=
"0"
data-slider-max=
"100"
data-slider-step=
"1"
data-slider-value=
"20"
data-slider-orientation=
"horizontal"
data-slider-handle=
"square"
data-slider-tooltip=
"hide"
/>
</div>
</p>
<p
class=
"row"
>
<div
class=
"col-sm-3"
>
<label
for=
"cpu-count-slider"
><i
class=
"icon-cogs"
></i>
CPU count
</label>
</div>
<div
class=
"col-sm-9"
>
<input
name=
"cpu-count"
type=
"text"
id=
"vm-cpu-count-slider"
class=
"vm-slider"
value=
"2"
data-slider-min=
"0"
data-slider-max=
"8"
data-slider-step=
"1"
data-slider-value=
"2"
data-slider-orientation=
"horizontal"
data-slider-handle=
"square"
data-slider-tooltip=
"hide"
/>
</div>
</p>
<p
class=
"row"
>
<div
class=
"col-sm-3"
>
<label
for=
"ram-slider"
><i
class=
"icon-ticket"
></i>
RAM amount
</label>
</div>
<div
class=
"col-sm-9"
>
<input
name=
"ram-size"
type=
"text"
id=
"vm-ram-size-slider"
class=
"vm-slider"
value=
"512"
data-slider-min=
"128"
data-slider-max=
"4096"
data-slider-step=
"128"
data-slider-value=
"512"
data-slider-orientation=
"horizontal"
data-slider-handle=
"square"
data-slider-tooltip=
"hide"
/>
MiB
</div>
</p>
</div>
<!-- disk -->
<div
class=
"row"
>
<div
class=
"col-sm-4"
>
<h2>
Disks
</h2>
</div>
<div
class=
"col-sm-8"
style=
"padding-top: 3px;"
>
<div
class=
"js-hidden"
style=
"padding-top: 15px; max-width: 450px;"
>
<select
class=
"form-control"
id=
"vm-create-disk-add-form"
multiple
name=
"disks"
>
{% for d in disks %}
<option
value=
"{{ d.pk }}"
>
{{ d.name }}
</option>
{% endfor %}
</select>
</div>
<div
class=
"no-js-hidden"
>
<h3
id=
"vm-create-disk-list"
>
No disks are added!
</h3>
<h3
id=
"vm-create-disk-add"
>
<div
class=
"input-group"
style=
"max-width: 330px;"
>
<select
class=
"form-control"
id=
"vm-create-disk-add-select"
>
<!-- options should be copied via js from above -->
</select>
<div
class=
"input-group-btn"
>
<!--<input type="submit" value="Add to network" class="btn btn-success"/>-->
<a
href=
"#"
id=
"vm-create-disk-add-button"
class=
"btn btn-success"
><i
class=
"icon-plus-sign"
></i></a>
</div>
</div>
</h3>
</div>
</div>
</div>
<!-- network -->
<div
class=
"row"
>
<div
class=
"col-sm-4"
>
<h2>
Network
</h2>
</div>
<style>
/* temporary inline css for dev */
a
.hover-black
{
color
:
white
;
}
.hover-black
:hover
{
color
:
black
/*#d9534f*/
;
text-decoration
:
none
;
}
.no-js-hidden
{
display
:
none
;
}
</style>
<div
class=
"col-sm-8"
style=
"padding-top: 3px;"
>
<div
class=
"js-hidden"
style=
"padding-top: 15px; max-width: 450px;"
>
<h4>
Managed networks
</h4>
<select
class=
"form-control"
id=
"vm-create-network-add-managed"
multiple
name=
"managed-vlans"
>
{% for v in vlans %}
<option
value=
"{{ v.pk }}"
>
{{ v.name }}
</option>
{% endfor %}
</select>
<h4>
Unmanaged networks
</h4>
<select
class=
"form-control"
id=
"vm-create-network-add-unmanaged"
multiple
name=
"unmanaged-vlans"
>
{% for v in vlans %}
<option
value=
"{{ v.pk }}"
>
{{ v.name }}
</option>
{% endfor %}
</select>
</div>
<div
class=
"no-js-hidden"
>
<h3
id=
"vm-create-network-list"
>
Not added to any network!
</h3>
<h3
id=
"vm-create-network-add"
>
<div
class=
"input-group"
style=
"max-width: 330px;"
>
<select
class=
"form-control"
id=
"vm-create-network-add-select"
>
<!-- options should be copied via js from above -->
</select>
<span
class=
"input-group-addon"
>
<input
id=
"vm-create-network-add-checkbox-managed"
type=
"checkbox"
title
data-original-title=
"Managed network?"
style=
"-webkit-transform: scale(1.4, 1.4); margin-top: 4px;"
checked
/>
</span>
<div
class=
"input-group-btn"
>
<!--<input type="submit" value="Add to network" class="btn btn-success"/>-->
<a
href=
"#"
id=
"vm-create-network-add-button"
class=
"btn btn-success"
><i
class=
"icon-plus-sign"
></i></a>
</div>
</div>
</h3>
</div>
</div>
</div>
</div>
<form
method=
"POST"
action=
"/dashboard/vm/create/"
>
{% csrf_token %}
{% crispy vm_create_form %}
</form>
circle/dashboard/views.py
View file @
e0ab1b77
...
...
@@ -21,6 +21,7 @@ from django.utils.translation import ugettext as _
from
django_tables2
import
SingleTableView
from
braces.views
import
LoginRequiredMixin
from
.forms
import
VmCreateForm
from
.tables
import
(
VmListTable
,
NodeListTable
)
from
vm.models
import
(
Instance
,
InstanceTemplate
,
InterfaceTemplate
,
InstanceActivity
,
Node
,
instance_activity
)
...
...
@@ -362,7 +363,8 @@ class VmCreate(TemplateView):
context
.
update
({
'templates'
:
InstanceTemplate
.
objects
.
all
(),
'vlans'
:
Vlan
.
objects
.
all
(),
'disks'
:
Disk
.
objects
.
exclude
(
type
=
"qcow2-snap"
)
'disks'
:
Disk
.
objects
.
exclude
(
type
=
"qcow2-snap"
),
'vm_create_form'
:
VmCreateForm
,
})
return
context
...
...
@@ -376,27 +378,31 @@ class VmCreate(TemplateView):
resp
=
{}
try
:
pk
=
request
.
POST
.
get
(
'template
-pk
'
)
pk
=
request
.
POST
.
get
(
'template'
)
template
=
InstanceTemplate
.
objects
.
get
(
pk
=
pk
)
except
ValueError
:
resp
[
'error'
]
=
True
resp
[
'message'
]
=
_
(
"Select a VM from the list!"
)
except
InstanceTemplate
.
DoesNotExist
as
e
:
logger
.
warning
(
'VmCreate.post:
%
s (pk=
%
d, user=
%
s)'
,
unicode
(
e
),
unicode
(
request
.
user
),
pk
)
unicode
(
e
),
pk
,
unicode
(
request
.
user
)
)
resp
[
'error'
]
=
True
else
:
if
request
.
user
.
has_perm
(
'vm.set_resources'
):
ikwargs
=
{
'num_cores'
:
int
(
request
.
POST
.
get
(
'cpu
-
count'
)),
'ram_size'
:
int
(
request
.
POST
.
get
(
'ram
-
size'
)),
'priority'
:
int
(
request
.
POST
.
get
(
'cpu
-
priority'
)),
'num_cores'
:
int
(
request
.
POST
.
get
(
'cpu
_
count'
)),
'ram_size'
:
int
(
request
.
POST
.
get
(
'ram
_
size'
)),
'priority'
:
int
(
request
.
POST
.
get
(
'cpu
_
priority'
)),
}
try
:
networks
=
[
InterfaceTemplate
(
vlan
=
Vlan
.
objects
.
get
(
pk
=
l
),
managed
=
True
)
for
l
in
request
.
POST
.
getlist
(
'managed-vlans'
)
for
l
in
request
.
POST
.
getlist
(
'managed_networks'
)
]
unmanaged
=
request
.
POST
.
getlist
(
'unmanaged
-vlan
s'
)
unmanaged
=
request
.
POST
.
getlist
(
'unmanaged
_network
s'
)
networks
.
extend
([
InterfaceTemplate
(
vlan
=
Vlan
.
objects
.
get
(
pk
=
l
),
managed
=
False
)
...
...
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