blob: 1d4fe1bd5f85b2789e7647abca3b062b1f6c4793 [file] [log] [blame]
Mark McClainb05c8762013-07-06 23:29:39 -04001# lib/neutron
Joe Gordon23946052014-01-15 21:42:32 +00002# functions - functions specific to neutron
Mark McClainb05c8762013-07-06 23:29:39 -04003
4# Dependencies:
5# ``functions`` file
6# ``DEST`` must be defined
Stephan Renatuse578eff2013-11-19 13:31:04 +01007# ``STACK_USER`` must be defined
Mark McClainb05c8762013-07-06 23:29:39 -04008
9# ``stack.sh`` calls the entry points in this order:
10#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010011# - install_neutron
12# - install_neutronclient
13# - install_neutron_agent_packages
14# - install_neutron_third_party
15# - configure_neutron
16# - init_neutron
17# - configure_neutron_third_party
18# - init_neutron_third_party
19# - start_neutron_third_party
Emilien Macchia677b7f2013-11-25 23:40:20 +010020# - create_neutron_cache_dir
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010021# - create_nova_conf_neutron
22# - start_neutron_service_and_check
yunhong jiang0d6e9922014-10-10 06:12:47 -070023# - start_neutron_agents
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010024# - create_neutron_initial_network
25# - setup_neutron_debug
Mark McClainb05c8762013-07-06 23:29:39 -040026#
27# ``unstack.sh`` calls the entry points in this order:
28#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010029# - stop_neutron
yunhong jiang0d6e9922014-10-10 06:12:47 -070030# - stop_neutron_third_party
31# - cleanup_neutron
Mark McClainb05c8762013-07-06 23:29:39 -040032
33# Functions in lib/neutron are classified into the following categories:
34#
35# - entry points (called from stack.sh or unstack.sh)
36# - internal functions
37# - neutron exercises
38# - 3rd party programs
39
40
41# Neutron Networking
42# ------------------
43
44# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
45# to run Neutron on this host, make sure that q-svc is also in
46# ``ENABLED_SERVICES``.
47#
Mark McClainb05c8762013-07-06 23:29:39 -040048# See "Neutron Network Configuration" below for additional variables
49# that must be set in localrc for connectivity across hosts with
50# Neutron.
51#
52# With Neutron networking the NETWORK_MANAGER variable is ignored.
Mark McClainb05c8762013-07-06 23:29:39 -040053
Mark McClainb05c8762013-07-06 23:29:39 -040054
55# Neutron Network Configuration
56# -----------------------------
57
58# Gateway and subnet defaults, in case they are not customized in localrc
59NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
Salvatore Orlando90234ac2013-11-25 05:44:10 -080060PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
Mark McClainb05c8762013-07-06 23:29:39 -040061PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
62PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
63
Rob Crittenden18d47782014-03-19 17:47:42 -040064if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then
65 Q_PROTOCOL="https"
66fi
67
68
Mark McClainb05c8762013-07-06 23:29:39 -040069# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050070GITDIR["python-neutronclient"]=$DEST/python-neutronclient
Sean Dague5cb19062014-11-01 01:37:45 +010071
72
Mark McClainb05c8762013-07-06 23:29:39 -040073NEUTRON_DIR=$DEST/neutron
Mark McClainb05c8762013-07-06 23:29:39 -040074NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
75
76# Support entry points installation of console scripts
77if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
78 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040079else
80 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040081fi
82
83NEUTRON_CONF_DIR=/etc/neutron
84NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
85export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
86
Adam Gandelman7614d212014-08-11 14:27:50 -070087# Agent binaries. Note, binary paths for other agents are set in per-service
88# scripts in lib/neutron_plugins/services/
89AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
90AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
91AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
92
93# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
94# loaded from per-plugin scripts in lib/neutron_plugins/
95Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
96Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
97Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
98Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
99Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
100
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400101# Default name for Neutron database
102Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400103# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000104Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400105# Default Neutron Port
106Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400107# Default Neutron Internal Port when using TLS proxy
108Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400109# Default Neutron Host
110Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400111# Default protocol
112Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Mark McClainb05c8762013-07-06 23:29:39 -0400113# Default admin username
114Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
115# Default auth strategy
116Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
117# Use namespace or not
118Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
119# RHEL's support for namespaces requires using veths with ovs
120Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
121Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
122# Meta data IP
123Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
124# Allow Overlapping IP among subnets
125Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
126# Use neutron-debug command
127Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
128# The name of the default q-l3 router
129Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Aaron Rosen4540d002013-10-24 13:59:33 -0700130# nova vif driver that all plugins should use
131NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500132Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
133Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800134VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
135VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Edgar Magana7bce8fa2014-11-04 17:32:54 +0100136# Specify if the initial private and external networks should be created
137NEUTRON_CREATE_INITIAL_NETWORKS=${NEUTRON_CREATE_INITIAL_NETWORKS:-True}
Aaron Rosen4540d002013-10-24 13:59:33 -0700138
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400139## Provider Network Information
140PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
141
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900142# Use flat providernet for public network
143#
144# If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network
145# for external interface of neutron l3-agent. In that case,
146# PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900147# used for the network. In case of ofagent, you should add the
148# corresponding entry to your OFAGENT_PHYSICAL_INTERFACE_MAPPINGS.
149# For openvswitch agent, you should add the corresponding entry to
150# your OVS_BRIDGE_MAPPINGS.
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900151#
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900152# eg. (ofagent)
153# Q_USE_PROVIDERNET_FOR_PUBLIC=True
154# Q_USE_PUBLIC_VETH=True
155# PUBLIC_PHYSICAL_NETWORK=public
156# OFAGENT_PHYSICAL_INTERFACE_MAPPINGS=public:veth-pub-int
157#
158# eg. (openvswitch agent)
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900159# Q_USE_PROVIDERNET_FOR_PUBLIC=True
160# PUBLIC_PHYSICAL_NETWORK=public
161# OVS_BRIDGE_MAPPINGS=public:br-ex
162Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-False}
163PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public}
164
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900165# If Q_USE_PUBLIC_VETH=True, create and use a veth pair instead of
166# PUBLIC_BRIDGE. This is intended to be used with
167# Q_USE_PROVIDERNET_FOR_PUBLIC=True.
168Q_USE_PUBLIC_VETH=${Q_USE_PUBLIC_VETH:-False}
169Q_PUBLIC_VETH_EX=${Q_PUBLIC_VETH_EX:-veth-pub-ex}
170Q_PUBLIC_VETH_INT=${Q_PUBLIC_VETH_INT:-veth-pub-int}
171
Tomoe Sugiharaafbc6312013-11-14 20:02:47 +0000172# The next two variables are configured by plugin
173# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
174#
175# The plugin supports L3.
176Q_L3_ENABLED=${Q_L3_ENABLED:-False}
177# L3 routers exist per tenant
178Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False}
Aaron Rosen4540d002013-10-24 13:59:33 -0700179
Mark McClainb05c8762013-07-06 23:29:39 -0400180# List of config file names in addition to the main plugin config file
181# See _configure_neutron_common() for details about setting it up
182declare -a Q_PLUGIN_EXTRA_CONF_FILES
183
Paul Michali746dcee2014-04-02 19:12:22 +0000184# List of (optional) config files for VPN device drivers to use with
185# the neutron-q-vpn agent
186declare -a Q_VPN_EXTRA_CONF_FILES
187
Mark McClainb05c8762013-07-06 23:29:39 -0400188
Dean Troyere2907b42014-02-26 17:35:37 -0600189Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
190if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
191 Q_RR_COMMAND="sudo"
192else
193 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
194 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400195fi
196
Brian Haleyeea76212014-06-27 11:45:50 -0400197
198# Distributed Virtual Router (DVR) configuration
199# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500200# - ``legacy`` - No DVR functionality
201# - ``dvr_snat`` - Controller or single node DVR
202# - ``dvr`` - Compute node in multi-node DVR
203#
Brian Haleyeea76212014-06-27 11:45:50 -0400204Q_DVR_MODE=${Q_DVR_MODE:-legacy}
205if [[ "$Q_DVR_MODE" != "legacy" ]]; then
206 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
207fi
208
Dean Troyere2907b42014-02-26 17:35:37 -0600209# Provider Network Configurations
210# --------------------------------
211
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900212# The following variables control the Neutron ML2 plugins' allocation
213# of tenant networks and availability of provider networks. If these
214# are not configured in ``localrc``, tenant networks will be local to
215# the host (with no remote connectivity), and no physical resources
216# will be available for the allocation of provider networks.
Dean Troyere2907b42014-02-26 17:35:37 -0600217
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200218# To disable tunnels (GRE or VXLAN) for tenant networks,
219# set to False in ``local.conf``.
220# GRE tunnels are only supported by the openvswitch.
221ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600222
223# If using GRE tunnels for tenant networks, specify the range of
224# tunnel IDs from which tenant networks are allocated. Can be
225# overriden in ``localrc`` in necesssary.
Anant Patil3827dc02014-07-03 21:38:16 +0530226TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600227
228# To use VLANs for tenant networks, set to True in localrc. VLANs
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900229# are supported by the ML2 plugins, requiring additional configuration
230# described below.
Dean Troyere2907b42014-02-26 17:35:37 -0600231ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
232
233# If using VLANs for tenant networks, set in ``localrc`` to specify
234# the range of VLAN VIDs from which tenant networks are
235# allocated. An external network switch must be configured to
236# trunk these VLANs between hosts for multi-host connectivity.
237#
238# Example: ``TENANT_VLAN_RANGE=1000:1999``
239TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
240
241# If using VLANs for tenant networks, or if using flat or VLAN
242# provider networks, set in ``localrc`` to the name of the physical
243# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
244# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
245# agent, as described below.
246#
247# Example: ``PHYSICAL_NETWORK=default``
248PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
249
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900250# With the openvswitch agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600251# or if using flat or VLAN provider networks, set in ``localrc`` to
252# the name of the OVS bridge to use for the physical network. The
253# bridge will be created if it does not already exist, but a
254# physical interface must be manually added to the bridge as a
255# port for external connectivity.
256#
257# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
258OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
259
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900260# With the linuxbridge agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600261# or if using flat or VLAN provider networks, set in ``localrc`` to
262# the name of the network interface to use for the physical
263# network.
264#
265# Example: ``LB_PHYSICAL_INTERFACE=eth1``
266LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
267
Edgar Magana6f335b92014-07-10 15:42:44 -0700268# When Neutron tunnels are enabled it is needed to specify the
269# IP address of the end point in the local server. This IP is set
270# by default to the same IP address that the HOST IP.
271# This variable can be used to specify a different end point IP address
272# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
273TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
274
Dean Troyere2907b42014-02-26 17:35:37 -0600275# With the openvswitch plugin, set to True in ``localrc`` to enable
276# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
277#
278# Example: ``OVS_ENABLE_TUNNELING=True``
279OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
280
Tan Lin27a196e2014-10-31 15:44:34 +0800281# Use DHCP agent for providing metadata service in the case of
282# without L3 agent (No Route Agent), set to True in localrc.
283ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
284
285# Add a static route as dhcp option, so the request to 169.254.169.254
286# will be able to reach through a route(DHCP agent)
287# This option require ENABLE_ISOLATED_METADATA = True
288ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
Mark McClainb05c8762013-07-06 23:29:39 -0400289# Neutron plugin specific functions
290# ---------------------------------
291
292# Please refer to ``lib/neutron_plugins/README.md`` for details.
293source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
294
295# Agent loadbalancer service plugin functions
296# -------------------------------------------
297
298# Hardcoding for 1 service plugin for now
299source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
300
Emilien Macchi40546f72013-09-24 15:10:25 +0200301# Agent metering service plugin functions
302# -------------------------------------------
303
304# Hardcoding for 1 service plugin for now
305source $TOP_DIR/lib/neutron_plugins/services/metering
306
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700307# VPN service plugin functions
308# -------------------------------------------
309# Hardcoding for 1 service plugin for now
310source $TOP_DIR/lib/neutron_plugins/services/vpn
311
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700312# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100313# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700314source $TOP_DIR/lib/neutron_plugins/services/firewall
315
Mark McClainb05c8762013-07-06 23:29:39 -0400316# Use security group or not
317if has_neutron_plugin_security_group; then
318 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
319else
320 Q_USE_SECGROUP=False
321fi
322
Dean Troyer4237f592014-01-29 16:22:11 -0600323# Tell Tempest this project is present
324TEMPEST_SERVICES+=,neutron
325
326
Dean Troyere2907b42014-02-26 17:35:37 -0600327# Save trace setting
328XTRACE=$(set +o | grep xtrace)
329set +o xtrace
330
331
Mark McClainb05c8762013-07-06 23:29:39 -0400332# Functions
333# ---------
334
Adam Gandelman7614d212014-08-11 14:27:50 -0700335function _determine_config_server {
336 local cfg_file
337 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
338 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
339 opts+=" --config-file /$cfg_file"
340 done
341 echo "$opts"
342}
343
344function _determine_config_vpn {
345 local cfg_file
346 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
347 if is_service_enabled q-fwaas; then
348 opts+=" --config-file $Q_FWAAS_CONF_FILE"
349 fi
350 for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
351 opts+=" --config-file $cfg_file"
352 done
353 echo "$opts"
354
355}
356
357function _determine_config_l3 {
358 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
359 if is_service_enabled q-fwaas; then
360 opts+=" --config-file $Q_FWAAS_CONF_FILE"
361 fi
362 echo "$opts"
363}
364
365# For services and agents that require it, dynamically construct a list of
366# --config-file arguments that are passed to the binary.
367function determine_config_files {
368 local opts=""
369 case "$1" in
370 "neutron-server") opts="$(_determine_config_server)" ;;
371 "neutron-vpn-agent") opts="$(_determine_config_vpn)" ;;
372 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
373 esac
374 if [ -z "$opts" ] ; then
375 die $LINENO "Could not determine config files for $1."
376 fi
377 echo "$opts"
378}
379
Dean Troyere4fa7212014-01-15 15:04:49 -0600380# Test if any Neutron services are enabled
381# is_neutron_enabled
382function is_neutron_enabled {
383 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
384 return 1
385}
386
Mark McClainb05c8762013-07-06 23:29:39 -0400387# configure_neutron()
388# Set common config for all neutron server and agents.
Ian Wienandaee18c72014-02-21 15:35:08 +1100389function configure_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400390 _configure_neutron_common
391 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
392
393 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
394 if is_service_enabled q-lbaas; then
395 _configure_neutron_lbaas
396 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200397 if is_service_enabled q-metering; then
398 _configure_neutron_metering
399 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700400 if is_service_enabled q-vpn; then
401 _configure_neutron_vpn
402 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700403 if is_service_enabled q-fwaas; then
404 _configure_neutron_fwaas
405 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000406 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400407 _configure_neutron_service
408 fi
409 if is_service_enabled q-agt; then
410 _configure_neutron_plugin_agent
411 fi
412 if is_service_enabled q-dhcp; then
413 _configure_neutron_dhcp_agent
414 fi
415 if is_service_enabled q-l3; then
416 _configure_neutron_l3_agent
417 fi
418 if is_service_enabled q-meta; then
419 _configure_neutron_metadata_agent
420 fi
421
Brian Haleyeea76212014-06-27 11:45:50 -0400422 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
423 _configure_dvr
424 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400425 if is_service_enabled ceilometer; then
426 _configure_neutron_ceilometer_notifications
427 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400428
429 _configure_neutron_debug_command
430}
431
Ian Wienandaee18c72014-02-21 15:35:08 +1100432function create_nova_conf_neutron {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800433 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
Gary Kotton13d385e2014-06-17 23:24:53 -0700434 iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME"
435 iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD"
436 iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
437 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
438 iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME"
Bartosz Górski0abde392014-02-28 14:15:19 +0100439 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Rob Crittenden18d47782014-03-19 17:47:42 -0400440 iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400441
442 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
443 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400444 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800445 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400446 fi
447
448 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
449 neutron_plugin_create_nova_conf
450
Gary Kotton51c681d2014-04-22 01:40:56 -0700451 iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER"
Mark McClainb05c8762013-07-06 23:29:39 -0400452 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
453 if is_service_enabled q-meta; then
Gary Kottondd745502014-08-11 23:38:47 -0700454 iniset $NOVA_CONF neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400455 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800456
457 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
458 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400459}
460
Emilien Macchia677b7f2013-11-25 23:40:20 +0100461# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100462function create_neutron_cache_dir {
Emilien Macchia677b7f2013-11-25 23:40:20 +0100463 # Create cache dir
464 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
465 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
466 rm -f $NEUTRON_AUTH_CACHE_DIR/*
467}
468
Mark McClainb05c8762013-07-06 23:29:39 -0400469# create_neutron_accounts() - Set up common required neutron accounts
470
471# Tenant User Roles
472# ------------------------------------------------------------------
473# service neutron admin # if enabled
474
475# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100476function create_neutron_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400477
Dean Troyer188493d2014-07-25 15:54:11 -0500478 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700479 local service_role=$(openstack role list | awk "/ service / { print \$2 }")
Mark McClainb05c8762013-07-06 23:29:39 -0400480
481 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100482
Dean Troyer188493d2014-07-25 15:54:11 -0500483 local neutron_user=$(get_or_create_user "neutron" \
484 "$SERVICE_PASSWORD" $service_tenant)
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700485 get_or_add_user_role $service_role $neutron_user $service_tenant
Bartosz Górski0abde392014-02-28 14:15:19 +0100486
Mark McClainb05c8762013-07-06 23:29:39 -0400487 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100488
Dean Troyer188493d2014-07-25 15:54:11 -0500489 local neutron_service=$(get_or_create_service "neutron" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100490 "network" "Neutron Service")
Dean Troyer188493d2014-07-25 15:54:11 -0500491 get_or_create_endpoint $neutron_service \
Bartosz Górski0abde392014-02-28 14:15:19 +0100492 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400493 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
494 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
495 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400496 fi
497 fi
498}
499
Ian Wienandaee18c72014-02-21 15:35:08 +1100500function create_neutron_initial_network {
Steve Martinelli19685422014-01-24 13:02:26 -0600501 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500502 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400503
504 # Create a small network
505 # Since neutron command is executed in admin context at this point,
Dirk Mueller25049cd2014-01-09 13:53:52 +0100506 # ``--tenant-id`` needs to be specified.
Mark McClainb05c8762013-07-06 23:29:39 -0400507 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200508 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
509 die $LINENO "Neutron settings for baremetal not set.. exiting"
510 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400511 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
512 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
513 sudo ip addr del $IP dev $PUBLIC_INTERFACE
514 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
515 done
Dirk Mueller25049cd2014-01-09 13:53:52 +0100516 NET_ID=$(neutron net-create $PHYSICAL_NETWORK --tenant-id $TENANT_ID --provider:network_type flat --provider:physical_network "$PHYSICAL_NETWORK" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500517 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100518 SUBNET_ID=$(neutron subnet-create --tenant-id $TENANT_ID --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --gateway $NETWORK_GATEWAY --name $PRIVATE_SUBNET_NAME $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500519 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400520 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200521 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400522 elif is_provider_network; then
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900523 die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400524 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900525 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)
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700526 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 $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
Sean M. Collinse13fd602014-05-14 17:01:53 -0400527 SUBNET_V6_ID=$(neutron subnet-create --tenant_id $TENANT_ID --ip_version 6 --ipv6-address-mode slaac --gateway $V6_NETWORK_GATEWAY --name $PROVIDER_SUBNET_NAME_V6 $NET_ID $FIXED_RANGE_V6 | grep 'id' | get_field 2)
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400528 sudo ip link set $OVS_PHYSICAL_BRIDGE up
529 sudo ip link set br-int up
530 sudo ip link set $PUBLIC_INTERFACE up
Mark McClainb05c8762013-07-06 23:29:39 -0400531 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100532 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500533 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100534 SUBNET_ID=$(neutron subnet-create --tenant-id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY --name $PRIVATE_SUBNET_NAME $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500535 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400536 fi
537
538 if [[ "$Q_L3_ENABLED" == "True" ]]; then
539 # Create a router, and add the private subnet as one of its interfaces
540 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
541 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100542 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500543 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400544 else
545 # Plugin only supports creating a single router, which should be admin owned.
546 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500547 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400548 fi
549 neutron router-interface-add $ROUTER_ID $SUBNET_ID
550 # Create an external network, and a subnet. Configure the external network as router gw
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900551 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
552 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)
553 else
554 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
555 fi
DennyZhang23178a92013-10-22 17:07:32 -0500556 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400557 EXT_GW_IP=$(neutron subnet-create --ip_version 4 ${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} --gateway $PUBLIC_NETWORK_GATEWAY --name $PUBLIC_SUBNET_NAME $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500558 die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400559 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
560
561 if is_service_enabled q-l3; then
562 # logic is specific to using the l3-agent for l3
563 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900564 local ext_gw_interface
565
566 if [[ "$Q_USE_PUBLIC_VETH" = "True" ]]; then
567 ext_gw_interface=$Q_PUBLIC_VETH_EX
568 else
569 # Disable in-band as we are going to use local port
570 # to communicate with VMs
571 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
572 other_config:disable-in-band=true
573 ext_gw_interface=$PUBLIC_BRIDGE
574 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400575 CIDR_LEN=${FLOATING_RANGE#*/}
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900576 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $ext_gw_interface
577 sudo ip link set $ext_gw_interface up
Mark McClainb05c8762013-07-06 23:29:39 -0400578 ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'`
DennyZhang23178a92013-10-22 17:07:32 -0500579 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400580 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
581 fi
582 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
583 # Explicitly set router id in l3 agent configuration
584 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
585 fi
586 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400587 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400588}
589
590# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100591function init_neutron {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700592 recreate_database $Q_DB_NAME utf8
593 # Run Neutron db migrations
594 $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 -0400595}
596
597# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100598function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400599 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
600 setup_develop $NEUTRON_DIR
Mate Lakat6df64892014-10-17 13:09:49 +0200601
602 if [ "$VIRT_DRIVER" == 'xenserver' ]; then
603 local dom0_ip
604 dom0_ip=$(echo "$XENAPI_CONNECTION_URL" | cut -d "/" -f 3-)
605
606 local ssh_dom0
607 ssh_dom0="sudo -u $DOMZERO_USER ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$dom0_ip"
608
609 # Find where the plugins should go in dom0
610 local xen_functions
611 xen_functions=$(cat $TOP_DIR/tools/xen/functions)
612 local plugin_dir
613 plugin_dir=$($ssh_dom0 "$xen_functions; set -eux; xapi_plugin_location")
614
615 # install neutron plugins to dom0
616 tar -czf - -C $NEUTRON_DIR/neutron/plugins/openvswitch/agent/xenapi/etc/xapi.d/plugins/ ./ |
617 $ssh_dom0 "tar -xzf - -C $plugin_dir && chmod a+x $plugin_dir/*"
618 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400619}
620
621# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100622function install_neutronclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500623 if use_library_from_git "python-neutronclient"; then
624 git_clone_by_name "python-neutronclient"
625 setup_dev_lib "python-neutronclient"
626 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 +0100627 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400628}
629
630# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100631function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400632 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
633 if is_service_enabled q-l3; then
634 install_package radvd
635 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400636 # install packages that are specific to plugin agent(s)
637 if is_service_enabled q-agt q-dhcp q-l3; then
638 neutron_plugin_install_agent_packages
639 fi
640
641 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400642 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400643 fi
644}
645
646# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100647function start_neutron_service_and_check {
Adam Gandelman7614d212014-08-11 14:27:50 -0700648 local cfg_file_options="$(determine_config_files neutron-server)"
Rob Crittenden18d47782014-03-19 17:47:42 -0400649 local service_port=$Q_PORT
650 local service_protocol=$Q_PROTOCOL
651 if is_service_enabled tls-proxy; then
652 service_port=$Q_PORT_INT
653 service_protocol="http"
654 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400655 # Start the Neutron service
Chris Dent2f27a0e2014-09-09 13:46:02 +0100656 run_process q-svc "python $NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400657 echo "Waiting for Neutron to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400658 if is_ssl_enabled_service "neutron"; then
659 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
660 fi
661 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget ${ssl_ca} --no-proxy -q -O- $service_protocol://$Q_HOST:$service_port; do sleep 1; done"; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400662 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400663 fi
Rob Crittenden18d47782014-03-19 17:47:42 -0400664 # Start proxy if enabled
665 if is_service_enabled tls-proxy; then
666 start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT &
667 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400668}
669
670# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100671function start_neutron_agents {
Mark McClainb05c8762013-07-06 23:29:39 -0400672 # Start up the neutron agents if enabled
Chris Dent2f27a0e2014-09-09 13:46:02 +0100673 run_process q-agt "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
674 run_process q-dhcp "python $AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file=$Q_DHCP_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700675
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400676 if is_provider_network; then
677 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
678 sudo ip link set $OVS_PHYSICAL_BRIDGE up
679 sudo ip link set br-int up
680 sudo ip link set $PUBLIC_INTERFACE up
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700681 if is_ironic_hardware; then
682 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
683 sudo ip addr del $IP dev $PUBLIC_INTERFACE
684 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
685 done
686 sudo route add -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
687 fi
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400688 fi
689
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700690 if is_service_enabled q-vpn; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100691 run_process q-vpn "$AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700692 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100693 run_process q-l3 "python $AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700694 fi
695
Chris Dent2f27a0e2014-09-09 13:46:02 +0100696 run_process q-meta "python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400697
698 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
699 # For XenServer, start an agent for the domU openvswitch
Chris Dent2f27a0e2014-09-09 13:46:02 +0100700 run_process q-domua "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
Mark McClainb05c8762013-07-06 23:29:39 -0400701 fi
702
703 if is_service_enabled q-lbaas; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100704 run_process q-lbaas "python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400705 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200706
707 if is_service_enabled q-metering; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100708 run_process q-metering "python $AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
Emilien Macchi40546f72013-09-24 15:10:25 +0200709 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400710}
711
712# stop_neutron() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100713function stop_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400714 if is_service_enabled q-dhcp; then
715 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
716 [ ! -z "$pid" ] && sudo kill -9 $pid
717 fi
718 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100719 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400720 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900721
722 if is_service_enabled q-lbaas; then
723 neutron_lbaas_stop
724 fi
725 if is_service_enabled q-fwaas; then
726 neutron_fwaas_stop
727 fi
728 if is_service_enabled q-vpn; then
729 neutron_vpn_stop
730 fi
731 if is_service_enabled q-metering; then
732 neutron_metering_stop
733 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400734}
735
736# cleanup_neutron() - Remove residual data files, anything left over from previous
737# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100738function cleanup_neutron {
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700739 if [[ is_provider_network && is_ironic_hardware ]]; then
740 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
741 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
742 sudo ip addr add $IP dev $PUBLIC_INTERFACE
743 done
744 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
745 fi
746
Mark McClainb05c8762013-07-06 23:29:39 -0400747 if is_neutron_ovs_base_plugin; then
748 neutron_ovs_base_cleanup
749 fi
750
751 # delete all namespaces created by neutron
Brian Haleyeea76212014-06-27 11:45:50 -0400752 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 -0400753 sudo ip netns delete ${ns}
754 done
755}
756
757# _configure_neutron_common()
758# Set common config for all neutron server and agents.
759# This MUST be called before other ``_configure_neutron_*`` functions.
Ian Wienandaee18c72014-02-21 15:35:08 +1100760function _configure_neutron_common {
Mark McClainb05c8762013-07-06 23:29:39 -0400761 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
762 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
763 sudo mkdir -p $NEUTRON_CONF_DIR
764 fi
765 sudo chown $STACK_USER $NEUTRON_CONF_DIR
766
767 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
768
769 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
770 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
771 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
772 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100773 #
Mark McClainb05c8762013-07-06 23:29:39 -0400774 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
775 neutron_plugin_configure_common
776
sbauzae2c4ee22013-08-29 17:29:46 +0200777 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400778 die $LINENO "Neutron plugin not set.. exiting"
779 fi
780
781 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
782 mkdir -p /$Q_PLUGIN_CONF_PATH
783 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
784 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
785
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200786 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400787 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
salvatoree4e535b2014-10-29 18:22:46 +0100788 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
Mark McClainb05c8762013-07-06 23:29:39 -0400789 # If addition config files are set, make sure their path name is set as well
790 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
791 die $LINENO "Neutron additional plugin config not set.. exiting"
792 fi
793
794 # If additional config files exist, copy them over to neutron configuration
795 # directory
796 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400797 local f
798 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
799 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400800 done
801 fi
802
Joe Gordonbee5c502013-08-30 13:48:08 -0400803 if [ "$VIRT_DRIVER" = 'fake' ]; then
804 # Disable arbitrary limits
805 iniset $NEUTRON_CONF quotas quota_network -1
806 iniset $NEUTRON_CONF quotas quota_subnet -1
807 iniset $NEUTRON_CONF quotas quota_port -1
808 iniset $NEUTRON_CONF quotas quota_security_group -1
809 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
810 fi
811
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700812 # Format logging
813 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800814 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700815 fi
816
Rob Crittenden18d47782014-03-19 17:47:42 -0400817 if is_service_enabled tls-proxy; then
818 # Set the service port for a proxy to take the original
819 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
820 fi
821
822 if is_ssl_enabled_service "nova"; then
823 iniset $NEUTRON_CONF DEFAULT nova_ca_certificates_file "$SSL_BUNDLE_FILE"
824 fi
825
826 if is_ssl_enabled_service "neutron"; then
827 ensure_certificates NEUTRON
828
829 iniset $NEUTRON_CONF DEFAULT use_ssl True
830 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
831 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
832 fi
833
Mark McClainb05c8762013-07-06 23:29:39 -0400834 _neutron_setup_rootwrap
835}
836
Ian Wienandaee18c72014-02-21 15:35:08 +1100837function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400838 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
839 return
840 fi
841
842 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
843
844 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
845 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
846 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400847 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
848
Mark McClainb05c8762013-07-06 23:29:39 -0400849 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
850
851 neutron_plugin_configure_debug_command
852}
853
Ian Wienandaee18c72014-02-21 15:35:08 +1100854function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400855
856 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
857
858 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500859 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400860 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
861 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
862
Tan Lin27a196e2014-10-31 15:44:34 +0800863 if ! is_service_enabled q-l3; then
864 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
865 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
866 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
867 else
868 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
869 die "$LINENO" "Enable isolated metadata is a must for metadata network"
870 fi
871 fi
872 fi
873
Mark McClainb05c8762013-07-06 23:29:39 -0400874 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
875
876 neutron_plugin_configure_dhcp_agent
877}
878
Ian Wienandaee18c72014-02-21 15:35:08 +1100879function _configure_neutron_l3_agent {
Paul Michali746dcee2014-04-02 19:12:22 +0000880 local cfg_file
Mark McClainb05c8762013-07-06 23:29:39 -0400881 Q_L3_ENABLED=True
882 # for l3-agent, only use per tenant router if we have namespaces
883 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700884
Paul Michali746dcee2014-04-02 19:12:22 +0000885 if is_service_enabled q-vpn; then
Paul Michali746dcee2014-04-02 19:12:22 +0000886 cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
Paul Michali746dcee2014-04-02 19:12:22 +0000887 fi
888
Mark McClainb05c8762013-07-06 23:29:39 -0400889 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
890
891 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500892 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400893 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
894 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
895
Mark McClainb05c8762013-07-06 23:29:39 -0400896 _neutron_setup_interface_driver $Q_L3_CONF_FILE
897
898 neutron_plugin_configure_l3_agent
899}
900
Ian Wienandaee18c72014-02-21 15:35:08 +1100901function _configure_neutron_metadata_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400902 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
903
904 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500905 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400906 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
907 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
908
Brant Knudson05952372014-09-19 17:22:22 -0500909 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT
Maru Newbybf10ac52013-08-10 21:27:54 +0000910
Mark McClainb05c8762013-07-06 23:29:39 -0400911}
912
Dina Belova58adaa62014-07-11 18:18:12 +0400913function _configure_neutron_ceilometer_notifications {
JordanPd4d4a342014-09-15 09:26:53 +0000914 iniset $NEUTRON_CONF DEFAULT notification_driver messaging
Dina Belova58adaa62014-07-11 18:18:12 +0400915}
916
Ian Wienandaee18c72014-02-21 15:35:08 +1100917function _configure_neutron_lbaas {
Mark McClainb05c8762013-07-06 23:29:39 -0400918 neutron_agent_lbaas_configure_common
919 neutron_agent_lbaas_configure_agent
920}
921
Ian Wienandaee18c72014-02-21 15:35:08 +1100922function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200923 neutron_agent_metering_configure_common
924 neutron_agent_metering_configure_agent
925}
926
Ian Wienandaee18c72014-02-21 15:35:08 +1100927function _configure_neutron_fwaas {
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700928 neutron_fwaas_configure_common
929 neutron_fwaas_configure_driver
930}
931
Ian Wienandaee18c72014-02-21 15:35:08 +1100932function _configure_neutron_vpn {
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700933 neutron_vpn_install_agent_packages
934 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700935}
936
Brian Haleyeea76212014-06-27 11:45:50 -0400937function _configure_dvr {
938 iniset $NEUTRON_CONF DEFAULT router_distributed True
939 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
940}
941
942
Mark McClainb05c8762013-07-06 23:29:39 -0400943# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
944# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100945function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400946 # Specify the default root helper prior to agent configuration to
947 # ensure that an agent's configuration can override the default
948 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
949 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500950 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400951
952 # Configure agent for plugin
953 neutron_plugin_configure_plugin_agent
954}
955
956# _configure_neutron_service() - Set config files for neutron service
957# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100958function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400959 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
960 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
961
962 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
963 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
964
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700965 # allow neutron user to administer neutron to match neutron account
966 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
967
Mark McClainb05c8762013-07-06 23:29:39 -0400968 # Update either configuration file with plugin
969 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
970
971 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
972 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
973 fi
974
975 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500976 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400977 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
978 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
979
980 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
981 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
982
Aaron Rosencea32b12014-03-04 16:20:14 -0800983 # Configuration for neutron notifations to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500984 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
985 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Aaron Rosencea32b12014-03-04 16:20:14 -0800986 iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
Dirk Mueller5ca261a2014-04-04 22:48:02 +0200987 iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800988 iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
989 ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
990 iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
991 iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
992
Mark McClainb05c8762013-07-06 23:29:39 -0400993 # Configure plugin
994 neutron_plugin_configure_service
995}
996
997# Utility Functions
998#------------------
999
Isaku Yamahata9e136b42013-12-16 15:52:03 +09001000# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +11001001function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +09001002 local service_plugin_class=$1
1003 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1004 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1005 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1006 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1007 fi
1008}
1009
Mark McClainb05c8762013-07-06 23:29:39 -04001010# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +11001011function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -04001012 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1013 return
1014 fi
1015 # Deploy new rootwrap filters files (owned by root).
1016 # Wipe any existing ``rootwrap.d`` files first
1017 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1018 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1019 sudo rm -rf $Q_CONF_ROOTWRAP_D
1020 fi
1021 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
1022 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
1023 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1024 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
1025 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
1026 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1027 # location moved in newer versions, prefer new location
1028 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -04001029 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001030 else
Sean Dague3bdb9222013-10-22 08:36:16 -04001031 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001032 fi
1033 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
1034 sudo chown root:root $Q_RR_CONF_FILE
1035 sudo chmod 0644 $Q_RR_CONF_FILE
1036 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1037 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1038
1039 # Set up the rootwrap sudoers for neutron
1040 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +01001041 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -04001042 chmod 0440 $TEMPFILE
1043 sudo chown root:root $TEMPFILE
1044 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1045
1046 # Update the root_helper
1047 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
1048}
1049
1050# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +11001051function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -04001052 local conf_file=$1
1053 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +10001054
Brant Knudson05952372014-09-19 17:22:22 -05001055 create_neutron_cache_dir
1056 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -04001057}
1058
Ian Wienandaee18c72014-02-21 15:35:08 +11001059function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -04001060
1061 # ovs_use_veth needs to be set before the plugin configuration
1062 # occurs to allow plugins to override the setting.
1063 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1064
1065 neutron_plugin_setup_interface_driver $1
1066}
1067
1068# Functions for Neutron Exercises
1069#--------------------------------
1070
Ian Wienandaee18c72014-02-21 15:35:08 +11001071function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001072 local from_net="$1"
1073 net_id=`_get_net_id $from_net`
1074 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}'`
1075 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1076}
1077
Ian Wienandaee18c72014-02-21 15:35:08 +11001078function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001079 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
1080 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
1081 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
1082 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
1083 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
1084 fi
1085}
1086
Ian Wienandaee18c72014-02-21 15:35:08 +11001087function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001088 delete_probe $PUBLIC_NETWORK_NAME
1089 delete_probe $PRIVATE_NETWORK_NAME
1090}
1091
Ian Wienandaee18c72014-02-21 15:35:08 +11001092function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -04001093 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
1094}
1095
Ian Wienandaee18c72014-02-21 15:35:08 +11001096function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001097 local from_net="$1"
1098 net_id=`_get_net_id $from_net`
1099 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`
1100 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1101}
1102
Ian Wienandaee18c72014-02-21 15:35:08 +11001103function _ping_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001104 local from_net=$1
1105 local ip=$2
1106 local timeout_sec=$3
1107 local expected=${4:-"True"}
1108 local check_command=""
1109 probe_cmd=`_get_probe_cmd_prefix $from_net`
1110 if [[ "$expected" = "True" ]]; then
1111 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1112 else
1113 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1114 fi
1115 if ! timeout $timeout_sec sh -c "$check_command"; then
1116 if [[ "$expected" = "True" ]]; then
1117 die $LINENO "[Fail] Couldn't ping server"
1118 else
1119 die $LINENO "[Fail] Could ping server"
1120 fi
1121 fi
1122}
1123
1124# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001125function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001126 local from_net=$1
1127 local key_file=$2
1128 local ip=$3
1129 local user=$4
1130 local timeout_sec=$5
1131 local probe_cmd = ""
1132 probe_cmd=`_get_probe_cmd_prefix $from_net`
1133 if ! timeout $timeout_sec sh -c "while ! $probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success; do sleep 1; done"; then
1134 die $LINENO "server didn't become ssh-able!"
1135 fi
1136}
1137
1138# Neutron 3rd party programs
1139#---------------------------
1140
1141# please refer to ``lib/neutron_thirdparty/README.md`` for details
1142NEUTRON_THIRD_PARTIES=""
1143for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001144 third_party=$(basename $f)
1145 if is_service_enabled $third_party; then
1146 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1147 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1148 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001149done
1150
Ian Wienandaee18c72014-02-21 15:35:08 +11001151function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001152 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1153 ${1}_${third_party}
1154 done
1155}
1156
1157# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001158function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001159 _neutron_third_party_do configure
1160}
1161
1162# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001163function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001164 _neutron_third_party_do init
1165}
1166
1167# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001168function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001169 _neutron_third_party_do install
1170}
1171
1172# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001173function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001174 _neutron_third_party_do start
1175}
1176
1177# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001178function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001179 _neutron_third_party_do stop
1180}
1181
armando-migliaccioef1e0802014-01-02 16:33:53 -08001182# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001183function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001184 _neutron_third_party_do check
1185}
1186
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001187function is_provider_network {
1188 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1189 return 0
1190 fi
1191 return 1
1192}
1193
Mark McClainb05c8762013-07-06 23:29:39 -04001194
1195# Restore xtrace
1196$XTRACE
1197
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001198# Tell emacs to use shell-script-mode
1199## Local variables:
1200## mode: shell-script
1201## End: