summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceAzure.py
diff options
context:
space:
mode:
authorThomas Stringer <git@trstringer.com>2020-12-16 12:35:43 -0800
committerGitHub <noreply@github.com>2020-12-16 15:35:43 -0500
commit913818553a8db236e20751c81dd0e2a27124617c (patch)
tree76917da5ed094f4d57bd5fcd4813cd0be9d2ad99 /cloudinit/sources/DataSourceAzure.py
parente5f745954b273fbf1f917f034669c15720aa0f89 (diff)
downloadvyos-cloud-init-913818553a8db236e20751c81dd0e2a27124617c.tar.gz
vyos-cloud-init-913818553a8db236e20751c81dd0e2a27124617c.zip
Azure: only generate config for NICs with addresses (#709)
Prevent network interfaces without IP addresses from being added to the generated network configuration.
Diffstat (limited to 'cloudinit/sources/DataSourceAzure.py')
-rwxr-xr-xcloudinit/sources/DataSourceAzure.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index 04ff2131..bedf8ea0 100755
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -1969,6 +1969,7 @@ def _generate_network_config_from_imds_metadata(imds_metadata) -> dict:
netconfig = {'version': 2, 'ethernets': {}}
network_metadata = imds_metadata['network']
for idx, intf in enumerate(network_metadata['interface']):
+ has_ip_address = False
# First IPv4 and/or IPv6 address will be obtained via DHCP.
# Any additional IPs of each type will be set as static
# addresses.
@@ -1978,6 +1979,11 @@ def _generate_network_config_from_imds_metadata(imds_metadata) -> dict:
'dhcp6': False}
for addr_type in ('ipv4', 'ipv6'):
addresses = intf.get(addr_type, {}).get('ipAddress', [])
+ # If there are no available IP addresses, then we don't
+ # want to add this interface to the generated config.
+ if not addresses:
+ continue
+ has_ip_address = True
if addr_type == 'ipv4':
default_prefix = '24'
else:
@@ -1998,7 +2004,7 @@ def _generate_network_config_from_imds_metadata(imds_metadata) -> dict:
dev_config['addresses'].append(
'{ip}/{prefix}'.format(
ip=privateIp, prefix=netPrefix))
- if dev_config:
+ if dev_config and has_ip_address:
mac = ':'.join(re.findall(r'..', intf['macAddress']))
dev_config.update({
'match': {'macaddress': mac.lower()},