blob: 3a1bc64ec575e02556560d0e4334a13d9ec3652e [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
Matthew Treinishabde96a2016-05-12 19:26:20 -040064deprecated "Using lib/neutron-legacy is deprecated, and it will be removed in the future"
Armando Migliaccio7dbcfae2016-02-19 14:43:42 -080065
Rob Crittenden18d47782014-03-19 17:47:42 -040066if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then
67 Q_PROTOCOL="https"
68fi
69
70
Mark McClainb05c8762013-07-06 23:29:39 -040071# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050072GITDIR["python-neutronclient"]=$DEST/python-neutronclient
Sean Dague5cb19062014-11-01 01:37:45 +010073
Doug Wiegley93e682c2015-03-03 10:31:30 -070074
Mark McClainb05c8762013-07-06 23:29:39 -040075NEUTRON_DIR=$DEST/neutron
Kyle Mestery20b839f2014-12-08 06:17:27 +000076NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas
Armando Migliacciob3f26cb2016-04-13 23:28:06 +000077NEUTRON_LBAAS_DIR=$DEST/neutron-lbaas
Mark McClainb05c8762013-07-06 23:29:39 -040078NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
79
80# Support entry points installation of console scripts
81if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
82 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040083else
84 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040085fi
86
87NEUTRON_CONF_DIR=/etc/neutron
88NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
89export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
90
Armando Migliacciob3f26cb2016-04-13 23:28:06 +000091# Default provider for load balancer service
92DEFAULT_LB_PROVIDER=LOADBALANCER:Haproxy:neutron_lbaas.services.loadbalancer.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver:default
93
Adam Gandelman7614d212014-08-11 14:27:50 -070094# Agent binaries. Note, binary paths for other agents are set in per-service
95# scripts in lib/neutron_plugins/services/
96AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
97AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
98AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
99
100# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
101# loaded from per-plugin scripts in lib/neutron_plugins/
102Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
103Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
104Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
Adam Gandelman7614d212014-08-11 14:27:50 -0700105Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
106
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400107# Default name for Neutron database
108Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400109# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000110Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400111# Default Neutron Port
112Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400113# Default Neutron Internal Port when using TLS proxy
114Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400115# Default Neutron Host
116Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400117# Default protocol
118Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Brian Haley180f5eb2015-06-16 13:14:31 -0400119# Default listen address
120Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$SERVICE_LISTEN_ADDRESS}
Mark McClainb05c8762013-07-06 23:29:39 -0400121# Default admin username
122Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
123# Default auth strategy
124Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
Mark McClainb05c8762013-07-06 23:29:39 -0400125# RHEL's support for namespaces requires using veths with ovs
126Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
127Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
Yuriy Taraday26623952014-07-16 17:41:53 +0400128Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
Mark McClainb05c8762013-07-06 23:29:39 -0400129# Meta data IP
130Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
131# Allow Overlapping IP among subnets
132Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
Mark McClainb05c8762013-07-06 23:29:39 -0400133# The name of the default q-l3 router
134Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500135Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
136Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800137VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
138VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700139
Mark McClainb05c8762013-07-06 23:29:39 -0400140# List of config file names in addition to the main plugin config file
141# See _configure_neutron_common() for details about setting it up
142declare -a Q_PLUGIN_EXTRA_CONF_FILES
143
Mark McClainb05c8762013-07-06 23:29:39 -0400144
Dean Troyere2907b42014-02-26 17:35:37 -0600145Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
146if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
147 Q_RR_COMMAND="sudo"
148else
149 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
150 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Yuriy Taraday26623952014-07-16 17:41:53 +0400151 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
152 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
153 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400154fi
155
Brian Haleyeea76212014-06-27 11:45:50 -0400156
157# Distributed Virtual Router (DVR) configuration
158# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500159# - ``legacy`` - No DVR functionality
160# - ``dvr_snat`` - Controller or single node DVR
161# - ``dvr`` - Compute node in multi-node DVR
162#
Brian Haleyeea76212014-06-27 11:45:50 -0400163Q_DVR_MODE=${Q_DVR_MODE:-legacy}
164if [[ "$Q_DVR_MODE" != "legacy" ]]; then
165 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
166fi
167
Dean Troyere2907b42014-02-26 17:35:37 -0600168# Provider Network Configurations
169# --------------------------------
170
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900171# The following variables control the Neutron ML2 plugins' allocation
172# of tenant networks and availability of provider networks. If these
173# are not configured in ``localrc``, tenant networks will be local to
174# the host (with no remote connectivity), and no physical resources
175# will be available for the allocation of provider networks.
Dean Troyere2907b42014-02-26 17:35:37 -0600176
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200177# To disable tunnels (GRE or VXLAN) for tenant networks,
178# set to False in ``local.conf``.
179# GRE tunnels are only supported by the openvswitch.
180ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600181
Richard Theis8906b482016-06-08 10:28:37 -0500182# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
183# specify the range of IDs from which tenant networks are
184# allocated. Can be overridden in ``localrc`` if necessary.
Anant Patil3827dc02014-07-03 21:38:16 +0530185TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600186
187# To use VLANs for tenant networks, set to True in localrc. VLANs
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900188# are supported by the ML2 plugins, requiring additional configuration
189# described below.
Dean Troyere2907b42014-02-26 17:35:37 -0600190ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
191
192# If using VLANs for tenant networks, set in ``localrc`` to specify
193# the range of VLAN VIDs from which tenant networks are
194# allocated. An external network switch must be configured to
195# trunk these VLANs between hosts for multi-host connectivity.
196#
197# Example: ``TENANT_VLAN_RANGE=1000:1999``
198TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
199
200# If using VLANs for tenant networks, or if using flat or VLAN
201# provider networks, set in ``localrc`` to the name of the physical
202# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
203# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
204# agent, as described below.
205#
206# Example: ``PHYSICAL_NETWORK=default``
207PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
208
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900209# With the openvswitch agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600210# or if using flat or VLAN provider networks, set in ``localrc`` to
211# the name of the OVS bridge to use for the physical network. The
212# bridge will be created if it does not already exist, but a
213# physical interface must be manually added to the bridge as a
214# port for external connectivity.
215#
216# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
217OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
218
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900219# With the linuxbridge agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600220# or if using flat or VLAN provider networks, set in ``localrc`` to
221# the name of the network interface to use for the physical
222# network.
223#
224# Example: ``LB_PHYSICAL_INTERFACE=eth1``
225LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
226
Edgar Magana6f335b92014-07-10 15:42:44 -0700227# When Neutron tunnels are enabled it is needed to specify the
228# IP address of the end point in the local server. This IP is set
229# by default to the same IP address that the HOST IP.
230# This variable can be used to specify a different end point IP address
231# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
232TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
233
Dean Troyere2907b42014-02-26 17:35:37 -0600234# With the openvswitch plugin, set to True in ``localrc`` to enable
235# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
236#
237# Example: ``OVS_ENABLE_TUNNELING=True``
238OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
239
Tan Lin27a196e2014-10-31 15:44:34 +0800240# Use DHCP agent for providing metadata service in the case of
241# without L3 agent (No Route Agent), set to True in localrc.
242ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
243
244# Add a static route as dhcp option, so the request to 169.254.169.254
245# will be able to reach through a route(DHCP agent)
246# This option require ENABLE_ISOLATED_METADATA = True
247ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
Mark McClainb05c8762013-07-06 23:29:39 -0400248# Neutron plugin specific functions
249# ---------------------------------
250
251# Please refer to ``lib/neutron_plugins/README.md`` for details.
Hirofumi Ichihara36daecd2015-07-23 17:50:40 +0900252if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
253 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
254fi
Mark McClainb05c8762013-07-06 23:29:39 -0400255
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000256# Agent loadbalancer service plugin functions
257# -------------------------------------------
258
259# Hardcoding for 1 service plugin for now
260source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
261
Emilien Macchi40546f72013-09-24 15:10:25 +0200262# Agent metering service plugin functions
263# -------------------------------------------
264
265# Hardcoding for 1 service plugin for now
266source $TOP_DIR/lib/neutron_plugins/services/metering
267
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700268# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100269# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700270source $TOP_DIR/lib/neutron_plugins/services/firewall
271
Sean M. Collins2a242512016-05-03 09:03:09 -0400272# L3 Service functions
273source $TOP_DIR/lib/neutron_plugins/services/l3
274
Mark McClainb05c8762013-07-06 23:29:39 -0400275# Use security group or not
276if has_neutron_plugin_security_group; then
277 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
278else
279 Q_USE_SECGROUP=False
280fi
281
Dean Troyere2907b42014-02-26 17:35:37 -0600282# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +1100283_XTRACE_NEUTRON=$(set +o | grep xtrace)
Dean Troyere2907b42014-02-26 17:35:37 -0600284set +o xtrace
285
286
Mark McClainb05c8762013-07-06 23:29:39 -0400287# Functions
288# ---------
289
Adam Gandelman7614d212014-08-11 14:27:50 -0700290function _determine_config_server {
291 local cfg_file
292 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
293 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
Tom Patzig73467042016-04-19 17:02:34 +0200294 opts+=" --config-file $cfg_file"
Adam Gandelman7614d212014-08-11 14:27:50 -0700295 done
296 echo "$opts"
297}
298
Adam Gandelman7614d212014-08-11 14:27:50 -0700299function _determine_config_l3 {
Angus Leesa1c70f22016-05-31 14:43:14 +1000300 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
Adam Gandelman7614d212014-08-11 14:27:50 -0700301 if is_service_enabled q-fwaas; then
302 opts+=" --config-file $Q_FWAAS_CONF_FILE"
303 fi
304 echo "$opts"
305}
306
307# For services and agents that require it, dynamically construct a list of
308# --config-file arguments that are passed to the binary.
309function determine_config_files {
310 local opts=""
311 case "$1" in
312 "neutron-server") opts="$(_determine_config_server)" ;;
Adam Gandelman7614d212014-08-11 14:27:50 -0700313 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
314 esac
315 if [ -z "$opts" ] ; then
316 die $LINENO "Could not determine config files for $1."
317 fi
318 echo "$opts"
319}
320
Sean M. Collins2a242512016-05-03 09:03:09 -0400321# configure_mutnauq()
Mark McClainb05c8762013-07-06 23:29:39 -0400322# Set common config for all neutron server and agents.
Sean M. Collins2a242512016-05-03 09:03:09 -0400323function configure_mutnauq {
Mark McClainb05c8762013-07-06 23:29:39 -0400324 _configure_neutron_common
Brant Knudson2dd110c2015-03-14 12:39:14 -0500325 iniset_rpc_backend neutron $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400326
327 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000328 if is_service_enabled q-lbaas; then
329 deprecated "Configuring q-lbaas through devstack is deprecated"
330 _configure_neutron_lbaas
331 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200332 if is_service_enabled q-metering; then
333 _configure_neutron_metering
334 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700335 if is_service_enabled q-fwaas; then
Sean Dagued6f92232016-02-09 06:34:36 -0500336 deprecated "Configuring q-fwaas through devstack is deprecated"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700337 _configure_neutron_fwaas
338 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000339 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400340 _configure_neutron_service
341 fi
342 if is_service_enabled q-agt; then
343 _configure_neutron_plugin_agent
344 fi
345 if is_service_enabled q-dhcp; then
346 _configure_neutron_dhcp_agent
347 fi
348 if is_service_enabled q-l3; then
349 _configure_neutron_l3_agent
350 fi
351 if is_service_enabled q-meta; then
352 _configure_neutron_metadata_agent
353 fi
354
Brian Haleyeea76212014-06-27 11:45:50 -0400355 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
356 _configure_dvr
357 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400358 if is_service_enabled ceilometer; then
359 _configure_neutron_ceilometer_notifications
360 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400361
armando-migliaccioe155b892015-06-12 08:55:02 -0700362 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
Mark McClainb05c8762013-07-06 23:29:39 -0400363}
364
Ian Wienandaee18c72014-02-21 15:35:08 +1100365function create_nova_conf_neutron {
Sean Daguef21cc1f2016-03-04 11:08:32 -0500366 iniset $NOVA_CONF DEFAULT use_neutron True
Matthew Kassawara28af7962016-02-10 19:04:08 +0000367 iniset $NOVA_CONF neutron auth_type "password"
Brant Knudsone86b91b2016-05-03 15:21:47 -0500368 iniset $NOVA_CONF neutron auth_url "$KEYSTONE_AUTH_URI/v3"
Jamie Lennox394968f2015-08-28 09:18:26 +1000369 iniset $NOVA_CONF neutron username "$Q_ADMIN_USERNAME"
370 iniset $NOVA_CONF neutron password "$SERVICE_PASSWORD"
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600371 iniset $NOVA_CONF neutron user_domain_name "$SERVICE_DOMAIN_NAME"
Sean Dague7580a0c2016-02-17 06:23:36 -0500372 iniset $NOVA_CONF neutron project_name "$SERVICE_PROJECT_NAME"
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600373 iniset $NOVA_CONF neutron project_domain_name "$SERVICE_DOMAIN_NAME"
Gary Kotton13d385e2014-06-17 23:24:53 -0700374 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
Bartosz Górski0abde392014-02-28 14:15:19 +0100375 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Rob Crittenden18d47782014-03-19 17:47:42 -0400376 iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400377
378 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
379 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400380 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Mark McClainb05c8762013-07-06 23:29:39 -0400381 fi
382
Matt Riedemann925c2562015-08-25 13:40:25 -0700383 # optionally set options in nova_conf
Mark McClainb05c8762013-07-06 23:29:39 -0400384 neutron_plugin_create_nova_conf
385
Mark McClainb05c8762013-07-06 23:29:39 -0400386 if is_service_enabled q-meta; then
Gary Kottondd745502014-08-11 23:38:47 -0700387 iniset $NOVA_CONF neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400388 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800389
390 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
391 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400392}
393
Sean M. Collins2a242512016-05-03 09:03:09 -0400394# create_mutnauq_accounts() - Set up common required neutron accounts
Mark McClainb05c8762013-07-06 23:29:39 -0400395
396# Tenant User Roles
397# ------------------------------------------------------------------
398# service neutron admin # if enabled
399
400# Migrated from keystone_data.sh
Sean M. Collins2a242512016-05-03 09:03:09 -0400401function create_mutnauq_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400402 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100403
Jamie Lennox85ff5322015-01-28 14:28:01 +1000404 create_service_user "neutron"
Bartosz Górski0abde392014-02-28 14:15:19 +0100405
Sean Dague985e9582016-02-10 07:25:24 -0500406 get_or_create_service "neutron" "network" "Neutron Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000407 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500408 "network" \
409 "$REGION_NAME" \
410 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
411 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
412 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400413 fi
414}
415
Sean M. Collins2a242512016-05-03 09:03:09 -0400416# init_mutnauq() - Initialize databases, etc.
417function init_mutnauq {
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200418 recreate_database $Q_DB_NAME
Salvatore Orlandodd649882013-08-05 08:56:17 -0700419 # Run Neutron db migrations
420 $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 -0400421}
422
Sean M. Collins2a242512016-05-03 09:03:09 -0400423# install_mutnauq() - Collect source and prepare
424function install_mutnauq {
Doug Wiegley86561c32016-02-10 18:37:21 -0700425 # Install neutron-lib from git so we make sure we're testing
426 # the latest code.
427 if use_library_from_git "neutron-lib"; then
428 git_clone_by_name "neutron-lib"
429 setup_dev_lib "neutron-lib"
430 fi
431
Mark McClainb05c8762013-07-06 23:29:39 -0400432 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
433 setup_develop $NEUTRON_DIR
Kyle Mestery20b839f2014-12-08 06:17:27 +0000434 if is_service_enabled q-fwaas; then
435 git_clone $NEUTRON_FWAAS_REPO $NEUTRON_FWAAS_DIR $NEUTRON_FWAAS_BRANCH
436 setup_develop $NEUTRON_FWAAS_DIR
437 fi
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000438 if is_service_enabled q-lbaas; then
439 git_clone $NEUTRON_LBAAS_REPO $NEUTRON_LBAAS_DIR $NEUTRON_LBAAS_BRANCH
440 setup_develop $NEUTRON_LBAAS_DIR
441 fi
Mate Lakat6df64892014-10-17 13:09:49 +0200442
443 if [ "$VIRT_DRIVER" == 'xenserver' ]; then
444 local dom0_ip
445 dom0_ip=$(echo "$XENAPI_CONNECTION_URL" | cut -d "/" -f 3-)
446
447 local ssh_dom0
448 ssh_dom0="sudo -u $DOMZERO_USER ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$dom0_ip"
449
450 # Find where the plugins should go in dom0
451 local xen_functions
452 xen_functions=$(cat $TOP_DIR/tools/xen/functions)
453 local plugin_dir
454 plugin_dir=$($ssh_dom0 "$xen_functions; set -eux; xapi_plugin_location")
455
456 # install neutron plugins to dom0
Huan Xie201e3c12015-08-27 12:34:24 +0100457 tar -czf - -C $NEUTRON_DIR/neutron/plugins/ml2/drivers/openvswitch/agent/xenapi/etc/xapi.d/plugins/ ./ |
Mate Lakat6df64892014-10-17 13:09:49 +0200458 $ssh_dom0 "tar -xzf - -C $plugin_dir && chmod a+x $plugin_dir/*"
459 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400460}
461
Mark McClainb05c8762013-07-06 23:29:39 -0400462# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100463function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400464 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
465 if is_service_enabled q-l3; then
466 install_package radvd
467 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400468 # install packages that are specific to plugin agent(s)
469 if is_service_enabled q-agt q-dhcp q-l3; then
470 neutron_plugin_install_agent_packages
471 fi
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000472
473 if is_service_enabled q-lbaas; then
474 neutron_agent_lbaas_install_agent_packages
475 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400476}
477
478# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100479function start_neutron_service_and_check {
Rob Crittenden18d47782014-03-19 17:47:42 -0400480 local service_port=$Q_PORT
481 local service_protocol=$Q_PROTOCOL
Ian Wienand7ae97292016-02-16 14:50:53 +1100482 local cfg_file_options
483
484 cfg_file_options="$(determine_config_files neutron-server)"
485
Rob Crittenden18d47782014-03-19 17:47:42 -0400486 if is_service_enabled tls-proxy; then
487 service_port=$Q_PORT_INT
488 service_protocol="http"
489 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400490 # Start the Neutron service
Davanum Srinivas59756e92015-09-23 17:42:54 -0400491 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400492 echo "Waiting for Neutron to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400493 if is_ssl_enabled_service "neutron"; then
494 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
495 fi
Sean Dague442e4e92015-06-24 13:24:02 -0400496
497 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $service_protocol://$Q_HOST:$service_port"
498 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
499
Rob Crittenden18d47782014-03-19 17:47:42 -0400500 # Start proxy if enabled
501 if is_service_enabled tls-proxy; then
502 start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT &
503 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400504}
505
Russell Bryant09b94602015-06-08 15:25:43 -0400506# Control of the l2 agent is separated out to make it easier to test partial
507# upgrades (everything upgraded except the L2 agent)
Sean M. Collins2a242512016-05-03 09:03:09 -0400508function start_mutnauq_l2_agent {
Davanum Srinivas59756e92015-09-23 17:42:54 -0400509 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700510
Kahou Leid663e292015-10-24 12:18:57 -0700511 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
Zhongyue Luo56b7efb2014-12-16 11:36:49 +0800512 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400513 sudo ip link set $OVS_PHYSICAL_BRIDGE up
514 sudo ip link set br-int up
515 sudo ip link set $PUBLIC_INTERFACE up
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700516 if is_ironic_hardware; then
517 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
518 sudo ip addr del $IP dev $PUBLIC_INTERFACE
519 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
520 done
gong yong sheng348c6ac2015-06-23 14:03:47 +0800521 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700522 fi
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400523 fi
Russell Bryant09b94602015-06-08 15:25:43 -0400524}
525
Sean M. Collins2a242512016-05-03 09:03:09 -0400526function start_mutnauq_other_agents {
Angus Leesa1c70f22016-05-31 14:43:14 +1000527 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 -0400528
Paul Michalie4289c82015-08-14 11:49:27 -0400529 if is_service_enabled neutron-vpnaas; then
530 : # Started by plugin
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700531 else
Davanum Srinivas59756e92015-09-23 17:42:54 -0400532 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700533 fi
534
Angus Leesa1c70f22016-05-31 14:43:14 +1000535 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
536 run_process q-lbaas "$AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file $LBAAS_AGENT_CONF_FILENAME"
Davanum Srinivas59756e92015-09-23 17:42:54 -0400537 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400538
539 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
540 # For XenServer, start an agent for the domU openvswitch
Davanum Srinivas59756e92015-09-23 17:42:54 -0400541 run_process q-domua "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
Mark McClainb05c8762013-07-06 23:29:39 -0400542 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400543}
544
Russell Bryant09b94602015-06-08 15:25:43 -0400545# Start running processes, including screen
546function start_neutron_agents {
547 # Start up the neutron agents if enabled
Sean M. Collins2a242512016-05-03 09:03:09 -0400548 start_mutnauq_l2_agent
549 start_mutnauq_other_agents
Russell Bryant09b94602015-06-08 15:25:43 -0400550}
551
Sean M. Collins2a242512016-05-03 09:03:09 -0400552function stop_mutnauq_l2_agent {
Russell Bryant09b94602015-06-08 15:25:43 -0400553 stop_process q-agt
554}
555
Sean M. Collins2a242512016-05-03 09:03:09 -0400556# stop_mutnauq_other() - Stop running processes (non-screen)
557function stop_mutnauq_other {
Mark McClainb05c8762013-07-06 23:29:39 -0400558 if is_service_enabled q-dhcp; then
Chris Dent36891dc2015-02-03 16:22:44 +0000559 stop_process q-dhcp
Mark McClainb05c8762013-07-06 23:29:39 -0400560 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
561 [ ! -z "$pid" ] && sudo kill -9 $pid
562 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000563
564 stop_process q-svc
Li Maa15d9de2016-01-19 19:11:51 +0800565
566 if is_service_enabled q-l3; then
567 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
568 stop_process q-l3
569 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000570
Mark McClainb05c8762013-07-06 23:29:39 -0400571 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100572 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Chris Dent36891dc2015-02-03 16:22:44 +0000573 stop_process q-meta
Mark McClainb05c8762013-07-06 23:29:39 -0400574 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900575
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000576 if is_service_enabled q-lbaas; then
577 neutron_lbaas_stop
578 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900579 if is_service_enabled q-fwaas; then
580 neutron_fwaas_stop
581 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900582 if is_service_enabled q-metering; then
583 neutron_metering_stop
584 fi
Li Ma50120fa2015-12-13 10:41:34 +0800585
586 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
587 sudo pkill -9 -f $NEUTRON_ROOTWRAP-daemon || :
588 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400589}
590
Russell Bryant09b94602015-06-08 15:25:43 -0400591# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400592function stop_mutnauq {
593 stop_mutnauq_other
594 stop_mutnauq_l2_agent
Russell Bryant09b94602015-06-08 15:25:43 -0400595}
596
Sean M. Collins00e16a92015-02-20 11:45:21 -0500597# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600598# on startup, or back to the public interface on cleanup. If no IP is
599# configured on the interface, just add it as a port to the OVS bridge.
Sean M. Collins00e16a92015-02-20 11:45:21 -0500600function _move_neutron_addresses_route {
601 local from_intf=$1
602 local to_intf=$2
603 local add_ovs_port=$3
Brian Haleya0d1b012015-11-16 17:30:48 -0500604 local del_ovs_port=$4
605 local af=$5
Sean M. Collins00e16a92015-02-20 11:45:21 -0500606
607 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
608 # Remove the primary IP address from $from_intf and add it to $to_intf,
609 # along with the default route, if it exists. Also, when called
610 # on configure we will also add $from_intf as a port on $to_intf,
611 # assuming it is an OVS bridge.
612
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600613 local IP_ADD=""
614 local IP_DEL=""
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900615 local IP_UP=""
Ian Wienandada886d2015-10-07 14:06:26 +1100616 local DEFAULT_ROUTE_GW
Sean M. Collins59e86a32015-11-09 11:06:39 -0500617 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf/ { print \$3; exit }")
Sean M. Collins00e16a92015-02-20 11:45:21 -0500618 local ADD_OVS_PORT=""
Brian Haleya0d1b012015-11-16 17:30:48 -0500619 local DEL_OVS_PORT=""
Sean M. Collins17398a32016-05-11 18:24:46 +0000620 local ARP_CMD=""
Sean M. Collins00e16a92015-02-20 11:45:21 -0500621
Brian Haleybb9caea2015-11-16 17:18:42 -0500622 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 -0600623
Sean M. Collins00e16a92015-02-20 11:45:21 -0500624 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
Sean M. Collins59e86a32015-11-09 11:06:39 -0500625 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 -0500626 fi
627
628 if [[ "$add_ovs_port" == "True" ]]; then
Raman Budnydb02bbf2015-03-31 13:09:09 +0300629 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
Sean M. Collins00e16a92015-02-20 11:45:21 -0500630 fi
631
Brian Haleya0d1b012015-11-16 17:30:48 -0500632 if [[ "$del_ovs_port" == "True" ]]; then
633 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
634 fi
635
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600636 if [[ "$IP_BRD" != "" ]]; then
Brian Haley94510212015-09-02 15:40:04 -0400637 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
638 IP_ADD="sudo ip addr add $IP_BRD dev $to_intf"
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900639 IP_UP="sudo ip link set $to_intf up"
Sean M. Collins6d4843e2016-05-12 16:14:26 -0400640 if [[ "$af" == "inet" ]]; then
641 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
642 ARP_CMD="arping -A -c 3 -w 4.5 -I $to_intf $IP "
643 fi
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600644 fi
645
Brian Haleya0d1b012015-11-16 17:30:48 -0500646 # The add/del OVS port calls have to happen either before or
647 # after the address is moved in order to not leave it orphaned.
Sean M. Collins53b63cc2016-04-28 13:33:38 -0500648 $DEL_OVS_PORT; $IP_DEL; $IP_ADD; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
Sean M. Collins00e16a92015-02-20 11:45:21 -0500649 fi
650}
651
Sean M. Collins2a242512016-05-03 09:03:09 -0400652# cleanup_mutnauq() - Remove residual data files, anything left over from previous
Mark McClainb05c8762013-07-06 23:29:39 -0400653# runs that a clean run would need to clean up
Sean M. Collins2a242512016-05-03 09:03:09 -0400654function cleanup_mutnauq {
Sean M. Collins00e16a92015-02-20 11:45:21 -0500655
Yalei Wang316b3482015-07-15 21:00:31 +0800656 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
Brian Haleya0d1b012015-11-16 17:30:48 -0500657 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
Adam Kacmarsky11298a02015-06-26 14:49:47 -0600658
Yalei Wang316b3482015-07-15 21:00:31 +0800659 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
Sean M. Collins790266f2015-11-11 13:36:35 -0500660 # ip(8) wants the prefix length when deleting
661 local v6_gateway
662 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
663 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
Brian Haleya0d1b012015-11-16 17:30:48 -0500664 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
Yalei Wang316b3482015-07-15 21:00:31 +0800665 fi
Sean M. Collins00e16a92015-02-20 11:45:21 -0500666
Yalei Wang316b3482015-07-15 21:00:31 +0800667 if is_provider_network && is_ironic_hardware; then
668 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
669 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
670 sudo ip addr add $IP dev $PUBLIC_INTERFACE
671 done
672 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
673 fi
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700674 fi
675
Mark McClainb05c8762013-07-06 23:29:39 -0400676 if is_neutron_ovs_base_plugin; then
677 neutron_ovs_base_cleanup
678 fi
679
Sean M. Collins7bc2af72015-06-08 12:36:30 -0400680 if [[ $Q_AGENT == "linuxbridge" ]]; then
681 neutron_lb_cleanup
682 fi
683
Mark McClainb05c8762013-07-06 23:29:39 -0400684 # delete all namespaces created by neutron
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000685 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 -0400686 sudo ip netns delete ${ns}
687 done
688}
689
Doug Wiegley93e682c2015-03-03 10:31:30 -0700690
Maru Newby952fd902015-01-30 22:27:12 +0000691function _create_neutron_conf_dir {
Mark McClainb05c8762013-07-06 23:29:39 -0400692 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
Dean Troyer8421c2b2015-03-16 13:52:19 -0500693 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
Maru Newby952fd902015-01-30 22:27:12 +0000694}
695
696# _configure_neutron_common()
697# Set common config for all neutron server and agents.
698# This MUST be called before other ``_configure_neutron_*`` functions.
699function _configure_neutron_common {
700 _create_neutron_conf_dir
Mark McClainb05c8762013-07-06 23:29:39 -0400701
Martin Hickey30d5fae2015-11-10 13:44:15 +0000702 # Uses oslo config generator to generate core sample configuration files
703 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
704
705 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400706
Jerry Zhao296c1e32015-08-07 20:43:54 -0400707 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
708 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
709
710 # allow neutron user to administer neutron to match neutron account
711 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
712
Mark McClainb05c8762013-07-06 23:29:39 -0400713 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
714 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
Tom Patzig67223b02016-04-19 16:43:05 +0200715 # For additional plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH`` and
Mark McClainb05c8762013-07-06 23:29:39 -0400716 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100717 #
Tom Patzig67223b02016-04-19 16:43:05 +0200718 # ``Q_PLUGIN_EXTRA_CONF_PATH=/path/to/plugins``
Boden R82bca442016-04-15 10:56:09 -0600719 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1 file2)``
Mark McClainb05c8762013-07-06 23:29:39 -0400720 neutron_plugin_configure_common
721
sbauzae2c4ee22013-08-29 17:29:46 +0200722 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400723 die $LINENO "Neutron plugin not set.. exiting"
724 fi
725
726 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
727 mkdir -p /$Q_PLUGIN_CONF_PATH
728 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900729 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
730 # there is no config file in Neutron tree. They should prepare the file in each plugin.
Martin Hickey30d5fae2015-11-10 13:44:15 +0000731 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
732 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
733 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900734 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
735 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400736
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200737 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400738 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
salvatoree4e535b2014-10-29 18:22:46 +0100739 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
Brian Haley180f5eb2015-06-16 13:14:31 -0400740 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
Martin Hickey30d5fae2015-11-10 13:44:15 +0000741 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
742
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +0300743 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
744 iniset $NEUTRON_CONF nova region_name $REGION_NAME
745
Mark McClainb05c8762013-07-06 23:29:39 -0400746 # If addition config files are set, make sure their path name is set as well
747 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
748 die $LINENO "Neutron additional plugin config not set.. exiting"
749 fi
750
751 # If additional config files exist, copy them over to neutron configuration
752 # directory
753 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400754 local f
755 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
756 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400757 done
758 fi
759
Joe Gordonbee5c502013-08-30 13:48:08 -0400760 if [ "$VIRT_DRIVER" = 'fake' ]; then
761 # Disable arbitrary limits
762 iniset $NEUTRON_CONF quotas quota_network -1
763 iniset $NEUTRON_CONF quotas quota_subnet -1
764 iniset $NEUTRON_CONF quotas quota_port -1
765 iniset $NEUTRON_CONF quotas quota_security_group -1
766 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
767 fi
768
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700769 # Format logging
770 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800771 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
venkata anil9b1df572015-01-15 07:38:22 +0000772 else
773 # Show user_name and project_name by default like in nova
Ronald Bradforde8264902016-01-20 21:16:33 +0000774 iniset $NEUTRON_CONF DEFAULT logging_user_identity_format "%(user_name)s %(project_name)s"
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700775 fi
776
Rob Crittenden18d47782014-03-19 17:47:42 -0400777 if is_service_enabled tls-proxy; then
778 # Set the service port for a proxy to take the original
779 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
780 fi
781
782 if is_ssl_enabled_service "nova"; then
Jamie Lennoxdc757dd2015-03-09 14:48:09 +1100783 iniset $NEUTRON_CONF nova cafile $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400784 fi
785
786 if is_ssl_enabled_service "neutron"; then
787 ensure_certificates NEUTRON
788
789 iniset $NEUTRON_CONF DEFAULT use_ssl True
790 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
791 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
792 fi
793
Mark McClainb05c8762013-07-06 23:29:39 -0400794 _neutron_setup_rootwrap
795}
796
Ian Wienandaee18c72014-02-21 15:35:08 +1100797function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400798
Martin Hickey30d5fae2015-11-10 13:44:15 +0000799 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400800
Ben Nemec03997942013-08-10 09:56:16 -0500801 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700802 iniset $Q_DHCP_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400803 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700804 iniset $Q_DHCP_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400805 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400806
Tan Lin27a196e2014-10-31 15:44:34 +0800807 if ! is_service_enabled q-l3; then
808 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
809 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
810 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
811 else
812 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
813 die "$LINENO" "Enable isolated metadata is a must for metadata network"
814 fi
815 fi
816 fi
817
Mark McClainb05c8762013-07-06 23:29:39 -0400818 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
819
xurong000379977ef31d02016-07-05 11:09:40 +0800820 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400821}
822
Mark McClainb05c8762013-07-06 23:29:39 -0400823
Ian Wienandaee18c72014-02-21 15:35:08 +1100824function _configure_neutron_metadata_agent {
Martin Hickey30d5fae2015-11-10 13:44:15 +0000825 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400826
Ben Nemec03997942013-08-10 09:56:16 -0500827 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400828 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700829 iniset $Q_META_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400830 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700831 iniset $Q_META_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400832 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400833}
834
Dina Belova58adaa62014-07-11 18:18:12 +0400835function _configure_neutron_ceilometer_notifications {
Wanlong Gaocf04a9a2016-01-16 17:46:35 +0800836 iniset $NEUTRON_CONF oslo_messaging_notifications driver messaging
Dina Belova58adaa62014-07-11 18:18:12 +0400837}
838
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000839function _configure_neutron_lbaas {
840 # Uses oslo config generator to generate LBaaS sample configuration files
841 (cd $NEUTRON_LBAAS_DIR && exec ./tools/generate_config_file_samples.sh)
842
843 if [ -f $NEUTRON_LBAAS_DIR/etc/neutron_lbaas.conf.sample ]; then
844 cp $NEUTRON_LBAAS_DIR/etc/neutron_lbaas.conf.sample $NEUTRON_CONF_DIR/neutron_lbaas.conf
845 iniset $NEUTRON_CONF_DIR/neutron_lbaas.conf service_providers service_provider $DEFAULT_LB_PROVIDER
846 fi
847 neutron_agent_lbaas_configure_common
848 neutron_agent_lbaas_configure_agent
849}
850
Ian Wienandaee18c72014-02-21 15:35:08 +1100851function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200852 neutron_agent_metering_configure_common
853 neutron_agent_metering_configure_agent
854}
855
Ian Wienandaee18c72014-02-21 15:35:08 +1100856function _configure_neutron_fwaas {
Doug Wiegley37da4592015-01-30 23:30:08 -0700857 if [ -f $NEUTRON_FWAAS_DIR/etc/neutron_fwaas.conf ]; then
858 cp $NEUTRON_FWAAS_DIR/etc/neutron_fwaas.conf $NEUTRON_CONF_DIR
859 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700860 neutron_fwaas_configure_common
861 neutron_fwaas_configure_driver
862}
863
Brian Haleyeea76212014-06-27 11:45:50 -0400864function _configure_dvr {
865 iniset $NEUTRON_CONF DEFAULT router_distributed True
866 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
867}
868
869
Mark McClainb05c8762013-07-06 23:29:39 -0400870# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
871# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100872function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400873 # Specify the default root helper prior to agent configuration to
874 # ensure that an agent's configuration can override the default
875 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400876 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
877 iniset /$Q_PLUGIN_CONF_FILE agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
878 fi
Ben Nemec03997942013-08-10 09:56:16 -0500879 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400880
881 # Configure agent for plugin
882 neutron_plugin_configure_plugin_agent
883}
884
885# _configure_neutron_service() - Set config files for neutron service
886# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100887function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400888 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
Mark McClainb05c8762013-07-06 23:29:39 -0400889 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700890
Mark McClainb05c8762013-07-06 23:29:39 -0400891 # Update either configuration file with plugin
892 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
893
894 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
895 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
896 fi
897
Ben Nemec03997942013-08-10 09:56:16 -0500898 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Chris Dent74a85b02015-04-22 18:02:39 +0000899 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400900 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
901
902 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
903 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
904
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900905 # Configuration for neutron notifications to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500906 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
907 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Jamie Lennoxdc757dd2015-03-09 14:48:09 +1100908
Thomas Bechtoldfb948912016-03-27 08:59:42 +0200909 configure_auth_token_middleware $NEUTRON_CONF nova $NEUTRON_AUTH_CACHE_DIR nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800910
Mark McClainb05c8762013-07-06 23:29:39 -0400911 # Configure plugin
912 neutron_plugin_configure_service
913}
914
915# Utility Functions
916#------------------
917
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900918# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100919function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900920 local service_plugin_class=$1
921 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
922 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
923 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
924 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
925 fi
926}
927
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100928# _neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
929function _neutron_deploy_rootwrap_filters {
gong yong sheng3d6eaae2015-09-15 15:00:29 +0800930 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
931 return
932 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100933 local srcdir=$1
Dean Troyer8421c2b2015-03-16 13:52:19 -0500934 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
935 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100936}
937
Mark McClainb05c8762013-07-06 23:29:39 -0400938# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100939function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400940 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
941 return
942 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400943 # Wipe any existing ``rootwrap.d`` files first
944 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
945 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
946 sudo rm -rf $Q_CONF_ROOTWRAP_D
947 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100948
949 _neutron_deploy_rootwrap_filters $NEUTRON_DIR
950
Mark McClainb05c8762013-07-06 23:29:39 -0400951 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
952 # location moved in newer versions, prefer new location
953 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Dean Troyer8421c2b2015-03-16 13:52:19 -0500954 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 -0400955 else
Dean Troyer8421c2b2015-03-16 13:52:19 -0500956 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400957 fi
958 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
Robert Li2c5d4622015-04-21 15:48:22 -0400959 sudo sed -e 's:^exec_dirs=\(.*\)$:exec_dirs=\1,/usr/local/bin:' -i $Q_RR_CONF_FILE
960
Mark McClainb05c8762013-07-06 23:29:39 -0400961 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
962 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
Yuriy Taraday26623952014-07-16 17:41:53 +0400963 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400964
965 # Set up the rootwrap sudoers for neutron
966 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100967 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Yuriy Taraday26623952014-07-16 17:41:53 +0400968 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400969 chmod 0440 $TEMPFILE
970 sudo chown root:root $TEMPFILE
971 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
972
973 # Update the root_helper
974 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400975 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
976 iniset $NEUTRON_CONF agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
977 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400978}
979
Ihar Hrachyshkabb4654b2015-10-06 18:09:07 +0200980# Configures keystone integration for neutron service
Ian Wienandaee18c72014-02-21 15:35:08 +1100981function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -0400982 local conf_file=$1
983 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000984
Brant Knudson05952372014-09-19 17:22:22 -0500985 create_neutron_cache_dir
986 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -0400987}
988
Ian Wienandaee18c72014-02-21 15:35:08 +1100989function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -0400990
991 # ovs_use_veth needs to be set before the plugin configuration
992 # occurs to allow plugins to override the setting.
993 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
994
995 neutron_plugin_setup_interface_driver $1
996}
Mark McClainb05c8762013-07-06 23:29:39 -0400997# Functions for Neutron Exercises
998#--------------------------------
999
Ian Wienandaee18c72014-02-21 15:35:08 +11001000function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001001 local from_net="$1"
1002 net_id=`_get_net_id $from_net`
1003 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}'`
1004 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1005}
1006
Ian Wienandaee18c72014-02-21 15:35:08 +11001007function _get_net_id {
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +03001008 neutron --os-cloud devstack-admin --os-region "$REGION_NAME" --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
Mark McClainb05c8762013-07-06 23:29:39 -04001009}
1010
Ian Wienandaee18c72014-02-21 15:35:08 +11001011function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001012 local from_net="$1"
1013 net_id=`_get_net_id $from_net`
1014 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`
1015 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1016}
1017
Mark McClainb05c8762013-07-06 23:29:39 -04001018# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001019function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001020 local from_net=$1
1021 local key_file=$2
1022 local ip=$3
1023 local user=$4
1024 local timeout_sec=$5
1025 local probe_cmd = ""
1026 probe_cmd=`_get_probe_cmd_prefix $from_net`
Sean Dague442e4e92015-06-24 13:24:02 -04001027 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1028 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
Mark McClainb05c8762013-07-06 23:29:39 -04001029}
1030
1031# Neutron 3rd party programs
1032#---------------------------
1033
1034# please refer to ``lib/neutron_thirdparty/README.md`` for details
1035NEUTRON_THIRD_PARTIES=""
1036for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001037 third_party=$(basename $f)
1038 if is_service_enabled $third_party; then
1039 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1040 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1041 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001042done
1043
Ian Wienandaee18c72014-02-21 15:35:08 +11001044function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001045 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1046 ${1}_${third_party}
1047 done
1048}
1049
1050# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001051function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001052 _neutron_third_party_do configure
1053}
1054
1055# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001056function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001057 _neutron_third_party_do init
1058}
1059
1060# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001061function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001062 _neutron_third_party_do install
1063}
1064
1065# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001066function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001067 _neutron_third_party_do start
1068}
1069
1070# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001071function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001072 _neutron_third_party_do stop
1073}
1074
armando-migliaccioef1e0802014-01-02 16:33:53 -08001075# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001076function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001077 _neutron_third_party_do check
1078}
1079
Mark McClainb05c8762013-07-06 23:29:39 -04001080# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +11001081$_XTRACE_NEUTRON
Mark McClainb05c8762013-07-06 23:29:39 -04001082
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001083# Tell emacs to use shell-script-mode
1084## Local variables:
1085## mode: shell-script
1086## End: