← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~jcastets/cloud-init:fix-net-cfg into cloud-init:master

 

Julien Castets has proposed merging ~jcastets/cloud-init:fix-net-cfg into cloud-init:master.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~jcastets/cloud-init/+git/cloud-init/+merge/324114

Add address to config entry generated by _klibc_to_config_entry

If /run/net-<name>.cfg contains an IPV4ADDR or an IPV6ADDR, the config
file generated by _klibc_to_config_entry now contains the "address".

-- 
Your team cloud init development team is requested to review the proposed merge of ~jcastets/cloud-init:fix-net-cfg into cloud-init:master.
diff --git a/cloudinit/net/cmdline.py b/cloudinit/net/cmdline.py
index 7c5d11a..17aa2be 100755
--- a/cloudinit/net/cmdline.py
+++ b/cloudinit/net/cmdline.py
@@ -98,7 +98,11 @@ def _klibc_to_config_entry(content, mac_addrs=None):
 
         # PROTO for ipv4, IPV6PROTO for ipv6
         cur_proto = data.get(pre + 'PROTO', proto)
-        subnet = {'type': cur_proto, 'control': 'manual'}
+        subnet = {
+            'type': cur_proto,
+            'control': 'manual',
+            'address': data[pre + 'ADDR']
+        }
 
         # these fields go right on the subnet
         for key in ('NETMASK', 'BROADCAST', 'GATEWAY'):
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 7c5dc4e..aa96f56 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -53,7 +53,8 @@ DHCP_EXPECTED_1 = {
                  'dns_search': ['foo.com'],
                  'type': 'dhcp',
                  'netmask': '255.255.255.0',
-                 'dns_nameservers': ['192.168.122.1']}],
+                 'dns_nameservers': ['192.168.122.1'],
+                 'address': '192.168.122.89'}],
 }
 
 DHCP6_CONTENT_1 = """
@@ -75,7 +76,8 @@ DHCP6_EXPECTED_1 = {
     'subnets': [{'control': 'manual',
                  'dns_nameservers': ['2001:67c:1562:8010::2:1'],
                  'netmask': '64',
-                 'type': 'dhcp6'}]}
+                 'type': 'dhcp6',
+                 'address': '2001:67c:1562:8010:0:1::'}]}
 
 
 STATIC_CONTENT_1 = """
@@ -100,7 +102,8 @@ STATIC_EXPECTED_1 = {
                  'gateway': '10.0.0.1',
                  'dns_search': ['foo.com'], 'type': 'static',
                  'netmask': '255.255.255.0',
-                 'dns_nameservers': ['10.0.1.1']}],
+                 'dns_nameservers': ['10.0.1.1'],
+                 'address': '10.0.0.2'}],
 }
 
 # Examples (and expected outputs for various renderers).
@@ -1324,7 +1327,8 @@ class TestCmdlineReadKernelConfig(CiTestCase):
               'mac_address': self.macs['eno1'],
               'subnets': [
                   {'dns_nameservers': ['2001:67c:1562:8010::2:1'],
-                   'control': 'manual', 'type': 'dhcp6', 'netmask': '64'}]}]})
+                   'control': 'manual', 'type': 'dhcp6', 'netmask': '64',
+                   'address': '2001:67c:1562:8010:0:1::'}]}]})
 
     def test_ip_cmdline_read_kernel_cmdline_none(self):
         # if there is no ip= or ip6= on cmdline, return value should be None
@@ -1345,7 +1349,8 @@ class TestCmdlineReadKernelConfig(CiTestCase):
         eth0['mac_address'] = self.macs['eth0']
         eth0['subnets'].append(
             {'control': 'manual', 'type': 'dhcp6',
-             'netmask': '64', 'dns_nameservers': ['2001:67c:1562:8010::2:1']})
+             'netmask': '64', 'dns_nameservers': ['2001:67c:1562:8010::2:1'],
+             'address': '2001:67c:1562:8010:0:1::'})
         expected = [eth0]
         self.assertEqual(found['version'], 1)
         self.assertEqual(found['config'], expected)

Follow ups