blob: d05dcc806f7dcebad8f49d360e1e1fbafc339d5d [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
80NEUTRON_DIR=$DEST/neutron
81NEUTRONCLIENT_DIR=$DEST/python-neutronclient
82NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
83
84# Support entry points installation of console scripts
85if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
86 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040087else
88 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040089fi
90
91NEUTRON_CONF_DIR=/etc/neutron
92NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
93export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
94
Adam Gandelman7614d212014-08-11 14:27:50 -070095# Agent binaries. Note, binary paths for other agents are set in per-service
96# scripts in lib/neutron_plugins/services/
97AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
98AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
99AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
100
101# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
102# loaded from per-plugin scripts in lib/neutron_plugins/
103Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
104Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
105Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
106Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
107Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
108
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400109# Default name for Neutron database
110Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400111# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000112Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400113# Default Neutron Port
114Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400115# Default Neutron Internal Port when using TLS proxy
116Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400117# Default Neutron Host
118Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400119# Default protocol
120Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Mark McClainb05c8762013-07-06 23:29:39 -0400121# Default admin username
122Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
123# Default auth strategy
124Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
125# Use namespace or not
126Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
127# RHEL's support for namespaces requires using veths with ovs
128Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
129Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
130# Meta data IP
131Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
132# Allow Overlapping IP among subnets
133Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
134# Use neutron-debug command
135Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
136# The name of the default q-l3 router
137Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Aaron Rosen4540d002013-10-24 13:59:33 -0700138# nova vif driver that all plugins should use
139NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500140Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
141Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800142VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
143VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700144
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400145## Provider Network Information
146PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
147
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900148# Use flat providernet for public network
149#
150# If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network
151# for external interface of neutron l3-agent. In that case,
152# PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900153# used for the network. In case of ofagent, you should add the
154# corresponding entry to your OFAGENT_PHYSICAL_INTERFACE_MAPPINGS.
155# For openvswitch agent, you should add the corresponding entry to
156# your OVS_BRIDGE_MAPPINGS.
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900157#
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900158# eg. (ofagent)
159# Q_USE_PROVIDERNET_FOR_PUBLIC=True
160# Q_USE_PUBLIC_VETH=True
161# PUBLIC_PHYSICAL_NETWORK=public
162# OFAGENT_PHYSICAL_INTERFACE_MAPPINGS=public:veth-pub-int
163#
164# eg. (openvswitch agent)
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900165# Q_USE_PROVIDERNET_FOR_PUBLIC=True
166# PUBLIC_PHYSICAL_NETWORK=public
167# OVS_BRIDGE_MAPPINGS=public:br-ex
168Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-False}
169PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public}
170
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900171# If Q_USE_PUBLIC_VETH=True, create and use a veth pair instead of
172# PUBLIC_BRIDGE. This is intended to be used with
173# Q_USE_PROVIDERNET_FOR_PUBLIC=True.
174Q_USE_PUBLIC_VETH=${Q_USE_PUBLIC_VETH:-False}
175Q_PUBLIC_VETH_EX=${Q_PUBLIC_VETH_EX:-veth-pub-ex}
176Q_PUBLIC_VETH_INT=${Q_PUBLIC_VETH_INT:-veth-pub-int}
177
Tomoe Sugiharaafbc6312013-11-14 20:02:47 +0000178# The next two variables are configured by plugin
179# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
180#
181# The plugin supports L3.
182Q_L3_ENABLED=${Q_L3_ENABLED:-False}
183# L3 routers exist per tenant
184Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False}
Aaron Rosen4540d002013-10-24 13:59:33 -0700185
Mark McClainb05c8762013-07-06 23:29:39 -0400186# List of config file names in addition to the main plugin config file
187# See _configure_neutron_common() for details about setting it up
188declare -a Q_PLUGIN_EXTRA_CONF_FILES
189
Paul Michali746dcee2014-04-02 19:12:22 +0000190# List of (optional) config files for VPN device drivers to use with
191# the neutron-q-vpn agent
192declare -a Q_VPN_EXTRA_CONF_FILES
193
Mark McClainb05c8762013-07-06 23:29:39 -0400194
Dean Troyere2907b42014-02-26 17:35:37 -0600195Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
196if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
197 Q_RR_COMMAND="sudo"
198else
199 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
200 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400201fi
202
Brian Haleyeea76212014-06-27 11:45:50 -0400203
204# Distributed Virtual Router (DVR) configuration
205# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500206# - ``legacy`` - No DVR functionality
207# - ``dvr_snat`` - Controller or single node DVR
208# - ``dvr`` - Compute node in multi-node DVR
209#
Brian Haleyeea76212014-06-27 11:45:50 -0400210Q_DVR_MODE=${Q_DVR_MODE:-legacy}
211if [[ "$Q_DVR_MODE" != "legacy" ]]; then
212 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
213fi
214
Dean Troyere2907b42014-02-26 17:35:37 -0600215# Provider Network Configurations
216# --------------------------------
217
218# The following variables control the Neutron openvswitch and
219# linuxbridge plugins' allocation of tenant networks and
220# availability of provider networks. If these are not configured
221# in ``localrc``, tenant networks will be local to the host (with no
222# remote connectivity), and no physical resources will be
223# available for the allocation of provider networks.
224
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200225# To disable tunnels (GRE or VXLAN) for tenant networks,
226# set to False in ``local.conf``.
227# GRE tunnels are only supported by the openvswitch.
228ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600229
230# If using GRE tunnels for tenant networks, specify the range of
231# tunnel IDs from which tenant networks are allocated. Can be
232# overriden in ``localrc`` in necesssary.
Anant Patil3827dc02014-07-03 21:38:16 +0530233TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600234
235# To use VLANs for tenant networks, set to True in localrc. VLANs
236# are supported by the openvswitch and linuxbridge plugins, each
237# requiring additional configuration described below.
238ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
239
240# If using VLANs for tenant networks, set in ``localrc`` to specify
241# the range of VLAN VIDs from which tenant networks are
242# allocated. An external network switch must be configured to
243# trunk these VLANs between hosts for multi-host connectivity.
244#
245# Example: ``TENANT_VLAN_RANGE=1000:1999``
246TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
247
248# If using VLANs for tenant networks, or if using flat or VLAN
249# provider networks, set in ``localrc`` to the name of the physical
250# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
251# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
252# agent, as described below.
253#
254# Example: ``PHYSICAL_NETWORK=default``
255PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
256
257# With the openvswitch plugin, if using VLANs for tenant networks,
258# or if using flat or VLAN provider networks, set in ``localrc`` to
259# the name of the OVS bridge to use for the physical network. The
260# bridge will be created if it does not already exist, but a
261# physical interface must be manually added to the bridge as a
262# port for external connectivity.
263#
264# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
265OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
266
267# With the linuxbridge plugin, if using VLANs for tenant networks,
268# or if using flat or VLAN provider networks, set in ``localrc`` to
269# the name of the network interface to use for the physical
270# network.
271#
272# Example: ``LB_PHYSICAL_INTERFACE=eth1``
273LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
274
Edgar Magana6f335b92014-07-10 15:42:44 -0700275# When Neutron tunnels are enabled it is needed to specify the
276# IP address of the end point in the local server. This IP is set
277# by default to the same IP address that the HOST IP.
278# This variable can be used to specify a different end point IP address
279# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
280TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
281
Dean Troyere2907b42014-02-26 17:35:37 -0600282# With the openvswitch plugin, set to True in ``localrc`` to enable
283# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
284#
285# Example: ``OVS_ENABLE_TUNNELING=True``
286OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
287
Mark McClainb05c8762013-07-06 23:29:39 -0400288# Neutron plugin specific functions
289# ---------------------------------
290
291# Please refer to ``lib/neutron_plugins/README.md`` for details.
292source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
293
294# Agent loadbalancer service plugin functions
295# -------------------------------------------
296
297# Hardcoding for 1 service plugin for now
298source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
299
Emilien Macchi40546f72013-09-24 15:10:25 +0200300# Agent metering service plugin functions
301# -------------------------------------------
302
303# Hardcoding for 1 service plugin for now
304source $TOP_DIR/lib/neutron_plugins/services/metering
305
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700306# VPN service plugin functions
307# -------------------------------------------
308# Hardcoding for 1 service plugin for now
309source $TOP_DIR/lib/neutron_plugins/services/vpn
310
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700311# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100312# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700313source $TOP_DIR/lib/neutron_plugins/services/firewall
314
Mark McClainb05c8762013-07-06 23:29:39 -0400315# Use security group or not
316if has_neutron_plugin_security_group; then
317 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
318else
319 Q_USE_SECGROUP=False
320fi
321
Dean Troyer4237f592014-01-29 16:22:11 -0600322# Tell Tempest this project is present
323TEMPEST_SERVICES+=,neutron
324
325
Dean Troyere2907b42014-02-26 17:35:37 -0600326# Save trace setting
327XTRACE=$(set +o | grep xtrace)
328set +o xtrace
329
330
Mark McClainb05c8762013-07-06 23:29:39 -0400331# Functions
332# ---------
333
Adam Gandelman7614d212014-08-11 14:27:50 -0700334function _determine_config_server {
335 local cfg_file
336 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
337 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
338 opts+=" --config-file /$cfg_file"
339 done
340 echo "$opts"
341}
342
343function _determine_config_vpn {
344 local cfg_file
345 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
346 if is_service_enabled q-fwaas; then
347 opts+=" --config-file $Q_FWAAS_CONF_FILE"
348 fi
349 for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
350 opts+=" --config-file $cfg_file"
351 done
352 echo "$opts"
353
354}
355
356function _determine_config_l3 {
357 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
358 if is_service_enabled q-fwaas; then
359 opts+=" --config-file $Q_FWAAS_CONF_FILE"
360 fi
361 echo "$opts"
362}
363
364# For services and agents that require it, dynamically construct a list of
365# --config-file arguments that are passed to the binary.
366function determine_config_files {
367 local opts=""
368 case "$1" in
369 "neutron-server") opts="$(_determine_config_server)" ;;
370 "neutron-vpn-agent") opts="$(_determine_config_vpn)" ;;
371 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
372 esac
373 if [ -z "$opts" ] ; then
374 die $LINENO "Could not determine config files for $1."
375 fi
376 echo "$opts"
377}
378
Dean Troyere4fa7212014-01-15 15:04:49 -0600379# Test if any Neutron services are enabled
380# is_neutron_enabled
381function is_neutron_enabled {
382 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
383 return 1
384}
385
Mark McClainb05c8762013-07-06 23:29:39 -0400386# configure_neutron()
387# Set common config for all neutron server and agents.
Ian Wienandaee18c72014-02-21 15:35:08 +1100388function configure_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400389 _configure_neutron_common
390 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
391
392 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
393 if is_service_enabled q-lbaas; then
394 _configure_neutron_lbaas
395 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200396 if is_service_enabled q-metering; then
397 _configure_neutron_metering
398 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700399 if is_service_enabled q-vpn; then
400 _configure_neutron_vpn
401 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700402 if is_service_enabled q-fwaas; then
403 _configure_neutron_fwaas
404 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000405 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400406 _configure_neutron_service
407 fi
408 if is_service_enabled q-agt; then
409 _configure_neutron_plugin_agent
410 fi
411 if is_service_enabled q-dhcp; then
412 _configure_neutron_dhcp_agent
413 fi
414 if is_service_enabled q-l3; then
415 _configure_neutron_l3_agent
416 fi
417 if is_service_enabled q-meta; then
418 _configure_neutron_metadata_agent
419 fi
420
Brian Haleyeea76212014-06-27 11:45:50 -0400421 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
422 _configure_dvr
423 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400424 if is_service_enabled ceilometer; then
425 _configure_neutron_ceilometer_notifications
426 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400427
428 _configure_neutron_debug_command
429}
430
Ian Wienandaee18c72014-02-21 15:35:08 +1100431function create_nova_conf_neutron {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800432 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
Gary Kotton13d385e2014-06-17 23:24:53 -0700433 iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME"
434 iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD"
435 iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
436 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
437 iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME"
Bartosz Górski0abde392014-02-28 14:15:19 +0100438 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Rob Crittenden18d47782014-03-19 17:47:42 -0400439 iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400440
441 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
442 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400443 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800444 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400445 fi
446
447 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
448 neutron_plugin_create_nova_conf
449
Gary Kotton51c681d2014-04-22 01:40:56 -0700450 iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER"
Mark McClainb05c8762013-07-06 23:29:39 -0400451 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
452 if is_service_enabled q-meta; then
Gary Kottondd745502014-08-11 23:38:47 -0700453 iniset $NOVA_CONF neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400454 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800455
456 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
457 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400458}
459
Emilien Macchia677b7f2013-11-25 23:40:20 +0100460# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100461function create_neutron_cache_dir {
Emilien Macchia677b7f2013-11-25 23:40:20 +0100462 # Create cache dir
463 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
464 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
465 rm -f $NEUTRON_AUTH_CACHE_DIR/*
466}
467
Mark McClainb05c8762013-07-06 23:29:39 -0400468# create_neutron_accounts() - Set up common required neutron accounts
469
470# Tenant User Roles
471# ------------------------------------------------------------------
472# service neutron admin # if enabled
473
474# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100475function create_neutron_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400476
Dean Troyer188493d2014-07-25 15:54:11 -0500477 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700478 local service_role=$(openstack role list | awk "/ service / { print \$2 }")
Mark McClainb05c8762013-07-06 23:29:39 -0400479
480 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100481
Dean Troyer188493d2014-07-25 15:54:11 -0500482 local neutron_user=$(get_or_create_user "neutron" \
483 "$SERVICE_PASSWORD" $service_tenant)
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700484 get_or_add_user_role $service_role $neutron_user $service_tenant
Bartosz Górski0abde392014-02-28 14:15:19 +0100485
Mark McClainb05c8762013-07-06 23:29:39 -0400486 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100487
Dean Troyer188493d2014-07-25 15:54:11 -0500488 local neutron_service=$(get_or_create_service "neutron" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100489 "network" "Neutron Service")
Dean Troyer188493d2014-07-25 15:54:11 -0500490 get_or_create_endpoint $neutron_service \
Bartosz Górski0abde392014-02-28 14:15:19 +0100491 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400492 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
493 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
494 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400495 fi
496 fi
497}
498
Ian Wienandaee18c72014-02-21 15:35:08 +1100499function create_neutron_initial_network {
Steve Martinelli19685422014-01-24 13:02:26 -0600500 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500501 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400502
503 # Create a small network
504 # Since neutron command is executed in admin context at this point,
Dirk Mueller25049cd2014-01-09 13:53:52 +0100505 # ``--tenant-id`` needs to be specified.
Mark McClainb05c8762013-07-06 23:29:39 -0400506 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200507 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
508 die $LINENO "Neutron settings for baremetal not set.. exiting"
509 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400510 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
511 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
512 sudo ip addr del $IP dev $PUBLIC_INTERFACE
513 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
514 done
Dirk Mueller25049cd2014-01-09 13:53:52 +0100515 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 -0500516 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100517 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 -0500518 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400519 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200520 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400521 elif is_provider_network; then
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900522 die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400523 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900524 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 -0400525 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 -0400526 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 -0400527 sudo ip link set $OVS_PHYSICAL_BRIDGE up
528 sudo ip link set br-int up
529 sudo ip link set $PUBLIC_INTERFACE up
Mark McClainb05c8762013-07-06 23:29:39 -0400530 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100531 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500532 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100533 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 -0500534 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400535 fi
536
537 if [[ "$Q_L3_ENABLED" == "True" ]]; then
538 # Create a router, and add the private subnet as one of its interfaces
539 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
540 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100541 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500542 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400543 else
544 # Plugin only supports creating a single router, which should be admin owned.
545 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500546 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400547 fi
548 neutron router-interface-add $ROUTER_ID $SUBNET_ID
549 # Create an external network, and a subnet. Configure the external network as router gw
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900550 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
551 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)
552 else
553 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
554 fi
DennyZhang23178a92013-10-22 17:07:32 -0500555 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400556 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 -0500557 die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400558 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
559
560 if is_service_enabled q-l3; then
561 # logic is specific to using the l3-agent for l3
562 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900563 local ext_gw_interface
564
565 if [[ "$Q_USE_PUBLIC_VETH" = "True" ]]; then
566 ext_gw_interface=$Q_PUBLIC_VETH_EX
567 else
568 # Disable in-band as we are going to use local port
569 # to communicate with VMs
570 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
571 other_config:disable-in-band=true
572 ext_gw_interface=$PUBLIC_BRIDGE
573 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400574 CIDR_LEN=${FLOATING_RANGE#*/}
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900575 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $ext_gw_interface
576 sudo ip link set $ext_gw_interface up
Mark McClainb05c8762013-07-06 23:29:39 -0400577 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 -0500578 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400579 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
580 fi
581 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
582 # Explicitly set router id in l3 agent configuration
583 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
584 fi
585 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400586 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400587}
588
589# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100590function init_neutron {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700591 recreate_database $Q_DB_NAME utf8
592 # Run Neutron db migrations
593 $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 -0400594}
595
596# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100597function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400598 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
599 setup_develop $NEUTRON_DIR
600}
601
602# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100603function install_neutronclient {
Mark McClainb05c8762013-07-06 23:29:39 -0400604 git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH
605 setup_develop $NEUTRONCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200606 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 -0400607}
608
609# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100610function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400611 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
612 if is_service_enabled q-l3; then
613 install_package radvd
614 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400615 # install packages that are specific to plugin agent(s)
616 if is_service_enabled q-agt q-dhcp q-l3; then
617 neutron_plugin_install_agent_packages
618 fi
619
620 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400621 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400622 fi
623}
624
625# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100626function start_neutron_service_and_check {
Adam Gandelman7614d212014-08-11 14:27:50 -0700627 local cfg_file_options="$(determine_config_files neutron-server)"
Rob Crittenden18d47782014-03-19 17:47:42 -0400628 local service_port=$Q_PORT
629 local service_protocol=$Q_PROTOCOL
630 if is_service_enabled tls-proxy; then
631 service_port=$Q_PORT_INT
632 service_protocol="http"
633 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400634 # Start the Neutron service
Chris Dent2f27a0e2014-09-09 13:46:02 +0100635 run_process q-svc "python $NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400636 echo "Waiting for Neutron to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400637 if is_ssl_enabled_service "neutron"; then
638 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
639 fi
640 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 -0400641 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400642 fi
Rob Crittenden18d47782014-03-19 17:47:42 -0400643 # Start proxy if enabled
644 if is_service_enabled tls-proxy; then
645 start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT &
646 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400647}
648
649# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100650function start_neutron_agents {
Mark McClainb05c8762013-07-06 23:29:39 -0400651 # Start up the neutron agents if enabled
Chris Dent2f27a0e2014-09-09 13:46:02 +0100652 run_process q-agt "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
653 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 -0700654
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400655 if is_provider_network; then
656 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
657 sudo ip link set $OVS_PHYSICAL_BRIDGE up
658 sudo ip link set br-int up
659 sudo ip link set $PUBLIC_INTERFACE up
660 fi
661
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700662 if is_service_enabled q-vpn; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100663 run_process q-vpn "$AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700664 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100665 run_process q-l3 "python $AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700666 fi
667
Chris Dent2f27a0e2014-09-09 13:46:02 +0100668 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 -0400669
670 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
671 # For XenServer, start an agent for the domU openvswitch
Chris Dent2f27a0e2014-09-09 13:46:02 +0100672 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 -0400673 fi
674
675 if is_service_enabled q-lbaas; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100676 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 -0400677 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200678
679 if is_service_enabled q-metering; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100680 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 +0200681 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400682}
683
684# stop_neutron() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100685function stop_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400686 if is_service_enabled q-dhcp; then
687 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
688 [ ! -z "$pid" ] && sudo kill -9 $pid
689 fi
690 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100691 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400692 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900693
694 if is_service_enabled q-lbaas; then
695 neutron_lbaas_stop
696 fi
697 if is_service_enabled q-fwaas; then
698 neutron_fwaas_stop
699 fi
700 if is_service_enabled q-vpn; then
701 neutron_vpn_stop
702 fi
703 if is_service_enabled q-metering; then
704 neutron_metering_stop
705 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400706}
707
708# cleanup_neutron() - Remove residual data files, anything left over from previous
709# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100710function cleanup_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400711 if is_neutron_ovs_base_plugin; then
712 neutron_ovs_base_cleanup
713 fi
714
715 # delete all namespaces created by neutron
Brian Haleyeea76212014-06-27 11:45:50 -0400716 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 -0400717 sudo ip netns delete ${ns}
718 done
719}
720
721# _configure_neutron_common()
722# Set common config for all neutron server and agents.
723# This MUST be called before other ``_configure_neutron_*`` functions.
Ian Wienandaee18c72014-02-21 15:35:08 +1100724function _configure_neutron_common {
Mark McClainb05c8762013-07-06 23:29:39 -0400725 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
726 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
727 sudo mkdir -p $NEUTRON_CONF_DIR
728 fi
729 sudo chown $STACK_USER $NEUTRON_CONF_DIR
730
731 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
732
733 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
734 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
735 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
736 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100737 #
Mark McClainb05c8762013-07-06 23:29:39 -0400738 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
739 neutron_plugin_configure_common
740
sbauzae2c4ee22013-08-29 17:29:46 +0200741 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400742 die $LINENO "Neutron plugin not set.. exiting"
743 fi
744
745 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
746 mkdir -p /$Q_PLUGIN_CONF_PATH
747 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
748 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
749
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200750 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400751 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
752
753 # If addition config files are set, make sure their path name is set as well
754 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
755 die $LINENO "Neutron additional plugin config not set.. exiting"
756 fi
757
758 # If additional config files exist, copy them over to neutron configuration
759 # directory
760 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400761 local f
762 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
763 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400764 done
765 fi
766
Joe Gordonbee5c502013-08-30 13:48:08 -0400767 if [ "$VIRT_DRIVER" = 'fake' ]; then
768 # Disable arbitrary limits
769 iniset $NEUTRON_CONF quotas quota_network -1
770 iniset $NEUTRON_CONF quotas quota_subnet -1
771 iniset $NEUTRON_CONF quotas quota_port -1
772 iniset $NEUTRON_CONF quotas quota_security_group -1
773 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
774 fi
775
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700776 # Format logging
777 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800778 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700779 fi
780
Rob Crittenden18d47782014-03-19 17:47:42 -0400781 if is_service_enabled tls-proxy; then
782 # Set the service port for a proxy to take the original
783 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
784 fi
785
786 if is_ssl_enabled_service "nova"; then
787 iniset $NEUTRON_CONF DEFAULT nova_ca_certificates_file "$SSL_BUNDLE_FILE"
788 fi
789
790 if is_ssl_enabled_service "neutron"; then
791 ensure_certificates NEUTRON
792
793 iniset $NEUTRON_CONF DEFAULT use_ssl True
794 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
795 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
796 fi
797
Mark McClainb05c8762013-07-06 23:29:39 -0400798 _neutron_setup_rootwrap
799}
800
Ian Wienandaee18c72014-02-21 15:35:08 +1100801function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400802 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
803 return
804 fi
805
806 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
807
808 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
809 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
810 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400811 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
812
Mark McClainb05c8762013-07-06 23:29:39 -0400813 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
814
815 neutron_plugin_configure_debug_command
816}
817
Ian Wienandaee18c72014-02-21 15:35:08 +1100818function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400819
820 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
821
822 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500823 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400824 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
825 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
826
Mark McClainb05c8762013-07-06 23:29:39 -0400827 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
828
829 neutron_plugin_configure_dhcp_agent
830}
831
Ian Wienandaee18c72014-02-21 15:35:08 +1100832function _configure_neutron_l3_agent {
Paul Michali746dcee2014-04-02 19:12:22 +0000833 local cfg_file
Mark McClainb05c8762013-07-06 23:29:39 -0400834 Q_L3_ENABLED=True
835 # for l3-agent, only use per tenant router if we have namespaces
836 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700837
Paul Michali746dcee2014-04-02 19:12:22 +0000838 if is_service_enabled q-vpn; then
Paul Michali746dcee2014-04-02 19:12:22 +0000839 cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
Paul Michali746dcee2014-04-02 19:12:22 +0000840 fi
841
Mark McClainb05c8762013-07-06 23:29:39 -0400842 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
843
844 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500845 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400846 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
847 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
848
Mark McClainb05c8762013-07-06 23:29:39 -0400849 _neutron_setup_interface_driver $Q_L3_CONF_FILE
850
851 neutron_plugin_configure_l3_agent
852}
853
Ian Wienandaee18c72014-02-21 15:35:08 +1100854function _configure_neutron_metadata_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400855 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
856
857 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500858 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400859 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
860 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
861
Brant Knudson05952372014-09-19 17:22:22 -0500862 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT
Maru Newbybf10ac52013-08-10 21:27:54 +0000863
Mark McClainb05c8762013-07-06 23:29:39 -0400864}
865
Dina Belova58adaa62014-07-11 18:18:12 +0400866function _configure_neutron_ceilometer_notifications {
JordanPd4d4a342014-09-15 09:26:53 +0000867 iniset $NEUTRON_CONF DEFAULT notification_driver messaging
Dina Belova58adaa62014-07-11 18:18:12 +0400868}
869
Ian Wienandaee18c72014-02-21 15:35:08 +1100870function _configure_neutron_lbaas {
Mark McClainb05c8762013-07-06 23:29:39 -0400871 neutron_agent_lbaas_configure_common
872 neutron_agent_lbaas_configure_agent
873}
874
Ian Wienandaee18c72014-02-21 15:35:08 +1100875function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200876 neutron_agent_metering_configure_common
877 neutron_agent_metering_configure_agent
878}
879
Ian Wienandaee18c72014-02-21 15:35:08 +1100880function _configure_neutron_fwaas {
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700881 neutron_fwaas_configure_common
882 neutron_fwaas_configure_driver
883}
884
Ian Wienandaee18c72014-02-21 15:35:08 +1100885function _configure_neutron_vpn {
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700886 neutron_vpn_install_agent_packages
887 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700888}
889
Brian Haleyeea76212014-06-27 11:45:50 -0400890function _configure_dvr {
891 iniset $NEUTRON_CONF DEFAULT router_distributed True
892 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
893}
894
895
Mark McClainb05c8762013-07-06 23:29:39 -0400896# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
897# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100898function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400899 # Specify the default root helper prior to agent configuration to
900 # ensure that an agent's configuration can override the default
901 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
902 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500903 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400904
905 # Configure agent for plugin
906 neutron_plugin_configure_plugin_agent
907}
908
909# _configure_neutron_service() - Set config files for neutron service
910# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100911function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400912 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
913 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
914
915 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
916 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
917
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700918 # allow neutron user to administer neutron to match neutron account
919 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
920
Mark McClainb05c8762013-07-06 23:29:39 -0400921 # Update either configuration file with plugin
922 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
923
924 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
925 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
926 fi
927
928 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500929 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400930 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
931 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
932
933 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
934 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
935
Aaron Rosencea32b12014-03-04 16:20:14 -0800936 # Configuration for neutron notifations to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500937 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
938 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Aaron Rosencea32b12014-03-04 16:20:14 -0800939 iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
Dirk Mueller5ca261a2014-04-04 22:48:02 +0200940 iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800941 iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
942 ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
943 iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
944 iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
945
Mark McClainb05c8762013-07-06 23:29:39 -0400946 # Configure plugin
947 neutron_plugin_configure_service
948}
949
950# Utility Functions
951#------------------
952
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900953# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100954function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900955 local service_plugin_class=$1
956 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
957 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
958 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
959 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
960 fi
961}
962
Mark McClainb05c8762013-07-06 23:29:39 -0400963# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100964function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400965 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
966 return
967 fi
968 # Deploy new rootwrap filters files (owned by root).
969 # Wipe any existing ``rootwrap.d`` files first
970 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
971 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
972 sudo rm -rf $Q_CONF_ROOTWRAP_D
973 fi
974 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
975 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
976 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
977 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
978 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
979 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
980 # location moved in newer versions, prefer new location
981 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400982 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400983 else
Sean Dague3bdb9222013-10-22 08:36:16 -0400984 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400985 fi
986 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
987 sudo chown root:root $Q_RR_CONF_FILE
988 sudo chmod 0644 $Q_RR_CONF_FILE
989 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
990 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
991
992 # Set up the rootwrap sudoers for neutron
993 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100994 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400995 chmod 0440 $TEMPFILE
996 sudo chown root:root $TEMPFILE
997 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
998
999 # Update the root_helper
1000 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
1001}
1002
1003# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +11001004function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -04001005 local conf_file=$1
1006 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +10001007
Brant Knudson05952372014-09-19 17:22:22 -05001008 create_neutron_cache_dir
1009 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -04001010}
1011
Ian Wienandaee18c72014-02-21 15:35:08 +11001012function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -04001013
1014 # ovs_use_veth needs to be set before the plugin configuration
1015 # occurs to allow plugins to override the setting.
1016 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1017
1018 neutron_plugin_setup_interface_driver $1
1019}
1020
1021# Functions for Neutron Exercises
1022#--------------------------------
1023
Ian Wienandaee18c72014-02-21 15:35:08 +11001024function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001025 local from_net="$1"
1026 net_id=`_get_net_id $from_net`
1027 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}'`
1028 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1029}
1030
Ian Wienandaee18c72014-02-21 15:35:08 +11001031function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001032 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
1033 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
1034 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
1035 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
1036 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
1037 fi
1038}
1039
Ian Wienandaee18c72014-02-21 15:35:08 +11001040function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001041 delete_probe $PUBLIC_NETWORK_NAME
1042 delete_probe $PRIVATE_NETWORK_NAME
1043}
1044
Ian Wienandaee18c72014-02-21 15:35:08 +11001045function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -04001046 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
1047}
1048
Ian Wienandaee18c72014-02-21 15:35:08 +11001049function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001050 local from_net="$1"
1051 net_id=`_get_net_id $from_net`
1052 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`
1053 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1054}
1055
Ian Wienandaee18c72014-02-21 15:35:08 +11001056function _ping_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001057 local from_net=$1
1058 local ip=$2
1059 local timeout_sec=$3
1060 local expected=${4:-"True"}
1061 local check_command=""
1062 probe_cmd=`_get_probe_cmd_prefix $from_net`
1063 if [[ "$expected" = "True" ]]; then
1064 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1065 else
1066 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1067 fi
1068 if ! timeout $timeout_sec sh -c "$check_command"; then
1069 if [[ "$expected" = "True" ]]; then
1070 die $LINENO "[Fail] Couldn't ping server"
1071 else
1072 die $LINENO "[Fail] Could ping server"
1073 fi
1074 fi
1075}
1076
1077# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001078function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001079 local from_net=$1
1080 local key_file=$2
1081 local ip=$3
1082 local user=$4
1083 local timeout_sec=$5
1084 local probe_cmd = ""
1085 probe_cmd=`_get_probe_cmd_prefix $from_net`
1086 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
1087 die $LINENO "server didn't become ssh-able!"
1088 fi
1089}
1090
1091# Neutron 3rd party programs
1092#---------------------------
1093
1094# please refer to ``lib/neutron_thirdparty/README.md`` for details
1095NEUTRON_THIRD_PARTIES=""
1096for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001097 third_party=$(basename $f)
1098 if is_service_enabled $third_party; then
1099 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1100 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1101 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001102done
1103
Ian Wienandaee18c72014-02-21 15:35:08 +11001104function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001105 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1106 ${1}_${third_party}
1107 done
1108}
1109
1110# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001111function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001112 _neutron_third_party_do configure
1113}
1114
1115# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001116function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001117 _neutron_third_party_do init
1118}
1119
1120# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001121function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001122 _neutron_third_party_do install
1123}
1124
1125# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001126function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001127 _neutron_third_party_do start
1128}
1129
1130# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001131function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001132 _neutron_third_party_do stop
1133}
1134
armando-migliaccioef1e0802014-01-02 16:33:53 -08001135# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001136function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001137 _neutron_third_party_do check
1138}
1139
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001140function is_provider_network {
1141 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1142 return 0
1143 fi
1144 return 1
1145}
1146
Mark McClainb05c8762013-07-06 23:29:39 -04001147
1148# Restore xtrace
1149$XTRACE
1150
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001151# Tell emacs to use shell-script-mode
1152## Local variables:
1153## mode: shell-script
1154## End: