blob: e0c467629790a60c6eda8669ff59af550487cccb [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Mark McClainb05c8762013-07-06 23:29:39 -04003# lib/neutron
Joe Gordon23946052014-01-15 21:42:32 +00004# functions - functions specific to neutron
Mark McClainb05c8762013-07-06 23:29:39 -04005
6# Dependencies:
7# ``functions`` file
8# ``DEST`` must be defined
Stephan Renatuse578eff2013-11-19 13:31:04 +01009# ``STACK_USER`` must be defined
Mark McClainb05c8762013-07-06 23:29:39 -040010
11# ``stack.sh`` calls the entry points in this order:
12#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010013# - install_neutron_agent_packages
YAMAMOTO Takashi1a669dc2015-02-05 11:54:12 +090014# - install_neutronclient
15# - install_neutron
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010016# - install_neutron_third_party
17# - configure_neutron
18# - init_neutron
19# - configure_neutron_third_party
20# - init_neutron_third_party
21# - start_neutron_third_party
22# - create_nova_conf_neutron
23# - start_neutron_service_and_check
YAMAMOTO Takashi1a669dc2015-02-05 11:54:12 +090024# - check_neutron_third_party_integration
yunhong jiang0d6e9922014-10-10 06:12:47 -070025# - start_neutron_agents
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010026# - create_neutron_initial_network
27# - setup_neutron_debug
Mark McClainb05c8762013-07-06 23:29:39 -040028#
29# ``unstack.sh`` calls the entry points in this order:
30#
YAMAMOTO Takashi1a669dc2015-02-05 11:54:12 +090031# - teardown_neutron_debug
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010032# - stop_neutron
yunhong jiang0d6e9922014-10-10 06:12:47 -070033# - stop_neutron_third_party
34# - cleanup_neutron
Mark McClainb05c8762013-07-06 23:29:39 -040035
36# Functions in lib/neutron are classified into the following categories:
37#
38# - entry points (called from stack.sh or unstack.sh)
39# - internal functions
40# - neutron exercises
41# - 3rd party programs
42
43
44# Neutron Networking
45# ------------------
46
47# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
48# to run Neutron on this host, make sure that q-svc is also in
49# ``ENABLED_SERVICES``.
50#
Mark McClainb05c8762013-07-06 23:29:39 -040051# See "Neutron Network Configuration" below for additional variables
52# that must be set in localrc for connectivity across hosts with
53# Neutron.
54#
55# With Neutron networking the NETWORK_MANAGER variable is ignored.
Mark McClainb05c8762013-07-06 23:29:39 -040056
John Davidge21529a52014-06-30 09:55:11 -040057# Settings
58# --------
59
Mark McClainb05c8762013-07-06 23:29:39 -040060
61# Neutron Network Configuration
62# -----------------------------
63
John Davidge21529a52014-06-30 09:55:11 -040064# Subnet IP version
Sean M. Collins645114b2015-03-03 10:56:03 -050065IP_VERSION=${IP_VERSION:-"4+6"}
John Davidge21529a52014-06-30 09:55:11 -040066# Validate IP_VERSION
67if [[ $IP_VERSION != "4" ]] && [[ $IP_VERSION != "6" ]] && [[ $IP_VERSION != "4+6" ]]; then
68 die $LINENO "IP_VERSION must be either 4, 6, or 4+6"
69fi
Mark McClainb05c8762013-07-06 23:29:39 -040070# Gateway and subnet defaults, in case they are not customized in localrc
71NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
Salvatore Orlando90234ac2013-11-25 05:44:10 -080072PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
Mark McClainb05c8762013-07-06 23:29:39 -040073PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
74PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
75
Rob Crittenden18d47782014-03-19 17:47:42 -040076if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then
77 Q_PROTOCOL="https"
78fi
79
John Davidge21529a52014-06-30 09:55:11 -040080# Generate 40-bit IPv6 Global ID to comply with RFC 4193
81IPV6_GLOBAL_ID=`uuidgen | sed s/-//g | cut -c 23- | sed -e "s/\(..\)\(....\)\(....\)/\1:\2:\3/"`
82
83# IPv6 gateway and subnet defaults, in case they are not customized in localrc
84IPV6_RA_MODE=${IPV6_RA_MODE:-slaac}
85IPV6_ADDRESS_MODE=${IPV6_ADDRESS_MODE:-slaac}
86IPV6_PUBLIC_SUBNET_NAME=${IPV6_PUBLIC_SUBNET_NAME:-ipv6-public-subnet}
87IPV6_PRIVATE_SUBNET_NAME=${IPV6_PRIVATE_SUBNET_NAME:-ipv6-private-subnet}
88FIXED_RANGE_V6=${FIXED_RANGE_V6:-fd$IPV6_GLOBAL_ID::/64}
89IPV6_PRIVATE_NETWORK_GATEWAY=${IPV6_PRIVATE_NETWORK_GATEWAY:-fd$IPV6_GLOBAL_ID::1}
Dane LeBlanca79e1012015-03-26 14:48:07 -040090IPV6_PUBLIC_RANGE=${IPV6_PUBLIC_RANGE:-2001:db8::/64}
91IPV6_PUBLIC_NETWORK_GATEWAY=${IPV6_PUBLIC_NETWORK_GATEWAY:-2001:db8::2}
92IPV6_ROUTER_GW_IP=${IPV6_ROUTER_GW_IP:-2001:db8::1}
Rob Crittenden18d47782014-03-19 17:47:42 -040093
Mark McClainb05c8762013-07-06 23:29:39 -040094# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050095GITDIR["python-neutronclient"]=$DEST/python-neutronclient
Sean Dague5cb19062014-11-01 01:37:45 +010096
Doug Wiegley93e682c2015-03-03 10:31:30 -070097
Mark McClainb05c8762013-07-06 23:29:39 -040098NEUTRON_DIR=$DEST/neutron
Kyle Mestery20b839f2014-12-08 06:17:27 +000099NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas
Doug Wiegley93e682c2015-03-03 10:31:30 -0700100NEUTRON_LBAAS_DIR=$DEST/neutron-lbaas
Kyle Mestery20b839f2014-12-08 06:17:27 +0000101NEUTRON_VPNAAS_DIR=$DEST/neutron-vpnaas
Mark McClainb05c8762013-07-06 23:29:39 -0400102NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
103
104# Support entry points installation of console scripts
105if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
106 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -0400107else
108 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -0400109fi
110
111NEUTRON_CONF_DIR=/etc/neutron
112NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
113export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
114
Martin Hickey10bff0e2015-12-03 15:18:10 +0000115# Default provider for load balancer service
116DEFAULT_LB_PROVIDER=LOADBALANCER:Haproxy:neutron_lbaas.services.loadbalancer.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver:default
117
Adam Gandelman7614d212014-08-11 14:27:50 -0700118# Agent binaries. Note, binary paths for other agents are set in per-service
119# scripts in lib/neutron_plugins/services/
120AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
121AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
122AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
123
124# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
125# loaded from per-plugin scripts in lib/neutron_plugins/
126Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
127Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
128Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
129Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
130Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
131
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400132# Default name for Neutron database
133Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400134# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000135Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400136# Default Neutron Port
137Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400138# Default Neutron Internal Port when using TLS proxy
139Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400140# Default Neutron Host
141Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400142# Default protocol
143Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Brian Haley180f5eb2015-06-16 13:14:31 -0400144# Default listen address
145Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$SERVICE_LISTEN_ADDRESS}
Mark McClainb05c8762013-07-06 23:29:39 -0400146# Default admin username
147Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
148# Default auth strategy
149Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
Mark McClainb05c8762013-07-06 23:29:39 -0400150# RHEL's support for namespaces requires using veths with ovs
151Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
152Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
Yuriy Taraday26623952014-07-16 17:41:53 +0400153Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
Mark McClainb05c8762013-07-06 23:29:39 -0400154# Meta data IP
155Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
156# Allow Overlapping IP among subnets
157Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
158# Use neutron-debug command
159Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
160# The name of the default q-l3 router
161Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500162Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
163Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800164VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
165VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Edgar Magana7bce8fa2014-11-04 17:32:54 +0100166# Specify if the initial private and external networks should be created
167NEUTRON_CREATE_INITIAL_NETWORKS=${NEUTRON_CREATE_INITIAL_NETWORKS:-True}
Aaron Rosen4540d002013-10-24 13:59:33 -0700168
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400169## Provider Network Information
170PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
171
Sean M. Collins64d5ecf2015-06-01 14:13:41 -0400172# Define the public bridge that will transmit traffic from VMs to the
173# physical network - used by both the OVS and Linux Bridge drivers.
174PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex}
175
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900176# Use flat providernet for public network
177#
178# If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network
179# for external interface of neutron l3-agent. In that case,
180# PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900181# used for the network. In case of ofagent, you should add the
182# corresponding entry to your OFAGENT_PHYSICAL_INTERFACE_MAPPINGS.
183# For openvswitch agent, you should add the corresponding entry to
184# your OVS_BRIDGE_MAPPINGS.
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900185#
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900186# eg. (ofagent)
187# Q_USE_PROVIDERNET_FOR_PUBLIC=True
188# Q_USE_PUBLIC_VETH=True
189# PUBLIC_PHYSICAL_NETWORK=public
190# OFAGENT_PHYSICAL_INTERFACE_MAPPINGS=public:veth-pub-int
191#
192# eg. (openvswitch agent)
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900193# Q_USE_PROVIDERNET_FOR_PUBLIC=True
194# PUBLIC_PHYSICAL_NETWORK=public
195# OVS_BRIDGE_MAPPINGS=public:br-ex
196Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-False}
197PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public}
198
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900199# If Q_USE_PUBLIC_VETH=True, create and use a veth pair instead of
200# PUBLIC_BRIDGE. This is intended to be used with
201# Q_USE_PROVIDERNET_FOR_PUBLIC=True.
202Q_USE_PUBLIC_VETH=${Q_USE_PUBLIC_VETH:-False}
203Q_PUBLIC_VETH_EX=${Q_PUBLIC_VETH_EX:-veth-pub-ex}
204Q_PUBLIC_VETH_INT=${Q_PUBLIC_VETH_INT:-veth-pub-int}
205
Tomoe Sugiharaafbc6312013-11-14 20:02:47 +0000206# The next two variables are configured by plugin
207# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
208#
209# The plugin supports L3.
210Q_L3_ENABLED=${Q_L3_ENABLED:-False}
211# L3 routers exist per tenant
Cedric Brandilyb814b532015-10-22 22:25:45 +0200212Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-True}
Aaron Rosen4540d002013-10-24 13:59:33 -0700213
Mark McClainb05c8762013-07-06 23:29:39 -0400214# List of config file names in addition to the main plugin config file
215# See _configure_neutron_common() for details about setting it up
216declare -a Q_PLUGIN_EXTRA_CONF_FILES
217
Paul Michali746dcee2014-04-02 19:12:22 +0000218# List of (optional) config files for VPN device drivers to use with
219# the neutron-q-vpn agent
220declare -a Q_VPN_EXTRA_CONF_FILES
221
Mark McClainb05c8762013-07-06 23:29:39 -0400222
Dean Troyere2907b42014-02-26 17:35:37 -0600223Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
224if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
225 Q_RR_COMMAND="sudo"
226else
227 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
228 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Yuriy Taraday26623952014-07-16 17:41:53 +0400229 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
230 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
231 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400232fi
233
Brian Haleyeea76212014-06-27 11:45:50 -0400234
235# Distributed Virtual Router (DVR) configuration
236# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500237# - ``legacy`` - No DVR functionality
238# - ``dvr_snat`` - Controller or single node DVR
239# - ``dvr`` - Compute node in multi-node DVR
240#
Brian Haleyeea76212014-06-27 11:45:50 -0400241Q_DVR_MODE=${Q_DVR_MODE:-legacy}
242if [[ "$Q_DVR_MODE" != "legacy" ]]; then
243 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
244fi
245
Dean Troyere2907b42014-02-26 17:35:37 -0600246# Provider Network Configurations
247# --------------------------------
248
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900249# The following variables control the Neutron ML2 plugins' allocation
250# of tenant networks and availability of provider networks. If these
251# are not configured in ``localrc``, tenant networks will be local to
252# the host (with no remote connectivity), and no physical resources
253# will be available for the allocation of provider networks.
Dean Troyere2907b42014-02-26 17:35:37 -0600254
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200255# To disable tunnels (GRE or VXLAN) for tenant networks,
256# set to False in ``local.conf``.
257# GRE tunnels are only supported by the openvswitch.
258ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600259
260# If using GRE tunnels for tenant networks, specify the range of
261# tunnel IDs from which tenant networks are allocated. Can be
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900262# overridden in ``localrc`` in necessary.
Anant Patil3827dc02014-07-03 21:38:16 +0530263TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600264
265# To use VLANs for tenant networks, set to True in localrc. VLANs
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900266# are supported by the ML2 plugins, requiring additional configuration
267# described below.
Dean Troyere2907b42014-02-26 17:35:37 -0600268ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
269
270# If using VLANs for tenant networks, set in ``localrc`` to specify
271# the range of VLAN VIDs from which tenant networks are
272# allocated. An external network switch must be configured to
273# trunk these VLANs between hosts for multi-host connectivity.
274#
275# Example: ``TENANT_VLAN_RANGE=1000:1999``
276TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
277
278# If using VLANs for tenant networks, or if using flat or VLAN
279# provider networks, set in ``localrc`` to the name of the physical
280# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
281# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
282# agent, as described below.
283#
284# Example: ``PHYSICAL_NETWORK=default``
285PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
286
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900287# With the openvswitch agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600288# or if using flat or VLAN provider networks, set in ``localrc`` to
289# the name of the OVS bridge to use for the physical network. The
290# bridge will be created if it does not already exist, but a
291# physical interface must be manually added to the bridge as a
292# port for external connectivity.
293#
294# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
295OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
296
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900297# With the linuxbridge agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600298# or if using flat or VLAN provider networks, set in ``localrc`` to
299# the name of the network interface to use for the physical
300# network.
301#
302# Example: ``LB_PHYSICAL_INTERFACE=eth1``
303LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
304
Edgar Magana6f335b92014-07-10 15:42:44 -0700305# When Neutron tunnels are enabled it is needed to specify the
306# IP address of the end point in the local server. This IP is set
307# by default to the same IP address that the HOST IP.
308# This variable can be used to specify a different end point IP address
309# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
310TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
311
Dean Troyere2907b42014-02-26 17:35:37 -0600312# With the openvswitch plugin, set to True in ``localrc`` to enable
313# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
314#
315# Example: ``OVS_ENABLE_TUNNELING=True``
316OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
317
Tan Lin27a196e2014-10-31 15:44:34 +0800318# Use DHCP agent for providing metadata service in the case of
319# without L3 agent (No Route Agent), set to True in localrc.
320ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
321
322# Add a static route as dhcp option, so the request to 169.254.169.254
323# will be able to reach through a route(DHCP agent)
324# This option require ENABLE_ISOLATED_METADATA = True
325ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
Mark McClainb05c8762013-07-06 23:29:39 -0400326# Neutron plugin specific functions
327# ---------------------------------
328
329# Please refer to ``lib/neutron_plugins/README.md`` for details.
Hirofumi Ichihara36daecd2015-07-23 17:50:40 +0900330if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
331 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
332fi
Mark McClainb05c8762013-07-06 23:29:39 -0400333
Doug Wiegley93e682c2015-03-03 10:31:30 -0700334# Agent loadbalancer service plugin functions
335# -------------------------------------------
336
337# Hardcoding for 1 service plugin for now
338source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
339
Emilien Macchi40546f72013-09-24 15:10:25 +0200340# Agent metering service plugin functions
341# -------------------------------------------
342
343# Hardcoding for 1 service plugin for now
344source $TOP_DIR/lib/neutron_plugins/services/metering
345
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700346# VPN service plugin functions
347# -------------------------------------------
348# Hardcoding for 1 service plugin for now
349source $TOP_DIR/lib/neutron_plugins/services/vpn
350
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700351# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100352# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700353source $TOP_DIR/lib/neutron_plugins/services/firewall
354
Mark McClainb05c8762013-07-06 23:29:39 -0400355# Use security group or not
356if has_neutron_plugin_security_group; then
357 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
358else
359 Q_USE_SECGROUP=False
360fi
361
Dean Troyere2907b42014-02-26 17:35:37 -0600362# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +1100363_XTRACE_NEUTRON=$(set +o | grep xtrace)
Dean Troyere2907b42014-02-26 17:35:37 -0600364set +o xtrace
365
366
Mark McClainb05c8762013-07-06 23:29:39 -0400367# Functions
368# ---------
369
Adam Gandelman7614d212014-08-11 14:27:50 -0700370function _determine_config_server {
371 local cfg_file
372 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
373 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
374 opts+=" --config-file /$cfg_file"
375 done
376 echo "$opts"
377}
378
379function _determine_config_vpn {
380 local cfg_file
381 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
382 if is_service_enabled q-fwaas; then
383 opts+=" --config-file $Q_FWAAS_CONF_FILE"
384 fi
385 for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
386 opts+=" --config-file $cfg_file"
387 done
388 echo "$opts"
389
390}
391
392function _determine_config_l3 {
393 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
394 if is_service_enabled q-fwaas; then
395 opts+=" --config-file $Q_FWAAS_CONF_FILE"
396 fi
397 echo "$opts"
398}
399
400# For services and agents that require it, dynamically construct a list of
401# --config-file arguments that are passed to the binary.
402function determine_config_files {
403 local opts=""
404 case "$1" in
405 "neutron-server") opts="$(_determine_config_server)" ;;
406 "neutron-vpn-agent") opts="$(_determine_config_vpn)" ;;
407 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
408 esac
409 if [ -z "$opts" ] ; then
410 die $LINENO "Could not determine config files for $1."
411 fi
412 echo "$opts"
413}
414
Dean Troyere4fa7212014-01-15 15:04:49 -0600415# Test if any Neutron services are enabled
416# is_neutron_enabled
417function is_neutron_enabled {
418 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
419 return 1
420}
421
Mark McClainb05c8762013-07-06 23:29:39 -0400422# configure_neutron()
423# Set common config for all neutron server and agents.
Ian Wienandaee18c72014-02-21 15:35:08 +1100424function configure_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400425 _configure_neutron_common
Brant Knudson2dd110c2015-03-14 12:39:14 -0500426 iniset_rpc_backend neutron $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400427
428 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
Doug Wiegley93e682c2015-03-03 10:31:30 -0700429 if is_service_enabled q-lbaas; then
430 _configure_neutron_lbaas
431 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200432 if is_service_enabled q-metering; then
433 _configure_neutron_metering
434 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700435 if is_service_enabled q-vpn; then
436 _configure_neutron_vpn
437 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700438 if is_service_enabled q-fwaas; then
439 _configure_neutron_fwaas
440 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000441 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400442 _configure_neutron_service
443 fi
444 if is_service_enabled q-agt; then
445 _configure_neutron_plugin_agent
446 fi
447 if is_service_enabled q-dhcp; then
448 _configure_neutron_dhcp_agent
449 fi
450 if is_service_enabled q-l3; then
451 _configure_neutron_l3_agent
452 fi
453 if is_service_enabled q-meta; then
454 _configure_neutron_metadata_agent
455 fi
456
Brian Haleyeea76212014-06-27 11:45:50 -0400457 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
458 _configure_dvr
459 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400460 if is_service_enabled ceilometer; then
461 _configure_neutron_ceilometer_notifications
462 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400463
464 _configure_neutron_debug_command
armando-migliaccioe155b892015-06-12 08:55:02 -0700465
466 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
Mark McClainb05c8762013-07-06 23:29:39 -0400467}
468
Ian Wienandaee18c72014-02-21 15:35:08 +1100469function create_nova_conf_neutron {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800470 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
Davanum Srinivasd6456e62015-08-19 10:33:23 -0400471
Jamie Lennox394968f2015-08-28 09:18:26 +1000472 iniset $NOVA_CONF neutron auth_plugin "v3password"
473 iniset $NOVA_CONF neutron auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v3"
474 iniset $NOVA_CONF neutron username "$Q_ADMIN_USERNAME"
475 iniset $NOVA_CONF neutron password "$SERVICE_PASSWORD"
476 iniset $NOVA_CONF neutron user_domain_name "Default"
477 iniset $NOVA_CONF neutron project_name "$SERVICE_TENANT_NAME"
478 iniset $NOVA_CONF neutron project_domain_name "Default"
Gary Kotton13d385e2014-06-17 23:24:53 -0700479 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
Bartosz Górski0abde392014-02-28 14:15:19 +0100480 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Rob Crittenden18d47782014-03-19 17:47:42 -0400481 iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400482
483 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
484 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400485 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800486 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400487 fi
488
Matt Riedemann925c2562015-08-25 13:40:25 -0700489 # optionally set options in nova_conf
Mark McClainb05c8762013-07-06 23:29:39 -0400490 neutron_plugin_create_nova_conf
491
Mark McClainb05c8762013-07-06 23:29:39 -0400492 if is_service_enabled q-meta; then
Gary Kottondd745502014-08-11 23:38:47 -0700493 iniset $NOVA_CONF neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400494 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800495
496 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
497 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400498}
499
Emilien Macchia677b7f2013-11-25 23:40:20 +0100500# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100501function create_neutron_cache_dir {
Emilien Macchia677b7f2013-11-25 23:40:20 +0100502 # Create cache dir
Dean Troyer8421c2b2015-03-16 13:52:19 -0500503 sudo install -d -o $STACK_USER $NEUTRON_AUTH_CACHE_DIR
Emilien Macchia677b7f2013-11-25 23:40:20 +0100504 rm -f $NEUTRON_AUTH_CACHE_DIR/*
505}
506
Mark McClainb05c8762013-07-06 23:29:39 -0400507# create_neutron_accounts() - Set up common required neutron accounts
508
509# Tenant User Roles
510# ------------------------------------------------------------------
511# service neutron admin # if enabled
512
513# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100514function create_neutron_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400515 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100516
Jamie Lennox85ff5322015-01-28 14:28:01 +1000517 create_service_user "neutron"
Bartosz Górski0abde392014-02-28 14:15:19 +0100518
Mark McClainb05c8762013-07-06 23:29:39 -0400519 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100520
Jamie Lennoxb17ad752015-05-29 06:04:47 +0000521 get_or_create_service "neutron" "network" "Neutron Service"
522 get_or_create_endpoint "network" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100523 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400524 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
525 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
526 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400527 fi
528 fi
529}
530
Ian Wienandaee18c72014-02-21 15:35:08 +1100531function create_neutron_initial_network {
Steve Martinelli19685422014-01-24 13:02:26 -0600532 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500533 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400534
Robd06a6d92014-12-04 20:32:22 +0000535 # Allow drivers that need to create an initial network to do so here
536 if type -p neutron_plugin_create_initial_network_profile > /dev/null; then
537 neutron_plugin_create_initial_network_profile $PHYSICAL_NETWORK
538 fi
539
Sean Dague2f8e08b2014-12-05 08:31:16 -0500540 if is_provider_network; then
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900541 die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900542 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specify the PROVIDER_NETWORK_TYPE"
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900543 NET_ID=$(neutron net-create $PHYSICAL_NETWORK --tenant_id $TENANT_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)
Naohiro Tamura907d41c2015-02-19 20:57:20 +0900544 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Zhongyue Luo2548e6f2014-12-18 15:57:31 +0800545
546 if [[ "$IP_VERSION" =~ 4.* ]]; then
John Davidge8a3b7d42015-07-07 11:10:54 +0100547 SUBNET_ID=$(neutron subnet-create --tenant_id $TENANT_ID --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --name $PROVIDER_SUBNET_NAME --gateway $NETWORK_GATEWAY --subnetpool None $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
Naohiro Tamura907d41c2015-02-19 20:57:20 +0900548 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $PROVIDER_SUBNET_NAME $TENANT_ID"
Zhongyue Luo2548e6f2014-12-18 15:57:31 +0800549 fi
550
551 if [[ "$IP_VERSION" =~ .*6 ]]; then
John Davidge8a3b7d42015-07-07 11:10:54 +0100552 SUBNET_V6_ID=$(neutron subnet-create --tenant_id $TENANT_ID --ip_version 6 --ipv6-address-mode $IPV6_ADDRESS_MODE --gateway $V6_NETWORK_GATEWAY --name $PROVIDER_SUBNET_NAME_V6 --subnetpool_id None $NET_ID $FIXED_RANGE_V6 | grep 'id' | get_field 2)
Naohiro Tamura907d41c2015-02-19 20:57:20 +0900553 die_if_not_set $LINENO SUBNET_V6_ID "Failure creating SUBNET_V6_ID for $PROVIDER_SUBNET_NAME_V6 $TENANT_ID"
Zhongyue Luo2548e6f2014-12-18 15:57:31 +0800554 fi
555
Kahou Leid663e292015-10-24 12:18:57 -0700556 if [[ $Q_AGENT == "openvswitch" ]]; then
557 sudo ip link set $OVS_PHYSICAL_BRIDGE up
558 sudo ip link set br-int up
559 sudo ip link set $PUBLIC_INTERFACE up
560 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400561 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100562 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
Naohiro Tamura4abc4d12015-02-17 22:20:19 +0900563 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PRIVATE_NETWORK_NAME $TENANT_ID"
John Davidge21529a52014-06-30 09:55:11 -0400564
565 if [[ "$IP_VERSION" =~ 4.* ]]; then
566 # Create IPv4 private subnet
567 SUBNET_ID=$(_neutron_create_private_subnet_v4)
568 fi
569
570 if [[ "$IP_VERSION" =~ .*6 ]]; then
571 # Create IPv6 private subnet
572 IPV6_SUBNET_ID=$(_neutron_create_private_subnet_v6)
573 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400574 fi
575
576 if [[ "$Q_L3_ENABLED" == "True" ]]; then
577 # Create a router, and add the private subnet as one of its interfaces
578 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
579 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100580 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500581 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400582 else
583 # Plugin only supports creating a single router, which should be admin owned.
584 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500585 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400586 fi
John Davidge21529a52014-06-30 09:55:11 -0400587
Mark McClainb05c8762013-07-06 23:29:39 -0400588 # Create an external network, and a subnet. Configure the external network as router gw
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900589 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
590 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True --provider:network_type=flat --provider:physical_network=${PUBLIC_PHYSICAL_NETWORK} | grep ' id ' | get_field 2)
591 else
592 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
593 fi
DennyZhang23178a92013-10-22 17:07:32 -0500594 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400595
John Davidge21529a52014-06-30 09:55:11 -0400596 if [[ "$IP_VERSION" =~ 4.* ]]; then
597 # Configure router for IPv4 public access
598 _neutron_configure_router_v4
599 fi
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900600
John Davidge21529a52014-06-30 09:55:11 -0400601 if [[ "$IP_VERSION" =~ .*6 ]]; then
602 # Configure router for IPv6 public access
603 _neutron_configure_router_v6
Mark McClainb05c8762013-07-06 23:29:39 -0400604 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400605 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400606}
607
608# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100609function init_neutron {
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200610 recreate_database $Q_DB_NAME
Salvatore Orlandodd649882013-08-05 08:56:17 -0700611 # Run Neutron db migrations
612 $NEUTRON_BIN_DIR/neutron-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head
Mark McClainb05c8762013-07-06 23:29:39 -0400613}
614
615# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100616function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400617 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
618 setup_develop $NEUTRON_DIR
Kyle Mestery20b839f2014-12-08 06:17:27 +0000619 if is_service_enabled q-fwaas; then
620 git_clone $NEUTRON_FWAAS_REPO $NEUTRON_FWAAS_DIR $NEUTRON_FWAAS_BRANCH
621 setup_develop $NEUTRON_FWAAS_DIR
622 fi
Doug Wiegley93e682c2015-03-03 10:31:30 -0700623 if is_service_enabled q-lbaas; then
624 git_clone $NEUTRON_LBAAS_REPO $NEUTRON_LBAAS_DIR $NEUTRON_LBAAS_BRANCH
625 setup_develop $NEUTRON_LBAAS_DIR
626 fi
Kyle Mestery20b839f2014-12-08 06:17:27 +0000627 if is_service_enabled q-vpn; then
628 git_clone $NEUTRON_VPNAAS_REPO $NEUTRON_VPNAAS_DIR $NEUTRON_VPNAAS_BRANCH
629 setup_develop $NEUTRON_VPNAAS_DIR
630 fi
Mate Lakat6df64892014-10-17 13:09:49 +0200631
632 if [ "$VIRT_DRIVER" == 'xenserver' ]; then
633 local dom0_ip
634 dom0_ip=$(echo "$XENAPI_CONNECTION_URL" | cut -d "/" -f 3-)
635
636 local ssh_dom0
637 ssh_dom0="sudo -u $DOMZERO_USER ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$dom0_ip"
638
639 # Find where the plugins should go in dom0
640 local xen_functions
641 xen_functions=$(cat $TOP_DIR/tools/xen/functions)
642 local plugin_dir
643 plugin_dir=$($ssh_dom0 "$xen_functions; set -eux; xapi_plugin_location")
644
645 # install neutron plugins to dom0
Huan Xie201e3c12015-08-27 12:34:24 +0100646 tar -czf - -C $NEUTRON_DIR/neutron/plugins/ml2/drivers/openvswitch/agent/xenapi/etc/xapi.d/plugins/ ./ |
Mate Lakat6df64892014-10-17 13:09:49 +0200647 $ssh_dom0 "tar -xzf - -C $plugin_dir && chmod a+x $plugin_dir/*"
648 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400649}
650
651# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100652function install_neutronclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500653 if use_library_from_git "python-neutronclient"; then
654 git_clone_by_name "python-neutronclient"
655 setup_dev_lib "python-neutronclient"
656 sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-neutronclient"]}/tools/,/etc/bash_completion.d/}neutron.bash_completion
Sean Dague5cb19062014-11-01 01:37:45 +0100657 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400658}
659
660# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100661function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400662 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
663 if is_service_enabled q-l3; then
664 install_package radvd
665 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400666 # install packages that are specific to plugin agent(s)
667 if is_service_enabled q-agt q-dhcp q-l3; then
668 neutron_plugin_install_agent_packages
669 fi
Doug Wiegley93e682c2015-03-03 10:31:30 -0700670
671 if is_service_enabled q-lbaas; then
672 neutron_agent_lbaas_install_agent_packages
673 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400674}
675
676# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100677function start_neutron_service_and_check {
Adam Gandelman7614d212014-08-11 14:27:50 -0700678 local cfg_file_options="$(determine_config_files neutron-server)"
Rob Crittenden18d47782014-03-19 17:47:42 -0400679 local service_port=$Q_PORT
680 local service_protocol=$Q_PROTOCOL
681 if is_service_enabled tls-proxy; then
682 service_port=$Q_PORT_INT
683 service_protocol="http"
684 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400685 # Start the Neutron service
Davanum Srinivas59756e92015-09-23 17:42:54 -0400686 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400687 echo "Waiting for Neutron to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400688 if is_ssl_enabled_service "neutron"; then
689 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
690 fi
Sean Dague442e4e92015-06-24 13:24:02 -0400691
692 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $service_protocol://$Q_HOST:$service_port"
693 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
694
Rob Crittenden18d47782014-03-19 17:47:42 -0400695 # Start proxy if enabled
696 if is_service_enabled tls-proxy; then
697 start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT &
698 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400699}
700
Russell Bryant09b94602015-06-08 15:25:43 -0400701# Control of the l2 agent is separated out to make it easier to test partial
702# upgrades (everything upgraded except the L2 agent)
703function start_neutron_l2_agent {
Davanum Srinivas59756e92015-09-23 17:42:54 -0400704 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700705
Kahou Leid663e292015-10-24 12:18:57 -0700706 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
Zhongyue Luo56b7efb2014-12-16 11:36:49 +0800707 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400708 sudo ip link set $OVS_PHYSICAL_BRIDGE up
709 sudo ip link set br-int up
710 sudo ip link set $PUBLIC_INTERFACE up
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700711 if is_ironic_hardware; then
712 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
713 sudo ip addr del $IP dev $PUBLIC_INTERFACE
714 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
715 done
gong yong sheng348c6ac2015-06-23 14:03:47 +0800716 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700717 fi
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400718 fi
Russell Bryant09b94602015-06-08 15:25:43 -0400719}
720
721function start_neutron_other_agents {
Davanum Srinivas59756e92015-09-23 17:42:54 -0400722 run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file=$Q_DHCP_CONF_FILE"
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400723
Paul Michalie4289c82015-08-14 11:49:27 -0400724 if is_service_enabled neutron-vpnaas; then
725 : # Started by plugin
726 elif is_service_enabled q-vpn; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100727 run_process q-vpn "$AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700728 else
Davanum Srinivas59756e92015-09-23 17:42:54 -0400729 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700730 fi
731
Davanum Srinivas59756e92015-09-23 17:42:54 -0400732 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
733 run_process q-lbaas "$AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
734 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400735
736 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
737 # For XenServer, start an agent for the domU openvswitch
Davanum Srinivas59756e92015-09-23 17:42:54 -0400738 run_process q-domua "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
Mark McClainb05c8762013-07-06 23:29:39 -0400739 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400740}
741
Russell Bryant09b94602015-06-08 15:25:43 -0400742# Start running processes, including screen
743function start_neutron_agents {
744 # Start up the neutron agents if enabled
745 start_neutron_l2_agent
746 start_neutron_other_agents
747}
748
749function stop_neutron_l2_agent {
750 stop_process q-agt
751}
752
753function stop_neutron_other {
Mark McClainb05c8762013-07-06 23:29:39 -0400754 if is_service_enabled q-dhcp; then
Chris Dent36891dc2015-02-03 16:22:44 +0000755 stop_process q-dhcp
Mark McClainb05c8762013-07-06 23:29:39 -0400756 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
757 [ ! -z "$pid" ] && sudo kill -9 $pid
758 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000759
760 stop_process q-svc
761 stop_process q-l3
762
Mark McClainb05c8762013-07-06 23:29:39 -0400763 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100764 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Chris Dent36891dc2015-02-03 16:22:44 +0000765 stop_process q-meta
Mark McClainb05c8762013-07-06 23:29:39 -0400766 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900767
Doug Wiegley93e682c2015-03-03 10:31:30 -0700768 if is_service_enabled q-lbaas; then
769 neutron_lbaas_stop
770 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900771 if is_service_enabled q-fwaas; then
772 neutron_fwaas_stop
773 fi
774 if is_service_enabled q-vpn; then
775 neutron_vpn_stop
776 fi
777 if is_service_enabled q-metering; then
778 neutron_metering_stop
779 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400780}
781
Russell Bryant09b94602015-06-08 15:25:43 -0400782# stop_neutron() - Stop running processes (non-screen)
783function stop_neutron {
784 stop_neutron_other
785 stop_neutron_l2_agent
786}
787
Sean M. Collins00e16a92015-02-20 11:45:21 -0500788# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600789# on startup, or back to the public interface on cleanup. If no IP is
790# configured on the interface, just add it as a port to the OVS bridge.
Sean M. Collins00e16a92015-02-20 11:45:21 -0500791function _move_neutron_addresses_route {
792 local from_intf=$1
793 local to_intf=$2
794 local add_ovs_port=$3
Adam Kacmarsky11298a02015-06-26 14:49:47 -0600795 local af=$4
Sean M. Collins00e16a92015-02-20 11:45:21 -0500796
797 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
798 # Remove the primary IP address from $from_intf and add it to $to_intf,
799 # along with the default route, if it exists. Also, when called
800 # on configure we will also add $from_intf as a port on $to_intf,
801 # assuming it is an OVS bridge.
802
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600803 local IP_ADD=""
804 local IP_DEL=""
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900805 local IP_UP=""
Ian Wienandada886d2015-10-07 14:06:26 +1100806 local DEFAULT_ROUTE_GW
Sean M. Collins59e86a32015-11-09 11:06:39 -0500807 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf/ { print \$3; exit }")
Sean M. Collins00e16a92015-02-20 11:45:21 -0500808 local ADD_OVS_PORT=""
809
Brian Haleybb9caea2015-11-16 17:18:42 -0500810 IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
Adam Kacmarsky11298a02015-06-26 14:49:47 -0600811
Sean M. Collins00e16a92015-02-20 11:45:21 -0500812 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
Sean M. Collins59e86a32015-11-09 11:06:39 -0500813 ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
Sean M. Collins00e16a92015-02-20 11:45:21 -0500814 fi
815
816 if [[ "$add_ovs_port" == "True" ]]; then
Raman Budnydb02bbf2015-03-31 13:09:09 +0300817 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
Sean M. Collins00e16a92015-02-20 11:45:21 -0500818 fi
819
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600820 if [[ "$IP_BRD" != "" ]]; then
Brian Haley94510212015-09-02 15:40:04 -0400821 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
822 IP_ADD="sudo ip addr add $IP_BRD dev $to_intf"
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900823 IP_UP="sudo ip link set $to_intf up"
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600824 fi
825
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900826 $IP_DEL; $IP_ADD; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE
Sean M. Collins00e16a92015-02-20 11:45:21 -0500827 fi
828}
829
Mark McClainb05c8762013-07-06 23:29:39 -0400830# cleanup_neutron() - Remove residual data files, anything left over from previous
831# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100832function cleanup_neutron {
Sean M. Collins00e16a92015-02-20 11:45:21 -0500833
Yalei Wang316b3482015-07-15 21:00:31 +0800834 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
835 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False "inet"
Adam Kacmarsky11298a02015-06-26 14:49:47 -0600836
Yalei Wang316b3482015-07-15 21:00:31 +0800837 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
Sean M. Collins790266f2015-11-11 13:36:35 -0500838 # ip(8) wants the prefix length when deleting
839 local v6_gateway
840 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
841 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
Yalei Wang316b3482015-07-15 21:00:31 +0800842 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False "inet6"
843 fi
Sean M. Collins00e16a92015-02-20 11:45:21 -0500844
Yalei Wang316b3482015-07-15 21:00:31 +0800845 if is_provider_network && is_ironic_hardware; then
846 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
847 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
848 sudo ip addr add $IP dev $PUBLIC_INTERFACE
849 done
850 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
851 fi
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700852 fi
853
Mark McClainb05c8762013-07-06 23:29:39 -0400854 if is_neutron_ovs_base_plugin; then
855 neutron_ovs_base_cleanup
856 fi
857
Sean M. Collins7bc2af72015-06-08 12:36:30 -0400858 if [[ $Q_AGENT == "linuxbridge" ]]; then
859 neutron_lb_cleanup
860 fi
861
Mark McClainb05c8762013-07-06 23:29:39 -0400862 # delete all namespaces created by neutron
Doug Wiegley93e682c2015-03-03 10:31:30 -0700863 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|qlbaas|fip|snat)-[0-9a-f-]*'); do
Mark McClainb05c8762013-07-06 23:29:39 -0400864 sudo ip netns delete ${ns}
865 done
866}
867
Doug Wiegley93e682c2015-03-03 10:31:30 -0700868
Maru Newby952fd902015-01-30 22:27:12 +0000869function _create_neutron_conf_dir {
Mark McClainb05c8762013-07-06 23:29:39 -0400870 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
Dean Troyer8421c2b2015-03-16 13:52:19 -0500871 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
Maru Newby952fd902015-01-30 22:27:12 +0000872}
873
874# _configure_neutron_common()
875# Set common config for all neutron server and agents.
876# This MUST be called before other ``_configure_neutron_*`` functions.
877function _configure_neutron_common {
878 _create_neutron_conf_dir
Mark McClainb05c8762013-07-06 23:29:39 -0400879
Martin Hickey30d5fae2015-11-10 13:44:15 +0000880 # Uses oslo config generator to generate core sample configuration files
881 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
882
883 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400884
Jerry Zhao296c1e32015-08-07 20:43:54 -0400885 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
886 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
887
888 # allow neutron user to administer neutron to match neutron account
889 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
890
Mark McClainb05c8762013-07-06 23:29:39 -0400891 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
892 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
893 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
894 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100895 #
Mark McClainb05c8762013-07-06 23:29:39 -0400896 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
897 neutron_plugin_configure_common
898
sbauzae2c4ee22013-08-29 17:29:46 +0200899 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400900 die $LINENO "Neutron plugin not set.. exiting"
901 fi
902
903 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
904 mkdir -p /$Q_PLUGIN_CONF_PATH
905 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900906 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
907 # there is no config file in Neutron tree. They should prepare the file in each plugin.
Martin Hickey30d5fae2015-11-10 13:44:15 +0000908 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
909 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
910 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900911 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
912 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400913
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200914 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400915 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
salvatoree4e535b2014-10-29 18:22:46 +0100916 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
Brian Haley180f5eb2015-06-16 13:14:31 -0400917 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
Martin Hickey30d5fae2015-11-10 13:44:15 +0000918 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
919
Mark McClainb05c8762013-07-06 23:29:39 -0400920 # If addition config files are set, make sure their path name is set as well
921 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
922 die $LINENO "Neutron additional plugin config not set.. exiting"
923 fi
924
925 # If additional config files exist, copy them over to neutron configuration
926 # directory
927 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400928 local f
929 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
930 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400931 done
932 fi
933
Joe Gordonbee5c502013-08-30 13:48:08 -0400934 if [ "$VIRT_DRIVER" = 'fake' ]; then
935 # Disable arbitrary limits
936 iniset $NEUTRON_CONF quotas quota_network -1
937 iniset $NEUTRON_CONF quotas quota_subnet -1
938 iniset $NEUTRON_CONF quotas quota_port -1
939 iniset $NEUTRON_CONF quotas quota_security_group -1
940 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
941 fi
942
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700943 # Format logging
944 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800945 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
venkata anil9b1df572015-01-15 07:38:22 +0000946 else
947 # Show user_name and project_name by default like in nova
948 iniset $NEUTRON_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s] %(instance)s%(message)s"
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700949 fi
950
Rob Crittenden18d47782014-03-19 17:47:42 -0400951 if is_service_enabled tls-proxy; then
952 # Set the service port for a proxy to take the original
953 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
954 fi
955
956 if is_ssl_enabled_service "nova"; then
Jamie Lennoxdc757dd2015-03-09 14:48:09 +1100957 iniset $NEUTRON_CONF nova cafile $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400958 fi
959
960 if is_ssl_enabled_service "neutron"; then
961 ensure_certificates NEUTRON
962
963 iniset $NEUTRON_CONF DEFAULT use_ssl True
964 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
965 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
966 fi
967
Mark McClainb05c8762013-07-06 23:29:39 -0400968 _neutron_setup_rootwrap
969}
970
Ian Wienandaee18c72014-02-21 15:35:08 +1100971function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400972 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
973 return
974 fi
975
Martin Hickey30d5fae2015-11-10 13:44:15 +0000976 cp $NEUTRON_DIR/etc/l3_agent.ini.sample $NEUTRON_TEST_CONFIG_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400977
978 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
979 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700980 iniset $NEUTRON_TEST_CONFIG_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400981 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700982 iniset $NEUTRON_TEST_CONFIG_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400983 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400984
Mark McClainb05c8762013-07-06 23:29:39 -0400985 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
986
987 neutron_plugin_configure_debug_command
988}
989
Ian Wienandaee18c72014-02-21 15:35:08 +1100990function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400991
Martin Hickey30d5fae2015-11-10 13:44:15 +0000992 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400993
994 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500995 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700996 iniset $Q_DHCP_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400997 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700998 iniset $Q_DHCP_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400999 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001000
Tan Lin27a196e2014-10-31 15:44:34 +08001001 if ! is_service_enabled q-l3; then
1002 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
1003 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
1004 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
1005 else
1006 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
1007 die "$LINENO" "Enable isolated metadata is a must for metadata network"
1008 fi
1009 fi
1010 fi
1011
Mark McClainb05c8762013-07-06 23:29:39 -04001012 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
1013
1014 neutron_plugin_configure_dhcp_agent
1015}
1016
Ian Wienandaee18c72014-02-21 15:35:08 +11001017function _configure_neutron_l3_agent {
Mark McClainb05c8762013-07-06 23:29:39 -04001018 Q_L3_ENABLED=True
Nachi Ueno69b3ff62013-06-07 10:28:33 -07001019
Paul Michali746dcee2014-04-02 19:12:22 +00001020 if is_service_enabled q-vpn; then
Paul Michali6fd47202015-02-23 17:07:48 -05001021 neutron_vpn_configure_agent
Paul Michali746dcee2014-04-02 19:12:22 +00001022 fi
1023
Martin Hickey30d5fae2015-11-10 13:44:15 +00001024 cp $NEUTRON_DIR/etc/l3_agent.ini.sample $Q_L3_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001025
1026 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -05001027 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -07001028 iniset $Q_L3_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +04001029 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -07001030 iniset $Q_L3_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +04001031 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001032
Mark McClainb05c8762013-07-06 23:29:39 -04001033 _neutron_setup_interface_driver $Q_L3_CONF_FILE
1034
1035 neutron_plugin_configure_l3_agent
Sean M. Collins00e16a92015-02-20 11:45:21 -05001036
Adam Kacmarsky6b172c82015-08-13 15:14:05 -06001037 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True "inet"
Adam Kacmarsky11298a02015-06-26 14:49:47 -06001038
1039 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
1040 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False "inet6"
Sean M. Collins00e16a92015-02-20 11:45:21 -05001041 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001042}
1043
Ian Wienandaee18c72014-02-21 15:35:08 +11001044function _configure_neutron_metadata_agent {
Martin Hickey30d5fae2015-11-10 13:44:15 +00001045 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001046
1047 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -05001048 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -04001049 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -07001050 iniset $Q_META_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +04001051 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -07001052 iniset $Q_META_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +04001053 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001054
Hirofumi Ichiharacc571552014-09-25 20:00:29 +09001055 # Configures keystone for metadata_agent
1056 # The third argument "True" sets auth_url needed to communicate with keystone
1057 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT True
Maru Newbybf10ac52013-08-10 21:27:54 +00001058
Mark McClainb05c8762013-07-06 23:29:39 -04001059}
1060
Dina Belova58adaa62014-07-11 18:18:12 +04001061function _configure_neutron_ceilometer_notifications {
JordanPd4d4a342014-09-15 09:26:53 +00001062 iniset $NEUTRON_CONF DEFAULT notification_driver messaging
Dina Belova58adaa62014-07-11 18:18:12 +04001063}
1064
Doug Wiegley93e682c2015-03-03 10:31:30 -07001065function _configure_neutron_lbaas {
Martin Hickey10bff0e2015-12-03 15:18:10 +00001066 # Uses oslo config generator to generate LBaaS sample configuration files
1067 (cd $NEUTRON_LBAAS_DIR && exec ./tools/generate_config_file_samples.sh)
1068
1069 if [ -f $NEUTRON_LBAAS_DIR/etc/neutron_lbaas.conf.sample ]; then
1070 cp $NEUTRON_LBAAS_DIR/etc/neutron_lbaas.conf.sample $NEUTRON_CONF_DIR/neutron_lbaas.conf
1071 iniset $NEUTRON_CONF_DIR/neutron_lbaas.conf service_providers service_provider $DEFAULT_LB_PROVIDER
Doug Wiegley93e682c2015-03-03 10:31:30 -07001072 fi
1073 neutron_agent_lbaas_configure_common
1074 neutron_agent_lbaas_configure_agent
1075}
1076
Ian Wienandaee18c72014-02-21 15:35:08 +11001077function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +02001078 neutron_agent_metering_configure_common
1079 neutron_agent_metering_configure_agent
1080}
1081
Ian Wienandaee18c72014-02-21 15:35:08 +11001082function _configure_neutron_fwaas {
Doug Wiegley37da4592015-01-30 23:30:08 -07001083 if [ -f $NEUTRON_FWAAS_DIR/etc/neutron_fwaas.conf ]; then
1084 cp $NEUTRON_FWAAS_DIR/etc/neutron_fwaas.conf $NEUTRON_CONF_DIR
1085 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -07001086 neutron_fwaas_configure_common
1087 neutron_fwaas_configure_driver
1088}
1089
Ian Wienandaee18c72014-02-21 15:35:08 +11001090function _configure_neutron_vpn {
Martin Hickey2b4d6d12015-12-04 14:40:03 +00001091 # Uses oslo config generator to generate VPNaaS sample configuration files
1092 (cd $NEUTRON_VPNAAS_DIR && exec ./tools/generate_config_file_samples.sh)
1093 if [ -f $NEUTRON_VPNAAS_DIR/etc/neutron_vpnaas.conf.sample ]; then
1094 cp $NEUTRON_VPNAAS_DIR/etc/neutron_vpnaas.conf.sample $NEUTRON_CONF_DIR/neutron_vpnaas.conf
Doug Wiegley37da4592015-01-30 23:30:08 -07001095 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -07001096 neutron_vpn_install_agent_packages
1097 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -07001098}
1099
Brian Haleyeea76212014-06-27 11:45:50 -04001100function _configure_dvr {
1101 iniset $NEUTRON_CONF DEFAULT router_distributed True
1102 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
1103}
1104
1105
Mark McClainb05c8762013-07-06 23:29:39 -04001106# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
1107# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +11001108function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -04001109 # Specify the default root helper prior to agent configuration to
1110 # ensure that an agent's configuration can override the default
1111 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +04001112 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1113 iniset /$Q_PLUGIN_CONF_FILE agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1114 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001115 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -05001116 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -04001117
1118 # Configure agent for plugin
1119 neutron_plugin_configure_plugin_agent
1120}
1121
1122# _configure_neutron_service() - Set config files for neutron service
1123# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +11001124function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -04001125 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
Mark McClainb05c8762013-07-06 23:29:39 -04001126 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
Kevin Benton08a5fcc2014-07-18 16:06:12 -07001127
Mark McClainb05c8762013-07-06 23:29:39 -04001128 # Update either configuration file with plugin
1129 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
1130
1131 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
1132 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
1133 fi
1134
1135 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -05001136 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Chris Dent74a85b02015-04-22 18:02:39 +00001137 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001138 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
1139
1140 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
1141 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
1142
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +09001143 # Configuration for neutron notifications to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -05001144 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
1145 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Jamie Lennoxdc757dd2015-03-09 14:48:09 +11001146
1147 iniset $NEUTRON_CONF nova auth_plugin password
1148 iniset $NEUTRON_CONF nova auth_url $KEYSTONE_AUTH_URI
1149 iniset $NEUTRON_CONF nova username nova
1150 iniset $NEUTRON_CONF nova password $SERVICE_PASSWORD
1151 iniset $NEUTRON_CONF nova user_domain_id default
1152 iniset $NEUTRON_CONF nova project_name $SERVICE_TENANT_NAME
1153 iniset $NEUTRON_CONF nova project_domain_id default
1154 iniset $NEUTRON_CONF nova region_name $REGION_NAME
Aaron Rosencea32b12014-03-04 16:20:14 -08001155
Mark McClainb05c8762013-07-06 23:29:39 -04001156 # Configure plugin
1157 neutron_plugin_configure_service
1158}
1159
1160# Utility Functions
1161#------------------
1162
Isaku Yamahata9e136b42013-12-16 15:52:03 +09001163# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +11001164function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +09001165 local service_plugin_class=$1
1166 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1167 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1168 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1169 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1170 fi
1171}
1172
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +01001173# _neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
1174function _neutron_deploy_rootwrap_filters {
gong yong sheng3d6eaae2015-09-15 15:00:29 +08001175 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1176 return
1177 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +01001178 local srcdir=$1
Dean Troyer8421c2b2015-03-16 13:52:19 -05001179 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
1180 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +01001181}
1182
Mark McClainb05c8762013-07-06 23:29:39 -04001183# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +11001184function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -04001185 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1186 return
1187 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001188 # Wipe any existing ``rootwrap.d`` files first
1189 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1190 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1191 sudo rm -rf $Q_CONF_ROOTWRAP_D
1192 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +01001193
1194 _neutron_deploy_rootwrap_filters $NEUTRON_DIR
1195
Mark McClainb05c8762013-07-06 23:29:39 -04001196 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1197 # location moved in newer versions, prefer new location
1198 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Dean Troyer8421c2b2015-03-16 13:52:19 -05001199 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001200 else
Dean Troyer8421c2b2015-03-16 13:52:19 -05001201 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001202 fi
1203 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
Robert Li2c5d4622015-04-21 15:48:22 -04001204 sudo sed -e 's:^exec_dirs=\(.*\)$:exec_dirs=\1,/usr/local/bin:' -i $Q_RR_CONF_FILE
1205
Mark McClainb05c8762013-07-06 23:29:39 -04001206 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1207 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
Yuriy Taraday26623952014-07-16 17:41:53 +04001208 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -04001209
1210 # Set up the rootwrap sudoers for neutron
1211 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +01001212 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Yuriy Taraday26623952014-07-16 17:41:53 +04001213 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -04001214 chmod 0440 $TEMPFILE
1215 sudo chown root:root $TEMPFILE
1216 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1217
1218 # Update the root_helper
1219 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +04001220 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1221 iniset $NEUTRON_CONF agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1222 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001223}
1224
1225# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +11001226function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -04001227 local conf_file=$1
1228 local section=$2
Hirofumi Ichiharacc571552014-09-25 20:00:29 +09001229 local use_auth_url=$3
1230
1231 # Configures keystone for metadata_agent
1232 # metadata_agent needs auth_url to communicate with keystone
1233 if [[ "$use_auth_url" == "True" ]]; then
1234 iniset $conf_file $section auth_url $KEYSTONE_SERVICE_URI/v2.0
1235 fi
Jamie Lennox3561d7f2014-05-21 17:18:43 +10001236
Brant Knudson05952372014-09-19 17:22:22 -05001237 create_neutron_cache_dir
1238 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -04001239}
1240
Ian Wienandaee18c72014-02-21 15:35:08 +11001241function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -04001242
1243 # ovs_use_veth needs to be set before the plugin configuration
1244 # occurs to allow plugins to override the setting.
1245 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1246
1247 neutron_plugin_setup_interface_driver $1
1248}
1249
John Davidge21529a52014-06-30 09:55:11 -04001250# Create private IPv4 subnet
1251function _neutron_create_private_subnet_v4 {
1252 local subnet_params="--tenant-id $TENANT_ID "
1253 subnet_params+="--ip_version 4 "
1254 subnet_params+="--gateway $NETWORK_GATEWAY "
1255 subnet_params+="--name $PRIVATE_SUBNET_NAME "
John Davidge8a3b7d42015-07-07 11:10:54 +01001256 subnet_params+="--subnetpool None "
John Davidge21529a52014-06-30 09:55:11 -04001257 subnet_params+="$NET_ID $FIXED_RANGE"
Ian Wienandada886d2015-10-07 14:06:26 +11001258 local subnet_id
1259 subnet_id=$(neutron subnet-create $subnet_params | grep ' id ' | get_field 2)
John Davidge21529a52014-06-30 09:55:11 -04001260 die_if_not_set $LINENO subnet_id "Failure creating private IPv4 subnet for $TENANT_ID"
1261 echo $subnet_id
1262}
1263
1264# Create private IPv6 subnet
1265function _neutron_create_private_subnet_v6 {
1266 die_if_not_set $LINENO IPV6_RA_MODE "IPV6 RA Mode not set"
1267 die_if_not_set $LINENO IPV6_ADDRESS_MODE "IPV6 Address Mode not set"
1268 local ipv6_modes="--ipv6-ra-mode $IPV6_RA_MODE --ipv6-address-mode $IPV6_ADDRESS_MODE"
1269 local subnet_params="--tenant-id $TENANT_ID "
1270 subnet_params+="--ip_version 6 "
1271 subnet_params+="--gateway $IPV6_PRIVATE_NETWORK_GATEWAY "
1272 subnet_params+="--name $IPV6_PRIVATE_SUBNET_NAME "
John Davidge8a3b7d42015-07-07 11:10:54 +01001273 subnet_params+="--subnetpool None "
John Davidge21529a52014-06-30 09:55:11 -04001274 subnet_params+="$NET_ID $FIXED_RANGE_V6 $ipv6_modes"
Ian Wienandada886d2015-10-07 14:06:26 +11001275 local ipv6_subnet_id
1276 ipv6_subnet_id=$(neutron subnet-create $subnet_params | grep ' id ' | get_field 2)
John Davidge21529a52014-06-30 09:55:11 -04001277 die_if_not_set $LINENO ipv6_subnet_id "Failure creating private IPv6 subnet for $TENANT_ID"
1278 echo $ipv6_subnet_id
1279}
1280
1281# Create public IPv4 subnet
1282function _neutron_create_public_subnet_v4 {
1283 local subnet_params+="--ip_version 4 "
1284 subnet_params+="${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} "
1285 subnet_params+="--gateway $PUBLIC_NETWORK_GATEWAY "
1286 subnet_params+="--name $PUBLIC_SUBNET_NAME "
John Davidge8a3b7d42015-07-07 11:10:54 +01001287 subnet_params+="--subnetpool None "
John Davidge21529a52014-06-30 09:55:11 -04001288 subnet_params+="$EXT_NET_ID $FLOATING_RANGE "
1289 subnet_params+="-- --enable_dhcp=False"
Ian Wienandada886d2015-10-07 14:06:26 +11001290 local id_and_ext_gw_ip
1291 id_and_ext_gw_ip=$(neutron subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
John Davidge21529a52014-06-30 09:55:11 -04001292 die_if_not_set $LINENO id_and_ext_gw_ip "Failure creating public IPv4 subnet"
1293 echo $id_and_ext_gw_ip
1294}
1295
1296# Create public IPv6 subnet
1297function _neutron_create_public_subnet_v6 {
1298 local subnet_params="--ip_version 6 "
1299 subnet_params+="--gateway $IPV6_PUBLIC_NETWORK_GATEWAY "
1300 subnet_params+="--name $IPV6_PUBLIC_SUBNET_NAME "
John Davidge8a3b7d42015-07-07 11:10:54 +01001301 subnet_params+="--subnetpool None "
John Davidge21529a52014-06-30 09:55:11 -04001302 subnet_params+="$EXT_NET_ID $IPV6_PUBLIC_RANGE "
1303 subnet_params+="-- --enable_dhcp=False"
Ian Wienandada886d2015-10-07 14:06:26 +11001304 local ipv6_id_and_ext_gw_ip
1305 ipv6_id_and_ext_gw_ip=$(neutron subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
John Davidge21529a52014-06-30 09:55:11 -04001306 die_if_not_set $LINENO ipv6_id_and_ext_gw_ip "Failure creating an IPv6 public subnet"
1307 echo $ipv6_id_and_ext_gw_ip
1308}
1309
1310# Configure neutron router for IPv4 public access
1311function _neutron_configure_router_v4 {
1312 neutron router-interface-add $ROUTER_ID $SUBNET_ID
1313 # Create a public subnet on the external network
Ian Wienandada886d2015-10-07 14:06:26 +11001314 local id_and_ext_gw_ip
1315 id_and_ext_gw_ip=$(_neutron_create_public_subnet_v4 $EXT_NET_ID)
1316 local ext_gw_ip
1317 ext_gw_ip=$(echo $id_and_ext_gw_ip | get_field 2)
John Davidge21529a52014-06-30 09:55:11 -04001318 PUB_SUBNET_ID=$(echo $id_and_ext_gw_ip | get_field 5)
1319 # Configure the external network as the default router gateway
1320 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
1321
1322 # This logic is specific to using the l3-agent for layer 3
1323 if is_service_enabled q-l3; then
1324 # Configure and enable public bridge
Sean M. Collins71947d52015-06-17 17:33:02 -04001325 local ext_gw_interface="none"
Cedric Brandilyb814b532015-10-22 22:25:45 +02001326 if is_neutron_ovs_base_plugin; then
Sean M. Collins71947d52015-06-17 17:33:02 -04001327 ext_gw_interface=$(_neutron_get_ext_gw_interface)
1328 elif [[ "$Q_AGENT" = "linuxbridge" ]]; then
1329 # Search for the brq device the neutron router and network for $FIXED_RANGE
1330 # will be using.
1331 # e.x. brq3592e767-da for NET_ID 3592e767-da66-4bcb-9bec-cdb03cd96102
1332 ext_gw_interface=brq${EXT_NET_ID:0:11}
1333 fi
1334 if [[ "$ext_gw_interface" != "none" ]]; then
John Davidge21529a52014-06-30 09:55:11 -04001335 local cidr_len=${FLOATING_RANGE#*/}
Sean M. Collins71947d52015-06-17 17:33:02 -04001336 local testcmd="ip -o link | grep -q $ext_gw_interface"
1337 test_with_retry "$testcmd" "$ext_gw_interface creation failed"
YAMAMOTO Takashi909fa8f2015-03-27 10:56:16 +09001338 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" ) ]]; then
Sean M. Collins00e16a92015-02-20 11:45:21 -05001339 sudo ip addr add $ext_gw_ip/$cidr_len dev $ext_gw_interface
1340 sudo ip link set $ext_gw_interface up
1341 fi
Sirushti Murugesanc00df202015-10-07 15:06:51 +05301342 ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F'ip_address' '{ print $2 }' | cut -f3 -d\" | tr '\n' ' '`
John Davidge21529a52014-06-30 09:55:11 -04001343 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
gong yong sheng348c6ac2015-06-23 14:03:47 +08001344 sudo ip route replace $FIXED_RANGE via $ROUTER_GW_IP
John Davidge21529a52014-06-30 09:55:11 -04001345 fi
1346 _neutron_set_router_id
1347 fi
1348}
1349
1350# Configure neutron router for IPv6 public access
1351function _neutron_configure_router_v6 {
1352 neutron router-interface-add $ROUTER_ID $IPV6_SUBNET_ID
1353 # Create a public subnet on the external network
Ian Wienandada886d2015-10-07 14:06:26 +11001354 local ipv6_id_and_ext_gw_ip
1355 ipv6_id_and_ext_gw_ip=$(_neutron_create_public_subnet_v6 $EXT_NET_ID)
1356 local ipv6_ext_gw_ip
1357 ipv6_ext_gw_ip=$(echo $ipv6_id_and_ext_gw_ip | get_field 2)
1358 local ipv6_pub_subnet_id
1359 ipv6_pub_subnet_id=$(echo $ipv6_id_and_ext_gw_ip | get_field 5)
John Davidge21529a52014-06-30 09:55:11 -04001360
1361 # If the external network has not already been set as the default router
1362 # gateway when configuring an IPv4 public subnet, do so now
1363 if [[ "$IP_VERSION" == "6" ]]; then
1364 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
1365 fi
1366
1367 # This logic is specific to using the l3-agent for layer 3
1368 if is_service_enabled q-l3; then
John Davidge21529a52014-06-30 09:55:11 -04001369 # Ensure IPv6 forwarding is enabled on the host
1370 sudo sysctl -w net.ipv6.conf.all.forwarding=1
1371 # Configure and enable public bridge
Dane LeBlanca79e1012015-03-26 14:48:07 -04001372 # Override global IPV6_ROUTER_GW_IP with the true value from neutron
Sirushti Murugesanc00df202015-10-07 15:06:51 +05301373 IPV6_ROUTER_GW_IP=`neutron port-list -c fixed_ips | grep $ipv6_pub_subnet_id | awk -F'ip_address' '{ print $2 }' | cut -f3 -d\" | tr '\n' ' '`
Dane LeBlanca79e1012015-03-26 14:48:07 -04001374 die_if_not_set $LINENO IPV6_ROUTER_GW_IP "Failure retrieving IPV6_ROUTER_GW_IP"
John Davidge21529a52014-06-30 09:55:11 -04001375
Cedric Brandilyb814b532015-10-22 22:25:45 +02001376 if is_neutron_ovs_base_plugin; then
Ian Wienandada886d2015-10-07 14:06:26 +11001377 local ext_gw_interface
1378 ext_gw_interface=$(_neutron_get_ext_gw_interface)
John Davidge21529a52014-06-30 09:55:11 -04001379 local ipv6_cidr_len=${IPV6_PUBLIC_RANGE#*/}
1380
John Davidge21529a52014-06-30 09:55:11 -04001381 # Configure interface for public bridge
1382 sudo ip -6 addr add $ipv6_ext_gw_ip/$ipv6_cidr_len dev $ext_gw_interface
gong yong sheng348c6ac2015-06-23 14:03:47 +08001383 sudo ip -6 route replace $FIXED_RANGE_V6 via $IPV6_ROUTER_GW_IP dev $ext_gw_interface
John Davidge21529a52014-06-30 09:55:11 -04001384 fi
1385 _neutron_set_router_id
1386 fi
1387}
1388
1389# Explicitly set router id in l3 agent configuration
1390function _neutron_set_router_id {
Cedric Brandilyb814b532015-10-22 22:25:45 +02001391 if [[ "$Q_L3_ROUTER_PER_TENANT" == "False" ]]; then
John Davidge21529a52014-06-30 09:55:11 -04001392 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
1393 fi
1394}
1395
1396# Get ext_gw_interface depending on value of Q_USE_PUBLIC_VETH
1397function _neutron_get_ext_gw_interface {
1398 if [[ "$Q_USE_PUBLIC_VETH" == "True" ]]; then
1399 echo $Q_PUBLIC_VETH_EX
1400 else
1401 # Disable in-band as we are going to use local port
1402 # to communicate with VMs
1403 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
1404 other_config:disable-in-band=true
1405 echo $PUBLIC_BRIDGE
1406 fi
1407}
1408
Mark McClainb05c8762013-07-06 23:29:39 -04001409# Functions for Neutron Exercises
1410#--------------------------------
1411
Ian Wienandaee18c72014-02-21 15:35:08 +11001412function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001413 local from_net="$1"
1414 net_id=`_get_net_id $from_net`
1415 probe_id=`neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-list -c id -c network_id | grep $net_id | awk '{print $2}'`
1416 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1417}
1418
Ian Wienandaee18c72014-02-21 15:35:08 +11001419function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001420 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
1421 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
1422 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
1423 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
1424 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
1425 fi
1426}
1427
Ian Wienandaee18c72014-02-21 15:35:08 +11001428function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001429 delete_probe $PUBLIC_NETWORK_NAME
1430 delete_probe $PRIVATE_NETWORK_NAME
1431}
1432
Ian Wienandaee18c72014-02-21 15:35:08 +11001433function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -04001434 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
1435}
1436
Ian Wienandaee18c72014-02-21 15:35:08 +11001437function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001438 local from_net="$1"
1439 net_id=`_get_net_id $from_net`
1440 probe_id=`neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-list -c id -c network_id | grep $net_id | awk '{print $2}' | head -n 1`
1441 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1442}
1443
Mark McClainb05c8762013-07-06 23:29:39 -04001444# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001445function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001446 local from_net=$1
1447 local key_file=$2
1448 local ip=$3
1449 local user=$4
1450 local timeout_sec=$5
1451 local probe_cmd = ""
1452 probe_cmd=`_get_probe_cmd_prefix $from_net`
Sean Dague442e4e92015-06-24 13:24:02 -04001453 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1454 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
Mark McClainb05c8762013-07-06 23:29:39 -04001455}
1456
1457# Neutron 3rd party programs
1458#---------------------------
1459
1460# please refer to ``lib/neutron_thirdparty/README.md`` for details
1461NEUTRON_THIRD_PARTIES=""
1462for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001463 third_party=$(basename $f)
1464 if is_service_enabled $third_party; then
1465 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1466 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1467 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001468done
1469
Ian Wienandaee18c72014-02-21 15:35:08 +11001470function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001471 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1472 ${1}_${third_party}
1473 done
1474}
1475
1476# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001477function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001478 _neutron_third_party_do configure
1479}
1480
1481# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001482function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001483 _neutron_third_party_do init
1484}
1485
1486# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001487function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001488 _neutron_third_party_do install
1489}
1490
1491# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001492function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001493 _neutron_third_party_do start
1494}
1495
1496# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001497function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001498 _neutron_third_party_do stop
1499}
1500
armando-migliaccioef1e0802014-01-02 16:33:53 -08001501# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001502function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001503 _neutron_third_party_do check
1504}
1505
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001506function is_provider_network {
1507 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1508 return 0
1509 fi
1510 return 1
1511}
1512
Mark McClainb05c8762013-07-06 23:29:39 -04001513
1514# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +11001515$_XTRACE_NEUTRON
Mark McClainb05c8762013-07-06 23:29:39 -04001516
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001517# Tell emacs to use shell-script-mode
1518## Local variables:
1519## mode: shell-script
1520## End: