diff options
author | James Falcon <TheRealFalcon@users.noreply.github.com> | 2021-03-08 14:09:47 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-08 14:09:47 -0600 |
commit | 9bd19645a61586b82e86db6f518dd05c3363b17f (patch) | |
tree | 419181fe1aab057b312d727e260d8efc4b641ee5 /cloudinit | |
parent | 6fe99157876f83ae2249d44c1b456a24cc70e258 (diff) | |
download | vyos-cloud-init-9bd19645a61586b82e86db6f518dd05c3363b17f.tar.gz vyos-cloud-init-9bd19645a61586b82e86db6f518dd05c3363b17f.zip |
Fix requiring device-number on EC2 derivatives (#836)
#342 (70dbccbb) introduced the ability to determine route-metrics based on
the `device-number` provided by the EC2 IMDS. Not all datasources that
subclass EC2 will have this attribute, so allow the old behavior if
`device-number` is not present.
LP: #1917875
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/sources/DataSourceEc2.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py index 1930a509..a2105dc7 100644 --- a/cloudinit/sources/DataSourceEc2.py +++ b/cloudinit/sources/DataSourceEc2.py @@ -765,13 +765,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 = 0 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 + nic_idx = int(nic_metadata.get('device-number', nic_idx)) + 1 dhcp_override = {'route-metric': nic_idx * 100} dev_config = {'dhcp4': True, 'dhcp4-overrides': dhcp_override, 'dhcp6': False, |