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
Roque
slapos.core
Commits
7ed9848e
Commit
7ed9848e
authored
Nov 28, 2019
by
Thomas Gambier
🚴🏼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format: support newer versions of netifaces
follow up of
f2798c25
it was still crashing when "create_tap = True"
parent
126c08e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
15 deletions
+12
-15
slapos/format.py
slapos/format.py
+4
-14
slapos/util.py
slapos/util.py
+8
-1
No files found.
slapos/format.py
View file @
7ed9848e
...
...
@@ -172,16 +172,6 @@ def netmaskToPrefixIPv4(netmask):
return
netaddr
.
strategy
.
ipv4
.
netmask_to_prefix
[
netaddr
.
strategy
.
ipv4
.
str_to_int
(
netmask
)]
def
netmaskToPrefixIPv6
(
netmask
):
"""Convert string represented netmask to its integer prefix"""
# Since version 0.10.7 of netifaces, the netmask is something like "ffff::/16",
# (it used to be "ffff::"). For old versions of netifaces, interpret the netmask
# as an address and return its netmask, but for newer versions returns the prefixlen.
try
:
return
netaddr
.
IPAddress
(
netmask
).
netmask_bits
()
except
ValueError
:
return
netaddr
.
IPNetwork
(
netmask
).
prefixlen
def
getIfaceAddressIPv4
(
iface
):
"""return dict containing ipv4 address netmask, network and broadcast address
of interface"""
...
...
@@ -498,7 +488,7 @@ class Computer(object):
try
:
for
address
in
partition
.
address_list
:
try
:
netmask
=
netmaskToPrefixIP
v6
(
address
[
'netmask'
])
netmask
=
lenNetmaskIp
v6
(
address
[
'netmask'
])
except
:
continue
callAndRead
([
'ip'
,
'addr'
,
'add'
,
...
...
@@ -1059,7 +1049,7 @@ class Interface(object):
"""
if
ipv6
:
address_string
=
'%s/%s'
%
(
address
,
netmaskToPrefixIP
v6
(
netmask
))
address_string
=
'%s/%s'
%
(
address
,
lenNetmaskIp
v6
(
netmask
))
af
=
socket
.
AF_INET6
interface_name
=
self
.
ipv6_interface
or
self
.
name
else
:
...
...
@@ -1188,9 +1178,9 @@ class Interface(object):
(
tap
and
lenNetmaskIpv6
(
netmask
)
==
128
):
# same netmask, so there is a chance to add good one
interface_network
=
netaddr
.
ip
.
IPNetwork
(
'%s/%s'
%
(
address_dict
[
'addr'
],
netmaskToPrefixIP
v6
(
address_dict
[
'netmask'
])))
lenNetmaskIp
v6
(
address_dict
[
'netmask'
])))
requested_network
=
netaddr
.
ip
.
IPNetwork
(
'%s/%s'
%
(
addr
,
netmaskToPrefixIP
v6
(
address_dict
[
'netmask'
])))
lenNetmaskIp
v6
(
address_dict
[
'netmask'
])))
if
interface_network
.
network
==
requested_network
.
network
:
# same network, try to add
if
self
.
_addSystemAddress
(
addr
,
netmask
,
tap
=
tap
):
...
...
slapos/util.py
View file @
7ed9848e
...
...
@@ -135,7 +135,14 @@ def ipv6FromBin(ip, suffix=''):
struct
.
pack
(
'>QQ'
,
int
(
ip
[:
64
],
2
),
int
(
ip
[
64
:],
2
)))
def
lenNetmaskIpv6
(
netmask
):
return
len
(
binFromIpv6
(
netmask
).
rstrip
(
'0'
))
"""Convert string represented netmask to its integer prefix"""
# Since version 0.10.7 of netifaces, the netmask is something like "ffff::/16",
# (it used to be "ffff::"). For old versions of netifaces, interpret the netmask
# as an address and return its netmask, but for newer versions returns the prefixlen.
try
:
return
netaddr
.
IPAddress
(
netmask
).
netmask_bits
()
except
ValueError
:
return
netaddr
.
IPNetwork
(
netmask
).
prefixlen
# Used for Python 2-3 compatibility
if
str
is
bytes
:
...
...
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