blob: 5513dbfca021d169a7e965d694447397bbf778c1 [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
23# - create_neutron_initial_network
24# - setup_neutron_debug
25# - start_neutron_agents
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
Mark McClainb05c8762013-07-06 23:29:39 -040030
31# Functions in lib/neutron are classified into the following categories:
32#
33# - entry points (called from stack.sh or unstack.sh)
34# - internal functions
35# - neutron exercises
36# - 3rd party programs
37
38
39# Neutron Networking
40# ------------------
41
42# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
43# to run Neutron on this host, make sure that q-svc is also in
44# ``ENABLED_SERVICES``.
45#
46# If you're planning to use the Neutron openvswitch plugin, set
47# ``Q_PLUGIN`` to "openvswitch" and make sure the q-agt service is enabled
48# in ``ENABLED_SERVICES``. If you're planning to use the Neutron
49# linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the
50# q-agt service is enabled in ``ENABLED_SERVICES``.
51#
52# See "Neutron Network Configuration" below for additional variables
53# that must be set in localrc for connectivity across hosts with
54# Neutron.
55#
56# With Neutron networking the NETWORK_MANAGER variable is ignored.
57#
58# To enable specific configuration options for either the Open vSwitch or
59# LinuxBridge plugin, please see the top level README file under the
60# Neutron section.
61
Mark McClainb05c8762013-07-06 23:29:39 -040062
63# Neutron Network Configuration
64# -----------------------------
65
66# Gateway and subnet defaults, in case they are not customized in localrc
67NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
Salvatore Orlando90234ac2013-11-25 05:44:10 -080068PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
Mark McClainb05c8762013-07-06 23:29:39 -040069PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
70PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
71
72# Set up default directories
73NEUTRON_DIR=$DEST/neutron
74NEUTRONCLIENT_DIR=$DEST/python-neutronclient
75NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
76
77# Support entry points installation of console scripts
78if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
79 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040080else
81 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040082fi
83
84NEUTRON_CONF_DIR=/etc/neutron
85NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
86export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
87
Adam Gandelman7614d212014-08-11 14:27:50 -070088# Agent binaries. Note, binary paths for other agents are set in per-service
89# scripts in lib/neutron_plugins/services/
90AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
91AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
92AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
93
94# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
95# loaded from per-plugin scripts in lib/neutron_plugins/
96Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
97Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
98Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
99Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
100Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
101
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400102# Default name for Neutron database
103Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400104# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000105Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400106# Default Neutron Port
107Q_PORT=${Q_PORT:-9696}
108# Default Neutron Host
109Q_HOST=${Q_HOST:-$SERVICE_HOST}
110# Default admin username
111Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
112# Default auth strategy
113Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
114# Use namespace or not
115Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
116# RHEL's support for namespaces requires using veths with ovs
117Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
118Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
119# Meta data IP
120Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
121# Allow Overlapping IP among subnets
122Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
123# Use neutron-debug command
124Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
125# The name of the default q-l3 router
126Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Aaron Rosen4540d002013-10-24 13:59:33 -0700127# nova vif driver that all plugins should use
128NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500129Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
130Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800131VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
132VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700133
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400134## Provider Network Information
135PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
136
Tomoe Sugiharaafbc6312013-11-14 20:02:47 +0000137# The next two variables are configured by plugin
138# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
139#
140# The plugin supports L3.
141Q_L3_ENABLED=${Q_L3_ENABLED:-False}
142# L3 routers exist per tenant
143Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False}
Aaron Rosen4540d002013-10-24 13:59:33 -0700144
Mark McClainb05c8762013-07-06 23:29:39 -0400145# List of config file names in addition to the main plugin config file
146# See _configure_neutron_common() for details about setting it up
147declare -a Q_PLUGIN_EXTRA_CONF_FILES
148
Paul Michali746dcee2014-04-02 19:12:22 +0000149# List of (optional) config files for VPN device drivers to use with
150# the neutron-q-vpn agent
151declare -a Q_VPN_EXTRA_CONF_FILES
152
Mark McClainb05c8762013-07-06 23:29:39 -0400153
Dean Troyere2907b42014-02-26 17:35:37 -0600154Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
155if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
156 Q_RR_COMMAND="sudo"
157else
158 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
159 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400160fi
161
Brian Haleyeea76212014-06-27 11:45:50 -0400162
163# Distributed Virtual Router (DVR) configuration
164# Can be:
165# legacy - No DVR functionality
166# dvr_snat - Controller or single node DVR
167# dvr - Compute node in multi-node DVR
168Q_DVR_MODE=${Q_DVR_MODE:-legacy}
169if [[ "$Q_DVR_MODE" != "legacy" ]]; then
170 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
171fi
172
Dean Troyere2907b42014-02-26 17:35:37 -0600173# Provider Network Configurations
174# --------------------------------
175
176# The following variables control the Neutron openvswitch and
177# linuxbridge plugins' allocation of tenant networks and
178# availability of provider networks. If these are not configured
179# in ``localrc``, tenant networks will be local to the host (with no
180# remote connectivity), and no physical resources will be
181# available for the allocation of provider networks.
182
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200183# To disable tunnels (GRE or VXLAN) for tenant networks,
184# set to False in ``local.conf``.
185# GRE tunnels are only supported by the openvswitch.
186ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600187
188# If using GRE tunnels for tenant networks, specify the range of
189# tunnel IDs from which tenant networks are allocated. Can be
190# overriden in ``localrc`` in necesssary.
Anant Patil3827dc02014-07-03 21:38:16 +0530191TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600192
193# To use VLANs for tenant networks, set to True in localrc. VLANs
194# are supported by the openvswitch and linuxbridge plugins, each
195# requiring additional configuration described below.
196ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
197
198# If using VLANs for tenant networks, set in ``localrc`` to specify
199# the range of VLAN VIDs from which tenant networks are
200# allocated. An external network switch must be configured to
201# trunk these VLANs between hosts for multi-host connectivity.
202#
203# Example: ``TENANT_VLAN_RANGE=1000:1999``
204TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
205
206# If using VLANs for tenant networks, or if using flat or VLAN
207# provider networks, set in ``localrc`` to the name of the physical
208# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
209# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
210# agent, as described below.
211#
212# Example: ``PHYSICAL_NETWORK=default``
213PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
214
215# With the openvswitch plugin, if using VLANs for tenant networks,
216# or if using flat or VLAN provider networks, set in ``localrc`` to
217# the name of the OVS bridge to use for the physical network. The
218# bridge will be created if it does not already exist, but a
219# physical interface must be manually added to the bridge as a
220# port for external connectivity.
221#
222# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
223OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
224
225# With the linuxbridge plugin, if using VLANs for tenant networks,
226# or if using flat or VLAN provider networks, set in ``localrc`` to
227# the name of the network interface to use for the physical
228# network.
229#
230# Example: ``LB_PHYSICAL_INTERFACE=eth1``
231LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
232
Edgar Magana6f335b92014-07-10 15:42:44 -0700233# When Neutron tunnels are enabled it is needed to specify the
234# IP address of the end point in the local server. This IP is set
235# by default to the same IP address that the HOST IP.
236# This variable can be used to specify a different end point IP address
237# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
238TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
239
Dean Troyere2907b42014-02-26 17:35:37 -0600240# With the openvswitch plugin, set to True in ``localrc`` to enable
241# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
242#
243# Example: ``OVS_ENABLE_TUNNELING=True``
244OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
245
Mark McClainb05c8762013-07-06 23:29:39 -0400246# Neutron plugin specific functions
247# ---------------------------------
248
249# Please refer to ``lib/neutron_plugins/README.md`` for details.
250source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
251
252# Agent loadbalancer service plugin functions
253# -------------------------------------------
254
255# Hardcoding for 1 service plugin for now
256source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
257
Emilien Macchi40546f72013-09-24 15:10:25 +0200258# Agent metering service plugin functions
259# -------------------------------------------
260
261# Hardcoding for 1 service plugin for now
262source $TOP_DIR/lib/neutron_plugins/services/metering
263
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700264# VPN service plugin functions
265# -------------------------------------------
266# Hardcoding for 1 service plugin for now
267source $TOP_DIR/lib/neutron_plugins/services/vpn
268
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700269# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100270# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700271source $TOP_DIR/lib/neutron_plugins/services/firewall
272
Mark McClainb05c8762013-07-06 23:29:39 -0400273# Use security group or not
274if has_neutron_plugin_security_group; then
275 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
276else
277 Q_USE_SECGROUP=False
278fi
279
Dean Troyer4237f592014-01-29 16:22:11 -0600280# Tell Tempest this project is present
281TEMPEST_SERVICES+=,neutron
282
283
Dean Troyere2907b42014-02-26 17:35:37 -0600284# Save trace setting
285XTRACE=$(set +o | grep xtrace)
286set +o xtrace
287
288
Mark McClainb05c8762013-07-06 23:29:39 -0400289# Functions
290# ---------
291
Adam Gandelman7614d212014-08-11 14:27:50 -0700292function _determine_config_server {
293 local cfg_file
294 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
295 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
296 opts+=" --config-file /$cfg_file"
297 done
298 echo "$opts"
299}
300
301function _determine_config_vpn {
302 local cfg_file
303 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
304 if is_service_enabled q-fwaas; then
305 opts+=" --config-file $Q_FWAAS_CONF_FILE"
306 fi
307 for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
308 opts+=" --config-file $cfg_file"
309 done
310 echo "$opts"
311
312}
313
314function _determine_config_l3 {
315 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
316 if is_service_enabled q-fwaas; then
317 opts+=" --config-file $Q_FWAAS_CONF_FILE"
318 fi
319 echo "$opts"
320}
321
322# For services and agents that require it, dynamically construct a list of
323# --config-file arguments that are passed to the binary.
324function determine_config_files {
325 local opts=""
326 case "$1" in
327 "neutron-server") opts="$(_determine_config_server)" ;;
328 "neutron-vpn-agent") opts="$(_determine_config_vpn)" ;;
329 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
330 esac
331 if [ -z "$opts" ] ; then
332 die $LINENO "Could not determine config files for $1."
333 fi
334 echo "$opts"
335}
336
Dean Troyere4fa7212014-01-15 15:04:49 -0600337# Test if any Neutron services are enabled
338# is_neutron_enabled
339function is_neutron_enabled {
340 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
341 return 1
342}
343
Mark McClainb05c8762013-07-06 23:29:39 -0400344# configure_neutron()
345# Set common config for all neutron server and agents.
Ian Wienandaee18c72014-02-21 15:35:08 +1100346function configure_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400347 _configure_neutron_common
348 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
349
350 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
351 if is_service_enabled q-lbaas; then
352 _configure_neutron_lbaas
353 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200354 if is_service_enabled q-metering; then
355 _configure_neutron_metering
356 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700357 if is_service_enabled q-vpn; then
358 _configure_neutron_vpn
359 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700360 if is_service_enabled q-fwaas; then
361 _configure_neutron_fwaas
362 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000363 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400364 _configure_neutron_service
365 fi
366 if is_service_enabled q-agt; then
367 _configure_neutron_plugin_agent
368 fi
369 if is_service_enabled q-dhcp; then
370 _configure_neutron_dhcp_agent
371 fi
372 if is_service_enabled q-l3; then
373 _configure_neutron_l3_agent
374 fi
375 if is_service_enabled q-meta; then
376 _configure_neutron_metadata_agent
377 fi
378
Brian Haleyeea76212014-06-27 11:45:50 -0400379 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
380 _configure_dvr
381 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400382 if is_service_enabled ceilometer; then
383 _configure_neutron_ceilometer_notifications
384 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400385
386 _configure_neutron_debug_command
387}
388
Ian Wienandaee18c72014-02-21 15:35:08 +1100389function create_nova_conf_neutron {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800390 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
Gary Kotton13d385e2014-06-17 23:24:53 -0700391 iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME"
392 iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD"
393 iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
394 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
395 iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME"
Bartosz Górski0abde392014-02-28 14:15:19 +0100396 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Gary Kotton13d385e2014-06-17 23:24:53 -0700397 iniset $NOVA_CONF neutron url "http://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400398
399 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
400 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400401 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800402 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400403 fi
404
405 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
406 neutron_plugin_create_nova_conf
407
Gary Kotton51c681d2014-04-22 01:40:56 -0700408 iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER"
Mark McClainb05c8762013-07-06 23:29:39 -0400409 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
410 if is_service_enabled q-meta; then
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800411 iniset $NOVA_CONF DEFAULT service_neutron_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400412 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800413
414 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
415 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400416}
417
Emilien Macchia677b7f2013-11-25 23:40:20 +0100418# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100419function create_neutron_cache_dir {
Emilien Macchia677b7f2013-11-25 23:40:20 +0100420 # Create cache dir
421 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
422 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
423 rm -f $NEUTRON_AUTH_CACHE_DIR/*
424}
425
Mark McClainb05c8762013-07-06 23:29:39 -0400426# create_neutron_accounts() - Set up common required neutron accounts
427
428# Tenant User Roles
429# ------------------------------------------------------------------
430# service neutron admin # if enabled
431
432# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100433function create_neutron_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400434
Steve Martinelli19685422014-01-24 13:02:26 -0600435 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
436 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Mark McClainb05c8762013-07-06 23:29:39 -0400437
438 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100439
440 NEUTRON_USER=$(get_or_create_user "neutron" \
Gael Chamoulaud6dd8a8b2014-07-22 01:12:12 +0200441 "$SERVICE_PASSWORD" $SERVICE_TENANT)
Bartosz Górski0abde392014-02-28 14:15:19 +0100442 get_or_add_user_role $ADMIN_ROLE $NEUTRON_USER $SERVICE_TENANT
443
Mark McClainb05c8762013-07-06 23:29:39 -0400444 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100445
446 NEUTRON_SERVICE=$(get_or_create_service "neutron" \
447 "network" "Neutron Service")
448 get_or_create_endpoint $NEUTRON_SERVICE \
449 "$REGION_NAME" \
Aaron Rosen186119c2014-07-25 15:35:09 -0700450 "http://$SERVICE_HOST:$Q_PORT/" \
451 "http://$SERVICE_HOST:$Q_PORT/" \
452 "http://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400453 fi
454 fi
455}
456
Ian Wienandaee18c72014-02-21 15:35:08 +1100457function create_neutron_initial_network {
Steve Martinelli19685422014-01-24 13:02:26 -0600458 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500459 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400460
461 # Create a small network
462 # Since neutron command is executed in admin context at this point,
Dirk Mueller25049cd2014-01-09 13:53:52 +0100463 # ``--tenant-id`` needs to be specified.
Mark McClainb05c8762013-07-06 23:29:39 -0400464 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200465 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
466 die $LINENO "Neutron settings for baremetal not set.. exiting"
467 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400468 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
469 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
470 sudo ip addr del $IP dev $PUBLIC_INTERFACE
471 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
472 done
Dirk Mueller25049cd2014-01-09 13:53:52 +0100473 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 -0500474 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100475 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 -0500476 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400477 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200478 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400479 elif is_provider_network; then
480 die_if_not_set $LINENO SEGMENTATION_ID "A SEGMENTATION_ID is required to use provider networking"
481 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
Sean M. Collins21e6c622014-06-16 11:19:48 -0400482 NET_ID=$(neutron net-create $PHYSICAL_NETWORK --tenant_id $TENANT_ID --provider:network_type $PROVIDER_NETWORK_TYPE --provider:physical_network "$PHYSICAL_NETWORK" --provider:segmentation_id "$SEGMENTATION_ID" --shared | grep ' id ' | get_field 2)
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400483 SUBNET_ID=$(neutron subnet-create --tenant_id $TENANT_ID --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --name $PROVIDER_SUBNET_NAME $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
Sean M. Collinse13fd602014-05-14 17:01:53 -0400484 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 -0400485 sudo ip link set $OVS_PHYSICAL_BRIDGE up
486 sudo ip link set br-int up
487 sudo ip link set $PUBLIC_INTERFACE up
Mark McClainb05c8762013-07-06 23:29:39 -0400488 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100489 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500490 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100491 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 -0500492 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400493 fi
494
495 if [[ "$Q_L3_ENABLED" == "True" ]]; then
496 # Create a router, and add the private subnet as one of its interfaces
497 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
498 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100499 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500500 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400501 else
502 # Plugin only supports creating a single router, which should be admin owned.
503 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500504 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400505 fi
506 neutron router-interface-add $ROUTER_ID $SUBNET_ID
507 # Create an external network, and a subnet. Configure the external network as router gw
508 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500509 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400510 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 -0500511 die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400512 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
513
514 if is_service_enabled q-l3; then
515 # logic is specific to using the l3-agent for l3
516 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
517 CIDR_LEN=${FLOATING_RANGE#*/}
518 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
519 sudo ip link set $PUBLIC_BRIDGE up
520 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 -0500521 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400522 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
523 fi
524 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
525 # Explicitly set router id in l3 agent configuration
526 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
527 fi
528 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400529 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400530}
531
532# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100533function init_neutron {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700534 recreate_database $Q_DB_NAME utf8
535 # Run Neutron db migrations
536 $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 -0400537}
538
539# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100540function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400541 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
542 setup_develop $NEUTRON_DIR
543}
544
545# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100546function install_neutronclient {
Mark McClainb05c8762013-07-06 23:29:39 -0400547 git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH
548 setup_develop $NEUTRONCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200549 sudo install -D -m 0644 -o $STACK_USER {$NEUTRONCLIENT_DIR/tools/,/etc/bash_completion.d/}neutron.bash_completion
Mark McClainb05c8762013-07-06 23:29:39 -0400550}
551
552# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100553function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400554 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
555 if is_service_enabled q-l3; then
556 install_package radvd
557 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400558 # install packages that are specific to plugin agent(s)
559 if is_service_enabled q-agt q-dhcp q-l3; then
560 neutron_plugin_install_agent_packages
561 fi
562
563 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400564 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400565 fi
566}
567
568# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100569function start_neutron_service_and_check {
Adam Gandelman7614d212014-08-11 14:27:50 -0700570 local cfg_file_options="$(determine_config_files neutron-server)"
Mark McClainb05c8762013-07-06 23:29:39 -0400571 # Start the Neutron service
Adam Gandelman7614d212014-08-11 14:27:50 -0700572 screen_it q-svc "cd $NEUTRON_DIR && python $NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400573 echo "Waiting for Neutron to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800574 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400575 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400576 fi
577}
578
579# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100580function start_neutron_agents {
Mark McClainb05c8762013-07-06 23:29:39 -0400581 # Start up the neutron agents if enabled
582 screen_it q-agt "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
583 screen_it q-dhcp "cd $NEUTRON_DIR && python $AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file=$Q_DHCP_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700584
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400585 if is_provider_network; then
586 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
587 sudo ip link set $OVS_PHYSICAL_BRIDGE up
588 sudo ip link set br-int up
589 sudo ip link set $PUBLIC_INTERFACE up
590 fi
591
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700592 if is_service_enabled q-vpn; then
Adam Gandelman7614d212014-08-11 14:27:50 -0700593 screen_it q-vpn "cd $NEUTRON_DIR && $AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700594 else
Adam Gandelman7614d212014-08-11 14:27:50 -0700595 screen_it q-l3 "cd $NEUTRON_DIR && python $AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700596 fi
597
Mark McClainb05c8762013-07-06 23:29:39 -0400598 screen_it q-meta "cd $NEUTRON_DIR && python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
599
600 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
601 # For XenServer, start an agent for the domU openvswitch
602 screen_it q-domua "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
603 fi
604
605 if is_service_enabled q-lbaas; then
606 screen_it q-lbaas "cd $NEUTRON_DIR && python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
607 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200608
609 if is_service_enabled q-metering; then
610 screen_it q-metering "cd $NEUTRON_DIR && python $AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
611 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400612}
613
614# stop_neutron() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100615function stop_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400616 if is_service_enabled q-dhcp; then
617 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
618 [ ! -z "$pid" ] && sudo kill -9 $pid
619 fi
620 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100621 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400622 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900623
624 if is_service_enabled q-lbaas; then
625 neutron_lbaas_stop
626 fi
627 if is_service_enabled q-fwaas; then
628 neutron_fwaas_stop
629 fi
630 if is_service_enabled q-vpn; then
631 neutron_vpn_stop
632 fi
633 if is_service_enabled q-metering; then
634 neutron_metering_stop
635 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400636}
637
638# cleanup_neutron() - Remove residual data files, anything left over from previous
639# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100640function cleanup_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400641 if is_neutron_ovs_base_plugin; then
642 neutron_ovs_base_cleanup
643 fi
644
645 # delete all namespaces created by neutron
Brian Haleyeea76212014-06-27 11:45:50 -0400646 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 -0400647 sudo ip netns delete ${ns}
648 done
649}
650
651# _configure_neutron_common()
652# Set common config for all neutron server and agents.
653# This MUST be called before other ``_configure_neutron_*`` functions.
Ian Wienandaee18c72014-02-21 15:35:08 +1100654function _configure_neutron_common {
Mark McClainb05c8762013-07-06 23:29:39 -0400655 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
656 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
657 sudo mkdir -p $NEUTRON_CONF_DIR
658 fi
659 sudo chown $STACK_USER $NEUTRON_CONF_DIR
660
661 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
662
663 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
664 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
665 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
666 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100667 #
Mark McClainb05c8762013-07-06 23:29:39 -0400668 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
669 neutron_plugin_configure_common
670
sbauzae2c4ee22013-08-29 17:29:46 +0200671 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400672 die $LINENO "Neutron plugin not set.. exiting"
673 fi
674
675 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
676 mkdir -p /$Q_PLUGIN_CONF_PATH
677 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
678 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
679
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200680 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400681 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
682
683 # If addition config files are set, make sure their path name is set as well
684 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
685 die $LINENO "Neutron additional plugin config not set.. exiting"
686 fi
687
688 # If additional config files exist, copy them over to neutron configuration
689 # directory
690 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400691 local f
692 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
693 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400694 done
695 fi
696
Joe Gordonbee5c502013-08-30 13:48:08 -0400697 if [ "$VIRT_DRIVER" = 'fake' ]; then
698 # Disable arbitrary limits
699 iniset $NEUTRON_CONF quotas quota_network -1
700 iniset $NEUTRON_CONF quotas quota_subnet -1
701 iniset $NEUTRON_CONF quotas quota_port -1
702 iniset $NEUTRON_CONF quotas quota_security_group -1
703 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
704 fi
705
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700706 # Format logging
707 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800708 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700709 fi
710
Mark McClainb05c8762013-07-06 23:29:39 -0400711 _neutron_setup_rootwrap
712}
713
Ian Wienandaee18c72014-02-21 15:35:08 +1100714function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400715 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
716 return
717 fi
718
719 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
720
721 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
722 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
723 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400724 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
725
Mark McClainb05c8762013-07-06 23:29:39 -0400726 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
727
728 neutron_plugin_configure_debug_command
729}
730
Ian Wienandaee18c72014-02-21 15:35:08 +1100731function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400732
733 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
734
735 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500736 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400737 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
738 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
739
Mark McClainb05c8762013-07-06 23:29:39 -0400740 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
741
742 neutron_plugin_configure_dhcp_agent
743}
744
Ian Wienandaee18c72014-02-21 15:35:08 +1100745function _configure_neutron_l3_agent {
Paul Michali746dcee2014-04-02 19:12:22 +0000746 local cfg_file
Mark McClainb05c8762013-07-06 23:29:39 -0400747 Q_L3_ENABLED=True
748 # for l3-agent, only use per tenant router if we have namespaces
749 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700750
Paul Michali746dcee2014-04-02 19:12:22 +0000751 if is_service_enabled q-vpn; then
Paul Michali746dcee2014-04-02 19:12:22 +0000752 cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
Paul Michali746dcee2014-04-02 19:12:22 +0000753 fi
754
Mark McClainb05c8762013-07-06 23:29:39 -0400755 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
756
757 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500758 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400759 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
760 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
761
Mark McClainb05c8762013-07-06 23:29:39 -0400762 _neutron_setup_interface_driver $Q_L3_CONF_FILE
763
764 neutron_plugin_configure_l3_agent
765}
766
Ian Wienandaee18c72014-02-21 15:35:08 +1100767function _configure_neutron_metadata_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400768 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
769
770 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500771 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400772 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
773 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
774
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000775 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT True True
Maru Newbybf10ac52013-08-10 21:27:54 +0000776
Mark McClainb05c8762013-07-06 23:29:39 -0400777}
778
Dina Belova58adaa62014-07-11 18:18:12 +0400779function _configure_neutron_ceilometer_notifications {
780 iniset $NEUTRON_CONF DEFAULT notification_driver neutron.openstack.common.notifier.rpc_notifier
781}
782
Ian Wienandaee18c72014-02-21 15:35:08 +1100783function _configure_neutron_lbaas {
Mark McClainb05c8762013-07-06 23:29:39 -0400784 neutron_agent_lbaas_configure_common
785 neutron_agent_lbaas_configure_agent
786}
787
Ian Wienandaee18c72014-02-21 15:35:08 +1100788function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200789 neutron_agent_metering_configure_common
790 neutron_agent_metering_configure_agent
791}
792
Ian Wienandaee18c72014-02-21 15:35:08 +1100793function _configure_neutron_fwaas {
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700794 neutron_fwaas_configure_common
795 neutron_fwaas_configure_driver
796}
797
Ian Wienandaee18c72014-02-21 15:35:08 +1100798function _configure_neutron_vpn {
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700799 neutron_vpn_install_agent_packages
800 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700801}
802
Brian Haleyeea76212014-06-27 11:45:50 -0400803function _configure_dvr {
804 iniset $NEUTRON_CONF DEFAULT router_distributed True
805 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
806}
807
808
Mark McClainb05c8762013-07-06 23:29:39 -0400809# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
810# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100811function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400812 # Specify the default root helper prior to agent configuration to
813 # ensure that an agent's configuration can override the default
814 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
815 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500816 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400817
818 # Configure agent for plugin
819 neutron_plugin_configure_plugin_agent
820}
821
822# _configure_neutron_service() - Set config files for neutron service
823# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100824function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400825 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
826 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
827
828 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
829 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
830
Mark McClainb05c8762013-07-06 23:29:39 -0400831 # Update either configuration file with plugin
832 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
833
834 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
835 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
836 fi
837
838 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500839 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400840 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
841 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
842
843 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
844 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
845
Aaron Rosencea32b12014-03-04 16:20:14 -0800846 # Configuration for neutron notifations to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500847 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
848 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Aaron Rosencea32b12014-03-04 16:20:14 -0800849 iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
Dirk Mueller5ca261a2014-04-04 22:48:02 +0200850 iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800851 iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
852 ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
853 iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
854 iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
855
Mark McClainb05c8762013-07-06 23:29:39 -0400856 # Configure plugin
857 neutron_plugin_configure_service
858}
859
860# Utility Functions
861#------------------
862
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900863# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100864function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900865 local service_plugin_class=$1
866 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
867 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
868 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
869 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
870 fi
871}
872
Mark McClainb05c8762013-07-06 23:29:39 -0400873# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100874function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400875 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
876 return
877 fi
878 # Deploy new rootwrap filters files (owned by root).
879 # Wipe any existing ``rootwrap.d`` files first
880 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
881 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
882 sudo rm -rf $Q_CONF_ROOTWRAP_D
883 fi
884 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
885 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
886 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
887 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
888 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
889 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
890 # location moved in newer versions, prefer new location
891 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400892 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400893 else
Sean Dague3bdb9222013-10-22 08:36:16 -0400894 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400895 fi
896 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
897 sudo chown root:root $Q_RR_CONF_FILE
898 sudo chmod 0644 $Q_RR_CONF_FILE
899 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
900 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
901
902 # Set up the rootwrap sudoers for neutron
903 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100904 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400905 chmod 0440 $TEMPFILE
906 sudo chown root:root $TEMPFILE
907 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
908
909 # Update the root_helper
910 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
911}
912
913# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +1100914function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -0400915 local conf_file=$1
916 local section=$2
917 local use_auth_url=$3
Maru Newbybf10ac52013-08-10 21:27:54 +0000918 local skip_auth_cache=$4
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000919
920 iniset $conf_file $section auth_uri $KEYSTONE_SERVICE_URI
921 iniset $conf_file $section identity_uri $KEYSTONE_AUTH_URI
Mark McClainb05c8762013-07-06 23:29:39 -0400922 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
923 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
924 iniset $conf_file $section admin_password $SERVICE_PASSWORD
Maru Newbybf10ac52013-08-10 21:27:54 +0000925 if [[ -z $skip_auth_cache ]]; then
926 iniset $conf_file $section signing_dir $NEUTRON_AUTH_CACHE_DIR
927 # Create cache dir
Emilien Macchia677b7f2013-11-25 23:40:20 +0100928 create_neutron_cache_dir
Maru Newbybf10ac52013-08-10 21:27:54 +0000929 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400930}
931
Ian Wienandaee18c72014-02-21 15:35:08 +1100932function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -0400933
934 # ovs_use_veth needs to be set before the plugin configuration
935 # occurs to allow plugins to override the setting.
936 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
937
938 neutron_plugin_setup_interface_driver $1
939}
940
941# Functions for Neutron Exercises
942#--------------------------------
943
Ian Wienandaee18c72014-02-21 15:35:08 +1100944function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -0400945 local from_net="$1"
946 net_id=`_get_net_id $from_net`
947 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}'`
948 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
949}
950
Ian Wienandaee18c72014-02-21 15:35:08 +1100951function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -0400952 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
953 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
954 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
955 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
956 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
957 fi
958}
959
Ian Wienandaee18c72014-02-21 15:35:08 +1100960function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -0400961 delete_probe $PUBLIC_NETWORK_NAME
962 delete_probe $PRIVATE_NETWORK_NAME
963}
964
Ian Wienandaee18c72014-02-21 15:35:08 +1100965function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -0400966 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
967}
968
Ian Wienandaee18c72014-02-21 15:35:08 +1100969function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -0400970 local from_net="$1"
971 net_id=`_get_net_id $from_net`
972 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`
973 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
974}
975
Ian Wienandaee18c72014-02-21 15:35:08 +1100976function _ping_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400977 local from_net=$1
978 local ip=$2
979 local timeout_sec=$3
980 local expected=${4:-"True"}
981 local check_command=""
982 probe_cmd=`_get_probe_cmd_prefix $from_net`
983 if [[ "$expected" = "True" ]]; then
984 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
985 else
986 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
987 fi
988 if ! timeout $timeout_sec sh -c "$check_command"; then
989 if [[ "$expected" = "True" ]]; then
990 die $LINENO "[Fail] Couldn't ping server"
991 else
992 die $LINENO "[Fail] Could ping server"
993 fi
994 fi
995}
996
997# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +1100998function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400999 local from_net=$1
1000 local key_file=$2
1001 local ip=$3
1002 local user=$4
1003 local timeout_sec=$5
1004 local probe_cmd = ""
1005 probe_cmd=`_get_probe_cmd_prefix $from_net`
1006 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
1007 die $LINENO "server didn't become ssh-able!"
1008 fi
1009}
1010
1011# Neutron 3rd party programs
1012#---------------------------
1013
1014# please refer to ``lib/neutron_thirdparty/README.md`` for details
1015NEUTRON_THIRD_PARTIES=""
1016for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001017 third_party=$(basename $f)
1018 if is_service_enabled $third_party; then
1019 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1020 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1021 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001022done
1023
Ian Wienandaee18c72014-02-21 15:35:08 +11001024function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001025 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1026 ${1}_${third_party}
1027 done
1028}
1029
1030# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001031function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001032 _neutron_third_party_do configure
1033}
1034
1035# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001036function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001037 _neutron_third_party_do init
1038}
1039
1040# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001041function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001042 _neutron_third_party_do install
1043}
1044
1045# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001046function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001047 _neutron_third_party_do start
1048}
1049
1050# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001051function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001052 _neutron_third_party_do stop
1053}
1054
armando-migliaccioef1e0802014-01-02 16:33:53 -08001055# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001056function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001057 _neutron_third_party_do check
1058}
1059
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001060function is_provider_network {
1061 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1062 return 0
1063 fi
1064 return 1
1065}
1066
Mark McClainb05c8762013-07-06 23:29:39 -04001067
1068# Restore xtrace
1069$XTRACE
1070
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001071# Tell emacs to use shell-script-mode
1072## Local variables:
1073## mode: shell-script
1074## End: