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
1
Merge Requests
1
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
Romain Courteaud
slapos.core
Commits
57118615
Commit
57118615
authored
Nov 24, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapformat: Introduce IPv6 range for each partition
parent
81c1e8ba
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
235 additions
and
83 deletions
+235
-83
slapos/format.py
slapos/format.py
+174
-75
slapos/tests/test_slapformat.py
slapos/tests/test_slapformat.py
+12
-8
slapos/util.py
slapos/util.py
+49
-0
No files found.
slapos/format.py
View file @
57118615
This diff is collapsed.
Click to expand it.
slapos/tests/test_slapformat.py
View file @
57118615
...
...
@@ -301,7 +301,7 @@ class SlapformatMixin(unittest.TestCase):
raise
ValueError
(
"{} already has logger attached"
.
format
(
self
.
__class__
.
__name__
))
self
.
logger
=
logger
self
.
partition
=
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
None
)
slapos
.
format
.
User
(
'testuser'
),
[],
None
,
None
)
global
USER_LIST
USER_LIST
=
[]
global
GROUP_LIST
...
...
@@ -423,7 +423,8 @@ class TestComputer(SlapformatMixin):
logger
=
self
.
logger
,
name
=
'myinterface'
,
ipv4_local_network
=
'127.0.0.1/16'
),
partition_list
=
[
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
ipv6_range
=
None
,
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
])
global
INTERFACE_DICT
INTERFACE_DICT
[
'myinterface'
]
=
{
...
...
@@ -466,7 +467,8 @@ class TestComputer(SlapformatMixin):
logger
=
self
.
logger
,
name
=
'myinterface'
,
ipv4_local_network
=
'127.0.0.1/16'
),
partition_list
=
[
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
ipv6_range
=
None
,
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
])
global
USER_LIST
USER_LIST
=
[
'testuser'
]
...
...
@@ -517,7 +519,7 @@ class TestComputer(SlapformatMixin):
partition_list
=
[
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
ipv6_range
=
None
,
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
])
global
USER_LIST
USER_LIST
=
[
'testuser'
]
...
...
@@ -577,7 +579,7 @@ class TestComputer(SlapformatMixin):
partition_list
=
[
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
ipv6_range
=
None
,
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
])
global
INTERFACE_DICT
INTERFACE_DICT
[
'myinterface'
]
=
{
...
...
@@ -618,7 +620,7 @@ class TestComputer(SlapformatMixin):
partition_list
=
[
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
ipv6_range
=
None
,
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
])
global
INTERFACE_DICT
INTERFACE_DICT
[
'myinterface'
]
=
{
...
...
@@ -660,7 +662,8 @@ class TestFormatDump(SlapformatMixin):
logger
=
self
.
logger
,
name
=
'myinterface'
,
ipv4_local_network
=
'127.0.0.1/16'
),
partition_list
=
[
slapos
.
format
.
Partition
(
'partition'
,
'part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
'partition'
,
'part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
ipv6_range
=
None
,
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
])
global
USER_LIST
USER_LIST
=
[
'testuser'
]
...
...
@@ -745,7 +748,8 @@ class TestComputerWithCPUSet(SlapformatMixin):
logger
=
self
.
logger
,
name
=
'lo'
,
ipv4_local_network
=
'127.0.0.1/16'
),
partition_list
=
[
slapos
.
format
.
Partition
(
'partition'
,
'/tmp/slapgrid/instance_root/part1'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
None
),
'partition'
,
'/tmp/slapgrid/instance_root/part1'
,
slapos
.
format
.
User
(
'testuser'
),
[],
ipv6_range
=
None
,
tap
=
None
),
],
config
=
{
"manager_list"
:
"cpuset"
,
...
...
slapos/util.py
View file @
57118615
...
...
@@ -205,6 +205,51 @@ def ipv6FromBin(ip, suffix=''):
return
socket
.
inet_ntop
(
socket
.
AF_INET6
,
struct
.
pack
(
'>QQ'
,
int
(
ip
[:
64
],
2
),
int
(
ip
[
64
:],
2
)))
def
getPartitionIpv6Addr
(
ipv6_range
,
partition_index
):
"""
from a IPv6 range in the form
{
'addr' : addr,
'prefixlen' : CIDR
}
returns the IPv6 addr
addr::(partition_index+2) (address 1 is is used by re6st)
"""
addr
=
ipv6_range
[
'addr'
]
prefixlen
=
ipv6_range
[
'prefixlen'
]
prefix
=
binFromIpv6
(
addr
)[:
prefixlen
]
return
dict
(
addr
=
ipv6FromBin
(
prefix
+
bin
(
partition_index
+
2
)[
2
:].
zfill
(
128
-
prefixlen
)),
prefixlen
=
prefixlen
)
def
getIpv6RangeFactory
(
k
,
s
):
def
getIpv6Range
(
ipv6_range
,
partition_index
):
"""
from a IPv6 range in the form
{
'addr' : addr,
'prefixlen' : CIDR
}
returns the IPv6 range
{
'addr' : addr:(k*(2^14) + partition_index+1)
'prefixlen' : CIDR+16
}
"""
addr
=
ipv6_range
[
'addr'
]
prefixlen
=
ipv6_range
[
'prefixlen'
]
prefix
=
binFromIpv6
(
addr
)[:
prefixlen
]
# we generate a subnetwork for the partition
# the subnetwork has 16 bits more than our IPv6 range
# make sure we have at least 2 IPs in the subnetwork
prefixlen
+=
16
if
prefixlen
>=
128
:
raise
ValueError
(
'The IPv6 range has prefixlen {} which is too big for generating IPv6 range for partitions.'
.
format
(
prefixlen
))
return
dict
(
addr
=
ipv6FromBin
(
prefix
+
bin
((
k
<<
14
)
+
partition_index
+
1
)[
2
:].
zfill
(
16
)
+
s
*
(
128
-
prefixlen
)),
prefixlen
=
prefixlen
)
return
getIpv6Range
getPartitionIpv6Range
=
getIpv6RangeFactory
(
1
,
'0'
)
getTapIpv6Range
=
getIpv6RangeFactory
(
2
,
'1'
)
def
lenNetmaskIpv6
(
netmask
):
"""Convert string represented netmask to its integer prefix"""
# Since version 0.10.7 of netifaces, the netmask is something like "ffff::/16",
...
...
@@ -215,6 +260,10 @@ def lenNetmaskIpv6(netmask):
except
ValueError
:
return
netaddr
.
IPNetwork
(
netmask
).
prefixlen
def
netmaskFromLenIPv6
(
netmask_len
):
""" opposite of lenNetmaskIpv6"""
return
ipv6FromBin
(
'1'
*
netmask_len
)
# Used for Python 2-3 compatibility
if
str
is
bytes
:
bytes2str
=
str2bytes
=
lambda
s
:
s
...
...
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