blob: faca3e0da2c198fb68cd0e1f70be34b0079b7ddd [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#
48# If you're planning to use the Neutron openvswitch plugin, set
49# ``Q_PLUGIN`` to "openvswitch" and make sure the q-agt service is enabled
50# in ``ENABLED_SERVICES``. If you're planning to use the Neutron
51# linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the
52# q-agt service is enabled in ``ENABLED_SERVICES``.
53#
54# See "Neutron Network Configuration" below for additional variables
55# that must be set in localrc for connectivity across hosts with
56# Neutron.
57#
58# With Neutron networking the NETWORK_MANAGER variable is ignored.
59#
60# To enable specific configuration options for either the Open vSwitch or
61# LinuxBridge plugin, please see the top level README file under the
62# Neutron section.
63
Mark McClainb05c8762013-07-06 23:29:39 -040064
65# Neutron Network Configuration
66# -----------------------------
67
68# Gateway and subnet defaults, in case they are not customized in localrc
69NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
Salvatore Orlando90234ac2013-11-25 05:44:10 -080070PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
Mark McClainb05c8762013-07-06 23:29:39 -040071PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
72PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
73
Rob Crittenden18d47782014-03-19 17:47:42 -040074if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then
75 Q_PROTOCOL="https"
76fi
77
78
Mark McClainb05c8762013-07-06 23:29:39 -040079# Set up default directories
Sean Dague5cb19062014-11-01 01:37:45 +010080GITDIR["neutronclient"]=$DEST/python-neutronclient
81
82
Mark McClainb05c8762013-07-06 23:29:39 -040083NEUTRON_DIR=$DEST/neutron
Mark McClainb05c8762013-07-06 23:29:39 -040084NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
85
86# Support entry points installation of console scripts
87if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
88 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040089else
90 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040091fi
92
93NEUTRON_CONF_DIR=/etc/neutron
94NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
95export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
96
Adam Gandelman7614d212014-08-11 14:27:50 -070097# Agent binaries. Note, binary paths for other agents are set in per-service
98# scripts in lib/neutron_plugins/services/
99AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
100AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
101AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
102
103# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
104# loaded from per-plugin scripts in lib/neutron_plugins/
105Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
106Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
107Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
108Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
109Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
110
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400111# Default name for Neutron database
112Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400113# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000114Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400115# Default Neutron Port
116Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400117# Default Neutron Internal Port when using TLS proxy
118Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400119# Default Neutron Host
120Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400121# Default protocol
122Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Mark McClainb05c8762013-07-06 23:29:39 -0400123# Default admin username
124Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
125# Default auth strategy
126Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
127# Use namespace or not
128Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
129# RHEL's support for namespaces requires using veths with ovs
130Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
131Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
132# Meta data IP
133Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
134# Allow Overlapping IP among subnets
135Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
136# Use neutron-debug command
137Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
138# The name of the default q-l3 router
139Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Aaron Rosen4540d002013-10-24 13:59:33 -0700140# nova vif driver that all plugins should use
141NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500142Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
143Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800144VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
145VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700146
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400147## Provider Network Information
148PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
149
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900150# Use flat providernet for public network
151#
152# If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network
153# for external interface of neutron l3-agent. In that case,
154# PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900155# used for the network. In case of ofagent, you should add the
156# corresponding entry to your OFAGENT_PHYSICAL_INTERFACE_MAPPINGS.
157# For openvswitch agent, you should add the corresponding entry to
158# your OVS_BRIDGE_MAPPINGS.
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900159#
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900160# eg. (ofagent)
161# Q_USE_PROVIDERNET_FOR_PUBLIC=True
162# Q_USE_PUBLIC_VETH=True
163# PUBLIC_PHYSICAL_NETWORK=public
164# OFAGENT_PHYSICAL_INTERFACE_MAPPINGS=public:veth-pub-int
165#
166# eg. (openvswitch agent)
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900167# Q_USE_PROVIDERNET_FOR_PUBLIC=True
168# PUBLIC_PHYSICAL_NETWORK=public
169# OVS_BRIDGE_MAPPINGS=public:br-ex
170Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-False}
171PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public}
172
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900173# If Q_USE_PUBLIC_VETH=True, create and use a veth pair instead of
174# PUBLIC_BRIDGE. This is intended to be used with
175# Q_USE_PROVIDERNET_FOR_PUBLIC=True.
176Q_USE_PUBLIC_VETH=${Q_USE_PUBLIC_VETH:-False}
177Q_PUBLIC_VETH_EX=${Q_PUBLIC_VETH_EX:-veth-pub-ex}
178Q_PUBLIC_VETH_INT=${Q_PUBLIC_VETH_INT:-veth-pub-int}
179
Tomoe Sugiharaafbc6312013-11-14 20:02:47 +0000180# The next two variables are configured by plugin
181# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
182#
183# The plugin supports L3.
184Q_L3_ENABLED=${Q_L3_ENABLED:-False}
185# L3 routers exist per tenant
186Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False}
Aaron Rosen4540d002013-10-24 13:59:33 -0700187
Mark McClainb05c8762013-07-06 23:29:39 -0400188# List of config file names in addition to the main plugin config file
189# See _configure_neutron_common() for details about setting it up
190declare -a Q_PLUGIN_EXTRA_CONF_FILES
191
Paul Michali746dcee2014-04-02 19:12:22 +0000192# List of (optional) config files for VPN device drivers to use with
193# the neutron-q-vpn agent
194declare -a Q_VPN_EXTRA_CONF_FILES
195
Mark McClainb05c8762013-07-06 23:29:39 -0400196
Dean Troyere2907b42014-02-26 17:35:37 -0600197Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
198if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
199 Q_RR_COMMAND="sudo"
200else
201 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
202 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400203fi
204
Brian Haleyeea76212014-06-27 11:45:50 -0400205
206# Distributed Virtual Router (DVR) configuration
207# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500208# - ``legacy`` - No DVR functionality
209# - ``dvr_snat`` - Controller or single node DVR
210# - ``dvr`` - Compute node in multi-node DVR
211#
Brian Haleyeea76212014-06-27 11:45:50 -0400212Q_DVR_MODE=${Q_DVR_MODE:-legacy}
213if [[ "$Q_DVR_MODE" != "legacy" ]]; then
214 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
215fi
216
Dean Troyere2907b42014-02-26 17:35:37 -0600217# Provider Network Configurations
218# --------------------------------
219
220# The following variables control the Neutron openvswitch and
221# linuxbridge plugins' allocation of tenant networks and
222# availability of provider networks. If these are not configured
223# in ``localrc``, tenant networks will be local to the host (with no
224# remote connectivity), and no physical resources will be
225# available for the allocation of provider networks.
226
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200227# To disable tunnels (GRE or VXLAN) for tenant networks,
228# set to False in ``local.conf``.
229# GRE tunnels are only supported by the openvswitch.
230ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600231
232# If using GRE tunnels for tenant networks, specify the range of
233# tunnel IDs from which tenant networks are allocated. Can be
234# overriden in ``localrc`` in necesssary.
Anant Patil3827dc02014-07-03 21:38:16 +0530235TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600236
237# To use VLANs for tenant networks, set to True in localrc. VLANs
238# are supported by the openvswitch and linuxbridge plugins, each
239# requiring additional configuration described below.
240ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
241
242# If using VLANs for tenant networks, set in ``localrc`` to specify
243# the range of VLAN VIDs from which tenant networks are
244# allocated. An external network switch must be configured to
245# trunk these VLANs between hosts for multi-host connectivity.
246#
247# Example: ``TENANT_VLAN_RANGE=1000:1999``
248TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
249
250# If using VLANs for tenant networks, or if using flat or VLAN
251# provider networks, set in ``localrc`` to the name of the physical
252# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
253# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
254# agent, as described below.
255#
256# Example: ``PHYSICAL_NETWORK=default``
257PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
258
259# With the openvswitch plugin, if using VLANs for tenant networks,
260# or if using flat or VLAN provider networks, set in ``localrc`` to
261# the name of the OVS bridge to use for the physical network. The
262# bridge will be created if it does not already exist, but a
263# physical interface must be manually added to the bridge as a
264# port for external connectivity.
265#
266# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
267OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
268
269# With the linuxbridge plugin, if using VLANs for tenant networks,
270# or if using flat or VLAN provider networks, set in ``localrc`` to
271# the name of the network interface to use for the physical
272# network.
273#
274# Example: ``LB_PHYSICAL_INTERFACE=eth1``
275LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
276
Edgar Magana6f335b92014-07-10 15:42:44 -0700277# When Neutron tunnels are enabled it is needed to specify the
278# IP address of the end point in the local server. This IP is set
279# by default to the same IP address that the HOST IP.
280# This variable can be used to specify a different end point IP address
281# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
282TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
283
Dean Troyere2907b42014-02-26 17:35:37 -0600284# With the openvswitch plugin, set to True in ``localrc`` to enable
285# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
286#
287# Example: ``OVS_ENABLE_TUNNELING=True``
288OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
289
Mark McClainb05c8762013-07-06 23:29:39 -0400290# Neutron plugin specific functions
291# ---------------------------------
292
293# Please refer to ``lib/neutron_plugins/README.md`` for details.
294source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
295
296# Agent loadbalancer service plugin functions
297# -------------------------------------------
298
299# Hardcoding for 1 service plugin for now
300source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
301
Emilien Macchi40546f72013-09-24 15:10:25 +0200302# Agent metering service plugin functions
303# -------------------------------------------
304
305# Hardcoding for 1 service plugin for now
306source $TOP_DIR/lib/neutron_plugins/services/metering
307
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700308# VPN service plugin functions
309# -------------------------------------------
310# Hardcoding for 1 service plugin for now
311source $TOP_DIR/lib/neutron_plugins/services/vpn
312
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700313# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100314# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700315source $TOP_DIR/lib/neutron_plugins/services/firewall
316
Mark McClainb05c8762013-07-06 23:29:39 -0400317# Use security group or not
318if has_neutron_plugin_security_group; then
319 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
320else
321 Q_USE_SECGROUP=False
322fi
323
Dean Troyer4237f592014-01-29 16:22:11 -0600324# Tell Tempest this project is present
325TEMPEST_SERVICES+=,neutron
326
327
Dean Troyere2907b42014-02-26 17:35:37 -0600328# Save trace setting
329XTRACE=$(set +o | grep xtrace)
330set +o xtrace
331
332
Mark McClainb05c8762013-07-06 23:29:39 -0400333# Functions
334# ---------
335
Adam Gandelman7614d212014-08-11 14:27:50 -0700336function _determine_config_server {
337 local cfg_file
338 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
339 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
340 opts+=" --config-file /$cfg_file"
341 done
342 echo "$opts"
343}
344
345function _determine_config_vpn {
346 local cfg_file
347 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
348 if is_service_enabled q-fwaas; then
349 opts+=" --config-file $Q_FWAAS_CONF_FILE"
350 fi
351 for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
352 opts+=" --config-file $cfg_file"
353 done
354 echo "$opts"
355
356}
357
358function _determine_config_l3 {
359 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
360 if is_service_enabled q-fwaas; then
361 opts+=" --config-file $Q_FWAAS_CONF_FILE"
362 fi
363 echo "$opts"
364}
365
366# For services and agents that require it, dynamically construct a list of
367# --config-file arguments that are passed to the binary.
368function determine_config_files {
369 local opts=""
370 case "$1" in
371 "neutron-server") opts="$(_determine_config_server)" ;;
372 "neutron-vpn-agent") opts="$(_determine_config_vpn)" ;;
373 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
374 esac
375 if [ -z "$opts" ] ; then
376 die $LINENO "Could not determine config files for $1."
377 fi
378 echo "$opts"
379}
380
Dean Troyere4fa7212014-01-15 15:04:49 -0600381# Test if any Neutron services are enabled
382# is_neutron_enabled
383function is_neutron_enabled {
384 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
385 return 1
386}
387
Mark McClainb05c8762013-07-06 23:29:39 -0400388# configure_neutron()
389# Set common config for all neutron server and agents.
Ian Wienandaee18c72014-02-21 15:35:08 +1100390function configure_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400391 _configure_neutron_common
392 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
393
394 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
395 if is_service_enabled q-lbaas; then
396 _configure_neutron_lbaas
397 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200398 if is_service_enabled q-metering; then
399 _configure_neutron_metering
400 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700401 if is_service_enabled q-vpn; then
402 _configure_neutron_vpn
403 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700404 if is_service_enabled q-fwaas; then
405 _configure_neutron_fwaas
406 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000407 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400408 _configure_neutron_service
409 fi
410 if is_service_enabled q-agt; then
411 _configure_neutron_plugin_agent
412 fi
413 if is_service_enabled q-dhcp; then
414 _configure_neutron_dhcp_agent
415 fi
416 if is_service_enabled q-l3; then
417 _configure_neutron_l3_agent
418 fi
419 if is_service_enabled q-meta; then
420 _configure_neutron_metadata_agent
421 fi
422
Brian Haleyeea76212014-06-27 11:45:50 -0400423 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
424 _configure_dvr
425 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400426 if is_service_enabled ceilometer; then
427 _configure_neutron_ceilometer_notifications
428 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400429
430 _configure_neutron_debug_command
431}
432
Ian Wienandaee18c72014-02-21 15:35:08 +1100433function create_nova_conf_neutron {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800434 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
Gary Kotton13d385e2014-06-17 23:24:53 -0700435 iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME"
436 iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD"
437 iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
438 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
439 iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME"
Bartosz Górski0abde392014-02-28 14:15:19 +0100440 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Rob Crittenden18d47782014-03-19 17:47:42 -0400441 iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400442
443 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
444 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400445 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800446 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400447 fi
448
449 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
450 neutron_plugin_create_nova_conf
451
Gary Kotton51c681d2014-04-22 01:40:56 -0700452 iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER"
Mark McClainb05c8762013-07-06 23:29:39 -0400453 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
454 if is_service_enabled q-meta; then
Gary Kottondd745502014-08-11 23:38:47 -0700455 iniset $NOVA_CONF neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400456 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800457
458 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
459 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400460}
461
Emilien Macchia677b7f2013-11-25 23:40:20 +0100462# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100463function create_neutron_cache_dir {
Emilien Macchia677b7f2013-11-25 23:40:20 +0100464 # Create cache dir
465 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
466 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
467 rm -f $NEUTRON_AUTH_CACHE_DIR/*
468}
469
Mark McClainb05c8762013-07-06 23:29:39 -0400470# create_neutron_accounts() - Set up common required neutron accounts
471
472# Tenant User Roles
473# ------------------------------------------------------------------
474# service neutron admin # if enabled
475
476# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100477function create_neutron_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400478
Dean Troyer188493d2014-07-25 15:54:11 -0500479 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700480 local service_role=$(openstack role list | awk "/ service / { print \$2 }")
Mark McClainb05c8762013-07-06 23:29:39 -0400481
482 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100483
Dean Troyer188493d2014-07-25 15:54:11 -0500484 local neutron_user=$(get_or_create_user "neutron" \
485 "$SERVICE_PASSWORD" $service_tenant)
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700486 get_or_add_user_role $service_role $neutron_user $service_tenant
Bartosz Górski0abde392014-02-28 14:15:19 +0100487
Mark McClainb05c8762013-07-06 23:29:39 -0400488 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100489
Dean Troyer188493d2014-07-25 15:54:11 -0500490 local neutron_service=$(get_or_create_service "neutron" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100491 "network" "Neutron Service")
Dean Troyer188493d2014-07-25 15:54:11 -0500492 get_or_create_endpoint $neutron_service \
Bartosz Górski0abde392014-02-28 14:15:19 +0100493 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400494 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
495 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
496 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400497 fi
498 fi
499}
500
Ian Wienandaee18c72014-02-21 15:35:08 +1100501function create_neutron_initial_network {
Steve Martinelli19685422014-01-24 13:02:26 -0600502 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500503 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400504
505 # Create a small network
506 # Since neutron command is executed in admin context at this point,
Dirk Mueller25049cd2014-01-09 13:53:52 +0100507 # ``--tenant-id`` needs to be specified.
Mark McClainb05c8762013-07-06 23:29:39 -0400508 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200509 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
510 die $LINENO "Neutron settings for baremetal not set.. exiting"
511 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400512 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
513 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
514 sudo ip addr del $IP dev $PUBLIC_INTERFACE
515 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
516 done
Dirk Mueller25049cd2014-01-09 13:53:52 +0100517 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 -0500518 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100519 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 -0500520 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400521 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200522 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400523 elif is_provider_network; then
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900524 die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400525 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900526 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)
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400527 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 -0400528 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 -0400529 sudo ip link set $OVS_PHYSICAL_BRIDGE up
530 sudo ip link set br-int up
531 sudo ip link set $PUBLIC_INTERFACE up
Mark McClainb05c8762013-07-06 23:29:39 -0400532 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100533 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500534 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100535 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 -0500536 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400537 fi
538
539 if [[ "$Q_L3_ENABLED" == "True" ]]; then
540 # Create a router, and add the private subnet as one of its interfaces
541 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
542 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100543 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500544 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400545 else
546 # Plugin only supports creating a single router, which should be admin owned.
547 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500548 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400549 fi
550 neutron router-interface-add $ROUTER_ID $SUBNET_ID
551 # Create an external network, and a subnet. Configure the external network as router gw
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900552 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
553 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)
554 else
555 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
556 fi
DennyZhang23178a92013-10-22 17:07:32 -0500557 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400558 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 -0500559 die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400560 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
561
562 if is_service_enabled q-l3; then
563 # logic is specific to using the l3-agent for l3
564 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900565 local ext_gw_interface
566
567 if [[ "$Q_USE_PUBLIC_VETH" = "True" ]]; then
568 ext_gw_interface=$Q_PUBLIC_VETH_EX
569 else
570 # Disable in-band as we are going to use local port
571 # to communicate with VMs
572 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
573 other_config:disable-in-band=true
574 ext_gw_interface=$PUBLIC_BRIDGE
575 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400576 CIDR_LEN=${FLOATING_RANGE#*/}
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900577 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $ext_gw_interface
578 sudo ip link set $ext_gw_interface up
Mark McClainb05c8762013-07-06 23:29:39 -0400579 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 -0500580 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400581 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
582 fi
583 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
584 # Explicitly set router id in l3 agent configuration
585 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
586 fi
587 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400588 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400589}
590
591# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100592function init_neutron {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700593 recreate_database $Q_DB_NAME utf8
594 # Run Neutron db migrations
595 $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 -0400596}
597
598# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100599function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400600 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
601 setup_develop $NEUTRON_DIR
602}
603
604# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100605function install_neutronclient {
Sean Dague5cb19062014-11-01 01:37:45 +0100606 if use_library_from_git "neutronclient"; then
607 git_clone_by_name "neutronclient"
608 setup_develop "neutronclient"
609 sudo install -D -m 0644 -o $STACK_USER {$NEUTRONCLIENT_DIR/tools/,/etc/bash_completion.d/}neutron.bash_completion
610 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400611}
612
613# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100614function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400615 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
616 if is_service_enabled q-l3; then
617 install_package radvd
618 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400619 # install packages that are specific to plugin agent(s)
620 if is_service_enabled q-agt q-dhcp q-l3; then
621 neutron_plugin_install_agent_packages
622 fi
623
624 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400625 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400626 fi
627}
628
629# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100630function start_neutron_service_and_check {
Adam Gandelman7614d212014-08-11 14:27:50 -0700631 local cfg_file_options="$(determine_config_files neutron-server)"
Rob Crittenden18d47782014-03-19 17:47:42 -0400632 local service_port=$Q_PORT
633 local service_protocol=$Q_PROTOCOL
634 if is_service_enabled tls-proxy; then
635 service_port=$Q_PORT_INT
636 service_protocol="http"
637 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400638 # Start the Neutron service
Chris Dent2f27a0e2014-09-09 13:46:02 +0100639 run_process q-svc "python $NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400640 echo "Waiting for Neutron to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400641 if is_ssl_enabled_service "neutron"; then
642 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
643 fi
644 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 -0400645 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400646 fi
Rob Crittenden18d47782014-03-19 17:47:42 -0400647 # Start proxy if enabled
648 if is_service_enabled tls-proxy; then
649 start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT &
650 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400651}
652
653# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100654function start_neutron_agents {
Mark McClainb05c8762013-07-06 23:29:39 -0400655 # Start up the neutron agents if enabled
Chris Dent2f27a0e2014-09-09 13:46:02 +0100656 run_process q-agt "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
657 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 -0700658
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400659 if is_provider_network; then
660 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
661 sudo ip link set $OVS_PHYSICAL_BRIDGE up
662 sudo ip link set br-int up
663 sudo ip link set $PUBLIC_INTERFACE up
664 fi
665
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700666 if is_service_enabled q-vpn; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100667 run_process q-vpn "$AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700668 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100669 run_process q-l3 "python $AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700670 fi
671
Chris Dent2f27a0e2014-09-09 13:46:02 +0100672 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 -0400673
674 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
675 # For XenServer, start an agent for the domU openvswitch
Chris Dent2f27a0e2014-09-09 13:46:02 +0100676 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 -0400677 fi
678
679 if is_service_enabled q-lbaas; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100680 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 -0400681 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200682
683 if is_service_enabled q-metering; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100684 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 +0200685 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400686}
687
688# stop_neutron() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100689function stop_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400690 if is_service_enabled q-dhcp; then
691 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
692 [ ! -z "$pid" ] && sudo kill -9 $pid
693 fi
694 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100695 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400696 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900697
698 if is_service_enabled q-lbaas; then
699 neutron_lbaas_stop
700 fi
701 if is_service_enabled q-fwaas; then
702 neutron_fwaas_stop
703 fi
704 if is_service_enabled q-vpn; then
705 neutron_vpn_stop
706 fi
707 if is_service_enabled q-metering; then
708 neutron_metering_stop
709 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400710}
711
712# cleanup_neutron() - Remove residual data files, anything left over from previous
713# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100714function cleanup_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400715 if is_neutron_ovs_base_plugin; then
716 neutron_ovs_base_cleanup
717 fi
718
719 # delete all namespaces created by neutron
Brian Haleyeea76212014-06-27 11:45:50 -0400720 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 -0400721 sudo ip netns delete ${ns}
722 done
723}
724
725# _configure_neutron_common()
726# Set common config for all neutron server and agents.
727# This MUST be called before other ``_configure_neutron_*`` functions.
Ian Wienandaee18c72014-02-21 15:35:08 +1100728function _configure_neutron_common {
Mark McClainb05c8762013-07-06 23:29:39 -0400729 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
730 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
731 sudo mkdir -p $NEUTRON_CONF_DIR
732 fi
733 sudo chown $STACK_USER $NEUTRON_CONF_DIR
734
735 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
736
737 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
738 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
739 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
740 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100741 #
Mark McClainb05c8762013-07-06 23:29:39 -0400742 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
743 neutron_plugin_configure_common
744
sbauzae2c4ee22013-08-29 17:29:46 +0200745 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400746 die $LINENO "Neutron plugin not set.. exiting"
747 fi
748
749 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
750 mkdir -p /$Q_PLUGIN_CONF_PATH
751 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
752 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
753
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200754 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400755 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
756
757 # If addition config files are set, make sure their path name is set as well
758 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
759 die $LINENO "Neutron additional plugin config not set.. exiting"
760 fi
761
762 # If additional config files exist, copy them over to neutron configuration
763 # directory
764 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400765 local f
766 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
767 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400768 done
769 fi
770
Joe Gordonbee5c502013-08-30 13:48:08 -0400771 if [ "$VIRT_DRIVER" = 'fake' ]; then
772 # Disable arbitrary limits
773 iniset $NEUTRON_CONF quotas quota_network -1
774 iniset $NEUTRON_CONF quotas quota_subnet -1
775 iniset $NEUTRON_CONF quotas quota_port -1
776 iniset $NEUTRON_CONF quotas quota_security_group -1
777 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
778 fi
779
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700780 # Format logging
781 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800782 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700783 fi
784
Rob Crittenden18d47782014-03-19 17:47:42 -0400785 if is_service_enabled tls-proxy; then
786 # Set the service port for a proxy to take the original
787 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
788 fi
789
790 if is_ssl_enabled_service "nova"; then
791 iniset $NEUTRON_CONF DEFAULT nova_ca_certificates_file "$SSL_BUNDLE_FILE"
792 fi
793
794 if is_ssl_enabled_service "neutron"; then
795 ensure_certificates NEUTRON
796
797 iniset $NEUTRON_CONF DEFAULT use_ssl True
798 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
799 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
800 fi
801
Mark McClainb05c8762013-07-06 23:29:39 -0400802 _neutron_setup_rootwrap
803}
804
Ian Wienandaee18c72014-02-21 15:35:08 +1100805function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400806 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
807 return
808 fi
809
810 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
811
812 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
813 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
814 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400815 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
816
Mark McClainb05c8762013-07-06 23:29:39 -0400817 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
818
819 neutron_plugin_configure_debug_command
820}
821
Ian Wienandaee18c72014-02-21 15:35:08 +1100822function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400823
824 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
825
826 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500827 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400828 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
829 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
830
Mark McClainb05c8762013-07-06 23:29:39 -0400831 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
832
833 neutron_plugin_configure_dhcp_agent
834}
835
Ian Wienandaee18c72014-02-21 15:35:08 +1100836function _configure_neutron_l3_agent {
Paul Michali746dcee2014-04-02 19:12:22 +0000837 local cfg_file
Mark McClainb05c8762013-07-06 23:29:39 -0400838 Q_L3_ENABLED=True
839 # for l3-agent, only use per tenant router if we have namespaces
840 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700841
Paul Michali746dcee2014-04-02 19:12:22 +0000842 if is_service_enabled q-vpn; then
Paul Michali746dcee2014-04-02 19:12:22 +0000843 cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
Paul Michali746dcee2014-04-02 19:12:22 +0000844 fi
845
Mark McClainb05c8762013-07-06 23:29:39 -0400846 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
847
848 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500849 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400850 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
851 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
852
Mark McClainb05c8762013-07-06 23:29:39 -0400853 _neutron_setup_interface_driver $Q_L3_CONF_FILE
854
855 neutron_plugin_configure_l3_agent
856}
857
Ian Wienandaee18c72014-02-21 15:35:08 +1100858function _configure_neutron_metadata_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400859 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
860
861 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500862 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400863 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
864 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
865
Brant Knudson05952372014-09-19 17:22:22 -0500866 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT
Maru Newbybf10ac52013-08-10 21:27:54 +0000867
Mark McClainb05c8762013-07-06 23:29:39 -0400868}
869
Dina Belova58adaa62014-07-11 18:18:12 +0400870function _configure_neutron_ceilometer_notifications {
JordanPd4d4a342014-09-15 09:26:53 +0000871 iniset $NEUTRON_CONF DEFAULT notification_driver messaging
Dina Belova58adaa62014-07-11 18:18:12 +0400872}
873
Ian Wienandaee18c72014-02-21 15:35:08 +1100874function _configure_neutron_lbaas {
Mark McClainb05c8762013-07-06 23:29:39 -0400875 neutron_agent_lbaas_configure_common
876 neutron_agent_lbaas_configure_agent
877}
878
Ian Wienandaee18c72014-02-21 15:35:08 +1100879function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200880 neutron_agent_metering_configure_common
881 neutron_agent_metering_configure_agent
882}
883
Ian Wienandaee18c72014-02-21 15:35:08 +1100884function _configure_neutron_fwaas {
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700885 neutron_fwaas_configure_common
886 neutron_fwaas_configure_driver
887}
888
Ian Wienandaee18c72014-02-21 15:35:08 +1100889function _configure_neutron_vpn {
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700890 neutron_vpn_install_agent_packages
891 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700892}
893
Brian Haleyeea76212014-06-27 11:45:50 -0400894function _configure_dvr {
895 iniset $NEUTRON_CONF DEFAULT router_distributed True
896 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
897}
898
899
Mark McClainb05c8762013-07-06 23:29:39 -0400900# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
901# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100902function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400903 # Specify the default root helper prior to agent configuration to
904 # ensure that an agent's configuration can override the default
905 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
906 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500907 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400908
909 # Configure agent for plugin
910 neutron_plugin_configure_plugin_agent
911}
912
913# _configure_neutron_service() - Set config files for neutron service
914# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100915function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400916 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
917 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
918
919 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
920 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
921
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700922 # allow neutron user to administer neutron to match neutron account
923 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
924
Mark McClainb05c8762013-07-06 23:29:39 -0400925 # Update either configuration file with plugin
926 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
927
928 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
929 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
930 fi
931
932 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500933 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400934 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
935 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
936
937 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
938 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
939
Aaron Rosencea32b12014-03-04 16:20:14 -0800940 # Configuration for neutron notifations to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500941 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
942 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Aaron Rosencea32b12014-03-04 16:20:14 -0800943 iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
Dirk Mueller5ca261a2014-04-04 22:48:02 +0200944 iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800945 iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
946 ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
947 iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
948 iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
949
Mark McClainb05c8762013-07-06 23:29:39 -0400950 # Configure plugin
951 neutron_plugin_configure_service
952}
953
954# Utility Functions
955#------------------
956
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900957# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100958function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900959 local service_plugin_class=$1
960 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
961 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
962 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
963 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
964 fi
965}
966
Mark McClainb05c8762013-07-06 23:29:39 -0400967# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100968function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400969 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
970 return
971 fi
972 # Deploy new rootwrap filters files (owned by root).
973 # Wipe any existing ``rootwrap.d`` files first
974 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
975 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
976 sudo rm -rf $Q_CONF_ROOTWRAP_D
977 fi
978 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
979 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
980 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
981 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
982 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
983 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
984 # location moved in newer versions, prefer new location
985 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400986 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400987 else
Sean Dague3bdb9222013-10-22 08:36:16 -0400988 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400989 fi
990 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
991 sudo chown root:root $Q_RR_CONF_FILE
992 sudo chmod 0644 $Q_RR_CONF_FILE
993 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
994 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
995
996 # Set up the rootwrap sudoers for neutron
997 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100998 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400999 chmod 0440 $TEMPFILE
1000 sudo chown root:root $TEMPFILE
1001 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1002
1003 # Update the root_helper
1004 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
1005}
1006
1007# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +11001008function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -04001009 local conf_file=$1
1010 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +10001011
Brant Knudson05952372014-09-19 17:22:22 -05001012 create_neutron_cache_dir
1013 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -04001014}
1015
Ian Wienandaee18c72014-02-21 15:35:08 +11001016function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -04001017
1018 # ovs_use_veth needs to be set before the plugin configuration
1019 # occurs to allow plugins to override the setting.
1020 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1021
1022 neutron_plugin_setup_interface_driver $1
1023}
1024
1025# Functions for Neutron Exercises
1026#--------------------------------
1027
Ian Wienandaee18c72014-02-21 15:35:08 +11001028function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001029 local from_net="$1"
1030 net_id=`_get_net_id $from_net`
1031 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}'`
1032 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1033}
1034
Ian Wienandaee18c72014-02-21 15:35:08 +11001035function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001036 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
1037 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
1038 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
1039 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
1040 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
1041 fi
1042}
1043
Ian Wienandaee18c72014-02-21 15:35:08 +11001044function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001045 delete_probe $PUBLIC_NETWORK_NAME
1046 delete_probe $PRIVATE_NETWORK_NAME
1047}
1048
Ian Wienandaee18c72014-02-21 15:35:08 +11001049function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -04001050 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
1051}
1052
Ian Wienandaee18c72014-02-21 15:35:08 +11001053function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001054 local from_net="$1"
1055 net_id=`_get_net_id $from_net`
1056 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`
1057 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1058}
1059
Ian Wienandaee18c72014-02-21 15:35:08 +11001060function _ping_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001061 local from_net=$1
1062 local ip=$2
1063 local timeout_sec=$3
1064 local expected=${4:-"True"}
1065 local check_command=""
1066 probe_cmd=`_get_probe_cmd_prefix $from_net`
1067 if [[ "$expected" = "True" ]]; then
1068 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1069 else
1070 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1071 fi
1072 if ! timeout $timeout_sec sh -c "$check_command"; then
1073 if [[ "$expected" = "True" ]]; then
1074 die $LINENO "[Fail] Couldn't ping server"
1075 else
1076 die $LINENO "[Fail] Could ping server"
1077 fi
1078 fi
1079}
1080
1081# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001082function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001083 local from_net=$1
1084 local key_file=$2
1085 local ip=$3
1086 local user=$4
1087 local timeout_sec=$5
1088 local probe_cmd = ""
1089 probe_cmd=`_get_probe_cmd_prefix $from_net`
1090 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
1091 die $LINENO "server didn't become ssh-able!"
1092 fi
1093}
1094
1095# Neutron 3rd party programs
1096#---------------------------
1097
1098# please refer to ``lib/neutron_thirdparty/README.md`` for details
1099NEUTRON_THIRD_PARTIES=""
1100for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001101 third_party=$(basename $f)
1102 if is_service_enabled $third_party; then
1103 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1104 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1105 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001106done
1107
Ian Wienandaee18c72014-02-21 15:35:08 +11001108function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001109 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1110 ${1}_${third_party}
1111 done
1112}
1113
1114# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001115function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001116 _neutron_third_party_do configure
1117}
1118
1119# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001120function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001121 _neutron_third_party_do init
1122}
1123
1124# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001125function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001126 _neutron_third_party_do install
1127}
1128
1129# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001130function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001131 _neutron_third_party_do start
1132}
1133
1134# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001135function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001136 _neutron_third_party_do stop
1137}
1138
armando-migliaccioef1e0802014-01-02 16:33:53 -08001139# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001140function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001141 _neutron_third_party_do check
1142}
1143
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001144function is_provider_network {
1145 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1146 return 0
1147 fi
1148 return 1
1149}
1150
Mark McClainb05c8762013-07-06 23:29:39 -04001151
1152# Restore xtrace
1153$XTRACE
1154
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001155# Tell emacs to use shell-script-mode
1156## Local variables:
1157## mode: shell-script
1158## End: