← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~chad.smith/cloud-init:ec2-dhcp-local-ipv4 into cloud-init:master

 

Chad Smith has proposed merging ~chad.smith/cloud-init:ec2-dhcp-local-ipv4 into cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/332954

EC2: Honor IPv4  local-only addresses on VPC instances

VPC instances have the option to specific internal only IPv4 addresses when
IPv6 public addresses are configured. Allow Ec2Datasource to enable dhcp4 on 
interfaces if only local-ipv4s is configured on an instance.


LP: #1728152
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:ec2-dhcp-local-ipv4 into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py
index 41367a8..67e32a3 100644
--- a/cloudinit/sources/DataSourceEc2.py
+++ b/cloudinit/sources/DataSourceEc2.py
@@ -480,7 +480,7 @@ def convert_ec2_metadata_network_config(network_md, macs_to_nics=None):
             continue  # Not a physical nic represented in metadata
         nic_cfg = {'type': 'physical', 'name': nic_name, 'subnets': []}
         nic_cfg['mac_address'] = mac
-        if nic_metadata.get('public-ipv4s'):
+        if nic_metadata.get('public-ipv4s') or nic_metadata.get('local-ipv4s'):
             nic_cfg['subnets'].append({'type': 'dhcp4'})
         if nic_metadata.get('ipv6s'):
             nic_cfg['subnets'].append({'type': 'dhcp6'})
diff --git a/tests/unittests/test_datasource/test_ec2.py b/tests/unittests/test_datasource/test_ec2.py
index a7301db..eba38ae 100644
--- a/tests/unittests/test_datasource/test_ec2.py
+++ b/tests/unittests/test_datasource/test_ec2.py
@@ -389,6 +389,24 @@ class TestConvertEc2MetadataNetworkConfig(test_helpers.CiTestCase):
             ec2.convert_ec2_metadata_network_config(
                 network_metadata_ipv6, macs_to_nics))
 
+    def test_convert_ec2_metadata_network_config_handles_local_v4_and_v6(self):
+        """When dhcp6 is public and dhcp4 is set to local enable both."""
+        macs_to_nics = {self.mac1: 'eth9'}
+        network_metadata_both = copy.deepcopy(self.network_metadata)
+        nic1_metadata = (
+            network_metadata_both['interfaces']['macs'][self.mac1])
+        nic1_metadata['ipv6s'] = '2620:0:1009:fd00:e442:c88d:c04d:dc85/64'
+        nic1_metadata.pop('public-ipv4s')
+        nic1_metadata['local-ipv4s'] = '10.0.0.42'  # Local ipv4 only on vpc
+        expected = {'version': 1, 'config': [
+            {'mac_address': self.mac1, 'type': 'physical',
+             'name': 'eth9',
+             'subnets': [{'type': 'dhcp4'}, {'type': 'dhcp6'}]}]}
+        self.assertEqual(
+            expected,
+            ec2.convert_ec2_metadata_network_config(
+                network_metadata_both, macs_to_nics))
+
     def test_convert_ec2_metadata_network_config_handles_dhcp4_and_dhcp6(self):
         """Config both dhcp4 and dhcp6 when both vpc-ipv6 and ipv4 exists."""
         macs_to_nics = {self.mac1: 'eth9'}

Follow ups