blob: eb07f402d0700719ad6e837e958b708611c5c960 [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
Tan Lin27a196e2014-10-31 15:44:34 +0800277# Use DHCP agent for providing metadata service in the case of
278# without L3 agent (No Route Agent), set to True in localrc.
279ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
280
281# Add a static route as dhcp option, so the request to 169.254.169.254
282# will be able to reach through a route(DHCP agent)
283# This option require ENABLE_ISOLATED_METADATA = True
284ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
Mark McClainb05c8762013-07-06 23:29:39 -0400285# Neutron plugin specific functions
286# ---------------------------------
287
288# Please refer to ``lib/neutron_plugins/README.md`` for details.
289source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
290
291# Agent loadbalancer service plugin functions
292# -------------------------------------------
293
294# Hardcoding for 1 service plugin for now
295source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
296
Emilien Macchi40546f72013-09-24 15:10:25 +0200297# Agent metering service plugin functions
298# -------------------------------------------
299
300# Hardcoding for 1 service plugin for now
301source $TOP_DIR/lib/neutron_plugins/services/metering
302
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700303# VPN service plugin functions
304# -------------------------------------------
305# Hardcoding for 1 service plugin for now
306source $TOP_DIR/lib/neutron_plugins/services/vpn
307
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700308# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100309# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700310source $TOP_DIR/lib/neutron_plugins/services/firewall
311
Mark McClainb05c8762013-07-06 23:29:39 -0400312# Use security group or not
313if has_neutron_plugin_security_group; then
314 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
315else
316 Q_USE_SECGROUP=False
317fi
318
Dean Troyer4237f592014-01-29 16:22:11 -0600319# Tell Tempest this project is present
320TEMPEST_SERVICES+=,neutron
321
322
Dean Troyere2907b42014-02-26 17:35:37 -0600323# Save trace setting
324XTRACE=$(set +o | grep xtrace)
325set +o xtrace
326
327
Mark McClainb05c8762013-07-06 23:29:39 -0400328# Functions
329# ---------
330
Adam Gandelman7614d212014-08-11 14:27:50 -0700331function _determine_config_server {
332 local cfg_file
333 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
334 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
335 opts+=" --config-file /$cfg_file"
336 done
337 echo "$opts"
338}
339
340function _determine_config_vpn {
341 local cfg_file
342 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
343 if is_service_enabled q-fwaas; then
344 opts+=" --config-file $Q_FWAAS_CONF_FILE"
345 fi
346 for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
347 opts+=" --config-file $cfg_file"
348 done
349 echo "$opts"
350
351}
352
353function _determine_config_l3 {
354 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
355 if is_service_enabled q-fwaas; then
356 opts+=" --config-file $Q_FWAAS_CONF_FILE"
357 fi
358 echo "$opts"
359}
360
361# For services and agents that require it, dynamically construct a list of
362# --config-file arguments that are passed to the binary.
363function determine_config_files {
364 local opts=""
365 case "$1" in
366 "neutron-server") opts="$(_determine_config_server)" ;;
367 "neutron-vpn-agent") opts="$(_determine_config_vpn)" ;;
368 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
369 esac
370 if [ -z "$opts" ] ; then
371 die $LINENO "Could not determine config files for $1."
372 fi
373 echo "$opts"
374}
375
Dean Troyere4fa7212014-01-15 15:04:49 -0600376# Test if any Neutron services are enabled
377# is_neutron_enabled
378function is_neutron_enabled {
379 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
380 return 1
381}
382
Mark McClainb05c8762013-07-06 23:29:39 -0400383# configure_neutron()
384# Set common config for all neutron server and agents.
Ian Wienandaee18c72014-02-21 15:35:08 +1100385function configure_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400386 _configure_neutron_common
387 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
388
389 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
390 if is_service_enabled q-lbaas; then
391 _configure_neutron_lbaas
392 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200393 if is_service_enabled q-metering; then
394 _configure_neutron_metering
395 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700396 if is_service_enabled q-vpn; then
397 _configure_neutron_vpn
398 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700399 if is_service_enabled q-fwaas; then
400 _configure_neutron_fwaas
401 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000402 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400403 _configure_neutron_service
404 fi
405 if is_service_enabled q-agt; then
406 _configure_neutron_plugin_agent
407 fi
408 if is_service_enabled q-dhcp; then
409 _configure_neutron_dhcp_agent
410 fi
411 if is_service_enabled q-l3; then
412 _configure_neutron_l3_agent
413 fi
414 if is_service_enabled q-meta; then
415 _configure_neutron_metadata_agent
416 fi
417
Brian Haleyeea76212014-06-27 11:45:50 -0400418 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
419 _configure_dvr
420 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400421 if is_service_enabled ceilometer; then
422 _configure_neutron_ceilometer_notifications
423 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400424
425 _configure_neutron_debug_command
426}
427
Ian Wienandaee18c72014-02-21 15:35:08 +1100428function create_nova_conf_neutron {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800429 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
Gary Kotton13d385e2014-06-17 23:24:53 -0700430 iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME"
431 iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD"
432 iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
433 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
434 iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME"
Bartosz Górski0abde392014-02-28 14:15:19 +0100435 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Rob Crittenden18d47782014-03-19 17:47:42 -0400436 iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400437
438 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
439 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400440 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800441 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400442 fi
443
444 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
445 neutron_plugin_create_nova_conf
446
Gary Kotton51c681d2014-04-22 01:40:56 -0700447 iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER"
Mark McClainb05c8762013-07-06 23:29:39 -0400448 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
449 if is_service_enabled q-meta; then
Gary Kottondd745502014-08-11 23:38:47 -0700450 iniset $NOVA_CONF neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400451 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800452
453 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
454 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400455}
456
Emilien Macchia677b7f2013-11-25 23:40:20 +0100457# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100458function create_neutron_cache_dir {
Emilien Macchia677b7f2013-11-25 23:40:20 +0100459 # Create cache dir
460 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
461 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
462 rm -f $NEUTRON_AUTH_CACHE_DIR/*
463}
464
Mark McClainb05c8762013-07-06 23:29:39 -0400465# create_neutron_accounts() - Set up common required neutron accounts
466
467# Tenant User Roles
468# ------------------------------------------------------------------
469# service neutron admin # if enabled
470
471# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100472function create_neutron_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400473
Dean Troyer188493d2014-07-25 15:54:11 -0500474 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700475 local service_role=$(openstack role list | awk "/ service / { print \$2 }")
Mark McClainb05c8762013-07-06 23:29:39 -0400476
477 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100478
Dean Troyer188493d2014-07-25 15:54:11 -0500479 local neutron_user=$(get_or_create_user "neutron" \
480 "$SERVICE_PASSWORD" $service_tenant)
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700481 get_or_add_user_role $service_role $neutron_user $service_tenant
Bartosz Górski0abde392014-02-28 14:15:19 +0100482
Mark McClainb05c8762013-07-06 23:29:39 -0400483 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100484
Dean Troyer188493d2014-07-25 15:54:11 -0500485 local neutron_service=$(get_or_create_service "neutron" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100486 "network" "Neutron Service")
Dean Troyer188493d2014-07-25 15:54:11 -0500487 get_or_create_endpoint $neutron_service \
Bartosz Górski0abde392014-02-28 14:15:19 +0100488 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400489 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
490 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
491 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400492 fi
493 fi
494}
495
Ian Wienandaee18c72014-02-21 15:35:08 +1100496function create_neutron_initial_network {
Steve Martinelli19685422014-01-24 13:02:26 -0600497 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500498 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400499
500 # Create a small network
501 # Since neutron command is executed in admin context at this point,
Dirk Mueller25049cd2014-01-09 13:53:52 +0100502 # ``--tenant-id`` needs to be specified.
Mark McClainb05c8762013-07-06 23:29:39 -0400503 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200504 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
505 die $LINENO "Neutron settings for baremetal not set.. exiting"
506 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400507 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
508 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
509 sudo ip addr del $IP dev $PUBLIC_INTERFACE
510 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
511 done
Dirk Mueller25049cd2014-01-09 13:53:52 +0100512 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 -0500513 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100514 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 -0500515 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400516 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200517 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400518 elif is_provider_network; then
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900519 die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400520 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900521 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 -0400522 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 -0400523 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 -0400524 sudo ip link set $OVS_PHYSICAL_BRIDGE up
525 sudo ip link set br-int up
526 sudo ip link set $PUBLIC_INTERFACE up
Mark McClainb05c8762013-07-06 23:29:39 -0400527 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100528 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500529 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100530 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 -0500531 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400532 fi
533
534 if [[ "$Q_L3_ENABLED" == "True" ]]; then
535 # Create a router, and add the private subnet as one of its interfaces
536 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
537 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100538 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500539 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400540 else
541 # Plugin only supports creating a single router, which should be admin owned.
542 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500543 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400544 fi
545 neutron router-interface-add $ROUTER_ID $SUBNET_ID
546 # Create an external network, and a subnet. Configure the external network as router gw
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900547 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
548 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)
549 else
550 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
551 fi
DennyZhang23178a92013-10-22 17:07:32 -0500552 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400553 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 -0500554 die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400555 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
556
557 if is_service_enabled q-l3; then
558 # logic is specific to using the l3-agent for l3
559 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900560 local ext_gw_interface
561
562 if [[ "$Q_USE_PUBLIC_VETH" = "True" ]]; then
563 ext_gw_interface=$Q_PUBLIC_VETH_EX
564 else
565 # Disable in-band as we are going to use local port
566 # to communicate with VMs
567 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
568 other_config:disable-in-band=true
569 ext_gw_interface=$PUBLIC_BRIDGE
570 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400571 CIDR_LEN=${FLOATING_RANGE#*/}
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900572 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $ext_gw_interface
573 sudo ip link set $ext_gw_interface up
Mark McClainb05c8762013-07-06 23:29:39 -0400574 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 -0500575 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400576 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
577 fi
578 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
579 # Explicitly set router id in l3 agent configuration
580 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
581 fi
582 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400583 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400584}
585
586# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100587function init_neutron {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700588 recreate_database $Q_DB_NAME utf8
589 # Run Neutron db migrations
590 $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 -0400591}
592
593# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100594function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400595 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
596 setup_develop $NEUTRON_DIR
Mate Lakat6df64892014-10-17 13:09:49 +0200597
598 if [ "$VIRT_DRIVER" == 'xenserver' ]; then
599 local dom0_ip
600 dom0_ip=$(echo "$XENAPI_CONNECTION_URL" | cut -d "/" -f 3-)
601
602 local ssh_dom0
603 ssh_dom0="sudo -u $DOMZERO_USER ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$dom0_ip"
604
605 # Find where the plugins should go in dom0
606 local xen_functions
607 xen_functions=$(cat $TOP_DIR/tools/xen/functions)
608 local plugin_dir
609 plugin_dir=$($ssh_dom0 "$xen_functions; set -eux; xapi_plugin_location")
610
611 # install neutron plugins to dom0
612 tar -czf - -C $NEUTRON_DIR/neutron/plugins/openvswitch/agent/xenapi/etc/xapi.d/plugins/ ./ |
613 $ssh_dom0 "tar -xzf - -C $plugin_dir && chmod a+x $plugin_dir/*"
614 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400615}
616
617# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100618function install_neutronclient {
Mark McClainb05c8762013-07-06 23:29:39 -0400619 git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH
620 setup_develop $NEUTRONCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200621 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 -0400622}
623
624# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100625function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400626 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
627 if is_service_enabled q-l3; then
628 install_package radvd
629 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400630 # install packages that are specific to plugin agent(s)
631 if is_service_enabled q-agt q-dhcp q-l3; then
632 neutron_plugin_install_agent_packages
633 fi
634
635 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400636 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400637 fi
638}
639
640# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100641function start_neutron_service_and_check {
Adam Gandelman7614d212014-08-11 14:27:50 -0700642 local cfg_file_options="$(determine_config_files neutron-server)"
Rob Crittenden18d47782014-03-19 17:47:42 -0400643 local service_port=$Q_PORT
644 local service_protocol=$Q_PROTOCOL
645 if is_service_enabled tls-proxy; then
646 service_port=$Q_PORT_INT
647 service_protocol="http"
648 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400649 # Start the Neutron service
Chris Dent2f27a0e2014-09-09 13:46:02 +0100650 run_process q-svc "python $NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400651 echo "Waiting for Neutron to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400652 if is_ssl_enabled_service "neutron"; then
653 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
654 fi
655 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 -0400656 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400657 fi
Rob Crittenden18d47782014-03-19 17:47:42 -0400658 # Start proxy if enabled
659 if is_service_enabled tls-proxy; then
660 start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT &
661 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400662}
663
664# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100665function start_neutron_agents {
Mark McClainb05c8762013-07-06 23:29:39 -0400666 # Start up the neutron agents if enabled
Chris Dent2f27a0e2014-09-09 13:46:02 +0100667 run_process q-agt "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
668 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 -0700669
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400670 if is_provider_network; then
671 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
672 sudo ip link set $OVS_PHYSICAL_BRIDGE up
673 sudo ip link set br-int up
674 sudo ip link set $PUBLIC_INTERFACE up
675 fi
676
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700677 if is_service_enabled q-vpn; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100678 run_process q-vpn "$AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700679 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100680 run_process q-l3 "python $AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700681 fi
682
Chris Dent2f27a0e2014-09-09 13:46:02 +0100683 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 -0400684
685 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
686 # For XenServer, start an agent for the domU openvswitch
Chris Dent2f27a0e2014-09-09 13:46:02 +0100687 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 -0400688 fi
689
690 if is_service_enabled q-lbaas; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100691 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 -0400692 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200693
694 if is_service_enabled q-metering; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100695 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 +0200696 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400697}
698
699# stop_neutron() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100700function stop_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400701 if is_service_enabled q-dhcp; then
702 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
703 [ ! -z "$pid" ] && sudo kill -9 $pid
704 fi
705 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100706 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400707 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900708
709 if is_service_enabled q-lbaas; then
710 neutron_lbaas_stop
711 fi
712 if is_service_enabled q-fwaas; then
713 neutron_fwaas_stop
714 fi
715 if is_service_enabled q-vpn; then
716 neutron_vpn_stop
717 fi
718 if is_service_enabled q-metering; then
719 neutron_metering_stop
720 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400721}
722
723# cleanup_neutron() - Remove residual data files, anything left over from previous
724# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100725function cleanup_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400726 if is_neutron_ovs_base_plugin; then
727 neutron_ovs_base_cleanup
728 fi
729
730 # delete all namespaces created by neutron
Brian Haleyeea76212014-06-27 11:45:50 -0400731 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 -0400732 sudo ip netns delete ${ns}
733 done
734}
735
736# _configure_neutron_common()
737# Set common config for all neutron server and agents.
738# This MUST be called before other ``_configure_neutron_*`` functions.
Ian Wienandaee18c72014-02-21 15:35:08 +1100739function _configure_neutron_common {
Mark McClainb05c8762013-07-06 23:29:39 -0400740 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
741 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
742 sudo mkdir -p $NEUTRON_CONF_DIR
743 fi
744 sudo chown $STACK_USER $NEUTRON_CONF_DIR
745
746 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
747
748 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
749 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
750 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
751 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100752 #
Mark McClainb05c8762013-07-06 23:29:39 -0400753 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
754 neutron_plugin_configure_common
755
sbauzae2c4ee22013-08-29 17:29:46 +0200756 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400757 die $LINENO "Neutron plugin not set.. exiting"
758 fi
759
760 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
761 mkdir -p /$Q_PLUGIN_CONF_PATH
762 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
763 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
764
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200765 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400766 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
767
768 # If addition config files are set, make sure their path name is set as well
769 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
770 die $LINENO "Neutron additional plugin config not set.. exiting"
771 fi
772
773 # If additional config files exist, copy them over to neutron configuration
774 # directory
775 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400776 local f
777 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
778 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400779 done
780 fi
781
Joe Gordonbee5c502013-08-30 13:48:08 -0400782 if [ "$VIRT_DRIVER" = 'fake' ]; then
783 # Disable arbitrary limits
784 iniset $NEUTRON_CONF quotas quota_network -1
785 iniset $NEUTRON_CONF quotas quota_subnet -1
786 iniset $NEUTRON_CONF quotas quota_port -1
787 iniset $NEUTRON_CONF quotas quota_security_group -1
788 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
789 fi
790
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700791 # Format logging
792 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800793 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700794 fi
795
Rob Crittenden18d47782014-03-19 17:47:42 -0400796 if is_service_enabled tls-proxy; then
797 # Set the service port for a proxy to take the original
798 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
799 fi
800
801 if is_ssl_enabled_service "nova"; then
802 iniset $NEUTRON_CONF DEFAULT nova_ca_certificates_file "$SSL_BUNDLE_FILE"
803 fi
804
805 if is_ssl_enabled_service "neutron"; then
806 ensure_certificates NEUTRON
807
808 iniset $NEUTRON_CONF DEFAULT use_ssl True
809 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
810 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
811 fi
812
Mark McClainb05c8762013-07-06 23:29:39 -0400813 _neutron_setup_rootwrap
814}
815
Ian Wienandaee18c72014-02-21 15:35:08 +1100816function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400817 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
818 return
819 fi
820
821 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
822
823 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
824 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
825 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400826 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
827
Mark McClainb05c8762013-07-06 23:29:39 -0400828 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
829
830 neutron_plugin_configure_debug_command
831}
832
Ian Wienandaee18c72014-02-21 15:35:08 +1100833function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400834
835 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
836
837 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500838 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400839 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
840 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
841
Tan Lin27a196e2014-10-31 15:44:34 +0800842 if ! is_service_enabled q-l3; then
843 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
844 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
845 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
846 else
847 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
848 die "$LINENO" "Enable isolated metadata is a must for metadata network"
849 fi
850 fi
851 fi
852
Mark McClainb05c8762013-07-06 23:29:39 -0400853 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
854
855 neutron_plugin_configure_dhcp_agent
856}
857
Ian Wienandaee18c72014-02-21 15:35:08 +1100858function _configure_neutron_l3_agent {
Paul Michali746dcee2014-04-02 19:12:22 +0000859 local cfg_file
Mark McClainb05c8762013-07-06 23:29:39 -0400860 Q_L3_ENABLED=True
861 # for l3-agent, only use per tenant router if we have namespaces
862 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700863
Paul Michali746dcee2014-04-02 19:12:22 +0000864 if is_service_enabled q-vpn; then
Paul Michali746dcee2014-04-02 19:12:22 +0000865 cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
Paul Michali746dcee2014-04-02 19:12:22 +0000866 fi
867
Mark McClainb05c8762013-07-06 23:29:39 -0400868 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
869
870 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500871 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400872 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
873 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
874
Mark McClainb05c8762013-07-06 23:29:39 -0400875 _neutron_setup_interface_driver $Q_L3_CONF_FILE
876
877 neutron_plugin_configure_l3_agent
878}
879
Ian Wienandaee18c72014-02-21 15:35:08 +1100880function _configure_neutron_metadata_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400881 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
882
883 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500884 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400885 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
886 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
887
Brant Knudson05952372014-09-19 17:22:22 -0500888 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT
Maru Newbybf10ac52013-08-10 21:27:54 +0000889
Mark McClainb05c8762013-07-06 23:29:39 -0400890}
891
Dina Belova58adaa62014-07-11 18:18:12 +0400892function _configure_neutron_ceilometer_notifications {
JordanPd4d4a342014-09-15 09:26:53 +0000893 iniset $NEUTRON_CONF DEFAULT notification_driver messaging
Dina Belova58adaa62014-07-11 18:18:12 +0400894}
895
Ian Wienandaee18c72014-02-21 15:35:08 +1100896function _configure_neutron_lbaas {
Mark McClainb05c8762013-07-06 23:29:39 -0400897 neutron_agent_lbaas_configure_common
898 neutron_agent_lbaas_configure_agent
899}
900
Ian Wienandaee18c72014-02-21 15:35:08 +1100901function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200902 neutron_agent_metering_configure_common
903 neutron_agent_metering_configure_agent
904}
905
Ian Wienandaee18c72014-02-21 15:35:08 +1100906function _configure_neutron_fwaas {
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700907 neutron_fwaas_configure_common
908 neutron_fwaas_configure_driver
909}
910
Ian Wienandaee18c72014-02-21 15:35:08 +1100911function _configure_neutron_vpn {
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700912 neutron_vpn_install_agent_packages
913 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700914}
915
Brian Haleyeea76212014-06-27 11:45:50 -0400916function _configure_dvr {
917 iniset $NEUTRON_CONF DEFAULT router_distributed True
918 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
919}
920
921
Mark McClainb05c8762013-07-06 23:29:39 -0400922# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
923# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100924function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400925 # Specify the default root helper prior to agent configuration to
926 # ensure that an agent's configuration can override the default
927 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
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
931 # Configure agent for plugin
932 neutron_plugin_configure_plugin_agent
933}
934
935# _configure_neutron_service() - Set config files for neutron service
936# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100937function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400938 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
939 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
940
941 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
942 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
943
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700944 # allow neutron user to administer neutron to match neutron account
945 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
946
Mark McClainb05c8762013-07-06 23:29:39 -0400947 # Update either configuration file with plugin
948 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
949
950 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
951 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
952 fi
953
954 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500955 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400956 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
957 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
958
959 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
960 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
961
Aaron Rosencea32b12014-03-04 16:20:14 -0800962 # Configuration for neutron notifations to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500963 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
964 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Aaron Rosencea32b12014-03-04 16:20:14 -0800965 iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
Dirk Mueller5ca261a2014-04-04 22:48:02 +0200966 iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800967 iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
968 ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
969 iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
970 iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
971
Mark McClainb05c8762013-07-06 23:29:39 -0400972 # Configure plugin
973 neutron_plugin_configure_service
974}
975
976# Utility Functions
977#------------------
978
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900979# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100980function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900981 local service_plugin_class=$1
982 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
983 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
984 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
985 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
986 fi
987}
988
Mark McClainb05c8762013-07-06 23:29:39 -0400989# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100990function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400991 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
992 return
993 fi
994 # Deploy new rootwrap filters files (owned by root).
995 # Wipe any existing ``rootwrap.d`` files first
996 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
997 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
998 sudo rm -rf $Q_CONF_ROOTWRAP_D
999 fi
1000 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
1001 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
1002 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1003 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
1004 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
1005 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1006 # location moved in newer versions, prefer new location
1007 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -04001008 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001009 else
Sean Dague3bdb9222013-10-22 08:36:16 -04001010 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001011 fi
1012 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
1013 sudo chown root:root $Q_RR_CONF_FILE
1014 sudo chmod 0644 $Q_RR_CONF_FILE
1015 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1016 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1017
1018 # Set up the rootwrap sudoers for neutron
1019 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +01001020 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -04001021 chmod 0440 $TEMPFILE
1022 sudo chown root:root $TEMPFILE
1023 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1024
1025 # Update the root_helper
1026 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
1027}
1028
1029# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +11001030function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -04001031 local conf_file=$1
1032 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +10001033
Brant Knudson05952372014-09-19 17:22:22 -05001034 create_neutron_cache_dir
1035 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -04001036}
1037
Ian Wienandaee18c72014-02-21 15:35:08 +11001038function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -04001039
1040 # ovs_use_veth needs to be set before the plugin configuration
1041 # occurs to allow plugins to override the setting.
1042 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1043
1044 neutron_plugin_setup_interface_driver $1
1045}
1046
1047# Functions for Neutron Exercises
1048#--------------------------------
1049
Ian Wienandaee18c72014-02-21 15:35:08 +11001050function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001051 local from_net="$1"
1052 net_id=`_get_net_id $from_net`
1053 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}'`
1054 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1055}
1056
Ian Wienandaee18c72014-02-21 15:35:08 +11001057function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001058 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
1059 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
1060 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
1061 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
1062 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
1063 fi
1064}
1065
Ian Wienandaee18c72014-02-21 15:35:08 +11001066function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001067 delete_probe $PUBLIC_NETWORK_NAME
1068 delete_probe $PRIVATE_NETWORK_NAME
1069}
1070
Ian Wienandaee18c72014-02-21 15:35:08 +11001071function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -04001072 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
1073}
1074
Ian Wienandaee18c72014-02-21 15:35:08 +11001075function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001076 local from_net="$1"
1077 net_id=`_get_net_id $from_net`
1078 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`
1079 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1080}
1081
Ian Wienandaee18c72014-02-21 15:35:08 +11001082function _ping_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001083 local from_net=$1
1084 local ip=$2
1085 local timeout_sec=$3
1086 local expected=${4:-"True"}
1087 local check_command=""
1088 probe_cmd=`_get_probe_cmd_prefix $from_net`
1089 if [[ "$expected" = "True" ]]; then
1090 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1091 else
1092 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1093 fi
1094 if ! timeout $timeout_sec sh -c "$check_command"; then
1095 if [[ "$expected" = "True" ]]; then
1096 die $LINENO "[Fail] Couldn't ping server"
1097 else
1098 die $LINENO "[Fail] Could ping server"
1099 fi
1100 fi
1101}
1102
1103# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001104function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001105 local from_net=$1
1106 local key_file=$2
1107 local ip=$3
1108 local user=$4
1109 local timeout_sec=$5
1110 local probe_cmd = ""
1111 probe_cmd=`_get_probe_cmd_prefix $from_net`
1112 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
1113 die $LINENO "server didn't become ssh-able!"
1114 fi
1115}
1116
1117# Neutron 3rd party programs
1118#---------------------------
1119
1120# please refer to ``lib/neutron_thirdparty/README.md`` for details
1121NEUTRON_THIRD_PARTIES=""
1122for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001123 third_party=$(basename $f)
1124 if is_service_enabled $third_party; then
1125 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1126 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1127 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001128done
1129
Ian Wienandaee18c72014-02-21 15:35:08 +11001130function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001131 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1132 ${1}_${third_party}
1133 done
1134}
1135
1136# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001137function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001138 _neutron_third_party_do configure
1139}
1140
1141# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001142function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001143 _neutron_third_party_do init
1144}
1145
1146# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001147function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001148 _neutron_third_party_do install
1149}
1150
1151# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001152function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001153 _neutron_third_party_do start
1154}
1155
1156# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001157function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001158 _neutron_third_party_do stop
1159}
1160
armando-migliaccioef1e0802014-01-02 16:33:53 -08001161# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001162function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001163 _neutron_third_party_do check
1164}
1165
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001166function is_provider_network {
1167 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1168 return 0
1169 fi
1170 return 1
1171}
1172
Mark McClainb05c8762013-07-06 23:29:39 -04001173
1174# Restore xtrace
1175$XTRACE
1176
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001177# Tell emacs to use shell-script-mode
1178## Local variables:
1179## mode: shell-script
1180## End: