Commit f2798c25 authored by Nicolas Wavrant's avatar Nicolas Wavrant Committed by Thomas Gambier

format: support newer versions of netifaces

fix the following crash in command ```slapos node boot``` in slapos package version "1.5.2+1.0.125+3-1" :

# slapos node boot
[BOOT] Checking if 'lo' has IPv6...
[BOOT] Invoking ipv6 ping to
[BOOT] IPv6 network reachable...
[BOOT] Invoking slapos node format...
2019-11-20 09:43:52 slapos[5511] WARNING Creating new computer data with id 'COMP-3121'
2019-11-20 09:43:52 slapos[5511] INFO Adding 10 new partitions
2019-11-20 09:43:52 slapos[5511] INFO Updating computer
2019-11-20 09:43:52 slapos[5511] ERROR u'ffff:ffff:ffff:ffff:ffff:ffff::/96' is not a valid IPv6 address string!
Traceback (most recent call last):
  File "/opt/slapos/eggs/slapos.core-1.5.2-py2.7.egg/slapos/cli/", line 300, in run_subcommand
    result =
  File "/opt/slapos/eggs/slapos.core-1.5.2-py2.7.egg/slapos/cli/", line 50, in run
    return self.take_action(parsed_args)
  File "/opt/slapos/eggs/slapos.core-1.5.2-py2.7.egg/slapos/cli/", line 128, in take_action
  File "/opt/slapos/eggs/slapos.core-1.5.2-py2.7.egg/slapos/", line 1401, in do_format
  File "/opt/slapos/eggs/slapos.core-1.5.2-py2.7.egg/slapos/", line 665, in format
  File "/opt/slapos/eggs/slapos.core-1.5.2-py2.7.egg/slapos/", line 1227, in addIPv6Address
    if self._addSystemAddress(addr, netmask, tap=tap):
  File "/opt/slapos/eggs/slapos.core-1.5.2-py2.7.egg/slapos/", line 1058, in _addSystemAddress
    address_string = '%s/%s' % (address, netmaskToPrefixIPv6(netmask))
  File "/opt/slapos/eggs/slapos.core-1.5.2-py2.7.egg/slapos/", line 179, in netmaskToPrefixIPv6
  File "/opt/slapos/eggs/netaddr-0.7.19-py2.7.egg/netaddr/strategy/", line 142, in str_to_int
    raise AddrFormatError('%r is not a valid IPv6 address string!' % addr)
AddrFormatError: u'ffff:ffff:ffff:ffff:ffff:ffff::/96' is not a valid IPv6 address string!
[BOOT] [ERROR] Fail to format, try again in 15 seconds...
[BOOT] Invoking slapos node format...

/reviewed-on !157
parent fd60c32e
......@@ -172,11 +172,15 @@ def netmaskToPrefixIPv4(netmask):
return netaddr.strategy.ipv4.netmask_to_prefix[
def netmaskToPrefixIPv6(netmask):
"""Convert string represented netmask to its integer prefix"""
return netaddr.strategy.ipv6.netmask_to_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.
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment