From 70dbccbbb27f7cc3f2decd692d41403f0d745c62 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 1 May 2020 16:56:56 -0400 Subject: DataSourceEc2: use metadata's NIC ordering to determine route-metrics (#342) We want to set route-metrics such that NICs are configured with the priority that they are given in the network metadata that we receive from the IMDS. (This switches away from using MAC ordering.) This also required the following test changes: * reverse the sort order of the MACs in test data (so that they would trigger the bug being fixed) * fix up the key names in `NIC2_MD` (which were under_scored instead of dash-separated) * use a full interface dict (rather than a minimal one) for `TestConvertEc2MetadataNetworkConfig` LP: #1876312 --- cloudinit/sources/DataSourceEc2.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py index 4203c3a6..355b4e2f 100644 --- a/cloudinit/sources/DataSourceEc2.py +++ b/cloudinit/sources/DataSourceEc2.py @@ -762,13 +762,14 @@ def convert_ec2_metadata_network_config( netcfg['ethernets'][nic_name] = dev_config return netcfg # Apply network config for all nics and any secondary IPv4/v6 addresses - nic_idx = 1 for mac, nic_name in sorted(macs_to_nics.items()): nic_metadata = macs_metadata.get(mac) if not nic_metadata: continue # Not a physical nic represented in metadata + # device-number is zero-indexed, we want it 1-indexed for the + # multiplication on the following line + nic_idx = int(nic_metadata['device-number']) + 1 dhcp_override = {'route-metric': nic_idx * 100} - nic_idx += 1 dev_config = {'dhcp4': True, 'dhcp4-overrides': dhcp_override, 'dhcp6': False, 'match': {'macaddress': mac.lower()}, -- cgit v1.2.3