blob: 4db6efdb9830b32b1bbbd2b37376f1defa02f789 [file] [log] [blame]
Mark McClainb05c8762013-07-06 23:29:39 -04001# lib/neutron
Joe Gordon23946052014-01-15 21:42:32 +00002# functions - functions specific to neutron
Mark McClainb05c8762013-07-06 23:29:39 -04003
4# Dependencies:
5# ``functions`` file
6# ``DEST`` must be defined
Stephan Renatuse578eff2013-11-19 13:31:04 +01007# ``STACK_USER`` must be defined
Mark McClainb05c8762013-07-06 23:29:39 -04008
9# ``stack.sh`` calls the entry points in this order:
10#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010011# - install_neutron
12# - install_neutronclient
13# - install_neutron_agent_packages
14# - install_neutron_third_party
15# - configure_neutron
16# - init_neutron
17# - configure_neutron_third_party
18# - init_neutron_third_party
19# - start_neutron_third_party
Emilien Macchia677b7f2013-11-25 23:40:20 +010020# - create_neutron_cache_dir
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010021# - create_nova_conf_neutron
22# - start_neutron_service_and_check
yunhong jiang0d6e9922014-10-10 06:12:47 -070023# - start_neutron_agents
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010024# - create_neutron_initial_network
25# - setup_neutron_debug
Mark McClainb05c8762013-07-06 23:29:39 -040026#
27# ``unstack.sh`` calls the entry points in this order:
28#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010029# - stop_neutron
yunhong jiang0d6e9922014-10-10 06:12:47 -070030# - stop_neutron_third_party
31# - cleanup_neutron
Mark McClainb05c8762013-07-06 23:29:39 -040032
33# Functions in lib/neutron are classified into the following categories:
34#
35# - entry points (called from stack.sh or unstack.sh)
36# - internal functions
37# - neutron exercises
38# - 3rd party programs
39
40
41# Neutron Networking
42# ------------------
43
44# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
45# to run Neutron on this host, make sure that q-svc is also in
46# ``ENABLED_SERVICES``.
47#
Mark McClainb05c8762013-07-06 23:29:39 -040048# See "Neutron Network Configuration" below for additional variables
49# that must be set in localrc for connectivity across hosts with
50# Neutron.
51#
52# With Neutron networking the NETWORK_MANAGER variable is ignored.
Mark McClainb05c8762013-07-06 23:29:39 -040053
Mark McClainb05c8762013-07-06 23:29:39 -040054
55# Neutron Network Configuration
56# -----------------------------
57
58# Gateway and subnet defaults, in case they are not customized in localrc
59NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
Salvatore Orlando90234ac2013-11-25 05:44:10 -080060PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
Mark McClainb05c8762013-07-06 23:29:39 -040061PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
62PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
63
Rob Crittenden18d47782014-03-19 17:47:42 -040064if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then
65 Q_PROTOCOL="https"
66fi
67
68
Mark McClainb05c8762013-07-06 23:29:39 -040069# Set up default directories
70NEUTRON_DIR=$DEST/neutron
71NEUTRONCLIENT_DIR=$DEST/python-neutronclient
72NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
73
74# Support entry points installation of console scripts
75if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
76 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040077else
78 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040079fi
80
81NEUTRON_CONF_DIR=/etc/neutron
82NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
83export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
84
Adam Gandelman7614d212014-08-11 14:27:50 -070085# Agent binaries. Note, binary paths for other agents are set in per-service
86# scripts in lib/neutron_plugins/services/
87AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
88AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
89AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
90
91# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
92# loaded from per-plugin scripts in lib/neutron_plugins/
93Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
94Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
95Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
96Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
97Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
98
Henry Gessau0fc1cc22014-07-06 22:54:34 -040099# Default name for Neutron database
100Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400101# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000102Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400103# Default Neutron Port
104Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400105# Default Neutron Internal Port when using TLS proxy
106Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400107# Default Neutron Host
108Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400109# Default protocol
110Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Mark McClainb05c8762013-07-06 23:29:39 -0400111# Default admin username
112Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
113# Default auth strategy
114Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
115# Use namespace or not
116Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
117# RHEL's support for namespaces requires using veths with ovs
118Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
119Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
120# Meta data IP
121Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
122# Allow Overlapping IP among subnets
123Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
124# Use neutron-debug command
125Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
126# The name of the default q-l3 router
127Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Aaron Rosen4540d002013-10-24 13:59:33 -0700128# nova vif driver that all plugins should use
129NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500130Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
131Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800132VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
133VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700134
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400135## Provider Network Information
136PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
137
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900138# Use flat providernet for public network
139#
140# If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network
141# for external interface of neutron l3-agent. In that case,
142# PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900143# used for the network. In case of ofagent, you should add the
144# corresponding entry to your OFAGENT_PHYSICAL_INTERFACE_MAPPINGS.
145# For openvswitch agent, you should add the corresponding entry to
146# your OVS_BRIDGE_MAPPINGS.
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900147#
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900148# eg. (ofagent)
149# Q_USE_PROVIDERNET_FOR_PUBLIC=True
150# Q_USE_PUBLIC_VETH=True
151# PUBLIC_PHYSICAL_NETWORK=public
152# OFAGENT_PHYSICAL_INTERFACE_MAPPINGS=public:veth-pub-int
153#
154# eg. (openvswitch agent)
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900155# Q_USE_PROVIDERNET_FOR_PUBLIC=True
156# PUBLIC_PHYSICAL_NETWORK=public
157# OVS_BRIDGE_MAPPINGS=public:br-ex
158Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-False}
159PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public}
160
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900161# If Q_USE_PUBLIC_VETH=True, create and use a veth pair instead of
162# PUBLIC_BRIDGE. This is intended to be used with
163# Q_USE_PROVIDERNET_FOR_PUBLIC=True.
164Q_USE_PUBLIC_VETH=${Q_USE_PUBLIC_VETH:-False}
165Q_PUBLIC_VETH_EX=${Q_PUBLIC_VETH_EX:-veth-pub-ex}
166Q_PUBLIC_VETH_INT=${Q_PUBLIC_VETH_INT:-veth-pub-int}
167
Tomoe Sugiharaafbc6312013-11-14 20:02:47 +0000168# The next two variables are configured by plugin
169# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
170#
171# The plugin supports L3.
172Q_L3_ENABLED=${Q_L3_ENABLED:-False}
173# L3 routers exist per tenant
174Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False}
Aaron Rosen4540d002013-10-24 13:59:33 -0700175
Mark McClainb05c8762013-07-06 23:29:39 -0400176# List of config file names in addition to the main plugin config file
177# See _configure_neutron_common() for details about setting it up
178declare -a Q_PLUGIN_EXTRA_CONF_FILES
179
Paul Michali746dcee2014-04-02 19:12:22 +0000180# List of (optional) config files for VPN device drivers to use with
181# the neutron-q-vpn agent
182declare -a Q_VPN_EXTRA_CONF_FILES
183
Mark McClainb05c8762013-07-06 23:29:39 -0400184
Dean Troyere2907b42014-02-26 17:35:37 -0600185Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
186if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
187 Q_RR_COMMAND="sudo"
188else
189 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
190 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400191fi
192
Brian Haleyeea76212014-06-27 11:45:50 -0400193
194# Distributed Virtual Router (DVR) configuration
195# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500196# - ``legacy`` - No DVR functionality
197# - ``dvr_snat`` - Controller or single node DVR
198# - ``dvr`` - Compute node in multi-node DVR
199#
Brian Haleyeea76212014-06-27 11:45:50 -0400200Q_DVR_MODE=${Q_DVR_MODE:-legacy}
201if [[ "$Q_DVR_MODE" != "legacy" ]]; then
202 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
203fi
204
Dean Troyere2907b42014-02-26 17:35:37 -0600205# Provider Network Configurations
206# --------------------------------
207
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900208# The following variables control the Neutron ML2 plugins' allocation
209# of tenant networks and availability of provider networks. If these
210# are not configured in ``localrc``, tenant networks will be local to
211# the host (with no remote connectivity), and no physical resources
212# will be available for the allocation of provider networks.
Dean Troyere2907b42014-02-26 17:35:37 -0600213
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200214# To disable tunnels (GRE or VXLAN) for tenant networks,
215# set to False in ``local.conf``.
216# GRE tunnels are only supported by the openvswitch.
217ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600218
219# If using GRE tunnels for tenant networks, specify the range of
220# tunnel IDs from which tenant networks are allocated. Can be
221# overriden in ``localrc`` in necesssary.
Anant Patil3827dc02014-07-03 21:38:16 +0530222TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600223
224# To use VLANs for tenant networks, set to True in localrc. VLANs
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900225# are supported by the ML2 plugins, requiring additional configuration
226# described below.
Dean Troyere2907b42014-02-26 17:35:37 -0600227ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
228
229# If using VLANs for tenant networks, set in ``localrc`` to specify
230# the range of VLAN VIDs from which tenant networks are
231# allocated. An external network switch must be configured to
232# trunk these VLANs between hosts for multi-host connectivity.
233#
234# Example: ``TENANT_VLAN_RANGE=1000:1999``
235TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
236
237# If using VLANs for tenant networks, or if using flat or VLAN
238# provider networks, set in ``localrc`` to the name of the physical
239# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
240# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
241# agent, as described below.
242#
243# Example: ``PHYSICAL_NETWORK=default``
244PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
245
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900246# With the openvswitch agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600247# or if using flat or VLAN provider networks, set in ``localrc`` to
248# the name of the OVS bridge to use for the physical network. The
249# bridge will be created if it does not already exist, but a
250# physical interface must be manually added to the bridge as a
251# port for external connectivity.
252#
253# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
254OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
255
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900256# With the linuxbridge agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600257# or if using flat or VLAN provider networks, set in ``localrc`` to
258# the name of the network interface to use for the physical
259# network.
260#
261# Example: ``LB_PHYSICAL_INTERFACE=eth1``
262LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
263
Edgar Magana6f335b92014-07-10 15:42:44 -0700264# When Neutron tunnels are enabled it is needed to specify the
265# IP address of the end point in the local server. This IP is set
266# by default to the same IP address that the HOST IP.
267# This variable can be used to specify a different end point IP address
268# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
269TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
270
Dean Troyere2907b42014-02-26 17:35:37 -0600271# With the openvswitch plugin, set to True in ``localrc`` to enable
272# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
273#
274# Example: ``OVS_ENABLE_TUNNELING=True``
275OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
276
Mark McClainb05c8762013-07-06 23:29:39 -0400277# Neutron plugin specific functions
278# ---------------------------------
279
280# Please refer to ``lib/neutron_plugins/README.md`` for details.
281source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
282
283# Agent loadbalancer service plugin functions
284# -------------------------------------------
285
286# Hardcoding for 1 service plugin for now
287source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
288
Emilien Macchi40546f72013-09-24 15:10:25 +0200289# Agent metering service plugin functions
290# -------------------------------------------
291
292# Hardcoding for 1 service plugin for now
293source $TOP_DIR/lib/neutron_plugins/services/metering
294
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700295# VPN service plugin functions
296# -------------------------------------------
297# Hardcoding for 1 service plugin for now
298source $TOP_DIR/lib/neutron_plugins/services/vpn
299
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700300# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100301# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700302source $TOP_DIR/lib/neutron_plugins/services/firewall
303
Mark McClainb05c8762013-07-06 23:29:39 -0400304# Use security group or not
305if has_neutron_plugin_security_group; then
306 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
307else
308 Q_USE_SECGROUP=False
309fi
310
Dean Troyer4237f592014-01-29 16:22:11 -0600311# Tell Tempest this project is present
312TEMPEST_SERVICES+=,neutron
313
314
Dean Troyere2907b42014-02-26 17:35:37 -0600315# Save trace setting
316XTRACE=$(set +o | grep xtrace)
317set +o xtrace
318
319
Mark McClainb05c8762013-07-06 23:29:39 -0400320# Functions
321# ---------
322
Adam Gandelman7614d212014-08-11 14:27:50 -0700323function _determine_config_server {
324 local cfg_file
325 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
326 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
327 opts+=" --config-file /$cfg_file"
328 done
329 echo "$opts"
330}
331
332function _determine_config_vpn {
333 local cfg_file
334 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
335 if is_service_enabled q-fwaas; then
336 opts+=" --config-file $Q_FWAAS_CONF_FILE"
337 fi
338 for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
339 opts+=" --config-file $cfg_file"
340 done
341 echo "$opts"
342
343}
344
345function _determine_config_l3 {
346 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
347 if is_service_enabled q-fwaas; then
348 opts+=" --config-file $Q_FWAAS_CONF_FILE"
349 fi
350 echo "$opts"
351}
352
353# For services and agents that require it, dynamically construct a list of
354# --config-file arguments that are passed to the binary.
355function determine_config_files {
356 local opts=""
357 case "$1" in
358 "neutron-server") opts="$(_determine_config_server)" ;;
359 "neutron-vpn-agent") opts="$(_determine_config_vpn)" ;;
360 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
361 esac
362 if [ -z "$opts" ] ; then
363 die $LINENO "Could not determine config files for $1."
364 fi
365 echo "$opts"
366}
367
Dean Troyere4fa7212014-01-15 15:04:49 -0600368# Test if any Neutron services are enabled
369# is_neutron_enabled
370function is_neutron_enabled {
371 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
372 return 1
373}
374
Mark McClainb05c8762013-07-06 23:29:39 -0400375# configure_neutron()
376# Set common config for all neutron server and agents.
Ian Wienandaee18c72014-02-21 15:35:08 +1100377function configure_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400378 _configure_neutron_common
379 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
380
381 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
382 if is_service_enabled q-lbaas; then
383 _configure_neutron_lbaas
384 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200385 if is_service_enabled q-metering; then
386 _configure_neutron_metering
387 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700388 if is_service_enabled q-vpn; then
389 _configure_neutron_vpn
390 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700391 if is_service_enabled q-fwaas; then
392 _configure_neutron_fwaas
393 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000394 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400395 _configure_neutron_service
396 fi
397 if is_service_enabled q-agt; then
398 _configure_neutron_plugin_agent
399 fi
400 if is_service_enabled q-dhcp; then
401 _configure_neutron_dhcp_agent
402 fi
403 if is_service_enabled q-l3; then
404 _configure_neutron_l3_agent
405 fi
406 if is_service_enabled q-meta; then
407 _configure_neutron_metadata_agent
408 fi
409
Brian Haleyeea76212014-06-27 11:45:50 -0400410 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
411 _configure_dvr
412 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400413 if is_service_enabled ceilometer; then
414 _configure_neutron_ceilometer_notifications
415 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400416
417 _configure_neutron_debug_command
418}
419
Ian Wienandaee18c72014-02-21 15:35:08 +1100420function create_nova_conf_neutron {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800421 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
Gary Kotton13d385e2014-06-17 23:24:53 -0700422 iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME"
423 iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD"
424 iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
425 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
426 iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME"
Bartosz Górski0abde392014-02-28 14:15:19 +0100427 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Rob Crittenden18d47782014-03-19 17:47:42 -0400428 iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400429
430 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
431 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400432 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800433 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400434 fi
435
436 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
437 neutron_plugin_create_nova_conf
438
Gary Kotton51c681d2014-04-22 01:40:56 -0700439 iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER"
Mark McClainb05c8762013-07-06 23:29:39 -0400440 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
441 if is_service_enabled q-meta; then
Gary Kottondd745502014-08-11 23:38:47 -0700442 iniset $NOVA_CONF neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400443 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800444
445 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
446 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400447}
448
Emilien Macchia677b7f2013-11-25 23:40:20 +0100449# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100450function create_neutron_cache_dir {
Emilien Macchia677b7f2013-11-25 23:40:20 +0100451 # Create cache dir
452 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
453 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
454 rm -f $NEUTRON_AUTH_CACHE_DIR/*
455}
456
Mark McClainb05c8762013-07-06 23:29:39 -0400457# create_neutron_accounts() - Set up common required neutron accounts
458
459# Tenant User Roles
460# ------------------------------------------------------------------
461# service neutron admin # if enabled
462
463# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100464function create_neutron_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400465
Dean Troyer188493d2014-07-25 15:54:11 -0500466 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700467 local service_role=$(openstack role list | awk "/ service / { print \$2 }")
Mark McClainb05c8762013-07-06 23:29:39 -0400468
469 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100470
Dean Troyer188493d2014-07-25 15:54:11 -0500471 local neutron_user=$(get_or_create_user "neutron" \
472 "$SERVICE_PASSWORD" $service_tenant)
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700473 get_or_add_user_role $service_role $neutron_user $service_tenant
Bartosz Górski0abde392014-02-28 14:15:19 +0100474
Mark McClainb05c8762013-07-06 23:29:39 -0400475 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100476
Dean Troyer188493d2014-07-25 15:54:11 -0500477 local neutron_service=$(get_or_create_service "neutron" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100478 "network" "Neutron Service")
Dean Troyer188493d2014-07-25 15:54:11 -0500479 get_or_create_endpoint $neutron_service \
Bartosz Górski0abde392014-02-28 14:15:19 +0100480 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400481 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
482 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
483 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400484 fi
485 fi
486}
487
Ian Wienandaee18c72014-02-21 15:35:08 +1100488function create_neutron_initial_network {
Steve Martinelli19685422014-01-24 13:02:26 -0600489 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500490 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400491
492 # Create a small network
493 # Since neutron command is executed in admin context at this point,
Dirk Mueller25049cd2014-01-09 13:53:52 +0100494 # ``--tenant-id`` needs to be specified.
Mark McClainb05c8762013-07-06 23:29:39 -0400495 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200496 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
497 die $LINENO "Neutron settings for baremetal not set.. exiting"
498 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400499 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
500 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
501 sudo ip addr del $IP dev $PUBLIC_INTERFACE
502 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
503 done
Dirk Mueller25049cd2014-01-09 13:53:52 +0100504 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 -0500505 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100506 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 -0500507 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400508 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200509 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400510 elif is_provider_network; then
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900511 die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400512 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900513 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 -0400514 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 -0400515 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 -0400516 sudo ip link set $OVS_PHYSICAL_BRIDGE up
517 sudo ip link set br-int up
518 sudo ip link set $PUBLIC_INTERFACE up
Mark McClainb05c8762013-07-06 23:29:39 -0400519 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100520 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500521 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100522 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 -0500523 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400524 fi
525
526 if [[ "$Q_L3_ENABLED" == "True" ]]; then
527 # Create a router, and add the private subnet as one of its interfaces
528 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
529 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100530 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500531 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400532 else
533 # Plugin only supports creating a single router, which should be admin owned.
534 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500535 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400536 fi
537 neutron router-interface-add $ROUTER_ID $SUBNET_ID
538 # Create an external network, and a subnet. Configure the external network as router gw
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900539 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
540 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)
541 else
542 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
543 fi
DennyZhang23178a92013-10-22 17:07:32 -0500544 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400545 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 -0500546 die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400547 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
548
549 if is_service_enabled q-l3; then
550 # logic is specific to using the l3-agent for l3
551 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900552 local ext_gw_interface
553
554 if [[ "$Q_USE_PUBLIC_VETH" = "True" ]]; then
555 ext_gw_interface=$Q_PUBLIC_VETH_EX
556 else
557 # Disable in-band as we are going to use local port
558 # to communicate with VMs
559 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
560 other_config:disable-in-band=true
561 ext_gw_interface=$PUBLIC_BRIDGE
562 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400563 CIDR_LEN=${FLOATING_RANGE#*/}
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900564 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $ext_gw_interface
565 sudo ip link set $ext_gw_interface up
Mark McClainb05c8762013-07-06 23:29:39 -0400566 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 -0500567 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400568 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
569 fi
570 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
571 # Explicitly set router id in l3 agent configuration
572 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
573 fi
574 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400575 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400576}
577
578# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100579function init_neutron {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700580 recreate_database $Q_DB_NAME utf8
581 # Run Neutron db migrations
582 $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 -0400583}
584
585# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100586function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400587 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
588 setup_develop $NEUTRON_DIR
Mate Lakat6df64892014-10-17 13:09:49 +0200589
590 if [ "$VIRT_DRIVER" == 'xenserver' ]; then
591 local dom0_ip
592 dom0_ip=$(echo "$XENAPI_CONNECTION_URL" | cut -d "/" -f 3-)
593
594 local ssh_dom0
595 ssh_dom0="sudo -u $DOMZERO_USER ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$dom0_ip"
596
597 # Find where the plugins should go in dom0
598 local xen_functions
599 xen_functions=$(cat $TOP_DIR/tools/xen/functions)
600 local plugin_dir
601 plugin_dir=$($ssh_dom0 "$xen_functions; set -eux; xapi_plugin_location")
602
603 # install neutron plugins to dom0
604 tar -czf - -C $NEUTRON_DIR/neutron/plugins/openvswitch/agent/xenapi/etc/xapi.d/plugins/ ./ |
605 $ssh_dom0 "tar -xzf - -C $plugin_dir && chmod a+x $plugin_dir/*"
606 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400607}
608
609# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100610function install_neutronclient {
Mark McClainb05c8762013-07-06 23:29:39 -0400611 git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH
612 setup_develop $NEUTRONCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200613 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 -0400614}
615
616# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100617function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400618 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
619 if is_service_enabled q-l3; then
620 install_package radvd
621 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400622 # install packages that are specific to plugin agent(s)
623 if is_service_enabled q-agt q-dhcp q-l3; then
624 neutron_plugin_install_agent_packages
625 fi
626
627 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400628 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400629 fi
630}
631
632# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100633function start_neutron_service_and_check {
Adam Gandelman7614d212014-08-11 14:27:50 -0700634 local cfg_file_options="$(determine_config_files neutron-server)"
Rob Crittenden18d47782014-03-19 17:47:42 -0400635 local service_port=$Q_PORT
636 local service_protocol=$Q_PROTOCOL
637 if is_service_enabled tls-proxy; then
638 service_port=$Q_PORT_INT
639 service_protocol="http"
640 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400641 # Start the Neutron service
Chris Dent2f27a0e2014-09-09 13:46:02 +0100642 run_process q-svc "python $NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400643 echo "Waiting for Neutron to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400644 if is_ssl_enabled_service "neutron"; then
645 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
646 fi
647 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 -0400648 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400649 fi
Rob Crittenden18d47782014-03-19 17:47:42 -0400650 # Start proxy if enabled
651 if is_service_enabled tls-proxy; then
652 start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT &
653 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400654}
655
656# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100657function start_neutron_agents {
Mark McClainb05c8762013-07-06 23:29:39 -0400658 # Start up the neutron agents if enabled
Chris Dent2f27a0e2014-09-09 13:46:02 +0100659 run_process q-agt "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
660 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 -0700661
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400662 if is_provider_network; then
663 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
664 sudo ip link set $OVS_PHYSICAL_BRIDGE up
665 sudo ip link set br-int up
666 sudo ip link set $PUBLIC_INTERFACE up
667 fi
668
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700669 if is_service_enabled q-vpn; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100670 run_process q-vpn "$AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700671 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100672 run_process q-l3 "python $AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700673 fi
674
Chris Dent2f27a0e2014-09-09 13:46:02 +0100675 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 -0400676
677 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
678 # For XenServer, start an agent for the domU openvswitch
Chris Dent2f27a0e2014-09-09 13:46:02 +0100679 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 -0400680 fi
681
682 if is_service_enabled q-lbaas; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100683 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 -0400684 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200685
686 if is_service_enabled q-metering; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100687 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 +0200688 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400689}
690
691# stop_neutron() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100692function stop_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400693 if is_service_enabled q-dhcp; then
694 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
695 [ ! -z "$pid" ] && sudo kill -9 $pid
696 fi
697 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100698 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400699 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900700
701 if is_service_enabled q-lbaas; then
702 neutron_lbaas_stop
703 fi
704 if is_service_enabled q-fwaas; then
705 neutron_fwaas_stop
706 fi
707 if is_service_enabled q-vpn; then
708 neutron_vpn_stop
709 fi
710 if is_service_enabled q-metering; then
711 neutron_metering_stop
712 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400713}
714
715# cleanup_neutron() - Remove residual data files, anything left over from previous
716# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100717function cleanup_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400718 if is_neutron_ovs_base_plugin; then
719 neutron_ovs_base_cleanup
720 fi
721
722 # delete all namespaces created by neutron
Brian Haleyeea76212014-06-27 11:45:50 -0400723 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 -0400724 sudo ip netns delete ${ns}
725 done
726}
727
728# _configure_neutron_common()
729# Set common config for all neutron server and agents.
730# This MUST be called before other ``_configure_neutron_*`` functions.
Ian Wienandaee18c72014-02-21 15:35:08 +1100731function _configure_neutron_common {
Mark McClainb05c8762013-07-06 23:29:39 -0400732 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
733 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
734 sudo mkdir -p $NEUTRON_CONF_DIR
735 fi
736 sudo chown $STACK_USER $NEUTRON_CONF_DIR
737
738 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
739
740 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
741 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
742 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
743 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100744 #
Mark McClainb05c8762013-07-06 23:29:39 -0400745 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
746 neutron_plugin_configure_common
747
sbauzae2c4ee22013-08-29 17:29:46 +0200748 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400749 die $LINENO "Neutron plugin not set.. exiting"
750 fi
751
752 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
753 mkdir -p /$Q_PLUGIN_CONF_PATH
754 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
755 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
756
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200757 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400758 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
759
760 # If addition config files are set, make sure their path name is set as well
761 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
762 die $LINENO "Neutron additional plugin config not set.. exiting"
763 fi
764
765 # If additional config files exist, copy them over to neutron configuration
766 # directory
767 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400768 local f
769 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
770 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400771 done
772 fi
773
Joe Gordonbee5c502013-08-30 13:48:08 -0400774 if [ "$VIRT_DRIVER" = 'fake' ]; then
775 # Disable arbitrary limits
776 iniset $NEUTRON_CONF quotas quota_network -1
777 iniset $NEUTRON_CONF quotas quota_subnet -1
778 iniset $NEUTRON_CONF quotas quota_port -1
779 iniset $NEUTRON_CONF quotas quota_security_group -1
780 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
781 fi
782
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700783 # Format logging
784 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800785 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700786 fi
787
Rob Crittenden18d47782014-03-19 17:47:42 -0400788 if is_service_enabled tls-proxy; then
789 # Set the service port for a proxy to take the original
790 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
791 fi
792
793 if is_ssl_enabled_service "nova"; then
794 iniset $NEUTRON_CONF DEFAULT nova_ca_certificates_file "$SSL_BUNDLE_FILE"
795 fi
796
797 if is_ssl_enabled_service "neutron"; then
798 ensure_certificates NEUTRON
799
800 iniset $NEUTRON_CONF DEFAULT use_ssl True
801 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
802 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
803 fi
804
Mark McClainb05c8762013-07-06 23:29:39 -0400805 _neutron_setup_rootwrap
806}
807
Ian Wienandaee18c72014-02-21 15:35:08 +1100808function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400809 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
810 return
811 fi
812
813 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
814
815 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
816 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
817 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400818 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
819
Mark McClainb05c8762013-07-06 23:29:39 -0400820 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
821
822 neutron_plugin_configure_debug_command
823}
824
Ian Wienandaee18c72014-02-21 15:35:08 +1100825function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400826
827 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
828
829 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500830 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400831 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
832 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
833
Mark McClainb05c8762013-07-06 23:29:39 -0400834 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
835
836 neutron_plugin_configure_dhcp_agent
837}
838
Ian Wienandaee18c72014-02-21 15:35:08 +1100839function _configure_neutron_l3_agent {
Paul Michali746dcee2014-04-02 19:12:22 +0000840 local cfg_file
Mark McClainb05c8762013-07-06 23:29:39 -0400841 Q_L3_ENABLED=True
842 # for l3-agent, only use per tenant router if we have namespaces
843 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700844
Paul Michali746dcee2014-04-02 19:12:22 +0000845 if is_service_enabled q-vpn; then
Paul Michali746dcee2014-04-02 19:12:22 +0000846 cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
Paul Michali746dcee2014-04-02 19:12:22 +0000847 fi
848
Mark McClainb05c8762013-07-06 23:29:39 -0400849 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
850
851 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500852 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400853 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
854 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
855
Mark McClainb05c8762013-07-06 23:29:39 -0400856 _neutron_setup_interface_driver $Q_L3_CONF_FILE
857
858 neutron_plugin_configure_l3_agent
859}
860
Ian Wienandaee18c72014-02-21 15:35:08 +1100861function _configure_neutron_metadata_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400862 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
863
864 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500865 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400866 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
867 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
868
Brant Knudson05952372014-09-19 17:22:22 -0500869 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT
Maru Newbybf10ac52013-08-10 21:27:54 +0000870
Mark McClainb05c8762013-07-06 23:29:39 -0400871}
872
Dina Belova58adaa62014-07-11 18:18:12 +0400873function _configure_neutron_ceilometer_notifications {
JordanPd4d4a342014-09-15 09:26:53 +0000874 iniset $NEUTRON_CONF DEFAULT notification_driver messaging
Dina Belova58adaa62014-07-11 18:18:12 +0400875}
876
Ian Wienandaee18c72014-02-21 15:35:08 +1100877function _configure_neutron_lbaas {
Mark McClainb05c8762013-07-06 23:29:39 -0400878 neutron_agent_lbaas_configure_common
879 neutron_agent_lbaas_configure_agent
880}
881
Ian Wienandaee18c72014-02-21 15:35:08 +1100882function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200883 neutron_agent_metering_configure_common
884 neutron_agent_metering_configure_agent
885}
886
Ian Wienandaee18c72014-02-21 15:35:08 +1100887function _configure_neutron_fwaas {
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700888 neutron_fwaas_configure_common
889 neutron_fwaas_configure_driver
890}
891
Ian Wienandaee18c72014-02-21 15:35:08 +1100892function _configure_neutron_vpn {
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700893 neutron_vpn_install_agent_packages
894 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700895}
896
Brian Haleyeea76212014-06-27 11:45:50 -0400897function _configure_dvr {
898 iniset $NEUTRON_CONF DEFAULT router_distributed True
899 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
900}
901
902
Mark McClainb05c8762013-07-06 23:29:39 -0400903# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
904# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100905function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400906 # Specify the default root helper prior to agent configuration to
907 # ensure that an agent's configuration can override the default
908 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
909 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500910 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400911
912 # Configure agent for plugin
913 neutron_plugin_configure_plugin_agent
914}
915
916# _configure_neutron_service() - Set config files for neutron service
917# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100918function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400919 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
920 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
921
922 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
923 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
924
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700925 # allow neutron user to administer neutron to match neutron account
926 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
927
Mark McClainb05c8762013-07-06 23:29:39 -0400928 # Update either configuration file with plugin
929 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
930
931 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
932 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
933 fi
934
935 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500936 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400937 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
938 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
939
940 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
941 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
942
Aaron Rosencea32b12014-03-04 16:20:14 -0800943 # Configuration for neutron notifations to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500944 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
945 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Aaron Rosencea32b12014-03-04 16:20:14 -0800946 iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
Dirk Mueller5ca261a2014-04-04 22:48:02 +0200947 iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800948 iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
949 ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
950 iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
951 iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
952
Mark McClainb05c8762013-07-06 23:29:39 -0400953 # Configure plugin
954 neutron_plugin_configure_service
955}
956
957# Utility Functions
958#------------------
959
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900960# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100961function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900962 local service_plugin_class=$1
963 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
964 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
965 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
966 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
967 fi
968}
969
Mark McClainb05c8762013-07-06 23:29:39 -0400970# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100971function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400972 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
973 return
974 fi
975 # Deploy new rootwrap filters files (owned by root).
976 # Wipe any existing ``rootwrap.d`` files first
977 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
978 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
979 sudo rm -rf $Q_CONF_ROOTWRAP_D
980 fi
981 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
982 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
983 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
984 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
985 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
986 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
987 # location moved in newer versions, prefer new location
988 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400989 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400990 else
Sean Dague3bdb9222013-10-22 08:36:16 -0400991 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400992 fi
993 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
994 sudo chown root:root $Q_RR_CONF_FILE
995 sudo chmod 0644 $Q_RR_CONF_FILE
996 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
997 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
998
999 # Set up the rootwrap sudoers for neutron
1000 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +01001001 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -04001002 chmod 0440 $TEMPFILE
1003 sudo chown root:root $TEMPFILE
1004 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1005
1006 # Update the root_helper
1007 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
1008}
1009
1010# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +11001011function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -04001012 local conf_file=$1
1013 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +10001014
Brant Knudson05952372014-09-19 17:22:22 -05001015 create_neutron_cache_dir
1016 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -04001017}
1018
Ian Wienandaee18c72014-02-21 15:35:08 +11001019function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -04001020
1021 # ovs_use_veth needs to be set before the plugin configuration
1022 # occurs to allow plugins to override the setting.
1023 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1024
1025 neutron_plugin_setup_interface_driver $1
1026}
1027
1028# Functions for Neutron Exercises
1029#--------------------------------
1030
Ian Wienandaee18c72014-02-21 15:35:08 +11001031function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001032 local from_net="$1"
1033 net_id=`_get_net_id $from_net`
1034 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}'`
1035 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1036}
1037
Ian Wienandaee18c72014-02-21 15:35:08 +11001038function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001039 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
1040 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
1041 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
1042 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
1043 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
1044 fi
1045}
1046
Ian Wienandaee18c72014-02-21 15:35:08 +11001047function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001048 delete_probe $PUBLIC_NETWORK_NAME
1049 delete_probe $PRIVATE_NETWORK_NAME
1050}
1051
Ian Wienandaee18c72014-02-21 15:35:08 +11001052function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -04001053 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
1054}
1055
Ian Wienandaee18c72014-02-21 15:35:08 +11001056function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001057 local from_net="$1"
1058 net_id=`_get_net_id $from_net`
1059 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`
1060 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1061}
1062
Ian Wienandaee18c72014-02-21 15:35:08 +11001063function _ping_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001064 local from_net=$1
1065 local ip=$2
1066 local timeout_sec=$3
1067 local expected=${4:-"True"}
1068 local check_command=""
1069 probe_cmd=`_get_probe_cmd_prefix $from_net`
1070 if [[ "$expected" = "True" ]]; then
1071 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1072 else
1073 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1074 fi
1075 if ! timeout $timeout_sec sh -c "$check_command"; then
1076 if [[ "$expected" = "True" ]]; then
1077 die $LINENO "[Fail] Couldn't ping server"
1078 else
1079 die $LINENO "[Fail] Could ping server"
1080 fi
1081 fi
1082}
1083
1084# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001085function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001086 local from_net=$1
1087 local key_file=$2
1088 local ip=$3
1089 local user=$4
1090 local timeout_sec=$5
1091 local probe_cmd = ""
1092 probe_cmd=`_get_probe_cmd_prefix $from_net`
1093 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
1094 die $LINENO "server didn't become ssh-able!"
1095 fi
1096}
1097
1098# Neutron 3rd party programs
1099#---------------------------
1100
1101# please refer to ``lib/neutron_thirdparty/README.md`` for details
1102NEUTRON_THIRD_PARTIES=""
1103for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001104 third_party=$(basename $f)
1105 if is_service_enabled $third_party; then
1106 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1107 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1108 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001109done
1110
Ian Wienandaee18c72014-02-21 15:35:08 +11001111function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001112 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1113 ${1}_${third_party}
1114 done
1115}
1116
1117# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001118function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001119 _neutron_third_party_do configure
1120}
1121
1122# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001123function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001124 _neutron_third_party_do init
1125}
1126
1127# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001128function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001129 _neutron_third_party_do install
1130}
1131
1132# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001133function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001134 _neutron_third_party_do start
1135}
1136
1137# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001138function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001139 _neutron_third_party_do stop
1140}
1141
armando-migliaccioef1e0802014-01-02 16:33:53 -08001142# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001143function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001144 _neutron_third_party_do check
1145}
1146
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001147function is_provider_network {
1148 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1149 return 0
1150 fi
1151 return 1
1152}
1153
Mark McClainb05c8762013-07-06 23:29:39 -04001154
1155# Restore xtrace
1156$XTRACE
1157
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001158# Tell emacs to use shell-script-mode
1159## Local variables:
1160## mode: shell-script
1161## End: