diff options
author | Tomoki Sekiyama <tomoki.sekiyama@hds.com> | 2015-08-17 21:37:08 +0000 |
---|---|---|
committer | Tomoki Sekiyama <tomoki.sekiyama@hds.com> | 2015-08-17 17:47:11 -0400 |
commit | eb39ca3268c805d5d57bdb224ab16c5bfb19857e (patch) | |
tree | 626f02d07ccd0497cc8064335bb4dbedb65fd574 | |
parent | 0b130b6b3b4a9e0768e99b1496d2852f2ca47bb7 (diff) |
Support multiple addresses assignment with eni
Currently only the first IPv4/v6 address is assigned to a NIC
even if multiple addresses are specified in config file.
With this change, eni implementation can configure multiple
IPv4/v6 addresses for a NIC.
Also this fixes IPv6 netmask format, which currently causes
an error on ifup.
Change-Id: I0a38d376bece8af297bddede594962fd3a193d09
-rw-r--r-- | os_net_config/impl_eni.py | 13 | ||||
-rw-r--r-- | os_net_config/objects.py | 1 | ||||
-rw-r--r-- | os_net_config/tests/test_impl_eni.py | 30 |
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 8899164..6d0921f 100644 --- a/os_net_config/objects.py +++ b/os_net_config/objects.py @@ -117,6 +117,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 |