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
7278c20e
authored
Mar 17, 2014
by
Kálmán Viktor
Committed by
Guba Sándor
Mar 18, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: create diskless vm from new template
parent
dba6a664
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
13 deletions
+22
-13
circle/dashboard/forms.py
+2
-9
circle/dashboard/views.py
+20
-4
No files found.
circle/dashboard/forms.py
View file @
7278c20e
...
...
@@ -451,10 +451,6 @@ class TemplateForm(forms.ModelForm):
parent
=
kwargs
.
pop
(
"parent"
,
None
)
self
.
user
=
kwargs
.
pop
(
"user"
,
None
)
super
(
TemplateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'disks'
]
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Disk
.
get_objects_with_level
(
'user'
,
self
.
user
)
.
exclude
(
type
=
"qcow2-snap"
)
)
data
=
self
.
data
.
copy
()
data
[
'owner'
]
=
self
.
user
.
pk
...
...
@@ -469,7 +465,6 @@ class TemplateForm(forms.ModelForm):
for
f
in
fields
:
self
.
initial
[
f
]
=
parent
[
f
]
self
.
initial
[
'lease'
]
=
parent
[
'lease_id'
]
self
.
initial
[
'disks'
]
=
template
.
disks
.
all
()
self
.
initial
[
'parent'
]
=
template
self
.
initial
[
'name'
]
=
"Clone of
%
s"
%
self
.
initial
[
'name'
]
self
.
for_networks
=
template
...
...
@@ -507,8 +502,6 @@ class TemplateForm(forms.ModelForm):
if
commit
:
instance
.
save
()
self
.
instance
.
disks
=
data
[
'disks'
]
# TODO why do I need this
# create and/or delete InterfaceTemplates
networks
=
InterfaceTemplate
.
objects
.
filter
(
template
=
self
.
instance
)
.
values_list
(
"vlan"
,
flat
=
True
)
...
...
@@ -527,6 +520,7 @@ class TemplateForm(forms.ModelForm):
kwargs_raw_data
=
{}
if
not
self
.
user
.
is_superuser
:
kwargs_raw_data
[
'readonly'
]
=
None
helper
=
FormHelper
()
helper
.
layout
=
Layout
(
Field
(
"name"
),
...
...
@@ -586,7 +580,6 @@ class TemplateForm(forms.ModelForm):
),
Fieldset
(
_
(
"External"
),
Field
(
"disks"
),
Field
(
"networks"
),
Field
(
"lease"
),
Field
(
"tags"
),
...
...
@@ -597,7 +590,7 @@ class TemplateForm(forms.ModelForm):
class
Meta
:
model
=
InstanceTemplate
exclude
=
(
'state'
,
)
exclude
=
(
'state'
,
'disks'
,
)
class
LeaseForm
(
forms
.
ModelForm
):
...
...
circle/dashboard/views.py
View file @
7278c20e
...
...
@@ -768,13 +768,29 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
form
=
self
.
form_class
(
request
.
POST
,
user
=
request
.
user
)
if
not
form
.
is_valid
():
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
post
=
form
.
cleaned_data
for
disk
in
post
[
'disks'
]:
if
not
disk
.
has_level
(
request
.
user
,
'user'
):
raise
PermissionDenied
()
else
:
post
=
form
.
cleaned_data
networks
=
self
.
__create_networks
(
post
.
pop
(
"networks"
))
req_traits
=
post
.
pop
(
"req_traits"
)
tags
=
post
.
pop
(
"tags"
)
post
[
'pw'
]
=
User
.
objects
.
make_random_password
()
post
.
pop
(
"parent"
)
inst
=
Instance
.
create
(
params
=
post
,
disks
=
[],
networks
=
networks
,
tags
=
tags
,
req_traits
=
req_traits
)
messages
.
success
(
request
,
_
(
"Your disk has been created, "
"you can now add disks to it!"
))
return
redirect
(
"
%
s#resources"
%
inst
.
get_absolute_url
())
return
super
(
TemplateCreate
,
self
)
.
post
(
self
,
request
,
args
,
kwargs
)
def
__create_networks
(
self
,
vlans
):
networks
=
[]
for
v
in
vlans
:
networks
.
append
(
InterfaceTemplate
(
vlan
=
v
,
managed
=
v
.
managed
))
return
networks
def
get_success_url
(
self
):
return
reverse_lazy
(
"dashboard.views.template-list"
)
...
...
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