summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorDaniel Watkins <oddbloke@ubuntu.com>2020-05-01 16:56:56 -0400
committerGitHub <noreply@github.com>2020-05-01 16:56:56 -0400
commit70dbccbbb27f7cc3f2decd692d41403f0d745c62 (patch)
tree57c20f40bc8d225bb9532db9c0d6a95c6109fcac /cloudinit
parent25698b144e3b6548ffc29ab14bed1882242b161a (diff)
downloadvyos-cloud-init-70dbccbbb27f7cc3f2decd692d41403f0d745c62.tar.gz
vyos-cloud-init-70dbccbbb27f7cc3f2decd692d41403f0d745c62.zip
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
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/sources/DataSourceEc2.py5
1 files changed, 3 insertions, 2 deletions
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()},