blob: 8c26b2b1994268dfa84b56554abd3b28b80f1076 [file] [log] [blame]
Sean M. Collins2a242512016-05-03 09:03:09 -04001#!/bin/bash
2# Subnet IP version
3IP_VERSION=${IP_VERSION:-"4+6"}
4# Validate IP_VERSION
5if [[ $IP_VERSION != "4" ]] && [[ $IP_VERSION != "6" ]] && [[ $IP_VERSION != "4+6" ]]; then
6 die $LINENO "IP_VERSION must be either 4, 6, or 4+6"
7fi
8# Specify if the initial private and external networks should be created
9NEUTRON_CREATE_INITIAL_NETWORKS=${NEUTRON_CREATE_INITIAL_NETWORKS:-True}
10
11## Provider Network Information
12PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
13IPV6_PROVIDER_SUBNET_NAME=${IPV6_PROVIDER_SUBNET_NAME:-"provider_net_v6"}
14IPV6_PROVIDER_FIXED_RANGE=${IPV6_PROVIDER_FIXED_RANGE:-}
15IPV6_PROVIDER_NETWORK_GATEWAY=${IPV6_PROVIDER_NETWORK_GATEWAY:-}
16
17PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex}
Ihar Hrachyshka7b5c7dc2016-07-15 20:17:13 +020018PUBLIC_BRIDGE_MTU=${PUBLIC_BRIDGE_MTU:-1500}
Sean M. Collins2a242512016-05-03 09:03:09 -040019
Kevin Benton1554ade2016-07-22 09:40:19 -070020# If Q_ASSIGN_GATEWAY_TO_PUBLIC_BRIDGE=True, assign the gateway IP of the public
21# subnet to the public bridge interface even if Q_USE_PROVIDERNET_FOR_PUBLIC is
22# used.
23Q_ASSIGN_GATEWAY_TO_PUBLIC_BRIDGE=${Q_ASSIGN_GATEWAY_TO_PUBLIC_BRIDGE:-True}
24
Sean M. Collins2a242512016-05-03 09:03:09 -040025# If Q_USE_PUBLIC_VETH=True, create and use a veth pair instead of
26# PUBLIC_BRIDGE. This is intended to be used with
27# Q_USE_PROVIDERNET_FOR_PUBLIC=True.
28Q_USE_PUBLIC_VETH=${Q_USE_PUBLIC_VETH:-False}
29Q_PUBLIC_VETH_EX=${Q_PUBLIC_VETH_EX:-veth-pub-ex}
30Q_PUBLIC_VETH_INT=${Q_PUBLIC_VETH_INT:-veth-pub-int}
31
vsaienkod8942212016-05-13 12:51:30 +030032# The next variable is configured by plugin
Sean M. Collins2a242512016-05-03 09:03:09 -040033# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
34#
Sean M. Collins2a242512016-05-03 09:03:09 -040035# L3 routers exist per tenant
36Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-True}
37
38
39# Use flat providernet for public network
40#
41# If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network
42# for external interface of neutron l3-agent. In that case,
43# PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value
44# used for the network. In case of ofagent, you should add the
45# corresponding entry to your OFAGENT_PHYSICAL_INTERFACE_MAPPINGS.
46# For openvswitch agent, you should add the corresponding entry to
47# your OVS_BRIDGE_MAPPINGS.
48#
49# eg. (ofagent)
50# Q_USE_PROVIDERNET_FOR_PUBLIC=True
51# Q_USE_PUBLIC_VETH=True
52# PUBLIC_PHYSICAL_NETWORK=public
53# OFAGENT_PHYSICAL_INTERFACE_MAPPINGS=public:veth-pub-int
54#
55# eg. (openvswitch agent)
56# Q_USE_PROVIDERNET_FOR_PUBLIC=True
57# PUBLIC_PHYSICAL_NETWORK=public
58# OVS_BRIDGE_MAPPINGS=public:br-ex
Kevin Benton1554ade2016-07-22 09:40:19 -070059Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-True}
Sean M. Collins2a242512016-05-03 09:03:09 -040060PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public}
61
62# Generate 40-bit IPv6 Global ID to comply with RFC 4193
63IPV6_GLOBAL_ID=`uuidgen | sed s/-//g | cut -c 23- | sed -e "s/\(..\)\(....\)\(....\)/\1:\2:\3/"`
64
65# IPv6 gateway and subnet defaults, in case they are not customized in localrc
66IPV6_RA_MODE=${IPV6_RA_MODE:-slaac}
67IPV6_ADDRESS_MODE=${IPV6_ADDRESS_MODE:-slaac}
68IPV6_PUBLIC_SUBNET_NAME=${IPV6_PUBLIC_SUBNET_NAME:-ipv6-public-subnet}
69IPV6_PRIVATE_SUBNET_NAME=${IPV6_PRIVATE_SUBNET_NAME:-ipv6-private-subnet}
70FIXED_RANGE_V6=${FIXED_RANGE_V6:-fd$IPV6_GLOBAL_ID::/64}
Brian Haley31813e92016-08-22 15:39:22 -040071IPV6_PRIVATE_NETWORK_GATEWAY=${IPV6_PRIVATE_NETWORK_GATEWAY:-}
Sean M. Collins2a242512016-05-03 09:03:09 -040072IPV6_PUBLIC_RANGE=${IPV6_PUBLIC_RANGE:-2001:db8::/64}
73IPV6_PUBLIC_NETWORK_GATEWAY=${IPV6_PUBLIC_NETWORK_GATEWAY:-2001:db8::2}
74IPV6_ROUTER_GW_IP=${IPV6_ROUTER_GW_IP:-2001:db8::1}
75
76# Gateway and subnet defaults, in case they are not customized in localrc
Brian Haley31813e92016-08-22 15:39:22 -040077NETWORK_GATEWAY=${NETWORK_GATEWAY:-}
78PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-}
Sean M. Collins2a242512016-05-03 09:03:09 -040079PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
80PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
81
82# Subnetpool defaults
83SUBNETPOOL_NAME=${SUBNETPOOL_NAME:-"shared-default-subnetpool"}
84
85SUBNETPOOL_PREFIX_V4=${SUBNETPOOL_PREFIX_V4:-10.0.0.0/8}
86SUBNETPOOL_PREFIX_V6=${SUBNETPOOL_PREFIX_V6:-2001:db8:8000::/48}
87
88SUBNETPOOL_SIZE_V4=${SUBNETPOOL_SIZE_V4:-24}
89SUBNETPOOL_SIZE_V6=${SUBNETPOOL_SIZE_V6:-64}
90
Henry Gessau734f1442016-09-17 19:28:53 -040091default_v4_route_devs=$(ip -4 route | grep ^default | awk '{print $5}')
92die_if_not_set $LINENO default_v4_route_devs "Failure retrieving default IPv4 route devices"
93
94default_v6_route_devs=$(ip -6 route | grep ^default | awk '{print $5}')
Monty Taylorc12d1d92016-08-23 19:07:57 -050095
Sean M. Collins2a242512016-05-03 09:03:09 -040096function _determine_config_l3 {
Angus Leesa1c70f22016-05-31 14:43:14 +100097 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
Sean M. Collins2a242512016-05-03 09:03:09 -040098 echo "$opts"
99}
100
101function _configure_neutron_l3_agent {
Sean M. Collins2a242512016-05-03 09:03:09 -0400102
103 cp $NEUTRON_DIR/etc/l3_agent.ini.sample $Q_L3_CONF_FILE
104
Sean M. Collins2a242512016-05-03 09:03:09 -0400105 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean M. Collinsa2ed0552016-05-11 15:35:10 -0400106 iniset $Q_L3_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Sean M. Collins2a242512016-05-03 09:03:09 -0400107 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Sean M. Collinsa2ed0552016-05-11 15:35:10 -0400108 iniset $Q_L3_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Sean M. Collins2a242512016-05-03 09:03:09 -0400109 fi
110
111 _neutron_setup_interface_driver $Q_L3_CONF_FILE
112
Stephen Finucane24e29f22016-06-15 14:31:51 +0100113 neutron_plugin_configure_l3_agent $Q_L3_CONF_FILE
Sean M. Collins2a242512016-05-03 09:03:09 -0400114
Sean Dague6a008fa2016-08-03 15:09:01 -0400115 # If we've given a PUBLIC_INTERFACE to take over, then we assume
116 # that we can own the whole thing, and privot it into the OVS
117 # bridge. If we are not, we're probably on a single interface
118 # machine, and we just setup NAT so that fixed guests can get out.
119 if [[ -n "$PUBLIC_INTERFACE" ]]; then
120 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
Sean M. Collins2a242512016-05-03 09:03:09 -0400121
Sean Dague6a008fa2016-08-03 15:09:01 -0400122 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
123 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
124 fi
125 else
Henry Gessau734f1442016-09-17 19:28:53 -0400126 for d in $default_v4_route_devs; do
127 sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE
128 done
Sean M. Collins2a242512016-05-03 09:03:09 -0400129 fi
130}
131
132# Explicitly set router id in l3 agent configuration
133function _neutron_set_router_id {
134 if [[ "$Q_L3_ROUTER_PER_TENANT" == "False" ]]; then
135 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
136 fi
137}
138
139# Get ext_gw_interface depending on value of Q_USE_PUBLIC_VETH
140function _neutron_get_ext_gw_interface {
141 if [[ "$Q_USE_PUBLIC_VETH" == "True" ]]; then
142 echo $Q_PUBLIC_VETH_EX
143 else
144 # Disable in-band as we are going to use local port
145 # to communicate with VMs
146 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
147 other_config:disable-in-band=true
148 echo $PUBLIC_BRIDGE
149 fi
150}
151
152function create_neutron_initial_network {
Gary Kotton88f85582016-08-14 06:55:42 -0700153 if ! is_service_enabled q-svc && ! is_service_enabled neutron-api; then
154 echo "Controller services not enabled. No networks configured!"
155 return
156 fi
157 if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" == "False" ]]; then
158 echo "Network creation disabled!"
159 return
160 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400161 local project_id
162 project_id=$(openstack project list | grep " demo " | get_field 1)
163 die_if_not_set $LINENO project_id "Failure retrieving project_id for demo"
164
165 # Allow drivers that need to create an initial network to do so here
166 if type -p neutron_plugin_create_initial_network_profile > /dev/null; then
167 neutron_plugin_create_initial_network_profile $PHYSICAL_NETWORK
168 fi
169
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000170 if is_networking_extension_supported "auto-allocated-topology"; then
171 if [[ "$IP_VERSION" =~ 4.* ]]; then
172 SUBNETPOOL_V4_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnetpool-create $SUBNETPOOL_NAME --default-prefixlen $SUBNETPOOL_SIZE_V4 --pool-prefix $SUBNETPOOL_PREFIX_V4 --shared --is-default=True | grep ' id ' | get_field 2)
173 fi
174 if [[ "$IP_VERSION" =~ .*6 ]]; then
175 SUBNETPOOL_V6_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnetpool-create $SUBNETPOOL_NAME --default-prefixlen $SUBNETPOOL_SIZE_V6 --pool-prefix $SUBNETPOOL_PREFIX_V6 --shared --is-default=True | grep ' id ' | get_field 2)
176 fi
177 fi
178
Sean M. Collins2a242512016-05-03 09:03:09 -0400179 if is_provider_network; then
180 die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
181 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specify the PROVIDER_NETWORK_TYPE"
182 NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create $PHYSICAL_NETWORK --tenant_id $project_id --provider:network_type $PROVIDER_NETWORK_TYPE --provider:physical_network "$PHYSICAL_NETWORK" ${SEGMENTATION_ID:+--provider:segmentation_id $SEGMENTATION_ID} --shared | grep ' id ' | get_field 2)
183 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $project_id"
184
185 if [[ "$IP_VERSION" =~ 4.* ]]; then
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000186 if [ -z $SUBNETPOOL_V4_ID ]; then
187 fixed_range_v4=$FIXED_RANGE
188 fi
189 SUBNET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create --tenant_id $project_id --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --name $PROVIDER_SUBNET_NAME --gateway $NETWORK_GATEWAY ${SUBNETPOOL_V4_ID:+--subnetpool $SUBNETPOOL_V4_ID} $NET_ID $fixed_range_v4 | grep ' id ' | get_field 2)
Sean M. Collins2a242512016-05-03 09:03:09 -0400190 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $PROVIDER_SUBNET_NAME $project_id"
191 fi
192
Sean M. Collinse34ec992016-06-07 12:36:50 -0400193 if [[ "$IP_VERSION" =~ .*6 ]]; then
194 die_if_not_set $LINENO IPV6_PROVIDER_FIXED_RANGE "IPV6_PROVIDER_FIXED_RANGE has not been set, but Q_USE_PROVIDERNET_FOR_PUBLIC is true and IP_VERSION includes 6"
195 die_if_not_set $LINENO IPV6_PROVIDER_NETWORK_GATEWAY "IPV6_PROVIDER_NETWORK_GATEWAY has not been set, but Q_USE_PROVIDERNET_FOR_PUBLIC is true and IP_VERSION includes 6"
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000196 if [ -z $SUBNETPOOL_V6_ID ]; then
197 fixed_range_v6=$IPV6_PROVIDER_FIXED_RANGE
198 fi
199 SUBNET_V6_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create --tenant_id $project_id --ip_version 6 --ipv6-address-mode $IPV6_ADDRESS_MODE --gateway $IPV6_PROVIDER_NETWORK_GATEWAY --name $IPV6_PROVIDER_SUBNET_NAME ${SUBNETPOOL_V6_ID:+--subnetpool $SUBNETPOOL_V6_ID} $NET_ID $fixed_range_v6 | grep 'id' | get_field 2)
Sean M. Collins2a242512016-05-03 09:03:09 -0400200 die_if_not_set $LINENO SUBNET_V6_ID "Failure creating SUBNET_V6_ID for $IPV6_PROVIDER_SUBNET_NAME $project_id"
201 fi
202
203 if [[ $Q_AGENT == "openvswitch" ]]; then
204 sudo ip link set $OVS_PHYSICAL_BRIDGE up
205 sudo ip link set br-int up
206 sudo ip link set $PUBLIC_INTERFACE up
207 fi
208 else
209 NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create --tenant-id $project_id "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
210 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PRIVATE_NETWORK_NAME $project_id"
211
212 if [[ "$IP_VERSION" =~ 4.* ]]; then
213 # Create IPv4 private subnet
214 SUBNET_ID=$(_neutron_create_private_subnet_v4 $project_id)
215 fi
216
217 if [[ "$IP_VERSION" =~ .*6 ]]; then
218 # Create IPv6 private subnet
219 IPV6_SUBNET_ID=$(_neutron_create_private_subnet_v6 $project_id)
220 fi
221 fi
222
Sean M. Collinsc35110e2016-05-18 10:38:51 -0400223 if is_networking_extension_supported "router" && is_networking_extension_supported "external-net"; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400224 # Create a router, and add the private subnet as one of its interfaces
225 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
226 # create a tenant-owned router.
227 ROUTER_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-create --tenant-id $project_id $Q_ROUTER_NAME | grep ' id ' | get_field 2)
228 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $project_id $Q_ROUTER_NAME"
229 else
230 # Plugin only supports creating a single router, which should be admin owned.
231 ROUTER_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
232 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
233 fi
234
Sean M. Collins2a242512016-05-03 09:03:09 -0400235 EXTERNAL_NETWORK_FLAGS="--router:external"
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000236 if is_networking_extension_supported "auto-allocated-topology"; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400237 EXTERNAL_NETWORK_FLAGS="$EXTERNAL_NETWORK_FLAGS --is-default"
Sean M. Collins2a242512016-05-03 09:03:09 -0400238 fi
239 # Create an external network, and a subnet. Configure the external network as router gw
240 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
241 EXT_NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create "$PUBLIC_NETWORK_NAME" -- $EXTERNAL_NETWORK_FLAGS --provider:network_type=flat --provider:physical_network=${PUBLIC_PHYSICAL_NETWORK} | grep ' id ' | get_field 2)
242 else
243 EXT_NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create "$PUBLIC_NETWORK_NAME" -- $EXTERNAL_NETWORK_FLAGS | grep ' id ' | get_field 2)
244 fi
245 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
246
247 if [[ "$IP_VERSION" =~ 4.* ]]; then
248 # Configure router for IPv4 public access
249 _neutron_configure_router_v4
250 fi
251
252 if [[ "$IP_VERSION" =~ .*6 ]]; then
253 # Configure router for IPv6 public access
254 _neutron_configure_router_v6
255 fi
256 fi
257}
258
259# Create private IPv4 subnet
260function _neutron_create_private_subnet_v4 {
261 local project_id=$1
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000262 if [ -z $SUBNETPOOL_V4_ID ]; then
263 fixed_range_v4=$FIXED_RANGE
264 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400265 local subnet_params="--tenant-id $project_id "
266 subnet_params+="--ip_version 4 "
Brian Haley31813e92016-08-22 15:39:22 -0400267 if [[ -n "$NETWORK_GATEWAY" ]]; then
268 subnet_params+="--gateway $NETWORK_GATEWAY "
269 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400270 subnet_params+="--name $PRIVATE_SUBNET_NAME "
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000271 subnet_params+="${SUBNETPOOL_V4_ID:+--subnetpool $SUBNETPOOL_V4_ID} "
272 subnet_params+="$NET_ID $fixed_range_v4"
Sean M. Collins2a242512016-05-03 09:03:09 -0400273 local subnet_id
274 subnet_id=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep ' id ' | get_field 2)
275 die_if_not_set $LINENO subnet_id "Failure creating private IPv4 subnet for $project_id"
276 echo $subnet_id
277}
278
279# Create private IPv6 subnet
280function _neutron_create_private_subnet_v6 {
281 local project_id=$1
282 die_if_not_set $LINENO IPV6_RA_MODE "IPV6 RA Mode not set"
283 die_if_not_set $LINENO IPV6_ADDRESS_MODE "IPV6 Address Mode not set"
284 local ipv6_modes="--ipv6-ra-mode $IPV6_RA_MODE --ipv6-address-mode $IPV6_ADDRESS_MODE"
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000285 if [ -z $SUBNETPOOL_V6_ID ]; then
286 fixed_range_v6=$FIXED_RANGE_V6
287 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400288 local subnet_params="--tenant-id $project_id "
289 subnet_params+="--ip_version 6 "
Brian Haley31813e92016-08-22 15:39:22 -0400290 if [[ -n "$IPV6_PRIVATE_NETWORK_GATEWAY" ]]; then
291 subnet_params+="--gateway $IPV6_PRIVATE_NETWORK_GATEWAY "
292 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400293 subnet_params+="--name $IPV6_PRIVATE_SUBNET_NAME "
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000294 subnet_params+="${SUBNETPOOL_V6_ID:+--subnetpool $SUBNETPOOL_V6_ID} "
295 subnet_params+="$NET_ID $fixed_range_v6 $ipv6_modes"
Sean M. Collins2a242512016-05-03 09:03:09 -0400296 local ipv6_subnet_id
297 ipv6_subnet_id=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep ' id ' | get_field 2)
298 die_if_not_set $LINENO ipv6_subnet_id "Failure creating private IPv6 subnet for $project_id"
299 echo $ipv6_subnet_id
300}
301
302# Create public IPv4 subnet
303function _neutron_create_public_subnet_v4 {
Brian Haley31813e92016-08-22 15:39:22 -0400304 local subnet_params="--ip_version 4 "
Sean M. Collins2a242512016-05-03 09:03:09 -0400305 subnet_params+="${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} "
Brian Haley31813e92016-08-22 15:39:22 -0400306 if [[ -n "$PUBLIC_NETWORK_GATEWAY" ]]; then
307 subnet_params+="--gateway $PUBLIC_NETWORK_GATEWAY "
308 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400309 subnet_params+="--name $PUBLIC_SUBNET_NAME "
310 subnet_params+="$EXT_NET_ID $FLOATING_RANGE "
311 subnet_params+="-- --enable_dhcp=False"
312 local id_and_ext_gw_ip
313 id_and_ext_gw_ip=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
314 die_if_not_set $LINENO id_and_ext_gw_ip "Failure creating public IPv4 subnet"
315 echo $id_and_ext_gw_ip
316}
317
318# Create public IPv6 subnet
319function _neutron_create_public_subnet_v6 {
320 local subnet_params="--ip_version 6 "
321 subnet_params+="--gateway $IPV6_PUBLIC_NETWORK_GATEWAY "
322 subnet_params+="--name $IPV6_PUBLIC_SUBNET_NAME "
323 subnet_params+="$EXT_NET_ID $IPV6_PUBLIC_RANGE "
324 subnet_params+="-- --enable_dhcp=False"
325 local ipv6_id_and_ext_gw_ip
326 ipv6_id_and_ext_gw_ip=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
327 die_if_not_set $LINENO ipv6_id_and_ext_gw_ip "Failure creating an IPv6 public subnet"
328 echo $ipv6_id_and_ext_gw_ip
329}
330
331# Configure neutron router for IPv4 public access
332function _neutron_configure_router_v4 {
333 neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-interface-add $ROUTER_ID $SUBNET_ID
334 # Create a public subnet on the external network
335 local id_and_ext_gw_ip
336 id_and_ext_gw_ip=$(_neutron_create_public_subnet_v4 $EXT_NET_ID)
337 local ext_gw_ip
338 ext_gw_ip=$(echo $id_and_ext_gw_ip | get_field 2)
339 PUB_SUBNET_ID=$(echo $id_and_ext_gw_ip | get_field 5)
340 # Configure the external network as the default router gateway
341 neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-gateway-set $ROUTER_ID $EXT_NET_ID
342
343 # This logic is specific to using the l3-agent for layer 3
Sean M. Collinsd00cbb72016-06-20 13:53:44 -0400344 if is_service_enabled q-l3 || is_service_enabled neutron-l3; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400345 # Configure and enable public bridge
346 local ext_gw_interface="none"
347 if is_neutron_ovs_base_plugin; then
348 ext_gw_interface=$(_neutron_get_ext_gw_interface)
349 elif [[ "$Q_AGENT" = "linuxbridge" ]]; then
Kevin Benton6a42a852016-07-21 11:11:54 -0700350 # Get the device the neutron router and network for $FIXED_RANGE
Sean M. Collins2a242512016-05-03 09:03:09 -0400351 # will be using.
Kevin Benton6a42a852016-07-21 11:11:54 -0700352 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
353 # in provider nets a bridge mapping uses the public bridge directly
354 ext_gw_interface=$PUBLIC_BRIDGE
355 else
356 # e.x. brq3592e767-da for NET_ID 3592e767-da66-4bcb-9bec-cdb03cd96102
357 ext_gw_interface=brq${EXT_NET_ID:0:11}
358 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400359 fi
360 if [[ "$ext_gw_interface" != "none" ]]; then
361 local cidr_len=${FLOATING_RANGE#*/}
362 local testcmd="ip -o link | grep -q $ext_gw_interface"
363 test_with_retry "$testcmd" "$ext_gw_interface creation failed"
Kevin Benton1554ade2016-07-22 09:40:19 -0700364 if [[ $(ip addr show dev $ext_gw_interface | grep -c $ext_gw_ip) == 0 && ( $Q_USE_PROVIDERNET_FOR_PUBLIC == "False" || $Q_USE_PUBLIC_VETH == "True" || $Q_ASSIGN_GATEWAY_TO_PUBLIC_BRIDGE == "True" ) ]]; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400365 sudo ip addr add $ext_gw_ip/$cidr_len dev $ext_gw_interface
366 sudo ip link set $ext_gw_interface up
367 fi
368 ROUTER_GW_IP=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F'ip_address' '{ print $2 }' | cut -f3 -d\" | tr '\n' ' ')
369 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000370 local replace_range=${SUBNETPOOL_PREFIX_V4}
371 if [[ -z "${SUBNETPOOL_V4_ID}" ]]; then
372 replace_range=${FIXED_RANGE}
373 fi
374 sudo ip route replace $replace_range via $ROUTER_GW_IP
Sean M. Collins2a242512016-05-03 09:03:09 -0400375 fi
376 _neutron_set_router_id
377 fi
378}
379
380# Configure neutron router for IPv6 public access
381function _neutron_configure_router_v6 {
382 neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-interface-add $ROUTER_ID $IPV6_SUBNET_ID
383 # Create a public subnet on the external network
384 local ipv6_id_and_ext_gw_ip
385 ipv6_id_and_ext_gw_ip=$(_neutron_create_public_subnet_v6 $EXT_NET_ID)
386 local ipv6_ext_gw_ip
387 ipv6_ext_gw_ip=$(echo $ipv6_id_and_ext_gw_ip | get_field 2)
388 local ipv6_pub_subnet_id
389 ipv6_pub_subnet_id=$(echo $ipv6_id_and_ext_gw_ip | get_field 5)
390
391 # If the external network has not already been set as the default router
392 # gateway when configuring an IPv4 public subnet, do so now
393 if [[ "$IP_VERSION" == "6" ]]; then
394 neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-gateway-set $ROUTER_ID $EXT_NET_ID
395 fi
396
397 # This logic is specific to using the l3-agent for layer 3
Sean M. Collinsd00cbb72016-06-20 13:53:44 -0400398 if is_service_enabled q-l3 || is_service_enabled neutron-l3; then
Henry Gessau734f1442016-09-17 19:28:53 -0400399 # Ensure IPv6 RAs are accepted on interfaces with a default route.
Monty Taylorc12d1d92016-08-23 19:07:57 -0500400 # This is needed for neutron-based devstack clouds to work in
401 # IPv6-only clouds in the gate. Please do not remove this without
402 # talking to folks in Infra.
Henry Gessau734f1442016-09-17 19:28:53 -0400403 for d in $default_v6_route_devs; do
Drago Rossonb34d4592016-09-26 13:23:23 -0500404 # Slashes must be used in this sysctl command because route devices
405 # can have dots in their names. If dots were used, dots in the
406 # device name would be reinterpreted as a slash, causing an error.
407 sudo sysctl -w net/ipv6/conf/$d/accept_ra=2
Henry Gessau734f1442016-09-17 19:28:53 -0400408 done
Sean M. Collins2a242512016-05-03 09:03:09 -0400409 # Ensure IPv6 forwarding is enabled on the host
410 sudo sysctl -w net.ipv6.conf.all.forwarding=1
411 # Configure and enable public bridge
412 # Override global IPV6_ROUTER_GW_IP with the true value from neutron
413 IPV6_ROUTER_GW_IP=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" port-list -c fixed_ips | grep $ipv6_pub_subnet_id | awk -F'ip_address' '{ print $2 }' | cut -f3 -d\" | tr '\n' ' ')
414 die_if_not_set $LINENO IPV6_ROUTER_GW_IP "Failure retrieving IPV6_ROUTER_GW_IP"
415
416 if is_neutron_ovs_base_plugin; then
417 local ext_gw_interface
418 ext_gw_interface=$(_neutron_get_ext_gw_interface)
419 local ipv6_cidr_len=${IPV6_PUBLIC_RANGE#*/}
420
421 # Configure interface for public bridge
Yi Zhaoa464ea72016-05-12 10:32:58 +0800422 sudo ip -6 addr replace $ipv6_ext_gw_ip/$ipv6_cidr_len dev $ext_gw_interface
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000423 local replace_range=${SUBNETPOOL_PREFIX_V6}
424 if [[ -z "${SUBNETPOOL_V6_ID}" ]]; then
425 replace_range=${FIXED_RANGE_V6}
426 fi
427 sudo ip -6 route replace $replace_range via $IPV6_ROUTER_GW_IP dev $ext_gw_interface
Sean M. Collins2a242512016-05-03 09:03:09 -0400428 fi
429 _neutron_set_router_id
430 fi
431}
watanabe.isao4f4d95a2016-05-12 20:35:20 +0900432
433function is_provider_network {
vsaienkod8942212016-05-13 12:51:30 +0300434 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ]; then
watanabe.isao4f4d95a2016-05-12 20:35:20 +0900435 return 0
436 fi
437 return 1
438}
Sean M. Collinsc35110e2016-05-18 10:38:51 -0400439
440function is_networking_extension_supported {
441 local extension=$1
442 # TODO(sc68cal) cache this instead of calling every time
443 EXT_LIST=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" ext-list -c alias -f value)
444 [[ $EXT_LIST =~ $extension ]] && return 0
445}