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
f42dd1df
authored
May 07, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: fix base vm creation
parent
1768643d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
55 deletions
+12
-55
circle/dashboard/forms.py
+2
-22
circle/dashboard/templates/dashboard/_template-choose.html
+0
-0
circle/dashboard/templates/dashboard/_template-create.html
+0
-0
circle/dashboard/views.py
+10
-33
No files found.
circle/dashboard/forms.py
View file @
f42dd1df
...
@@ -30,7 +30,6 @@ from crispy_forms.layout import (
...
@@ -30,7 +30,6 @@ from crispy_forms.layout import (
Layout
,
Div
,
BaseInput
,
Field
,
HTML
,
Submit
,
Fieldset
,
TEMPLATE_PACK
,
Layout
,
Div
,
BaseInput
,
Field
,
HTML
,
Submit
,
Fieldset
,
TEMPLATE_PACK
,
)
)
from
django.shortcuts
import
get_object_or_404
from
crispy_forms.utils
import
render_field
from
crispy_forms.utils
import
render_field
from
django
import
forms
from
django
import
forms
from
django.forms.widgets
import
TextInput
from
django.forms.widgets
import
TextInput
...
@@ -479,10 +478,8 @@ class NodeForm(forms.ModelForm):
...
@@ -479,10 +478,8 @@ class NodeForm(forms.ModelForm):
class
TemplateForm
(
forms
.
ModelForm
):
class
TemplateForm
(
forms
.
ModelForm
):
networks
=
forms
.
ModelMultipleChoiceField
(
networks
=
forms
.
ModelMultipleChoiceField
(
queryset
=
None
,
required
=
False
,
label
=
_
(
"Networks"
))
queryset
=
None
,
required
=
False
,
label
=
_
(
"Networks"
))
parent_type
=
forms
.
CharField
(
required
=
False
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
parent
=
kwargs
.
pop
(
"parent"
,
None
)
self
.
user
=
kwargs
.
pop
(
"user"
,
None
)
self
.
user
=
kwargs
.
pop
(
"user"
,
None
)
super
(
TemplateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
TemplateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
...
@@ -492,25 +489,9 @@ class TemplateForm(forms.ModelForm):
...
@@ -492,25 +489,9 @@ class TemplateForm(forms.ModelForm):
data
=
self
.
data
.
copy
()
data
=
self
.
data
.
copy
()
data
[
'owner'
]
=
self
.
user
.
pk
data
[
'owner'
]
=
self
.
user
.
pk
self
.
data
=
data
self
.
data
=
data
self
.
initial
[
'parent_type'
]
=
self
.
parent
if
self
.
parent
is
not
None
and
self
.
parent
.
isdigit
():
template
=
get_object_or_404
(
InstanceTemplate
,
pk
=
self
.
parent
)
parent
=
template
.
__dict__
fields
=
[
"system"
,
"name"
,
"num_cores"
,
"boot_menu"
,
"ram_size"
,
"priority"
,
"access_method"
,
"raw_data"
,
"arch"
,
"description"
]
for
f
in
fields
:
self
.
initial
[
f
]
=
parent
[
f
]
self
.
initial
[
'lease'
]
=
parent
[
'lease_id'
]
self
.
initial
[
'parent'
]
=
template
self
.
initial
[
'name'
]
=
"Clone of
%
s"
%
self
.
initial
[
'name'
]
self
.
for_networks
=
template
else
:
self
.
for_networks
=
self
.
instance
if
self
.
instance
.
pk
or
self
.
parent
is
not
None
:
if
self
.
instance
.
pk
:
n
=
self
.
for_networks
.
interface_set
.
values_list
(
"vlan"
,
flat
=
True
)
n
=
self
.
instance
.
interface_set
.
values_list
(
"vlan"
,
flat
=
True
)
self
.
initial
[
'networks'
]
=
n
self
.
initial
[
'networks'
]
=
n
if
not
self
.
instance
.
pk
and
len
(
self
.
errors
)
<
1
:
if
not
self
.
instance
.
pk
and
len
(
self
.
errors
)
<
1
:
...
@@ -561,7 +542,6 @@ class TemplateForm(forms.ModelForm):
...
@@ -561,7 +542,6 @@ class TemplateForm(forms.ModelForm):
helper
=
FormHelper
()
helper
=
FormHelper
()
helper
.
layout
=
Layout
(
helper
.
layout
=
Layout
(
Field
(
"parent_type"
,
type
=
"hidden"
),
Field
(
"name"
),
Field
(
"name"
),
Fieldset
(
Fieldset
(
_
(
"Resource configuration"
),
_
(
"Resource configuration"
),
...
...
circle/dashboard/templates/dashboard/_template-c
reate-1
.html
→
circle/dashboard/templates/dashboard/_template-c
hoose
.html
View file @
f42dd1df
File moved
circle/dashboard/templates/dashboard/_template-create
-2
.html
→
circle/dashboard/templates/dashboard/_template-create.html
View file @
f42dd1df
File moved
circle/dashboard/views.py
View file @
f42dd1df
...
@@ -841,7 +841,7 @@ class TemplateChoose(TemplateView):
...
@@ -841,7 +841,7 @@ class TemplateChoose(TemplateView):
context
.
update
({
context
.
update
({
'box_title'
:
_
(
'Choose template'
),
'box_title'
:
_
(
'Choose template'
),
'ajax_title'
:
False
,
'ajax_title'
:
False
,
'template'
:
"dashboard/_template-c
reate-1
.html"
,
'template'
:
"dashboard/_template-c
hoose
.html"
,
'templates'
:
templates
.
all
(),
# TODO acl?
'templates'
:
templates
.
all
(),
# TODO acl?
})
})
return
context
return
context
...
@@ -871,7 +871,7 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
...
@@ -871,7 +871,7 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
def
get_template_names
(
self
):
def
get_template_names
(
self
):
if
self
.
request
.
is_ajax
():
if
self
.
request
.
is_ajax
():
return
[
'dashboard/modal-wrapper.html'
]
pass
else
:
else
:
return
[
'dashboard/nojs-wrapper.html'
]
return
[
'dashboard/nojs-wrapper.html'
]
...
@@ -880,8 +880,7 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
...
@@ -880,8 +880,7 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
context
.
update
({
context
.
update
({
'box_title'
:
_
(
"Create a new base VM"
),
'box_title'
:
_
(
"Create a new base VM"
),
'ajax_title'
:
False
,
'template'
:
"dashboard/_template-create.html"
,
'template'
:
"dashboard/_template-create-2.html"
,
'leases'
:
Lease
.
objects
.
count
()
'leases'
:
Lease
.
objects
.
count
()
})
})
return
context
return
context
...
@@ -890,12 +889,10 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
...
@@ -890,12 +889,10 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
if
not
self
.
request
.
user
.
has_perm
(
'vm.create_template'
):
if
not
self
.
request
.
user
.
has_perm
(
'vm.create_template'
):
raise
PermissionDenied
()
raise
PermissionDenied
()
self
.
parent
=
self
.
request
.
GET
.
get
(
"parent"
)
return
super
(
TemplateCreate
,
self
)
.
get
(
*
args
,
**
kwargs
)
return
super
(
TemplateCreate
,
self
)
.
get
(
*
args
,
**
kwargs
)
def
get_form_kwargs
(
self
):
def
get_form_kwargs
(
self
):
kwargs
=
super
(
TemplateCreate
,
self
)
.
get_form_kwargs
()
kwargs
=
super
(
TemplateCreate
,
self
)
.
get_form_kwargs
()
kwargs
[
'parent'
]
=
getattr
(
self
,
"parent"
,
None
)
kwargs
[
'user'
]
=
self
.
request
.
user
kwargs
[
'user'
]
=
self
.
request
.
user
return
kwargs
return
kwargs
...
@@ -908,37 +905,17 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
...
@@ -908,37 +905,17 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
else
:
else
:
post
=
form
.
cleaned_data
post
=
form
.
cleaned_data
networks
=
self
.
__create_networks
(
post
.
pop
(
"networks"
),
networks
=
self
.
__create_networks
(
post
.
pop
(
"networks"
),
request
.
user
)
request
.
user
)
post
.
pop
(
"parent"
)
post
.
pop
(
"parent"
)
parent_type
=
post
.
pop
(
"parent_type"
)
post
[
'max_ram_size'
]
=
post
[
'ram_size'
]
post
[
'max_ram_size'
]
=
post
[
'ram_size'
]
req_traits
=
post
.
pop
(
"req_traits"
)
# if it's not a base vm we need to add disks and deploy it
tags
=
post
.
pop
(
"tags"
)
if
parent_type
!=
"base_vm"
:
post
[
'pw'
]
=
User
.
objects
.
make_random_password
()
template
=
get_object_or_404
(
InstanceTemplate
,
pk
=
parent_type
)
post
[
'is_base'
]
=
True
inst
=
Instance
.
create_from_template
(
template
=
template
,
inst
=
Instance
.
create
(
params
=
post
,
disks
=
[],
networks
=
networks
,
networks
=
networks
,
**
post
)
tags
=
tags
,
req_traits
=
req_traits
)
inst
.
deploy_async
()
messages
.
info
(
request
,
_
(
"Your instance has been created, "
"modify it then press the save as "
"button to save it as a new template!"
))
else
:
req_traits
=
post
.
pop
(
"req_traits"
)
tags
=
post
.
pop
(
"tags"
)
post
[
'pw'
]
=
User
.
objects
.
make_random_password
()
inst
=
Instance
.
create
(
params
=
post
,
disks
=
[],
networks
=
networks
,
tags
=
tags
,
req_traits
=
req_traits
)
messages
.
info
(
request
,
_
(
"Your new base vm has been created, "
"add disks, make modifications, then"
" use the save as button to save it"
" as a new template!"
))
return
redirect
(
"
%
s#resources"
%
inst
.
get_absolute_url
())
return
redirect
(
"
%
s#resources"
%
inst
.
get_absolute_url
())
...
...
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