From 9633891a8f6dbc4a96eb1ad58834356736133ebb Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 21 Jun 2016 12:26:02 -0400 Subject: net: fix inet value for subnets, don't add interface attributes to alias [copied from curtin revno 390] Apply two separate fixes for configuring bonding with ip aliases. Curtin re-used the interface's inet value for each subnet that might be configured. In the case where the configuration included an ipv4 address after an ipv6 one resulted in emitting 'inet6' for ipv4 address which is not correct. Resolve this issue by calculating the inet value independent of the current status of the iface, using the subnet config instead. When rendering a network_config which includes ip alias interfaces do not emit any attributes, like MTU, or bond/bridge options Including these values is almost always wrong or will result in confusing behavior on the target system. LP: #1588547 --- cloudinit/net/eni.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py index 5f33e177..86d2a830 100644 --- a/cloudinit/net/eni.py +++ b/cloudinit/net/eni.py @@ -68,8 +68,14 @@ def _iface_add_subnet(iface, subnet): # TODO: switch to valid_map for attrs - -def _iface_add_attrs(iface): +def _iface_add_attrs(iface, index): + # If the index is non-zero, this is an alias interface. Alias interfaces + # represent additional interface addresses, and should not have additional + # attributes. (extra attributes here are almost always either incorrect, + # or are applied to the parent interface.) So if this is an alias, stop + # right here. + if index != 0: + return [] content = [] ignore_map = [ 'control', @@ -363,17 +369,21 @@ class Renderer(renderer.Renderer): iface['index'] = index iface['mode'] = subnet['type'] iface['control'] = subnet.get('control', 'auto') + subnet_inet = 'inet' if iface['mode'].endswith('6'): - iface['inet'] += '6' + # This is a request for DHCPv6. + subnet_inet += '6' elif iface['mode'] == 'static' and ":" in subnet['address']: - iface['inet'] += '6' + # This is a static IPv6 address. + subnet_inet += '6' + iface['inet'] = subnet_inet if iface['mode'].startswith('dhcp'): iface['mode'] = 'dhcp' lines = list( _iface_start_entry(iface, index) + _iface_add_subnet(iface, subnet) + - _iface_add_attrs(iface) + _iface_add_attrs(iface, index) ) for route in subnet.get('routes', []): lines.extend(self._render_route(route, indent=" ")) @@ -390,7 +400,7 @@ class Renderer(renderer.Renderer): if 'bond-master' in iface: lines.append("auto {name}".format(**iface)) lines.append("iface {name} {inet} {mode}".format(**iface)) - lines.extend(_iface_add_attrs(iface)) + lines.extend(_iface_add_attrs(iface, index=0)) sections.append(lines) return sections -- cgit v1.2.3