Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
58a22093
authored
Dec 18, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: mass VM creation feature
closes #25
parent
74e7fb9a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
circle/vm/models/instance.py
+21
-2
No files found.
circle/vm/models/instance.py
View file @
58a22093
...
@@ -241,6 +241,20 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -241,6 +241,20 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
Can also specify parameters as keyword arguments which should override
Can also specify parameters as keyword arguments which should override
template settings.
template settings.
"""
"""
insts
=
cls
.
mass_create_from_template
(
template
,
owner
,
disks
=
disks
,
networks
=
networks
,
tags
=
tags
,
req_traits
=
req_traits
,
**
kwargs
)
return
insts
[
0
]
@classmethod
def
mass_create_from_template
(
cls
,
template
,
owner
,
amount
=
1
,
disks
=
None
,
networks
=
None
,
req_traits
=
None
,
tags
=
None
,
**
kwargs
):
"""Mass-create new instances based on an InstanceTemplate.
Can also specify parameters as keyword arguments which should override
template settings.
"""
disks
=
template
.
disks
.
all
()
if
disks
is
None
else
disks
disks
=
template
.
disks
.
all
()
if
disks
is
None
else
disks
networks
=
(
template
.
interface_set
.
all
()
if
networks
is
None
networks
=
(
template
.
interface_set
.
all
()
if
networks
is
None
...
@@ -259,6 +273,11 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -259,6 +273,11 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
params
.
update
([(
f
,
getattr
(
template
,
f
))
for
f
in
common_fields
])
params
.
update
([(
f
,
getattr
(
template
,
f
))
for
f
in
common_fields
])
params
.
update
(
kwargs
)
# override defaults w/ user supplied values
params
.
update
(
kwargs
)
# override defaults w/ user supplied values
return
[
cls
.
__create_instance
(
params
,
disks
,
networks
,
req_traits
,
tags
)
for
i
in
xrange
(
amount
)]
@classmethod
def
__create_instance
(
cls
,
params
,
disks
,
networks
,
req_traits
,
tags
):
# create instance and do additional setup
# create instance and do additional setup
inst
=
cls
(
**
params
)
inst
=
cls
(
**
params
)
...
@@ -270,8 +289,8 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -270,8 +289,8 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
inst
.
disks
.
add
(
*
[
disk
.
get_exclusive
()
for
disk
in
disks
])
inst
.
disks
.
add
(
*
[
disk
.
get_exclusive
()
for
disk
in
disks
])
for
net
in
networks
:
for
net
in
networks
:
i
=
Interface
.
create
(
instance
=
inst
,
vlan
=
net
.
vlan
,
owner
=
owner
,
i
=
Interface
.
create
(
instance
=
inst
,
vlan
=
net
.
vlan
,
managed
=
net
.
managed
)
owner
=
inst
.
owner
,
managed
=
net
.
managed
)
if
i
.
host
:
if
i
.
host
:
i
.
host
.
enable_net
()
i
.
host
.
enable_net
()
port
,
proto
=
ACCESS_PROTOCOLS
[
i
.
instance
.
access_method
][
1
:
3
]
port
,
proto
=
ACCESS_PROTOCOLS
[
i
.
instance
.
access_method
][
1
:
3
]
...
...
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