summaryrefslogtreecommitdiff
path: root/cloudinit/net
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/net
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/net')
-rw-r--r--cloudinit/net/network_state.py17
-rw-r--r--cloudinit/net/sysconfig.py6
2 files changed, 16 insertions, 7 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'])