Add host only network option

The host only network function was adding a global network address and a
host only network address which would flip flop should networkd or the
nspawn-macvlan service be restarted. This change makes resolves the flip
flopping and adds an option to enable this functionality when required.

Change-Id: Ia856723580d345d01e0df06ac41adb9cb7fcdb24
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2018-09-30 00:56:25 -05:00
parent 9c755bc166
commit e873bda7d6
No known key found for this signature in database
GPG Key ID: 9443251A787B9FB3
2 changed files with 21 additions and 17 deletions

View File

@ -35,6 +35,8 @@ nspawn_networks:
macvlan_mode: bridge
# Optional | set the routed interface
routed_interface: mv-nspawn0
# Optional | Force address space to be scoped to only the host
host_only: true
# Primary interface used for host to container communications. In the event that
# the underlying system is running a condensed network stack a route will be

View File

@ -103,7 +103,7 @@
{% if hostvars[inventory_hostname][key.split('_')[0] + '_cidr'] is defined and (value.address is undefined) %}
{% set net_cidr = hostvars[inventory_hostname][key.split('_')[0] + '_cidr'] %}
{% set _ = start_commands.append('-/sbin/ip route add ' + net_cidr + ' dev ' + (value.routed_interface | default(nspawn_primary_interface)) + ' metric 100 proto kernel scope link table local') %}
{% elif (value.address is defined) and ((interface_data['ipv4'] | default({'address': none}))['address'] != value.address) %}
{% elif (value.address is defined) and ((interface_data['ipv4'] | default({'address': none}))['address'] != value.address) and ((value.host_only | default(false)) | bool) %}
{% set _ = start_commands.append('-/sbin/ip address add ' + value.address + '/' + (value.netmask | default('32')) + ' dev ' + mv_interface + ' scope host') %}
{%- endif %}
{%- endif %}
@ -144,6 +144,7 @@
{% for _, value in (nspawn_networks | combine(container_extra_networks)).items() %}
{% set netname = value.interface | default('mv-' + value.bridge.split('br-')[-1]) %}
{% set _network = {'interface': netname} %}
{% if (not (value.host_only | default(false)) | bool) %}
{% if netname not in seen_networks %}
{% set _ = seen_networks.append(netname) %}
{% if value.address is defined %}
@ -163,6 +164,7 @@
{% set _ = _network.__setitem__('config_overrides', {'Network': {'IPForward': 'yes', 'IPMasquerade': 'yes'}, 'Link': {'ARP': 'yes'}}) %}
{% set _ = _networks.append(_network) %}
{% endif %}
{% endif %}
{% endfor %}
{{ _networks | sort(attribute='interface') }}
tags: