Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
12 deletions
+21
-12
circle/dashboard/forms.py
+2
-9
circle/dashboard/views.py
+19
-3
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
)
else
:
post
=
form
.
cleaned_data
for
disk
in
post
[
'disks'
]:
if
not
disk
.
has_level
(
request
.
user
,
'user'
):
raise
PermissionDenied
()
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