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
b81b0298
authored
Nov 06, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: add option to override network interfaces when creating VM from template
parent
5182afaa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
13 deletions
+16
-13
circle/vm/models.py
+16
-13
No files found.
circle/vm/models.py
View file @
b81b0298
...
@@ -341,7 +341,8 @@ class Instance(VirtualMachineDescModel, TimeStampedModel):
...
@@ -341,7 +341,8 @@ class Instance(VirtualMachineDescModel, TimeStampedModel):
return
" "
.
join
([
s
for
s
in
parts
if
s
!=
""
])
return
" "
.
join
([
s
for
s
in
parts
if
s
!=
""
])
@classmethod
@classmethod
def
create_from_template
(
cls
,
template
,
owner
,
disks
=
None
,
**
kwargs
):
def
create_from_template
(
cls
,
template
,
owner
,
disks
=
None
,
networks
=
None
,
**
kwargs
):
"""Create a new instance based on an InstanceTemplate.
"""Create a new instance based on an InstanceTemplate.
Can also specify parameters as keyword arguments which should override
Can also specify parameters as keyword arguments which should override
...
@@ -349,6 +350,9 @@ class Instance(VirtualMachineDescModel, TimeStampedModel):
...
@@ -349,6 +350,9 @@ class Instance(VirtualMachineDescModel, TimeStampedModel):
"""
"""
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
else
networks
)
# prepare parameters
# prepare parameters
kwargs
[
'template'
]
=
template
kwargs
[
'template'
]
=
template
kwargs
[
'owner'
]
=
owner
kwargs
[
'owner'
]
=
owner
...
@@ -366,10 +370,10 @@ class Instance(VirtualMachineDescModel, TimeStampedModel):
...
@@ -366,10 +370,10 @@ class Instance(VirtualMachineDescModel, TimeStampedModel):
for
disk
in
disks
:
for
disk
in
disks
:
inst
.
disks
.
add
(
disk
.
get_exclusive
())
inst
.
disks
.
add
(
disk
.
get_exclusive
())
for
iftmpl
in
template
.
interface_set
.
all
()
:
for
net
in
networks
:
i
=
Interface
.
create
_from_template
(
instance
=
inst
,
i
=
Interface
.
create
(
instance
=
inst
,
vlan
=
net
.
vlan
,
owner
=
owner
,
template
=
iftmpl
,
managed
=
net
.
managed
)
owner
=
owner
)
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
]
...
@@ -829,18 +833,17 @@ class Interface(Model):
...
@@ -829,18 +833,17 @@ class Interface(Model):
queue
=
self
.
instance
.
get_remote_queue_name
(
'net'
))
queue
=
self
.
instance
.
get_remote_queue_name
(
'net'
))
@classmethod
@classmethod
def
create_from_template
(
cls
,
instance
,
template
,
owner
=
None
):
def
create
(
cls
,
instance
,
vlan
,
managed
,
owner
=
None
):
"""Create a new interface for an instance based on an
"""Create a new interface for a VM instance to the specified VLAN.
InterfaceTemplate.
"""
"""
if
template
.
managed
:
if
managed
:
host
=
Host
()
host
=
Host
()
host
.
vlan
=
template
.
vlan
host
.
vlan
=
vlan
# TODO change Host's mac field's type to EUI in firewall
# TODO change Host's mac field's type to EUI in firewall
host
.
mac
=
str
(
cls
.
generate_mac
(
instance
,
template
.
vlan
))
host
.
mac
=
str
(
cls
.
generate_mac
(
instance
,
vlan
))
host
.
hostname
=
instance
.
vm_name
host
.
hostname
=
instance
.
vm_name
# Get adresses from firewall
# Get adresses from firewall
addresses
=
template
.
vlan
.
get_new_address
()
addresses
=
vlan
.
get_new_address
()
host
.
ipv4
=
addresses
[
'ipv4'
]
host
.
ipv4
=
addresses
[
'ipv4'
]
host
.
ipv6
=
addresses
[
'ipv6'
]
host
.
ipv6
=
addresses
[
'ipv6'
]
host
.
owner
=
owner
host
.
owner
=
owner
...
@@ -848,7 +851,7 @@ class Interface(Model):
...
@@ -848,7 +851,7 @@ class Interface(Model):
else
:
else
:
host
=
None
host
=
None
iface
=
cls
(
vlan
=
template
.
vlan
,
host
=
host
,
instance
=
instance
)
iface
=
cls
(
vlan
=
vlan
,
host
=
host
,
instance
=
instance
)
iface
.
save
()
iface
.
save
()
return
iface
return
iface
...
...
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