aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config
diff options
context:
space:
mode:
Diffstat (limited to 'os_net_config')
-rw-r--r--os_net_config/impl_eni.py13
-rw-r--r--os_net_config/objects.py1
-rw-r--r--os_net_config/tests/test_impl_eni.py30
3 files changed, 39 insertions, 5 deletions
diff --git a/os_net_config/impl_eni.py b/os_net_config/impl_eni.py
index 7eb69f3..68d91ef 100644
--- a/os_net_config/impl_eni.py
+++ b/os_net_config/impl_eni.py
@@ -44,22 +44,27 @@ class ENINetConfig(os_net_config.NetConfig):
self.bridges = {}
logger.info('ENI net config provider created.')
- def _add_common(self, interface, static_addr=None):
+ def _add_common(self, interface, static_addr=None, ip_version=4):
ovs_extra = []
data = ""
address_data = ""
if static_addr:
address_data += " address %s\n" % static_addr.ip
- address_data += " netmask %s\n" % static_addr.netmask
+ if ip_version == 6:
+ address_data += " netmask %s\n" % static_addr.prefixlen
+ else:
+ address_data += " netmask %s\n" % static_addr.netmask
else:
v4_addresses = interface.v4_addresses()
if v4_addresses:
- data += self._add_common(interface, v4_addresses[0])
+ for v4_address in v4_addresses:
+ data += self._add_common(interface, v4_address)
v6_addresses = interface.v6_addresses()
if v6_addresses:
- data += self._add_common(interface, v6_addresses[0])
+ for v6_address in v6_addresses:
+ data += self._add_common(interface, v6_address, 6)
if data:
return data
diff --git a/os_net_config/objects.py b/os_net_config/objects.py
index a8869ef..dd8489e 100644
--- a/os_net_config/objects.py
+++ b/os_net_config/objects.py
@@ -121,6 +121,7 @@ class Address(object):
ip_nw = netaddr.IPNetwork(self.ip_netmask)
self.ip = str(ip_nw.ip)
self.netmask = str(ip_nw.netmask)
+ self.prefixlen = ip_nw.prefixlen
self.version = ip_nw.version
@staticmethod
diff --git a/os_net_config/tests/test_impl_eni.py b/os_net_config/tests/test_impl_eni.py
index fe49c3e..e0e009d 100644
--- a/os_net_config/tests/test_impl_eni.py
+++ b/os_net_config/tests/test_impl_eni.py
@@ -32,11 +32,23 @@ _V4_IFACE_STATIC_IP = _AUTO + """iface eth0 inet static
netmask 255.255.255.0
"""
+_V4_IFACE_STATIC_IP_MULTIPLE = (_V4_IFACE_STATIC_IP + _AUTO +
+ """iface eth0 inet static
+ address 10.0.0.2
+ netmask 255.0.0.0
+""")
+
_V6_IFACE_STATIC_IP = _AUTO + """iface eth0 inet6 static
address fe80::2677:3ff:fe7d:4c
- netmask ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
+ netmask 128
"""
+_V6_IFACE_STATIC_IP_MULTIPLE = (_V6_IFACE_STATIC_IP + _AUTO +
+ """iface eth0 inet6 static
+ address 2001:abcd::2
+ netmask 64
+""")
+
_IFACE_DHCP = _AUTO + "iface eth0 inet dhcp\n"
_OVS_PORT_BASE = _AUTO + "allow-br0 eth0\n"
@@ -112,12 +124,28 @@ class TestENINetConfig(base.TestCase):
self.provider.add_interface(interface)
self.assertEqual(_V4_IFACE_STATIC_IP, self.get_interface_config())
+ def test_add_interface_with_v4_multiple(self):
+ v4_addresses = [objects.Address('192.168.1.2/24'),
+ objects.Address('10.0.0.2/8')]
+ interface = self._default_interface(v4_addresses)
+ self.provider.add_interface(interface)
+ self.assertEqual(_V4_IFACE_STATIC_IP_MULTIPLE,
+ self.get_interface_config())
+
def test_add_interface_with_v6(self):
v6_addr = objects.Address('fe80::2677:3ff:fe7d:4c')
interface = self._default_interface([v6_addr])
self.provider.add_interface(interface)
self.assertEqual(_V6_IFACE_STATIC_IP, self.get_interface_config())
+ def test_add_interface_with_v6_multiple(self):
+ v6_addresses = [objects.Address('fe80::2677:3ff:fe7d:4c'),
+ objects.Address('2001:abcd::2/64')]
+ interface = self._default_interface(v6_addresses)
+ self.provider.add_interface(interface)
+ self.assertEqual(_V6_IFACE_STATIC_IP_MULTIPLE,
+ self.get_interface_config())
+
def test_add_interface_dhcp(self):
interface = self._default_interface()
interface.use_dhcp = True