summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-10-01 18:29:53 +0000
committerGerrit Code Review <review@openstack.org>2018-10-01 18:29:53 +0000
commit02923183f3ca89a4a36e2f27f2aa4aa7d1ce75e4 (patch)
treef168d4d82d0b087a0dd9ce3fd28604947f367771
parent05bf17b157b35b46c356d95aa0fe332b4b82d3bb (diff)
parente873bda7d62ca3582226cdcfad6fe39add05f574 (diff)
Merge "Add host only network option"
-rw-r--r--defaults/main.yml2
-rw-r--r--tasks/nspawn_networking.yml36
2 files changed, 21 insertions, 17 deletions
diff --git a/defaults/main.yml b/defaults/main.yml
index 0c94dc8..7ab00f0 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -35,6 +35,8 @@ nspawn_networks:
35 macvlan_mode: bridge 35 macvlan_mode: bridge
36 # Optional | set the routed interface 36 # Optional | set the routed interface
37 routed_interface: mv-nspawn0 37 routed_interface: mv-nspawn0
38 # Optional | Force address space to be scoped to only the host
39 host_only: true
38 40
39# Primary interface used for host to container communications. In the event that 41# Primary interface used for host to container communications. In the event that
40# the underlying system is running a condensed network stack a route will be 42# the underlying system is running a condensed network stack a route will be
diff --git a/tasks/nspawn_networking.yml b/tasks/nspawn_networking.yml
index cf3371d..b555db3 100644
--- a/tasks/nspawn_networking.yml
+++ b/tasks/nspawn_networking.yml
@@ -103,7 +103,7 @@
103 {% if hostvars[inventory_hostname][key.split('_')[0] + '_cidr'] is defined and (value.address is undefined) %} 103 {% if hostvars[inventory_hostname][key.split('_')[0] + '_cidr'] is defined and (value.address is undefined) %}
104 {% set net_cidr = hostvars[inventory_hostname][key.split('_')[0] + '_cidr'] %} 104 {% set net_cidr = hostvars[inventory_hostname][key.split('_')[0] + '_cidr'] %}
105 {% 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') %} 105 {% 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') %}
106 {% elif (value.address is defined) and ((interface_data['ipv4'] | default({'address': none}))['address'] != value.address) %} 106 {% elif (value.address is defined) and ((interface_data['ipv4'] | default({'address': none}))['address'] != value.address) and ((value.host_only | default(false)) | bool) %}
107 {% set _ = start_commands.append('-/sbin/ip address add ' + value.address + '/' + (value.netmask | default('32')) + ' dev ' + mv_interface + ' scope host') %} 107 {% set _ = start_commands.append('-/sbin/ip address add ' + value.address + '/' + (value.netmask | default('32')) + ' dev ' + mv_interface + ' scope host') %}
108 {%- endif %} 108 {%- endif %}
109 {%- endif %} 109 {%- endif %}
@@ -144,24 +144,26 @@
144 {% for _, value in (nspawn_networks | combine(container_extra_networks)).items() %} 144 {% for _, value in (nspawn_networks | combine(container_extra_networks)).items() %}
145 {% set netname = value.interface | default('mv-' + value.bridge.split('br-')[-1]) %} 145 {% set netname = value.interface | default('mv-' + value.bridge.split('br-')[-1]) %}
146 {% set _network = {'interface': netname} %} 146 {% set _network = {'interface': netname} %}
147 {% if netname not in seen_networks %} 147 {% if (not (value.host_only | default(false)) | bool) %}
148 {% set _ = seen_networks.append(netname) %} 148 {% if netname not in seen_networks %}
149 {% if value.address is defined %} 149 {% set _ = seen_networks.append(netname) %}
150 {% set _ = _network.__setitem__('address', value.address) %} 150 {% if value.address is defined %}
151 {% if (value.netmask is defined) and (_network.address != 'dhcp') %} 151 {% set _ = _network.__setitem__('address', value.address) %}
152 {% set _ = _network.__setitem__('netmask', value.netmask) %} 152 {% if (value.netmask is defined) and (_network.address != 'dhcp') %}
153 {% set prefix = (value.address + '/' + value.netmask) | ipaddr('prefix') %} 153 {% set _ = _network.__setitem__('netmask', value.netmask) %}
154 {% set _ = _network.__setitem__('address', [value.address + '/' + prefix | string]) %} 154 {% set prefix = (value.address + '/' + value.netmask) | ipaddr('prefix') %}
155 {% set _ = _network.__setitem__('address', [value.address + '/' + prefix | string]) %}
156 {% endif %}
155 {% endif %} 157 {% endif %}
158 {% set _ = _network.__setitem__('usedns', (value.usedns | default(true) | bool) | ternary('yes', 'no')) %}
159 {% set _ = _network.__setitem__('static_routes', value.static_routes | default([])) %}
160 {% if value.gateway is defined %}
161 {% set _ = _network.__setitem__('gateway', value.gateway) %}
162 {% endif %}
163 {% set _ = _network.__setitem__('mtu', value.mtu | default(1500 | string)) %}
164 {% set _ = _network.__setitem__('config_overrides', {'Network': {'IPForward': 'yes', 'IPMasquerade': 'yes'}, 'Link': {'ARP': 'yes'}}) %}
165 {% set _ = _networks.append(_network) %}
156 {% endif %} 166 {% endif %}
157 {% set _ = _network.__setitem__('usedns', (value.usedns | default(true) | bool) | ternary('yes', 'no')) %}
158 {% set _ = _network.__setitem__('static_routes', value.static_routes | default([])) %}
159 {% if value.gateway is defined %}
160 {% set _ = _network.__setitem__('gateway', value.gateway) %}
161 {% endif %}
162 {% set _ = _network.__setitem__('mtu', value.mtu | default(1500 | string)) %}
163 {% set _ = _network.__setitem__('config_overrides', {'Network': {'IPForward': 'yes', 'IPMasquerade': 'yes'}, 'Link': {'ARP': 'yes'}}) %}
164 {% set _ = _networks.append(_network) %}
165 {% endif %} 167 {% endif %}
166 {% endfor %} 168 {% endfor %}
167 {{ _networks | sort(attribute='interface') }} 169 {{ _networks | sort(attribute='interface') }}