summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os_net_config/impl_ifcfg.py15
-rw-r--r--os_net_config/tests/test_impl_ifcfg.py28
2 files changed, 37 insertions, 6 deletions
diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py
index 2c36590..0deb61e 100644
--- a/os_net_config/impl_ifcfg.py
+++ b/os_net_config/impl_ifcfg.py
@@ -170,19 +170,24 @@ class IfcfgNetConfig(os_net_config.NetConfig):
if base_opt.use_dhcpv6:
data += "DHCPV6C=yes\n"
elif base_opt.addresses:
- #TODO(dprince): Do we want to support multiple addresses?
v4_addresses = base_opt.v4_addresses()
if v4_addresses:
- first_v4 = v4_addresses[0]
data += "BOOTPROTO=static\n"
- data += "IPADDR=%s\n" % first_v4.ip
- data += "NETMASK=%s\n" % first_v4.netmask
+ for i, address in enumerate(v4_addresses):
+ num = '%s' % i if i else ''
+ data += "IPADDR%s=%s\n" % (num, address.ip)
+ data += "NETMASK%s=%s\n" % (num, address.netmask)
v6_addresses = base_opt.v6_addresses()
if v6_addresses:
first_v6 = v6_addresses[0]
data += "IPV6_AUTOCONF=no\n"
- data += "IPV6ADDR=%s\n" % first_v6.ip
+ data += "IPV6ADDR=%s\n" % first_v6.ip_netmask
+ if len(v6_addresses) > 1:
+ secondaries_v6 = " ".join(map(lambda a: a.ip_netmask,
+ v6_addresses[1:]))
+ data += "IPV6ADDR_SECONDARIES=\"%s\"\n" % secondaries_v6
+
if base_opt.hwaddr:
data += "HWADDR=%s\n" % base_opt.hwaddr
if ovs_extra:
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py
index b9c0a2d..db61795 100644
--- a/os_net_config/tests/test_impl_ifcfg.py
+++ b/os_net_config/tests/test_impl_ifcfg.py
@@ -41,11 +41,20 @@ NETMASK=255.255.255.0
_V4_IFCFG_MAPPED = _V4_IFCFG.replace('em1', 'nic1') + "HWADDR=a1:b2:c3:d4:e5\n"
+_V4_IFCFG_MULTIPLE = _V4_IFCFG + """IPADDR1=192.168.1.3
+NETMASK1=255.255.255.255
+IPADDR2=10.0.0.2
+NETMASK2=255.0.0.0
+"""
+
_V6_IFCFG = _BASE_IFCFG + """IPV6INIT=yes
IPV6_AUTOCONF=no
-IPV6ADDR=2001:abc:a::
+IPV6ADDR=2001:abc:a::/64
"""
+_V6_IFCFG_MULTIPLE = (_V6_IFCFG + "IPV6ADDR_SECONDARIES=\"2001:abc:b::1/64 " +
+ "2001:abc:c::2/96\"\n")
+
_OVS_IFCFG = _BASE_IFCFG + "DEVICETYPE=ovs\nBOOTPROTO=none\n"
@@ -203,6 +212,15 @@ class TestIfcfgNetConfig(base.TestCase):
self.assertEqual(_V4_IFCFG, self.get_interface_config())
self.assertEqual('', self.get_route_config())
+ def test_add_interface_with_v4_multiple(self):
+ addresses = [objects.Address('192.168.1.2/24'),
+ objects.Address('192.168.1.3/32'),
+ objects.Address('10.0.0.2/8')]
+ interface = objects.Interface('em1', addresses=addresses)
+ self.provider.add_interface(interface)
+ self.assertEqual(_V4_IFCFG_MULTIPLE, self.get_interface_config())
+ self.assertEqual('', self.get_route_config())
+
def test_add_interface_map_persisted(self):
def test_interface_mac(name):
macs = {'em1': 'a1:b2:c3:d4:e5'}
@@ -226,6 +244,14 @@ class TestIfcfgNetConfig(base.TestCase):
self.provider.add_interface(interface)
self.assertEqual(_V6_IFCFG, self.get_interface_config())
+ def test_add_interface_with_v6_multiple(self):
+ addresses = [objects.Address('2001:abc:a::/64'),
+ objects.Address('2001:abc:b::1/64'),
+ objects.Address('2001:abc:c::2/96')]
+ interface = objects.Interface('em1', addresses=addresses)
+ self.provider.add_interface(interface)
+ self.assertEqual(_V6_IFCFG_MULTIPLE, self.get_interface_config())
+
def test_network_with_routes(self):
route1 = objects.Route('192.168.1.1', default=True)
route2 = objects.Route('192.168.1.1', '172.19.0.0/24')