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
b86972f5
authored
Mar 06, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
instance: added save_as_async and refactored save_as
parent
0e472d2f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
40 deletions
+47
-40
circle/vm/models/instance.py
+47
-40
No files found.
circle/vm/models/instance.py
View file @
b86972f5
...
...
@@ -968,47 +968,54 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
for
net
in
self
.
interface_set
.
all
():
net
.
deploy
()
def
save_as_template
(
self
,
name
,
**
kwargs
):
# prepare parameters
kwargs
.
setdefault
(
'name'
,
name
)
kwargs
.
setdefault
(
'description'
,
self
.
description
)
kwargs
.
setdefault
(
'parent'
,
self
.
template
)
kwargs
.
setdefault
(
'num_cores'
,
self
.
num_cores
)
kwargs
.
setdefault
(
'ram_size'
,
self
.
ram_size
)
kwargs
.
setdefault
(
'max_ram_size'
,
self
.
max_ram_size
)
kwargs
.
setdefault
(
'arch'
,
self
.
arch
)
kwargs
.
setdefault
(
'priority'
,
self
.
priority
)
kwargs
.
setdefault
(
'boot_menu'
,
self
.
boot_menu
)
kwargs
.
setdefault
(
'raw_data'
,
self
.
raw_data
)
kwargs
.
setdefault
(
'lease'
,
self
.
lease
)
kwargs
.
setdefault
(
'access_method'
,
self
.
access_method
)
kwargs
.
setdefault
(
'system'
,
self
.
template
.
system
if
self
.
template
else
None
)
def
__try_save_disk
(
disk
):
try
:
return
disk
.
save_as
()
# can do in parallel
except
Disk
.
WrongDiskTypeError
:
return
disk
# copy disks
disks
=
[
__try_save_disk
(
disk
)
for
disk
in
self
.
disks
.
all
()]
kwargs
.
setdefault
(
'disks'
,
disks
)
def
save_as_template_async
(
self
,
name
,
user
=
None
,
**
kwargs
):
return
local_tasks
.
save_as_template
.
apply_async
(
args
=
[
self
,
name
,
user
,
kwargs
],
queue
=
"localhost.man"
)
# create template and do additional setup
tmpl
=
InstanceTemplate
(
**
kwargs
)
# save template
tmpl
.
save
()
try
:
# create interface templates
for
i
in
self
.
interface_set
.
all
():
i
.
save_as_template
(
tmpl
)
except
:
tmpl
.
delete
()
raise
else
:
return
tmpl
def
save_as_template
(
self
,
name
,
task_uuid
=
None
,
user
=
None
,
timeout
=
300
,
**
kwargs
):
with
instance_activity
(
code_suffix
=
"save_as_template"
,
instance
=
self
,
task_uuid
=
task_uuid
,
user
=
user
):
# prepare parameters
kwargs
.
setdefault
(
'name'
,
name
)
kwargs
.
setdefault
(
'description'
,
self
.
description
)
kwargs
.
setdefault
(
'parent'
,
self
.
template
)
kwargs
.
setdefault
(
'num_cores'
,
self
.
num_cores
)
kwargs
.
setdefault
(
'ram_size'
,
self
.
ram_size
)
kwargs
.
setdefault
(
'max_ram_size'
,
self
.
max_ram_size
)
kwargs
.
setdefault
(
'arch'
,
self
.
arch
)
kwargs
.
setdefault
(
'priority'
,
self
.
priority
)
kwargs
.
setdefault
(
'boot_menu'
,
self
.
boot_menu
)
kwargs
.
setdefault
(
'raw_data'
,
self
.
raw_data
)
kwargs
.
setdefault
(
'lease'
,
self
.
lease
)
kwargs
.
setdefault
(
'access_method'
,
self
.
access_method
)
kwargs
.
setdefault
(
'system'
,
self
.
template
.
system
if
self
.
template
else
None
)
def
__try_save_disk
(
disk
):
try
:
return
disk
.
save_as
()
# can do in parallel
except
Disk
.
WrongDiskTypeError
:
return
disk
# create template and do additional setup
tmpl
=
InstanceTemplate
(
**
kwargs
)
tmpl
.
full_clean
()
logger
.
info
(
"Clean utani save"
)
tmpl
.
save
()
tmpl
.
disks
.
add
(
*
[
__try_save_disk
(
disk
)
for
disk
in
self
.
disks
.
all
()])
# save template
tmpl
.
save
()
try
:
# create interface templates
for
i
in
self
.
interface_set
.
all
():
i
.
save_as_template
(
tmpl
)
except
:
tmpl
.
delete
()
raise
else
:
return
tmpl
def
shutdown_and_save_as_template
(
self
,
name
,
user
=
None
,
task_uuid
=
None
,
**
kwargs
):
...
...
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