blob: 09d935423e58d7b024ce623345488ad664cd9831 [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
John Davidge21529a52014-06-30 09:55:11 -040054# Settings
55# --------
56
57# Timeout value in seconds to wait for IPv6 gateway configuration
58GATEWAY_TIMEOUT=30
59
Mark McClainb05c8762013-07-06 23:29:39 -040060
61# Neutron Network Configuration
62# -----------------------------
63
John Davidge21529a52014-06-30 09:55:11 -040064# Subnet IP version
65IP_VERSION=${IP_VERSION:-4}
66# Validate IP_VERSION
67if [[ $IP_VERSION != "4" ]] && [[ $IP_VERSION != "6" ]] && [[ $IP_VERSION != "4+6" ]]; then
68 die $LINENO "IP_VERSION must be either 4, 6, or 4+6"
69fi
Mark McClainb05c8762013-07-06 23:29:39 -040070# Gateway and subnet defaults, in case they are not customized in localrc
71NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
Salvatore Orlando90234ac2013-11-25 05:44:10 -080072PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
Mark McClainb05c8762013-07-06 23:29:39 -040073PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
74PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
75
Rob Crittenden18d47782014-03-19 17:47:42 -040076if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then
77 Q_PROTOCOL="https"
78fi
79
John Davidge21529a52014-06-30 09:55:11 -040080# Generate 40-bit IPv6 Global ID to comply with RFC 4193
81IPV6_GLOBAL_ID=`uuidgen | sed s/-//g | cut -c 23- | sed -e "s/\(..\)\(....\)\(....\)/\1:\2:\3/"`
82
83# IPv6 gateway and subnet defaults, in case they are not customized in localrc
84IPV6_RA_MODE=${IPV6_RA_MODE:-slaac}
85IPV6_ADDRESS_MODE=${IPV6_ADDRESS_MODE:-slaac}
86IPV6_PUBLIC_SUBNET_NAME=${IPV6_PUBLIC_SUBNET_NAME:-ipv6-public-subnet}
87IPV6_PRIVATE_SUBNET_NAME=${IPV6_PRIVATE_SUBNET_NAME:-ipv6-private-subnet}
88FIXED_RANGE_V6=${FIXED_RANGE_V6:-fd$IPV6_GLOBAL_ID::/64}
89IPV6_PRIVATE_NETWORK_GATEWAY=${IPV6_PRIVATE_NETWORK_GATEWAY:-fd$IPV6_GLOBAL_ID::1}
90IPV6_PUBLIC_RANGE=${IPV6_PUBLIC_RANGE:-fe80:cafe:cafe::/64}
91IPV6_PUBLIC_NETWORK_GATEWAY=${IPV6_PUBLIC_NETWORK_GATEWAY:-fe80:cafe:cafe::2}
92# IPV6_ROUTER_GW_IP must be defined when IP_VERSION=4+6 as it cannot be
93# obtained conventionally until the l3-agent has support for dual-stack
94# TODO (john-davidge) Remove once l3-agent supports dual-stack
95IPV6_ROUTER_GW_IP=${IPV6_ROUTER_GW_IP:-fe80:cafe:cafe::1}
Rob Crittenden18d47782014-03-19 17:47:42 -040096
Mark McClainb05c8762013-07-06 23:29:39 -040097# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050098GITDIR["python-neutronclient"]=$DEST/python-neutronclient
Sean Dague5cb19062014-11-01 01:37:45 +010099
100
Mark McClainb05c8762013-07-06 23:29:39 -0400101NEUTRON_DIR=$DEST/neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400102NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
103
104# Support entry points installation of console scripts
105if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
106 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -0400107else
108 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -0400109fi
110
111NEUTRON_CONF_DIR=/etc/neutron
112NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
113export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
114
Adam Gandelman7614d212014-08-11 14:27:50 -0700115# Agent binaries. Note, binary paths for other agents are set in per-service
116# scripts in lib/neutron_plugins/services/
117AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
118AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
119AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
120
121# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
122# loaded from per-plugin scripts in lib/neutron_plugins/
123Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
124Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
125Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
126Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
127Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
128
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400129# Default name for Neutron database
130Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400131# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000132Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400133# Default Neutron Port
134Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400135# Default Neutron Internal Port when using TLS proxy
136Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400137# Default Neutron Host
138Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400139# Default protocol
140Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Mark McClainb05c8762013-07-06 23:29:39 -0400141# Default admin username
142Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
143# Default auth strategy
144Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
145# Use namespace or not
146Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
147# RHEL's support for namespaces requires using veths with ovs
148Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
149Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
150# Meta data IP
151Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
152# Allow Overlapping IP among subnets
153Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
154# Use neutron-debug command
155Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
156# The name of the default q-l3 router
157Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Aaron Rosen4540d002013-10-24 13:59:33 -0700158# nova vif driver that all plugins should use
159NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500160Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
161Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800162VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
163VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Edgar Magana7bce8fa2014-11-04 17:32:54 +0100164# Specify if the initial private and external networks should be created
165NEUTRON_CREATE_INITIAL_NETWORKS=${NEUTRON_CREATE_INITIAL_NETWORKS:-True}
Aaron Rosen4540d002013-10-24 13:59:33 -0700166
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400167## Provider Network Information
168PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
169
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900170# Use flat providernet for public network
171#
172# If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network
173# for external interface of neutron l3-agent. In that case,
174# PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900175# used for the network. In case of ofagent, you should add the
176# corresponding entry to your OFAGENT_PHYSICAL_INTERFACE_MAPPINGS.
177# For openvswitch agent, you should add the corresponding entry to
178# your OVS_BRIDGE_MAPPINGS.
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900179#
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900180# eg. (ofagent)
181# Q_USE_PROVIDERNET_FOR_PUBLIC=True
182# Q_USE_PUBLIC_VETH=True
183# PUBLIC_PHYSICAL_NETWORK=public
184# OFAGENT_PHYSICAL_INTERFACE_MAPPINGS=public:veth-pub-int
185#
186# eg. (openvswitch agent)
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900187# Q_USE_PROVIDERNET_FOR_PUBLIC=True
188# PUBLIC_PHYSICAL_NETWORK=public
189# OVS_BRIDGE_MAPPINGS=public:br-ex
190Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-False}
191PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public}
192
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900193# If Q_USE_PUBLIC_VETH=True, create and use a veth pair instead of
194# PUBLIC_BRIDGE. This is intended to be used with
195# Q_USE_PROVIDERNET_FOR_PUBLIC=True.
196Q_USE_PUBLIC_VETH=${Q_USE_PUBLIC_VETH:-False}
197Q_PUBLIC_VETH_EX=${Q_PUBLIC_VETH_EX:-veth-pub-ex}
198Q_PUBLIC_VETH_INT=${Q_PUBLIC_VETH_INT:-veth-pub-int}
199
Tomoe Sugiharaafbc6312013-11-14 20:02:47 +0000200# The next two variables are configured by plugin
201# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
202#
203# The plugin supports L3.
204Q_L3_ENABLED=${Q_L3_ENABLED:-False}
205# L3 routers exist per tenant
206Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False}
Aaron Rosen4540d002013-10-24 13:59:33 -0700207
Mark McClainb05c8762013-07-06 23:29:39 -0400208# List of config file names in addition to the main plugin config file
209# See _configure_neutron_common() for details about setting it up
210declare -a Q_PLUGIN_EXTRA_CONF_FILES
211
Paul Michali746dcee2014-04-02 19:12:22 +0000212# List of (optional) config files for VPN device drivers to use with
213# the neutron-q-vpn agent
214declare -a Q_VPN_EXTRA_CONF_FILES
215
Mark McClainb05c8762013-07-06 23:29:39 -0400216
Dean Troyere2907b42014-02-26 17:35:37 -0600217Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
218if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
219 Q_RR_COMMAND="sudo"
220else
221 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
222 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400223fi
224
Brian Haleyeea76212014-06-27 11:45:50 -0400225
226# Distributed Virtual Router (DVR) configuration
227# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500228# - ``legacy`` - No DVR functionality
229# - ``dvr_snat`` - Controller or single node DVR
230# - ``dvr`` - Compute node in multi-node DVR
231#
Brian Haleyeea76212014-06-27 11:45:50 -0400232Q_DVR_MODE=${Q_DVR_MODE:-legacy}
233if [[ "$Q_DVR_MODE" != "legacy" ]]; then
234 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
235fi
236
Dean Troyere2907b42014-02-26 17:35:37 -0600237# Provider Network Configurations
238# --------------------------------
239
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900240# The following variables control the Neutron ML2 plugins' allocation
241# of tenant networks and availability of provider networks. If these
242# are not configured in ``localrc``, tenant networks will be local to
243# the host (with no remote connectivity), and no physical resources
244# will be available for the allocation of provider networks.
Dean Troyere2907b42014-02-26 17:35:37 -0600245
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200246# To disable tunnels (GRE or VXLAN) for tenant networks,
247# set to False in ``local.conf``.
248# GRE tunnels are only supported by the openvswitch.
249ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600250
251# If using GRE tunnels for tenant networks, specify the range of
252# tunnel IDs from which tenant networks are allocated. Can be
253# overriden in ``localrc`` in necesssary.
Anant Patil3827dc02014-07-03 21:38:16 +0530254TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600255
256# To use VLANs for tenant networks, set to True in localrc. VLANs
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900257# are supported by the ML2 plugins, requiring additional configuration
258# described below.
Dean Troyere2907b42014-02-26 17:35:37 -0600259ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
260
261# If using VLANs for tenant networks, set in ``localrc`` to specify
262# the range of VLAN VIDs from which tenant networks are
263# allocated. An external network switch must be configured to
264# trunk these VLANs between hosts for multi-host connectivity.
265#
266# Example: ``TENANT_VLAN_RANGE=1000:1999``
267TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
268
269# If using VLANs for tenant networks, or if using flat or VLAN
270# provider networks, set in ``localrc`` to the name of the physical
271# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
272# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
273# agent, as described below.
274#
275# Example: ``PHYSICAL_NETWORK=default``
276PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
277
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900278# With the openvswitch agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600279# or if using flat or VLAN provider networks, set in ``localrc`` to
280# the name of the OVS bridge to use for the physical network. The
281# bridge will be created if it does not already exist, but a
282# physical interface must be manually added to the bridge as a
283# port for external connectivity.
284#
285# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
286OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
287
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900288# With the linuxbridge agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600289# or if using flat or VLAN provider networks, set in ``localrc`` to
290# the name of the network interface to use for the physical
291# network.
292#
293# Example: ``LB_PHYSICAL_INTERFACE=eth1``
294LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
295
Edgar Magana6f335b92014-07-10 15:42:44 -0700296# When Neutron tunnels are enabled it is needed to specify the
297# IP address of the end point in the local server. This IP is set
298# by default to the same IP address that the HOST IP.
299# This variable can be used to specify a different end point IP address
300# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
301TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
302
Dean Troyere2907b42014-02-26 17:35:37 -0600303# With the openvswitch plugin, set to True in ``localrc`` to enable
304# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
305#
306# Example: ``OVS_ENABLE_TUNNELING=True``
307OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
308
Tan Lin27a196e2014-10-31 15:44:34 +0800309# Use DHCP agent for providing metadata service in the case of
310# without L3 agent (No Route Agent), set to True in localrc.
311ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
312
313# Add a static route as dhcp option, so the request to 169.254.169.254
314# will be able to reach through a route(DHCP agent)
315# This option require ENABLE_ISOLATED_METADATA = True
316ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
Mark McClainb05c8762013-07-06 23:29:39 -0400317# Neutron plugin specific functions
318# ---------------------------------
319
320# Please refer to ``lib/neutron_plugins/README.md`` for details.
321source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
322
323# Agent loadbalancer service plugin functions
324# -------------------------------------------
325
326# Hardcoding for 1 service plugin for now
327source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
328
Emilien Macchi40546f72013-09-24 15:10:25 +0200329# Agent metering service plugin functions
330# -------------------------------------------
331
332# Hardcoding for 1 service plugin for now
333source $TOP_DIR/lib/neutron_plugins/services/metering
334
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700335# VPN service plugin functions
336# -------------------------------------------
337# Hardcoding for 1 service plugin for now
338source $TOP_DIR/lib/neutron_plugins/services/vpn
339
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700340# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100341# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700342source $TOP_DIR/lib/neutron_plugins/services/firewall
343
Mark McClainb05c8762013-07-06 23:29:39 -0400344# Use security group or not
345if has_neutron_plugin_security_group; then
346 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
347else
348 Q_USE_SECGROUP=False
349fi
350
Dean Troyer4237f592014-01-29 16:22:11 -0600351# Tell Tempest this project is present
352TEMPEST_SERVICES+=,neutron
353
354
Dean Troyere2907b42014-02-26 17:35:37 -0600355# Save trace setting
356XTRACE=$(set +o | grep xtrace)
357set +o xtrace
358
359
Mark McClainb05c8762013-07-06 23:29:39 -0400360# Functions
361# ---------
362
Adam Gandelman7614d212014-08-11 14:27:50 -0700363function _determine_config_server {
364 local cfg_file
365 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
366 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
367 opts+=" --config-file /$cfg_file"
368 done
369 echo "$opts"
370}
371
372function _determine_config_vpn {
373 local cfg_file
374 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
375 if is_service_enabled q-fwaas; then
376 opts+=" --config-file $Q_FWAAS_CONF_FILE"
377 fi
378 for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
379 opts+=" --config-file $cfg_file"
380 done
381 echo "$opts"
382
383}
384
385function _determine_config_l3 {
386 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
387 if is_service_enabled q-fwaas; then
388 opts+=" --config-file $Q_FWAAS_CONF_FILE"
389 fi
390 echo "$opts"
391}
392
393# For services and agents that require it, dynamically construct a list of
394# --config-file arguments that are passed to the binary.
395function determine_config_files {
396 local opts=""
397 case "$1" in
398 "neutron-server") opts="$(_determine_config_server)" ;;
399 "neutron-vpn-agent") opts="$(_determine_config_vpn)" ;;
400 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
401 esac
402 if [ -z "$opts" ] ; then
403 die $LINENO "Could not determine config files for $1."
404 fi
405 echo "$opts"
406}
407
Dean Troyere4fa7212014-01-15 15:04:49 -0600408# Test if any Neutron services are enabled
409# is_neutron_enabled
410function is_neutron_enabled {
411 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
412 return 1
413}
414
Mark McClainb05c8762013-07-06 23:29:39 -0400415# configure_neutron()
416# Set common config for all neutron server and agents.
Ian Wienandaee18c72014-02-21 15:35:08 +1100417function configure_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400418 _configure_neutron_common
419 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
420
421 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
422 if is_service_enabled q-lbaas; then
423 _configure_neutron_lbaas
424 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200425 if is_service_enabled q-metering; then
426 _configure_neutron_metering
427 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700428 if is_service_enabled q-vpn; then
429 _configure_neutron_vpn
430 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700431 if is_service_enabled q-fwaas; then
432 _configure_neutron_fwaas
433 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000434 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400435 _configure_neutron_service
436 fi
437 if is_service_enabled q-agt; then
438 _configure_neutron_plugin_agent
439 fi
440 if is_service_enabled q-dhcp; then
441 _configure_neutron_dhcp_agent
442 fi
443 if is_service_enabled q-l3; then
444 _configure_neutron_l3_agent
445 fi
446 if is_service_enabled q-meta; then
447 _configure_neutron_metadata_agent
448 fi
449
Brian Haleyeea76212014-06-27 11:45:50 -0400450 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
451 _configure_dvr
452 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400453 if is_service_enabled ceilometer; then
454 _configure_neutron_ceilometer_notifications
455 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400456
457 _configure_neutron_debug_command
458}
459
Ian Wienandaee18c72014-02-21 15:35:08 +1100460function create_nova_conf_neutron {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800461 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
Gary Kotton13d385e2014-06-17 23:24:53 -0700462 iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME"
463 iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD"
464 iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
465 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
466 iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME"
Bartosz Górski0abde392014-02-28 14:15:19 +0100467 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Rob Crittenden18d47782014-03-19 17:47:42 -0400468 iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400469
470 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
471 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400472 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800473 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400474 fi
475
476 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
477 neutron_plugin_create_nova_conf
478
Gary Kotton51c681d2014-04-22 01:40:56 -0700479 iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER"
Mark McClainb05c8762013-07-06 23:29:39 -0400480 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
481 if is_service_enabled q-meta; then
Gary Kottondd745502014-08-11 23:38:47 -0700482 iniset $NOVA_CONF neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400483 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800484
485 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
486 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400487}
488
Emilien Macchia677b7f2013-11-25 23:40:20 +0100489# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100490function create_neutron_cache_dir {
Emilien Macchia677b7f2013-11-25 23:40:20 +0100491 # Create cache dir
492 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
493 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
494 rm -f $NEUTRON_AUTH_CACHE_DIR/*
495}
496
Mark McClainb05c8762013-07-06 23:29:39 -0400497# create_neutron_accounts() - Set up common required neutron accounts
498
499# Tenant User Roles
500# ------------------------------------------------------------------
501# service neutron admin # if enabled
502
503# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100504function create_neutron_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400505
Dean Troyer188493d2014-07-25 15:54:11 -0500506 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700507 local service_role=$(openstack role list | awk "/ service / { print \$2 }")
Mark McClainb05c8762013-07-06 23:29:39 -0400508
509 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100510
Dean Troyer188493d2014-07-25 15:54:11 -0500511 local neutron_user=$(get_or_create_user "neutron" \
512 "$SERVICE_PASSWORD" $service_tenant)
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700513 get_or_add_user_role $service_role $neutron_user $service_tenant
Bartosz Górski0abde392014-02-28 14:15:19 +0100514
Mark McClainb05c8762013-07-06 23:29:39 -0400515 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100516
Dean Troyer188493d2014-07-25 15:54:11 -0500517 local neutron_service=$(get_or_create_service "neutron" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100518 "network" "Neutron Service")
Dean Troyer188493d2014-07-25 15:54:11 -0500519 get_or_create_endpoint $neutron_service \
Bartosz Górski0abde392014-02-28 14:15:19 +0100520 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400521 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
522 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
523 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400524 fi
525 fi
526}
527
Ian Wienandaee18c72014-02-21 15:35:08 +1100528function create_neutron_initial_network {
Steve Martinelli19685422014-01-24 13:02:26 -0600529 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500530 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400531
532 # Create a small network
533 # Since neutron command is executed in admin context at this point,
Dirk Mueller25049cd2014-01-09 13:53:52 +0100534 # ``--tenant-id`` needs to be specified.
Mark McClainb05c8762013-07-06 23:29:39 -0400535 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200536 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
537 die $LINENO "Neutron settings for baremetal not set.. exiting"
538 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400539 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
540 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
541 sudo ip addr del $IP dev $PUBLIC_INTERFACE
542 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
543 done
Dirk Mueller25049cd2014-01-09 13:53:52 +0100544 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 -0500545 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100546 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 -0500547 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400548 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200549 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400550 elif is_provider_network; then
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900551 die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400552 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900553 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)
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700554 SUBNET_ID=$(neutron subnet-create --tenant_id $TENANT_ID --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --name $PROVIDER_SUBNET_NAME --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
Sean M. Collinse13fd602014-05-14 17:01:53 -0400555 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 -0400556 sudo ip link set $OVS_PHYSICAL_BRIDGE up
557 sudo ip link set br-int up
558 sudo ip link set $PUBLIC_INTERFACE up
Mark McClainb05c8762013-07-06 23:29:39 -0400559 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100560 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500561 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
John Davidge21529a52014-06-30 09:55:11 -0400562
563 if [[ "$IP_VERSION" =~ 4.* ]]; then
564 # Create IPv4 private subnet
565 SUBNET_ID=$(_neutron_create_private_subnet_v4)
566 fi
567
568 if [[ "$IP_VERSION" =~ .*6 ]]; then
569 # Create IPv6 private subnet
570 IPV6_SUBNET_ID=$(_neutron_create_private_subnet_v6)
571 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400572 fi
573
574 if [[ "$Q_L3_ENABLED" == "True" ]]; then
575 # Create a router, and add the private subnet as one of its interfaces
576 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
577 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100578 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500579 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400580 else
581 # Plugin only supports creating a single router, which should be admin owned.
582 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500583 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400584 fi
John Davidge21529a52014-06-30 09:55:11 -0400585
Mark McClainb05c8762013-07-06 23:29:39 -0400586 # Create an external network, and a subnet. Configure the external network as router gw
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900587 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
588 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)
589 else
590 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
591 fi
DennyZhang23178a92013-10-22 17:07:32 -0500592 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400593
John Davidge21529a52014-06-30 09:55:11 -0400594 if [[ "$IP_VERSION" =~ 4.* ]]; then
595 # Configure router for IPv4 public access
596 _neutron_configure_router_v4
597 fi
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900598
John Davidge21529a52014-06-30 09:55:11 -0400599 if [[ "$IP_VERSION" =~ .*6 ]]; then
600 # Configure router for IPv6 public access
601 _neutron_configure_router_v6
Mark McClainb05c8762013-07-06 23:29:39 -0400602 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400603 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400604}
605
606# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100607function init_neutron {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700608 recreate_database $Q_DB_NAME utf8
609 # Run Neutron db migrations
610 $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 -0400611}
612
613# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100614function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400615 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
616 setup_develop $NEUTRON_DIR
Mate Lakat6df64892014-10-17 13:09:49 +0200617
618 if [ "$VIRT_DRIVER" == 'xenserver' ]; then
619 local dom0_ip
620 dom0_ip=$(echo "$XENAPI_CONNECTION_URL" | cut -d "/" -f 3-)
621
622 local ssh_dom0
623 ssh_dom0="sudo -u $DOMZERO_USER ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$dom0_ip"
624
625 # Find where the plugins should go in dom0
626 local xen_functions
627 xen_functions=$(cat $TOP_DIR/tools/xen/functions)
628 local plugin_dir
629 plugin_dir=$($ssh_dom0 "$xen_functions; set -eux; xapi_plugin_location")
630
631 # install neutron plugins to dom0
632 tar -czf - -C $NEUTRON_DIR/neutron/plugins/openvswitch/agent/xenapi/etc/xapi.d/plugins/ ./ |
633 $ssh_dom0 "tar -xzf - -C $plugin_dir && chmod a+x $plugin_dir/*"
634 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400635}
636
637# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100638function install_neutronclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500639 if use_library_from_git "python-neutronclient"; then
640 git_clone_by_name "python-neutronclient"
641 setup_dev_lib "python-neutronclient"
642 sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-neutronclient"]}/tools/,/etc/bash_completion.d/}neutron.bash_completion
Sean Dague5cb19062014-11-01 01:37:45 +0100643 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400644}
645
646# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100647function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400648 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
649 if is_service_enabled q-l3; then
650 install_package radvd
651 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400652 # install packages that are specific to plugin agent(s)
653 if is_service_enabled q-agt q-dhcp q-l3; then
654 neutron_plugin_install_agent_packages
655 fi
656
657 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400658 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400659 fi
660}
661
662# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100663function start_neutron_service_and_check {
Adam Gandelman7614d212014-08-11 14:27:50 -0700664 local cfg_file_options="$(determine_config_files neutron-server)"
Rob Crittenden18d47782014-03-19 17:47:42 -0400665 local service_port=$Q_PORT
666 local service_protocol=$Q_PROTOCOL
667 if is_service_enabled tls-proxy; then
668 service_port=$Q_PORT_INT
669 service_protocol="http"
670 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400671 # Start the Neutron service
Chris Dent2f27a0e2014-09-09 13:46:02 +0100672 run_process q-svc "python $NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400673 echo "Waiting for Neutron to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400674 if is_ssl_enabled_service "neutron"; then
675 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
676 fi
677 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 -0400678 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400679 fi
Rob Crittenden18d47782014-03-19 17:47:42 -0400680 # Start proxy if enabled
681 if is_service_enabled tls-proxy; then
682 start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT &
683 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400684}
685
686# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100687function start_neutron_agents {
Mark McClainb05c8762013-07-06 23:29:39 -0400688 # Start up the neutron agents if enabled
Chris Dent2f27a0e2014-09-09 13:46:02 +0100689 run_process q-agt "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
690 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 -0700691
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400692 if is_provider_network; then
693 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
694 sudo ip link set $OVS_PHYSICAL_BRIDGE up
695 sudo ip link set br-int up
696 sudo ip link set $PUBLIC_INTERFACE up
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700697 if is_ironic_hardware; then
698 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
699 sudo ip addr del $IP dev $PUBLIC_INTERFACE
700 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
701 done
702 sudo route add -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
703 fi
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400704 fi
705
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700706 if is_service_enabled q-vpn; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100707 run_process q-vpn "$AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700708 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100709 run_process q-l3 "python $AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700710 fi
711
Chris Dent2f27a0e2014-09-09 13:46:02 +0100712 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 -0400713
714 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
715 # For XenServer, start an agent for the domU openvswitch
Chris Dent2f27a0e2014-09-09 13:46:02 +0100716 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 -0400717 fi
718
719 if is_service_enabled q-lbaas; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100720 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 -0400721 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200722
723 if is_service_enabled q-metering; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100724 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 +0200725 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400726}
727
728# stop_neutron() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100729function stop_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400730 if is_service_enabled q-dhcp; then
731 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
732 [ ! -z "$pid" ] && sudo kill -9 $pid
733 fi
734 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100735 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400736 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900737
738 if is_service_enabled q-lbaas; then
739 neutron_lbaas_stop
740 fi
741 if is_service_enabled q-fwaas; then
742 neutron_fwaas_stop
743 fi
744 if is_service_enabled q-vpn; then
745 neutron_vpn_stop
746 fi
747 if is_service_enabled q-metering; then
748 neutron_metering_stop
749 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400750}
751
752# cleanup_neutron() - Remove residual data files, anything left over from previous
753# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100754function cleanup_neutron {
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700755 if [[ is_provider_network && is_ironic_hardware ]]; then
756 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
757 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
758 sudo ip addr add $IP dev $PUBLIC_INTERFACE
759 done
760 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
761 fi
762
Mark McClainb05c8762013-07-06 23:29:39 -0400763 if is_neutron_ovs_base_plugin; then
764 neutron_ovs_base_cleanup
765 fi
766
767 # delete all namespaces created by neutron
Brian Haleyeea76212014-06-27 11:45:50 -0400768 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 -0400769 sudo ip netns delete ${ns}
770 done
771}
772
773# _configure_neutron_common()
774# Set common config for all neutron server and agents.
775# This MUST be called before other ``_configure_neutron_*`` functions.
Ian Wienandaee18c72014-02-21 15:35:08 +1100776function _configure_neutron_common {
Mark McClainb05c8762013-07-06 23:29:39 -0400777 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
778 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
779 sudo mkdir -p $NEUTRON_CONF_DIR
780 fi
781 sudo chown $STACK_USER $NEUTRON_CONF_DIR
782
783 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
784
785 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
786 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
787 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
788 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100789 #
Mark McClainb05c8762013-07-06 23:29:39 -0400790 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
791 neutron_plugin_configure_common
792
sbauzae2c4ee22013-08-29 17:29:46 +0200793 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400794 die $LINENO "Neutron plugin not set.. exiting"
795 fi
796
797 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
798 mkdir -p /$Q_PLUGIN_CONF_PATH
799 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
800 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
801
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200802 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400803 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
salvatoree4e535b2014-10-29 18:22:46 +0100804 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
Mark McClainb05c8762013-07-06 23:29:39 -0400805 # If addition config files are set, make sure their path name is set as well
806 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
807 die $LINENO "Neutron additional plugin config not set.. exiting"
808 fi
809
810 # If additional config files exist, copy them over to neutron configuration
811 # directory
812 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400813 local f
814 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
815 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400816 done
817 fi
818
Joe Gordonbee5c502013-08-30 13:48:08 -0400819 if [ "$VIRT_DRIVER" = 'fake' ]; then
820 # Disable arbitrary limits
821 iniset $NEUTRON_CONF quotas quota_network -1
822 iniset $NEUTRON_CONF quotas quota_subnet -1
823 iniset $NEUTRON_CONF quotas quota_port -1
824 iniset $NEUTRON_CONF quotas quota_security_group -1
825 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
826 fi
827
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700828 # Format logging
829 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800830 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700831 fi
832
Rob Crittenden18d47782014-03-19 17:47:42 -0400833 if is_service_enabled tls-proxy; then
834 # Set the service port for a proxy to take the original
835 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
836 fi
837
838 if is_ssl_enabled_service "nova"; then
839 iniset $NEUTRON_CONF DEFAULT nova_ca_certificates_file "$SSL_BUNDLE_FILE"
840 fi
841
842 if is_ssl_enabled_service "neutron"; then
843 ensure_certificates NEUTRON
844
845 iniset $NEUTRON_CONF DEFAULT use_ssl True
846 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
847 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
848 fi
849
Mark McClainb05c8762013-07-06 23:29:39 -0400850 _neutron_setup_rootwrap
851}
852
Ian Wienandaee18c72014-02-21 15:35:08 +1100853function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400854 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
855 return
856 fi
857
858 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
859
860 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
861 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
862 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400863 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
864
Mark McClainb05c8762013-07-06 23:29:39 -0400865 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
866
867 neutron_plugin_configure_debug_command
868}
869
Ian Wienandaee18c72014-02-21 15:35:08 +1100870function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400871
872 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
873
874 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500875 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400876 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
877 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
878
Tan Lin27a196e2014-10-31 15:44:34 +0800879 if ! is_service_enabled q-l3; then
880 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
881 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
882 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
883 else
884 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
885 die "$LINENO" "Enable isolated metadata is a must for metadata network"
886 fi
887 fi
888 fi
889
Mark McClainb05c8762013-07-06 23:29:39 -0400890 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
891
892 neutron_plugin_configure_dhcp_agent
893}
894
Ian Wienandaee18c72014-02-21 15:35:08 +1100895function _configure_neutron_l3_agent {
Paul Michali746dcee2014-04-02 19:12:22 +0000896 local cfg_file
Mark McClainb05c8762013-07-06 23:29:39 -0400897 Q_L3_ENABLED=True
898 # for l3-agent, only use per tenant router if we have namespaces
899 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700900
Paul Michali746dcee2014-04-02 19:12:22 +0000901 if is_service_enabled q-vpn; then
Paul Michali746dcee2014-04-02 19:12:22 +0000902 cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
Paul Michali746dcee2014-04-02 19:12:22 +0000903 fi
904
Mark McClainb05c8762013-07-06 23:29:39 -0400905 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
906
907 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500908 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400909 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
910 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
911
Mark McClainb05c8762013-07-06 23:29:39 -0400912 _neutron_setup_interface_driver $Q_L3_CONF_FILE
913
914 neutron_plugin_configure_l3_agent
915}
916
Ian Wienandaee18c72014-02-21 15:35:08 +1100917function _configure_neutron_metadata_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400918 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
919
920 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500921 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400922 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
923 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
924
Brant Knudson05952372014-09-19 17:22:22 -0500925 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT
Maru Newbybf10ac52013-08-10 21:27:54 +0000926
Mark McClainb05c8762013-07-06 23:29:39 -0400927}
928
Dina Belova58adaa62014-07-11 18:18:12 +0400929function _configure_neutron_ceilometer_notifications {
JordanPd4d4a342014-09-15 09:26:53 +0000930 iniset $NEUTRON_CONF DEFAULT notification_driver messaging
Dina Belova58adaa62014-07-11 18:18:12 +0400931}
932
Ian Wienandaee18c72014-02-21 15:35:08 +1100933function _configure_neutron_lbaas {
Mark McClainb05c8762013-07-06 23:29:39 -0400934 neutron_agent_lbaas_configure_common
935 neutron_agent_lbaas_configure_agent
936}
937
Ian Wienandaee18c72014-02-21 15:35:08 +1100938function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200939 neutron_agent_metering_configure_common
940 neutron_agent_metering_configure_agent
941}
942
Ian Wienandaee18c72014-02-21 15:35:08 +1100943function _configure_neutron_fwaas {
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700944 neutron_fwaas_configure_common
945 neutron_fwaas_configure_driver
946}
947
Ian Wienandaee18c72014-02-21 15:35:08 +1100948function _configure_neutron_vpn {
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700949 neutron_vpn_install_agent_packages
950 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700951}
952
Brian Haleyeea76212014-06-27 11:45:50 -0400953function _configure_dvr {
954 iniset $NEUTRON_CONF DEFAULT router_distributed True
955 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
956}
957
958
Mark McClainb05c8762013-07-06 23:29:39 -0400959# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
960# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100961function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400962 # Specify the default root helper prior to agent configuration to
963 # ensure that an agent's configuration can override the default
964 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
965 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500966 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400967
968 # Configure agent for plugin
969 neutron_plugin_configure_plugin_agent
970}
971
972# _configure_neutron_service() - Set config files for neutron service
973# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100974function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400975 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
976 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
977
978 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
979 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
980
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700981 # allow neutron user to administer neutron to match neutron account
982 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
983
Mark McClainb05c8762013-07-06 23:29:39 -0400984 # Update either configuration file with plugin
985 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
986
987 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
988 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
989 fi
990
991 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500992 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400993 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
994 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
995
996 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
997 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
998
Aaron Rosencea32b12014-03-04 16:20:14 -0800999 # Configuration for neutron notifations to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -05001000 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
1001 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Aaron Rosencea32b12014-03-04 16:20:14 -08001002 iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
Dirk Mueller5ca261a2014-04-04 22:48:02 +02001003 iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
Aaron Rosencea32b12014-03-04 16:20:14 -08001004 iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
1005 ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
1006 iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
1007 iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
1008
Mark McClainb05c8762013-07-06 23:29:39 -04001009 # Configure plugin
1010 neutron_plugin_configure_service
1011}
1012
1013# Utility Functions
1014#------------------
1015
Isaku Yamahata9e136b42013-12-16 15:52:03 +09001016# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +11001017function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +09001018 local service_plugin_class=$1
1019 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1020 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1021 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1022 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1023 fi
1024}
1025
Mark McClainb05c8762013-07-06 23:29:39 -04001026# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +11001027function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -04001028 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1029 return
1030 fi
1031 # Deploy new rootwrap filters files (owned by root).
1032 # Wipe any existing ``rootwrap.d`` files first
1033 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1034 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1035 sudo rm -rf $Q_CONF_ROOTWRAP_D
1036 fi
1037 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
1038 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
1039 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1040 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
1041 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
1042 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1043 # location moved in newer versions, prefer new location
1044 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -04001045 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001046 else
Sean Dague3bdb9222013-10-22 08:36:16 -04001047 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001048 fi
1049 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
1050 sudo chown root:root $Q_RR_CONF_FILE
1051 sudo chmod 0644 $Q_RR_CONF_FILE
1052 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1053 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1054
1055 # Set up the rootwrap sudoers for neutron
1056 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +01001057 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -04001058 chmod 0440 $TEMPFILE
1059 sudo chown root:root $TEMPFILE
1060 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1061
1062 # Update the root_helper
1063 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
1064}
1065
1066# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +11001067function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -04001068 local conf_file=$1
1069 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +10001070
Brant Knudson05952372014-09-19 17:22:22 -05001071 create_neutron_cache_dir
1072 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -04001073}
1074
Ian Wienandaee18c72014-02-21 15:35:08 +11001075function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -04001076
1077 # ovs_use_veth needs to be set before the plugin configuration
1078 # occurs to allow plugins to override the setting.
1079 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1080
1081 neutron_plugin_setup_interface_driver $1
1082}
1083
John Davidge21529a52014-06-30 09:55:11 -04001084# Create private IPv4 subnet
1085function _neutron_create_private_subnet_v4 {
1086 local subnet_params="--tenant-id $TENANT_ID "
1087 subnet_params+="--ip_version 4 "
1088 subnet_params+="--gateway $NETWORK_GATEWAY "
1089 subnet_params+="--name $PRIVATE_SUBNET_NAME "
1090 subnet_params+="$NET_ID $FIXED_RANGE"
1091 local subnet_id=$(neutron subnet-create $subnet_params | grep ' id ' | get_field 2)
1092 die_if_not_set $LINENO subnet_id "Failure creating private IPv4 subnet for $TENANT_ID"
1093 echo $subnet_id
1094}
1095
1096# Create private IPv6 subnet
1097function _neutron_create_private_subnet_v6 {
1098 die_if_not_set $LINENO IPV6_RA_MODE "IPV6 RA Mode not set"
1099 die_if_not_set $LINENO IPV6_ADDRESS_MODE "IPV6 Address Mode not set"
1100 local ipv6_modes="--ipv6-ra-mode $IPV6_RA_MODE --ipv6-address-mode $IPV6_ADDRESS_MODE"
1101 local subnet_params="--tenant-id $TENANT_ID "
1102 subnet_params+="--ip_version 6 "
1103 subnet_params+="--gateway $IPV6_PRIVATE_NETWORK_GATEWAY "
1104 subnet_params+="--name $IPV6_PRIVATE_SUBNET_NAME "
1105 subnet_params+="$NET_ID $FIXED_RANGE_V6 $ipv6_modes"
1106 local ipv6_subnet_id=$(neutron subnet-create $subnet_params | grep ' id ' | get_field 2)
1107 die_if_not_set $LINENO ipv6_subnet_id "Failure creating private IPv6 subnet for $TENANT_ID"
1108 echo $ipv6_subnet_id
1109}
1110
1111# Create public IPv4 subnet
1112function _neutron_create_public_subnet_v4 {
1113 local subnet_params+="--ip_version 4 "
1114 subnet_params+="${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} "
1115 subnet_params+="--gateway $PUBLIC_NETWORK_GATEWAY "
1116 subnet_params+="--name $PUBLIC_SUBNET_NAME "
1117 subnet_params+="$EXT_NET_ID $FLOATING_RANGE "
1118 subnet_params+="-- --enable_dhcp=False"
1119 local id_and_ext_gw_ip=$(neutron subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
1120 die_if_not_set $LINENO id_and_ext_gw_ip "Failure creating public IPv4 subnet"
1121 echo $id_and_ext_gw_ip
1122}
1123
1124# Create public IPv6 subnet
1125function _neutron_create_public_subnet_v6 {
1126 local subnet_params="--ip_version 6 "
1127 subnet_params+="--gateway $IPV6_PUBLIC_NETWORK_GATEWAY "
1128 subnet_params+="--name $IPV6_PUBLIC_SUBNET_NAME "
1129 subnet_params+="$EXT_NET_ID $IPV6_PUBLIC_RANGE "
1130 subnet_params+="-- --enable_dhcp=False"
1131 local ipv6_id_and_ext_gw_ip=$(neutron subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
1132 die_if_not_set $LINENO ipv6_id_and_ext_gw_ip "Failure creating an IPv6 public subnet"
1133 echo $ipv6_id_and_ext_gw_ip
1134}
1135
1136# Configure neutron router for IPv4 public access
1137function _neutron_configure_router_v4 {
1138 neutron router-interface-add $ROUTER_ID $SUBNET_ID
1139 # Create a public subnet on the external network
1140 local id_and_ext_gw_ip=$(_neutron_create_public_subnet_v4 $EXT_NET_ID)
1141 local ext_gw_ip=$(echo $id_and_ext_gw_ip | get_field 2)
1142 PUB_SUBNET_ID=$(echo $id_and_ext_gw_ip | get_field 5)
1143 # Configure the external network as the default router gateway
1144 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
1145
1146 # This logic is specific to using the l3-agent for layer 3
1147 if is_service_enabled q-l3; then
1148 # Configure and enable public bridge
1149 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
1150 local ext_gw_interface=$(_neutron_get_ext_gw_interface)
1151 local cidr_len=${FLOATING_RANGE#*/}
1152 sudo ip addr add $ext_gw_ip/$cidr_len dev $ext_gw_interface
1153 sudo ip link set $ext_gw_interface up
1154 ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' -v subnet_id=$PUB_SUBNET_ID '$4 == subnet_id { print $8; }'`
1155 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
1156 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
1157 fi
1158 _neutron_set_router_id
1159 fi
1160}
1161
1162# Configure neutron router for IPv6 public access
1163function _neutron_configure_router_v6 {
1164 neutron router-interface-add $ROUTER_ID $IPV6_SUBNET_ID
1165 # Create a public subnet on the external network
1166 local ipv6_id_and_ext_gw_ip=$(_neutron_create_public_subnet_v6 $EXT_NET_ID)
1167 local ipv6_ext_gw_ip=$(echo $ipv6_id_and_ext_gw_ip | get_field 2)
1168 local ipv6_pub_subnet_id=$(echo $ipv6_id_and_ext_gw_ip | get_field 5)
1169
1170 # If the external network has not already been set as the default router
1171 # gateway when configuring an IPv4 public subnet, do so now
1172 if [[ "$IP_VERSION" == "6" ]]; then
1173 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
1174 fi
1175
1176 # This logic is specific to using the l3-agent for layer 3
1177 if is_service_enabled q-l3; then
1178 local ipv6_router_gw_port
1179 # Ensure IPv6 forwarding is enabled on the host
1180 sudo sysctl -w net.ipv6.conf.all.forwarding=1
1181 # Configure and enable public bridge
1182 if [[ "$IP_VERSION" = "6" ]]; then
1183 # Override global IPV6_ROUTER_GW_IP with the true value from neutron
1184 IPV6_ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' -v subnet_id=$ipv6_pub_subnet_id '$4 == subnet_id { print $8; }'`
1185 die_if_not_set $LINENO IPV6_ROUTER_GW_IP "Failure retrieving IPV6_ROUTER_GW_IP"
1186 ipv6_router_gw_port=`neutron port-list -c id -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' -v subnet_id=$ipv6_pub_subnet_id '$4 == subnet_id { print $1; }' | awk -F ' | ' '{ print $2; }'`
1187 die_if_not_set $LINENO ipv6_router_gw_port "Failure retrieving ipv6_router_gw_port"
1188 else
1189 ipv6_router_gw_port=`neutron port-list -c id -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' -v subnet_id=$PUB_SUBNET_ID '$4 == subnet_id { print $1; }' | awk -F ' | ' '{ print $2; }'`
1190 die_if_not_set $LINENO ipv6_router_gw_port "Failure retrieving ipv6_router_gw_port"
1191 fi
1192
1193 # The ovs_base_configure_l3_agent function flushes the public
1194 # bridge's ip addresses, so turn IPv6 support in the host off
1195 # and then on to recover the public bridge's link local address
1196 sudo sysctl -w net.ipv6.conf.${PUBLIC_BRIDGE}.disable_ipv6=1
1197 sudo sysctl -w net.ipv6.conf.${PUBLIC_BRIDGE}.disable_ipv6=0
1198 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
1199 local ext_gw_interface=$(_neutron_get_ext_gw_interface)
1200 local ipv6_cidr_len=${IPV6_PUBLIC_RANGE#*/}
1201
1202 # Define router_ns based on whether DVR is enabled
1203 local router_ns=qrouter
1204 if [[ "$Q_DVR_MODE" == "dvr_snat" ]]; then
1205 router_ns=snat
1206 fi
1207
1208 # Configure interface for public bridge
1209 sudo ip -6 addr add $ipv6_ext_gw_ip/$ipv6_cidr_len dev $ext_gw_interface
1210
1211 # Wait until layer 3 agent has configured the gateway port on
1212 # the public bridge, then add gateway address to the interface
1213 # TODO (john-davidge) Remove once l3-agent supports dual-stack
1214 if [[ "$IP_VERSION" == "4+6" ]]; then
1215 if ! timeout $GATEWAY_TIMEOUT sh -c "until sudo ip netns exec $router_ns-$ROUTER_ID ip addr show qg-${ipv6_router_gw_port:0:11} | grep $ROUTER_GW_IP; do sleep 1; done"; then
1216 die $LINENO "Timeout retrieving ROUTER_GW_IP"
1217 fi
1218 # Configure the gateway port with the public IPv6 adress
1219 sudo ip netns exec $router_ns-$ROUTER_ID ip -6 addr add $IPV6_ROUTER_GW_IP/$ipv6_cidr_len dev qg-${ipv6_router_gw_port:0:11}
1220 # Add a default IPv6 route to the neutron router as the
1221 # l3-agent does not add one in the dual-stack case
1222 sudo ip netns exec $router_ns-$ROUTER_ID ip -6 route replace default via $ipv6_ext_gw_ip dev qg-${ipv6_router_gw_port:0:11}
1223 fi
1224 sudo ip -6 route add $FIXED_RANGE_V6 via $IPV6_ROUTER_GW_IP dev $ext_gw_interface
1225 fi
1226 _neutron_set_router_id
1227 fi
1228}
1229
1230# Explicitly set router id in l3 agent configuration
1231function _neutron_set_router_id {
1232 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
1233 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
1234 fi
1235}
1236
1237# Get ext_gw_interface depending on value of Q_USE_PUBLIC_VETH
1238function _neutron_get_ext_gw_interface {
1239 if [[ "$Q_USE_PUBLIC_VETH" == "True" ]]; then
1240 echo $Q_PUBLIC_VETH_EX
1241 else
1242 # Disable in-band as we are going to use local port
1243 # to communicate with VMs
1244 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
1245 other_config:disable-in-band=true
1246 echo $PUBLIC_BRIDGE
1247 fi
1248}
1249
Mark McClainb05c8762013-07-06 23:29:39 -04001250# Functions for Neutron Exercises
1251#--------------------------------
1252
Ian Wienandaee18c72014-02-21 15:35:08 +11001253function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001254 local from_net="$1"
1255 net_id=`_get_net_id $from_net`
1256 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}'`
1257 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1258}
1259
Ian Wienandaee18c72014-02-21 15:35:08 +11001260function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001261 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
1262 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
1263 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
1264 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
1265 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
1266 fi
1267}
1268
Ian Wienandaee18c72014-02-21 15:35:08 +11001269function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001270 delete_probe $PUBLIC_NETWORK_NAME
1271 delete_probe $PRIVATE_NETWORK_NAME
1272}
1273
Ian Wienandaee18c72014-02-21 15:35:08 +11001274function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -04001275 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
1276}
1277
Ian Wienandaee18c72014-02-21 15:35:08 +11001278function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001279 local from_net="$1"
1280 net_id=`_get_net_id $from_net`
1281 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`
1282 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1283}
1284
Ian Wienandaee18c72014-02-21 15:35:08 +11001285function _ping_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001286 local from_net=$1
1287 local ip=$2
1288 local timeout_sec=$3
1289 local expected=${4:-"True"}
1290 local check_command=""
1291 probe_cmd=`_get_probe_cmd_prefix $from_net`
1292 if [[ "$expected" = "True" ]]; then
1293 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1294 else
1295 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1296 fi
1297 if ! timeout $timeout_sec sh -c "$check_command"; then
1298 if [[ "$expected" = "True" ]]; then
1299 die $LINENO "[Fail] Couldn't ping server"
1300 else
1301 die $LINENO "[Fail] Could ping server"
1302 fi
1303 fi
1304}
1305
1306# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001307function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001308 local from_net=$1
1309 local key_file=$2
1310 local ip=$3
1311 local user=$4
1312 local timeout_sec=$5
1313 local probe_cmd = ""
1314 probe_cmd=`_get_probe_cmd_prefix $from_net`
1315 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
1316 die $LINENO "server didn't become ssh-able!"
1317 fi
1318}
1319
1320# Neutron 3rd party programs
1321#---------------------------
1322
1323# please refer to ``lib/neutron_thirdparty/README.md`` for details
1324NEUTRON_THIRD_PARTIES=""
1325for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001326 third_party=$(basename $f)
1327 if is_service_enabled $third_party; then
1328 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1329 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1330 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001331done
1332
Ian Wienandaee18c72014-02-21 15:35:08 +11001333function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001334 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1335 ${1}_${third_party}
1336 done
1337}
1338
1339# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001340function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001341 _neutron_third_party_do configure
1342}
1343
1344# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001345function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001346 _neutron_third_party_do init
1347}
1348
1349# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001350function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001351 _neutron_third_party_do install
1352}
1353
1354# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001355function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001356 _neutron_third_party_do start
1357}
1358
1359# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001360function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001361 _neutron_third_party_do stop
1362}
1363
armando-migliaccioef1e0802014-01-02 16:33:53 -08001364# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001365function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001366 _neutron_third_party_do check
1367}
1368
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001369function is_provider_network {
1370 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1371 return 0
1372 fi
1373 return 1
1374}
1375
Mark McClainb05c8762013-07-06 23:29:39 -04001376
1377# Restore xtrace
1378$XTRACE
1379
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001380# Tell emacs to use shell-script-mode
1381## Local variables:
1382## mode: shell-script
1383## End: