Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
49 deletions
+6
-49
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
+4
-27
No files found.
circle/dashboard/forms.py
View file @
f42dd1df
...
...
@@ -30,7 +30,6 @@ from crispy_forms.layout import (
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
django
import
forms
from
django.forms.widgets
import
TextInput
...
...
@@ -479,10 +478,8 @@ class NodeForm(forms.ModelForm):
class
TemplateForm
(
forms
.
ModelForm
):
networks
=
forms
.
ModelMultipleChoiceField
(
queryset
=
None
,
required
=
False
,
label
=
_
(
"Networks"
))
parent_type
=
forms
.
CharField
(
required
=
False
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
parent
=
kwargs
.
pop
(
"parent"
,
None
)
self
.
user
=
kwargs
.
pop
(
"user"
,
None
)
super
(
TemplateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
...
...
@@ -492,25 +489,9 @@ class TemplateForm(forms.ModelForm):
data
=
self
.
data
.
copy
()
data
[
'owner'
]
=
self
.
user
.
pk
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
:
n
=
self
.
for_networks
.
interface_set
.
values_list
(
"vlan"
,
flat
=
True
)
if
self
.
instance
.
pk
:
n
=
self
.
instance
.
interface_set
.
values_list
(
"vlan"
,
flat
=
True
)
self
.
initial
[
'networks'
]
=
n
if
not
self
.
instance
.
pk
and
len
(
self
.
errors
)
<
1
:
...
...
@@ -561,7 +542,6 @@ class TemplateForm(forms.ModelForm):
helper
=
FormHelper
()
helper
.
layout
=
Layout
(
Field
(
"parent_type"
,
type
=
"hidden"
),
Field
(
"name"
),
Fieldset
(
_
(
"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):
context
.
update
({
'box_title'
:
_
(
'Choose template'
),
'ajax_title'
:
False
,
'template'
:
"dashboard/_template-c
reate-1
.html"
,
'template'
:
"dashboard/_template-c
hoose
.html"
,
'templates'
:
templates
.
all
(),
# TODO acl?
})
return
context
...
...
@@ -871,7 +871,7 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
def
get_template_names
(
self
):
if
self
.
request
.
is_ajax
():
return
[
'dashboard/modal-wrapper.html'
]
pass
else
:
return
[
'dashboard/nojs-wrapper.html'
]
...
...
@@ -880,8 +880,7 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
context
.
update
({
'box_title'
:
_
(
"Create a new base VM"
),
'ajax_title'
:
False
,
'template'
:
"dashboard/_template-create-2.html"
,
'template'
:
"dashboard/_template-create.html"
,
'leases'
:
Lease
.
objects
.
count
()
})
return
context
...
...
@@ -890,12 +889,10 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
if
not
self
.
request
.
user
.
has_perm
(
'vm.create_template'
):
raise
PermissionDenied
()
self
.
parent
=
self
.
request
.
GET
.
get
(
"parent"
)
return
super
(
TemplateCreate
,
self
)
.
get
(
*
args
,
**
kwargs
)
def
get_form_kwargs
(
self
):
kwargs
=
super
(
TemplateCreate
,
self
)
.
get_form_kwargs
()
kwargs
[
'parent'
]
=
getattr
(
self
,
"parent"
,
None
)
kwargs
[
'user'
]
=
self
.
request
.
user
return
kwargs
...
...
@@ -908,37 +905,17 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
else
:
post
=
form
.
cleaned_data
networks
=
self
.
__create_networks
(
post
.
pop
(
"networks"
),
request
.
user
)
post
.
pop
(
"parent"
)
parent_type
=
post
.
pop
(
"parent_type"
)
post
[
'max_ram_size'
]
=
post
[
'ram_size'
]
# if it's not a base vm we need to add disks and deploy it
if
parent_type
!=
"base_vm"
:
template
=
get_object_or_404
(
InstanceTemplate
,
pk
=
parent_type
)
inst
=
Instance
.
create_from_template
(
template
=
template
,
networks
=
networks
,
**
post
)
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
()
post
[
'is_base'
]
=
True
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
())
...
...
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