summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2019-11-04 22:11:37 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2019-11-04 22:11:37 +0000
commit02f07b666adc62d70c4f1a98c2ae80cb6629fa9a (patch)
tree5d5172affdee635aae20e8b935eb06dca7194a19 /cloudinit
parent15fa154602f281c9239084d7d20a0999c6b09970 (diff)
downloadvyos-cloud-init-02f07b666adc62d70c4f1a98c2ae80cb6629fa9a.tar.gz
vyos-cloud-init-02f07b666adc62d70c4f1a98c2ae80cb6629fa9a.zip
azure: support matching dhcp route-metrics for dual-stack ipv4 ipv6
Network v2 configuration for Azure will set both dhcp4 and dhcp6 to False by default. When IPv6 privateIpAddresses are present for an interface in Azure's Instance Metadata Service (IMDS), set dhcp6: True and provide a route-metric value that will match the corresponding dhcp4 route-metric. The route-metric value will increase by 100 for each additional interface present to ensure the primary interface has a route to IMDS. Also fix dhcp route-metric rendering for eni and sysconfig distros. LP: #1850308
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/net/network_state.py17
-rw-r--r--cloudinit/net/sysconfig.py6
-rwxr-xr-xcloudinit/sources/DataSourceAzure.py10
3 files changed, 23 insertions, 10 deletions
diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
index ba85c69e..20b7716b 100644
--- a/cloudinit/net/network_state.py
+++ b/cloudinit/net/network_state.py
@@ -22,8 +22,9 @@ NETWORK_STATE_REQUIRED_KEYS = {
1: ['version', 'config', 'network_state'],
}
NETWORK_V2_KEY_FILTER = [
- 'addresses', 'dhcp4', 'dhcp6', 'gateway4', 'gateway6', 'interfaces',
- 'match', 'mtu', 'nameservers', 'renderer', 'set-name', 'wakeonlan'
+ 'addresses', 'dhcp4', 'dhcp4-overrides', 'dhcp6', 'dhcp6-overrides',
+ 'gateway4', 'gateway6', 'interfaces', 'match', 'mtu', 'nameservers',
+ 'renderer', 'set-name', 'wakeonlan'
]
NET_CONFIG_TO_V2 = {
@@ -747,12 +748,20 @@ class NetworkStateInterpreter(object):
def _v2_to_v1_ipcfg(self, cfg):
"""Common ipconfig extraction from v2 to v1 subnets array."""
+ def _add_dhcp_overrides(overrides, subnet):
+ if 'route-metric' in overrides:
+ subnet['metric'] = overrides['route-metric']
+
subnets = []
if cfg.get('dhcp4'):
- subnets.append({'type': 'dhcp4'})
+ subnet = {'type': 'dhcp4'}
+ _add_dhcp_overrides(cfg.get('dhcp4-overrides', {}), subnet)
+ subnets.append(subnet)
if cfg.get('dhcp6'):
+ subnet = {'type': 'dhcp6'}
self.use_ipv6 = True
- subnets.append({'type': 'dhcp6'})
+ _add_dhcp_overrides(cfg.get('dhcp6-overrides', {}), subnet)
+ subnets.append(subnet)
gateway4 = None
gateway6 = None
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
index 6717d924..fe0c67ca 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -395,6 +395,9 @@ class Renderer(renderer.Renderer):
ipv6_index = -1
for i, subnet in enumerate(subnets, start=len(iface_cfg.children)):
subnet_type = subnet.get('type')
+ # metric may apply to both dhcp and static config
+ if 'metric' in subnet:
+ iface_cfg['METRIC'] = subnet['metric']
if subnet_type in ['dhcp', 'dhcp4', 'dhcp6']:
if has_default_route and iface_cfg['BOOTPROTO'] != 'none':
iface_cfg['DHCLIENT_SET_DEFAULT_ROUTE'] = False
@@ -426,9 +429,6 @@ class Renderer(renderer.Renderer):
else:
iface_cfg['GATEWAY'] = subnet['gateway']
- if 'metric' in subnet:
- iface_cfg['METRIC'] = subnet['metric']
-
if 'dns_search' in subnet:
iface_cfg['DOMAIN'] = ' '.join(subnet['dns_search'])
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index cdf49d36..44cca210 100755
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -1322,7 +1322,8 @@ def parse_network_config(imds_metadata):
network_metadata = imds_metadata['network']
for idx, intf in enumerate(network_metadata['interface']):
nicname = 'eth{idx}'.format(idx=idx)
- dev_config = {}
+ dev_config = {'dhcp4': False, 'dhcp6': False}
+ dhcp_override = {'route-metric': (idx + 1) * 100}
for addr4 in intf['ipv4']['ipAddress']:
privateIpv4 = addr4['privateIpAddress']
if privateIpv4:
@@ -1340,12 +1341,15 @@ def parse_network_config(imds_metadata):
# non-primary interfaces should have a higher
# route-metric (cost) so default routes prefer
# primary nic due to lower route-metric value
- dev_config['dhcp4-overrides'] = {
- 'route-metric': (idx + 1) * 100}
+ dev_config['dhcp4-overrides'] = dhcp_override
for addr6 in intf['ipv6']['ipAddress']:
privateIpv6 = addr6['privateIpAddress']
if privateIpv6:
dev_config['dhcp6'] = True
+ # non-primary interfaces should have a higher
+ # route-metric (cost) so default routes prefer
+ # primary nic due to lower route-metric value
+ dev_config['dhcp6-overrides'] = dhcp_override
break
if dev_config:
mac = ':'.join(re.findall(r'..', intf['macAddress']))