Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hardik Juneja
slapos.core
Commits
eb76d6cc
Commit
eb76d6cc
authored
Mar 19, 2015
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not regenerate tap ip address it exists in slapos.xml
parent
8f6917f9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
15 deletions
+22
-15
slapos/format.py
slapos/format.py
+22
-15
No files found.
slapos/format.py
View file @
eb76d6cc
...
@@ -176,7 +176,7 @@ def getIPv4SubnetAddressRange(ip_address, mask, size):
...
@@ -176,7 +176,7 @@ def getIPv4SubnetAddressRange(ip_address, mask, size):
host ip address, then return list of ip address in the subnet"""
host ip address, then return list of ip address in the subnet"""
ip
=
netaddr
.
IPNetwork
(
'%s/%s'
%
(
ip_address
,
mask
))
ip
=
netaddr
.
IPNetwork
(
'%s/%s'
%
(
ip_address
,
mask
))
# Delete network and default ip_address from the list
# Delete network and default ip_address from the list
ip_list
=
[
x
for
x
in
list
(
ip
)
ip_list
=
[
x
for
x
in
sorted
(
list
(
ip
))
if
str
(
x
)
!=
ip_address
and
x
.
value
!=
ip
.
cidr
.
network
.
value
]
if
str
(
x
)
!=
ip_address
and
x
.
value
!=
ip
.
cidr
.
network
.
value
]
if
len
(
ip_list
)
<
size
:
if
len
(
ip_list
)
<
size
:
raise
ValueError
(
'Could not create %s tap interfaces from address %s.'
%
(
raise
ValueError
(
'Could not create %s tap interfaces from address %s.'
%
(
...
@@ -383,6 +383,10 @@ class Computer(object):
...
@@ -383,6 +383,10 @@ class Computer(object):
if
partition_dict
[
'tap'
]:
if
partition_dict
[
'tap'
]:
tap
=
Tap
(
partition_dict
[
'tap'
][
'name'
])
tap
=
Tap
(
partition_dict
[
'tap'
][
'name'
])
tap
.
ipv4_addr
=
partition_dict
[
'tap'
].
get
(
'ipv4_addr'
,
''
)
tap
.
ipv4_netmask
=
partition_dict
[
'tap'
].
get
(
'ipv4_netmask'
,
''
)
tap
.
ipv4_gateway
=
partition_dict
[
'tap'
].
get
(
'ipv4_gateway'
,
''
)
tap
.
ipv4_network
=
partition_dict
[
'tap'
].
get
(
'ipv4_network'
,
''
)
else
:
else
:
tap
=
Tap
(
partition_dict
[
'reference'
])
tap
=
Tap
(
partition_dict
[
'reference'
])
...
@@ -517,10 +521,13 @@ class Computer(object):
...
@@ -517,10 +521,13 @@ class Computer(object):
self
.
interface
.
addTap
(
partition
.
tap
)
self
.
interface
.
addTap
(
partition
.
tap
)
else
:
else
:
next_ipv4_addr
=
'%s'
%
tap_address_list
.
pop
(
0
)
next_ipv4_addr
=
'%s'
%
tap_address_list
.
pop
(
0
)
partition
.
tap
.
addRoutes
(
next_ipv4_addr
,
if
not
partition
.
tap
.
ipv4_addr
:
gateway_addr_dict
[
'netmask'
],
# define new ipv4 address for this tap
gateway_addr_dict
[
'addr'
],
partition
.
tap
.
ipv4_addr
=
next_ipv4_addr
gateway_addr_dict
[
'network'
])
partition
.
tap
.
ipv4_netmask
=
gateway_addr_dict
[
'netmask'
]
partition
.
tap
.
ipv4_gateway
=
gateway_addr_dict
[
'addr'
]
partition
.
tap
.
ipv4_network
=
gateway_addr_dict
[
'network'
]
partition
.
tap
.
createRoutes
()
# Reconstructing partition's directory
# Reconstructing partition's directory
partition
.
createPath
(
alter_user
)
partition
.
createPath
(
alter_user
)
...
@@ -786,19 +793,19 @@ class Tap(object):
...
@@ -786,19 +793,19 @@ class Tap(object):
if
attach_to_tap
:
if
attach_to_tap
:
threading
.
Thread
(
target
=
self
.
attach
).
start
()
threading
.
Thread
(
target
=
self
.
attach
).
start
()
def
addRoutes
(
self
,
ipv4
,
netmask
,
gateway
,
network
):
def
createRoutes
(
self
):
"""
"""
Configure ipv4 route to reach this interface from local network
Configure ipv4 route to reach this interface from local network
"""
"""
self
.
ipv4_addr
=
ipv4
if
self
.
ipv4_addr
:
self
.
ipv4_netmask
=
netmask
self
.
ipv4_gateway
=
gateway
self
.
ipv4_network
=
network
# Check if this route exits
# Check if this route exits
code
,
result
=
callAndRead
([
'ip'
,
'route'
,
'show'
,
ipv4
])
code
,
result
=
callAndRead
([
'ip'
,
'route'
,
'show'
,
self
.
ipv4_addr
])
if
code
==
0
and
ipv4
in
result
and
self
.
name
in
result
:
if
code
==
0
and
self
.
ipv4_addr
in
result
and
self
.
name
in
result
:
return
return
callAndRead
([
'route'
,
'add'
,
'-host'
,
ipv4
,
'dev'
,
self
.
name
])
callAndRead
([
'route'
,
'add'
,
'-host'
,
self
.
ipv4_addr
,
'dev'
,
self
.
name
])
else
:
raise
ValueError
(
"%s should not be empty. No ipv4 address assigned to %s"
%
(
self
.
ipv4_addr
,
self
.
name
))
class
Interface
(
object
):
class
Interface
(
object
):
"""Represent a network interface on the system"""
"""Represent a network interface on the system"""
...
...
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