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
1b86ea7f
authored
Oct 16, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: implement saving VM instance as template
parent
adbea233
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
3 deletions
+45
-3
circle/storage/models.py
+2
-2
circle/vm/models.py
+43
-1
No files found.
circle/storage/models.py
View file @
1b86ea7f
...
@@ -206,7 +206,7 @@ class Disk(TimeStampedModel):
...
@@ -206,7 +206,7 @@ class Disk(TimeStampedModel):
local_tasks
.
restore
.
apply_async
(
args
=
[
self
,
user
],
local_tasks
.
restore
.
apply_async
(
args
=
[
self
,
user
],
queue
=
'localhost.man'
)
queue
=
'localhost.man'
)
def
save_as
(
self
,
name
,
user
=
None
,
task_uuid
=
None
):
def
save_as
(
self
,
user
=
None
,
task_uuid
=
None
):
mapping
=
{
mapping
=
{
'qcow2-snap'
:
(
'qcow2-norm'
,
self
.
base
),
'qcow2-snap'
:
(
'qcow2-norm'
,
self
.
base
),
}
}
...
@@ -226,7 +226,7 @@ class Disk(TimeStampedModel):
...
@@ -226,7 +226,7 @@ class Disk(TimeStampedModel):
new_type
,
new_base
=
mapping
[
self
.
type
]
new_type
,
new_base
=
mapping
[
self
.
type
]
disk
=
Disk
.
objects
.
create
(
base
=
new_base
,
datastore
=
self
.
datastore
,
disk
=
Disk
.
objects
.
create
(
base
=
new_base
,
datastore
=
self
.
datastore
,
filename
=
filename
,
name
=
name
,
filename
=
filename
,
name
=
self
.
name
,
size
=
self
.
size
,
type
=
new_type
)
size
=
self
.
size
,
type
=
new_type
)
queue_name
=
self
.
datastore
.
hostname
+
".storage"
queue_name
=
self
.
datastore
.
hostname
+
".storage"
...
...
circle/vm/models.py
View file @
1b86ea7f
...
@@ -359,9 +359,10 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -359,9 +359,10 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
inst
=
cls
(
**
kwargs
)
inst
=
cls
(
**
kwargs
)
# save instance
# save instance
inst
.
save
()
inst
.
save
()
# create related entities
for
disk
in
template
.
disks
.
all
():
for
disk
in
template
.
disks
.
all
():
inst
.
disks
.
add
(
disk
.
get_exclusive
())
inst
.
disks
.
add
(
disk
.
get_exclusive
())
# create related entities
for
iftmpl
in
template
.
interface_set
.
all
():
for
iftmpl
in
template
.
interface_set
.
all
():
i
=
Interface
.
create_from_template
(
instance
=
inst
,
i
=
Interface
.
create_from_template
(
instance
=
inst
,
template
=
iftmpl
,
template
=
iftmpl
,
...
@@ -689,6 +690,39 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -689,6 +690,39 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
return
local_tasks
.
reboot
.
apply_async
(
args
=
[
self
,
user
],
return
local_tasks
.
reboot
.
apply_async
(
args
=
[
self
,
user
],
queue
=
"localhost.man"
)
queue
=
"localhost.man"
)
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
)
# create template and do additional setup
tmpl
=
InstanceTemplate
(
**
kwargs
)
# save template
tmpl
.
save
()
# create related entities
for
disk
in
self
.
disks
.
all
():
try
:
d
=
disk
.
save_as
()
except
Disk
.
WrongDiskTypeError
:
d
=
disk
tmpl
.
disks
.
add
(
d
)
for
i
in
self
.
interface_set
.
all
():
i
.
save_as_template
(
tmpl
)
return
tmpl
class
InstanceActivity
(
ActivityModel
):
class
InstanceActivity
(
ActivityModel
):
...
@@ -800,3 +834,11 @@ class Interface(Model):
...
@@ -800,3 +834,11 @@ class Interface(Model):
iface
=
cls
(
vlan
=
template
.
vlan
,
host
=
host
,
instance
=
instance
)
iface
=
cls
(
vlan
=
template
.
vlan
,
host
=
host
,
instance
=
instance
)
iface
.
save
()
iface
.
save
()
return
iface
return
iface
def
save_as_template
(
self
,
instance_template
):
"""Create a template based on this interface.
"""
i
=
InterfaceTemplate
(
vlan
=
self
.
vlan
,
managed
=
self
.
host
is
not
None
,
template
=
instance_template
)
i
.
save
()
return
i
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