blob: 5a2bfea801e1e5193bed2451b340d08e7d9a64e1 [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
Sean Dague2f8e08b2014-12-05 08:31:16 -0500532 if is_provider_network; then
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900533 die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400534 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900535 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 -0700536 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 -0400537 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 -0400538 sudo ip link set $OVS_PHYSICAL_BRIDGE up
539 sudo ip link set br-int up
540 sudo ip link set $PUBLIC_INTERFACE up
Mark McClainb05c8762013-07-06 23:29:39 -0400541 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100542 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500543 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
John Davidge21529a52014-06-30 09:55:11 -0400544
545 if [[ "$IP_VERSION" =~ 4.* ]]; then
546 # Create IPv4 private subnet
547 SUBNET_ID=$(_neutron_create_private_subnet_v4)
548 fi
549
550 if [[ "$IP_VERSION" =~ .*6 ]]; then
551 # Create IPv6 private subnet
552 IPV6_SUBNET_ID=$(_neutron_create_private_subnet_v6)
553 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400554 fi
555
556 if [[ "$Q_L3_ENABLED" == "True" ]]; then
557 # Create a router, and add the private subnet as one of its interfaces
558 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
559 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100560 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500561 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400562 else
563 # Plugin only supports creating a single router, which should be admin owned.
564 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500565 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400566 fi
John Davidge21529a52014-06-30 09:55:11 -0400567
Mark McClainb05c8762013-07-06 23:29:39 -0400568 # Create an external network, and a subnet. Configure the external network as router gw
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900569 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
570 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)
571 else
572 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
573 fi
DennyZhang23178a92013-10-22 17:07:32 -0500574 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400575
John Davidge21529a52014-06-30 09:55:11 -0400576 if [[ "$IP_VERSION" =~ 4.* ]]; then
577 # Configure router for IPv4 public access
578 _neutron_configure_router_v4
579 fi
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900580
John Davidge21529a52014-06-30 09:55:11 -0400581 if [[ "$IP_VERSION" =~ .*6 ]]; then
582 # Configure router for IPv6 public access
583 _neutron_configure_router_v6
Mark McClainb05c8762013-07-06 23:29:39 -0400584 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400585 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400586}
587
588# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100589function init_neutron {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700590 recreate_database $Q_DB_NAME utf8
591 # Run Neutron db migrations
592 $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 -0400593}
594
595# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100596function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400597 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
598 setup_develop $NEUTRON_DIR
Mate Lakat6df64892014-10-17 13:09:49 +0200599
600 if [ "$VIRT_DRIVER" == 'xenserver' ]; then
601 local dom0_ip
602 dom0_ip=$(echo "$XENAPI_CONNECTION_URL" | cut -d "/" -f 3-)
603
604 local ssh_dom0
605 ssh_dom0="sudo -u $DOMZERO_USER ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$dom0_ip"
606
607 # Find where the plugins should go in dom0
608 local xen_functions
609 xen_functions=$(cat $TOP_DIR/tools/xen/functions)
610 local plugin_dir
611 plugin_dir=$($ssh_dom0 "$xen_functions; set -eux; xapi_plugin_location")
612
613 # install neutron plugins to dom0
614 tar -czf - -C $NEUTRON_DIR/neutron/plugins/openvswitch/agent/xenapi/etc/xapi.d/plugins/ ./ |
615 $ssh_dom0 "tar -xzf - -C $plugin_dir && chmod a+x $plugin_dir/*"
616 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400617}
618
619# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100620function install_neutronclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500621 if use_library_from_git "python-neutronclient"; then
622 git_clone_by_name "python-neutronclient"
623 setup_dev_lib "python-neutronclient"
624 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 +0100625 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400626}
627
628# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100629function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400630 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
631 if is_service_enabled q-l3; then
632 install_package radvd
633 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400634 # install packages that are specific to plugin agent(s)
635 if is_service_enabled q-agt q-dhcp q-l3; then
636 neutron_plugin_install_agent_packages
637 fi
638
639 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400640 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400641 fi
642}
643
644# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100645function start_neutron_service_and_check {
Adam Gandelman7614d212014-08-11 14:27:50 -0700646 local cfg_file_options="$(determine_config_files neutron-server)"
Rob Crittenden18d47782014-03-19 17:47:42 -0400647 local service_port=$Q_PORT
648 local service_protocol=$Q_PROTOCOL
649 if is_service_enabled tls-proxy; then
650 service_port=$Q_PORT_INT
651 service_protocol="http"
652 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400653 # Start the Neutron service
Chris Dent2f27a0e2014-09-09 13:46:02 +0100654 run_process q-svc "python $NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400655 echo "Waiting for Neutron to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400656 if is_ssl_enabled_service "neutron"; then
657 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
658 fi
659 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 -0400660 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400661 fi
Rob Crittenden18d47782014-03-19 17:47:42 -0400662 # Start proxy if enabled
663 if is_service_enabled tls-proxy; then
664 start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT &
665 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400666}
667
668# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100669function start_neutron_agents {
Mark McClainb05c8762013-07-06 23:29:39 -0400670 # Start up the neutron agents if enabled
Chris Dent2f27a0e2014-09-09 13:46:02 +0100671 run_process q-agt "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
672 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 -0700673
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400674 if is_provider_network; then
675 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
676 sudo ip link set $OVS_PHYSICAL_BRIDGE up
677 sudo ip link set br-int up
678 sudo ip link set $PUBLIC_INTERFACE up
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700679 if is_ironic_hardware; then
680 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
681 sudo ip addr del $IP dev $PUBLIC_INTERFACE
682 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
683 done
684 sudo route add -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
685 fi
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400686 fi
687
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700688 if is_service_enabled q-vpn; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100689 run_process q-vpn "$AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700690 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100691 run_process q-l3 "python $AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700692 fi
693
Chris Dent2f27a0e2014-09-09 13:46:02 +0100694 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 -0400695
696 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
697 # For XenServer, start an agent for the domU openvswitch
Chris Dent2f27a0e2014-09-09 13:46:02 +0100698 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 -0400699 fi
700
701 if is_service_enabled q-lbaas; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100702 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 -0400703 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200704
705 if is_service_enabled q-metering; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100706 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 +0200707 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400708}
709
710# stop_neutron() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100711function stop_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400712 if is_service_enabled q-dhcp; then
713 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
714 [ ! -z "$pid" ] && sudo kill -9 $pid
715 fi
716 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100717 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400718 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900719
720 if is_service_enabled q-lbaas; then
721 neutron_lbaas_stop
722 fi
723 if is_service_enabled q-fwaas; then
724 neutron_fwaas_stop
725 fi
726 if is_service_enabled q-vpn; then
727 neutron_vpn_stop
728 fi
729 if is_service_enabled q-metering; then
730 neutron_metering_stop
731 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400732}
733
734# cleanup_neutron() - Remove residual data files, anything left over from previous
735# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100736function cleanup_neutron {
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700737 if [[ is_provider_network && is_ironic_hardware ]]; then
738 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
739 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
740 sudo ip addr add $IP dev $PUBLIC_INTERFACE
741 done
742 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
743 fi
744
Mark McClainb05c8762013-07-06 23:29:39 -0400745 if is_neutron_ovs_base_plugin; then
746 neutron_ovs_base_cleanup
747 fi
748
749 # delete all namespaces created by neutron
Brian Haleyeea76212014-06-27 11:45:50 -0400750 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 -0400751 sudo ip netns delete ${ns}
752 done
753}
754
755# _configure_neutron_common()
756# Set common config for all neutron server and agents.
757# This MUST be called before other ``_configure_neutron_*`` functions.
Ian Wienandaee18c72014-02-21 15:35:08 +1100758function _configure_neutron_common {
Mark McClainb05c8762013-07-06 23:29:39 -0400759 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
760 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
761 sudo mkdir -p $NEUTRON_CONF_DIR
762 fi
763 sudo chown $STACK_USER $NEUTRON_CONF_DIR
764
765 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
766
767 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
768 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
769 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
770 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100771 #
Mark McClainb05c8762013-07-06 23:29:39 -0400772 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
773 neutron_plugin_configure_common
774
sbauzae2c4ee22013-08-29 17:29:46 +0200775 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400776 die $LINENO "Neutron plugin not set.. exiting"
777 fi
778
779 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
780 mkdir -p /$Q_PLUGIN_CONF_PATH
781 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
782 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
783
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200784 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400785 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
salvatoree4e535b2014-10-29 18:22:46 +0100786 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
Mark McClainb05c8762013-07-06 23:29:39 -0400787 # If addition config files are set, make sure their path name is set as well
788 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
789 die $LINENO "Neutron additional plugin config not set.. exiting"
790 fi
791
792 # If additional config files exist, copy them over to neutron configuration
793 # directory
794 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400795 local f
796 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
797 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400798 done
799 fi
800
Joe Gordonbee5c502013-08-30 13:48:08 -0400801 if [ "$VIRT_DRIVER" = 'fake' ]; then
802 # Disable arbitrary limits
803 iniset $NEUTRON_CONF quotas quota_network -1
804 iniset $NEUTRON_CONF quotas quota_subnet -1
805 iniset $NEUTRON_CONF quotas quota_port -1
806 iniset $NEUTRON_CONF quotas quota_security_group -1
807 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
808 fi
809
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700810 # Format logging
811 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800812 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700813 fi
814
Rob Crittenden18d47782014-03-19 17:47:42 -0400815 if is_service_enabled tls-proxy; then
816 # Set the service port for a proxy to take the original
817 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
818 fi
819
820 if is_ssl_enabled_service "nova"; then
821 iniset $NEUTRON_CONF DEFAULT nova_ca_certificates_file "$SSL_BUNDLE_FILE"
822 fi
823
824 if is_ssl_enabled_service "neutron"; then
825 ensure_certificates NEUTRON
826
827 iniset $NEUTRON_CONF DEFAULT use_ssl True
828 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
829 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
830 fi
831
Mark McClainb05c8762013-07-06 23:29:39 -0400832 _neutron_setup_rootwrap
833}
834
Ian Wienandaee18c72014-02-21 15:35:08 +1100835function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400836 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
837 return
838 fi
839
840 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
841
842 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
843 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
844 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400845 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
846
Mark McClainb05c8762013-07-06 23:29:39 -0400847 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
848
849 neutron_plugin_configure_debug_command
850}
851
Ian Wienandaee18c72014-02-21 15:35:08 +1100852function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400853
854 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
855
856 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500857 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400858 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
859 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
860
Tan Lin27a196e2014-10-31 15:44:34 +0800861 if ! is_service_enabled q-l3; then
862 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
863 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
864 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
865 else
866 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
867 die "$LINENO" "Enable isolated metadata is a must for metadata network"
868 fi
869 fi
870 fi
871
Mark McClainb05c8762013-07-06 23:29:39 -0400872 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
873
874 neutron_plugin_configure_dhcp_agent
875}
876
Ian Wienandaee18c72014-02-21 15:35:08 +1100877function _configure_neutron_l3_agent {
Paul Michali746dcee2014-04-02 19:12:22 +0000878 local cfg_file
Mark McClainb05c8762013-07-06 23:29:39 -0400879 Q_L3_ENABLED=True
880 # for l3-agent, only use per tenant router if we have namespaces
881 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700882
Paul Michali746dcee2014-04-02 19:12:22 +0000883 if is_service_enabled q-vpn; then
Paul Michali746dcee2014-04-02 19:12:22 +0000884 cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
Paul Michali746dcee2014-04-02 19:12:22 +0000885 fi
886
Mark McClainb05c8762013-07-06 23:29:39 -0400887 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
888
889 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500890 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400891 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
892 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
893
Mark McClainb05c8762013-07-06 23:29:39 -0400894 _neutron_setup_interface_driver $Q_L3_CONF_FILE
895
896 neutron_plugin_configure_l3_agent
897}
898
Ian Wienandaee18c72014-02-21 15:35:08 +1100899function _configure_neutron_metadata_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400900 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
901
902 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500903 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400904 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
905 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
906
Brant Knudson05952372014-09-19 17:22:22 -0500907 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT
Maru Newbybf10ac52013-08-10 21:27:54 +0000908
Mark McClainb05c8762013-07-06 23:29:39 -0400909}
910
Dina Belova58adaa62014-07-11 18:18:12 +0400911function _configure_neutron_ceilometer_notifications {
JordanPd4d4a342014-09-15 09:26:53 +0000912 iniset $NEUTRON_CONF DEFAULT notification_driver messaging
Dina Belova58adaa62014-07-11 18:18:12 +0400913}
914
Ian Wienandaee18c72014-02-21 15:35:08 +1100915function _configure_neutron_lbaas {
Mark McClainb05c8762013-07-06 23:29:39 -0400916 neutron_agent_lbaas_configure_common
917 neutron_agent_lbaas_configure_agent
918}
919
Ian Wienandaee18c72014-02-21 15:35:08 +1100920function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200921 neutron_agent_metering_configure_common
922 neutron_agent_metering_configure_agent
923}
924
Ian Wienandaee18c72014-02-21 15:35:08 +1100925function _configure_neutron_fwaas {
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700926 neutron_fwaas_configure_common
927 neutron_fwaas_configure_driver
928}
929
Ian Wienandaee18c72014-02-21 15:35:08 +1100930function _configure_neutron_vpn {
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700931 neutron_vpn_install_agent_packages
932 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700933}
934
Brian Haleyeea76212014-06-27 11:45:50 -0400935function _configure_dvr {
936 iniset $NEUTRON_CONF DEFAULT router_distributed True
937 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
938}
939
940
Mark McClainb05c8762013-07-06 23:29:39 -0400941# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
942# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100943function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400944 # Specify the default root helper prior to agent configuration to
945 # ensure that an agent's configuration can override the default
946 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
947 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500948 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400949
950 # Configure agent for plugin
951 neutron_plugin_configure_plugin_agent
952}
953
954# _configure_neutron_service() - Set config files for neutron service
955# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100956function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400957 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
958 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
959
960 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
961 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
962
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700963 # allow neutron user to administer neutron to match neutron account
964 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
965
Mark McClainb05c8762013-07-06 23:29:39 -0400966 # Update either configuration file with plugin
967 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
968
969 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
970 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
971 fi
972
973 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500974 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400975 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
976 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
977
978 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
979 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
980
Aaron Rosencea32b12014-03-04 16:20:14 -0800981 # Configuration for neutron notifations to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500982 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
983 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Aaron Rosencea32b12014-03-04 16:20:14 -0800984 iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
Dirk Mueller5ca261a2014-04-04 22:48:02 +0200985 iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800986 iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
987 ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
988 iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
989 iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
990
Mark McClainb05c8762013-07-06 23:29:39 -0400991 # Configure plugin
992 neutron_plugin_configure_service
993}
994
995# Utility Functions
996#------------------
997
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900998# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100999function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +09001000 local service_plugin_class=$1
1001 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1002 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1003 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1004 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1005 fi
1006}
1007
Mark McClainb05c8762013-07-06 23:29:39 -04001008# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +11001009function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -04001010 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1011 return
1012 fi
1013 # Deploy new rootwrap filters files (owned by root).
1014 # Wipe any existing ``rootwrap.d`` files first
1015 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1016 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1017 sudo rm -rf $Q_CONF_ROOTWRAP_D
1018 fi
1019 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
1020 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
1021 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1022 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
1023 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
1024 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1025 # location moved in newer versions, prefer new location
1026 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -04001027 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001028 else
Sean Dague3bdb9222013-10-22 08:36:16 -04001029 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -04001030 fi
1031 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
1032 sudo chown root:root $Q_RR_CONF_FILE
1033 sudo chmod 0644 $Q_RR_CONF_FILE
1034 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1035 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1036
1037 # Set up the rootwrap sudoers for neutron
1038 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +01001039 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -04001040 chmod 0440 $TEMPFILE
1041 sudo chown root:root $TEMPFILE
1042 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1043
1044 # Update the root_helper
1045 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
1046}
1047
1048# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +11001049function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -04001050 local conf_file=$1
1051 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +10001052
Brant Knudson05952372014-09-19 17:22:22 -05001053 create_neutron_cache_dir
1054 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -04001055}
1056
Ian Wienandaee18c72014-02-21 15:35:08 +11001057function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -04001058
1059 # ovs_use_veth needs to be set before the plugin configuration
1060 # occurs to allow plugins to override the setting.
1061 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1062
1063 neutron_plugin_setup_interface_driver $1
1064}
1065
John Davidge21529a52014-06-30 09:55:11 -04001066# Create private IPv4 subnet
1067function _neutron_create_private_subnet_v4 {
1068 local subnet_params="--tenant-id $TENANT_ID "
1069 subnet_params+="--ip_version 4 "
1070 subnet_params+="--gateway $NETWORK_GATEWAY "
1071 subnet_params+="--name $PRIVATE_SUBNET_NAME "
1072 subnet_params+="$NET_ID $FIXED_RANGE"
1073 local subnet_id=$(neutron subnet-create $subnet_params | grep ' id ' | get_field 2)
1074 die_if_not_set $LINENO subnet_id "Failure creating private IPv4 subnet for $TENANT_ID"
1075 echo $subnet_id
1076}
1077
1078# Create private IPv6 subnet
1079function _neutron_create_private_subnet_v6 {
1080 die_if_not_set $LINENO IPV6_RA_MODE "IPV6 RA Mode not set"
1081 die_if_not_set $LINENO IPV6_ADDRESS_MODE "IPV6 Address Mode not set"
1082 local ipv6_modes="--ipv6-ra-mode $IPV6_RA_MODE --ipv6-address-mode $IPV6_ADDRESS_MODE"
1083 local subnet_params="--tenant-id $TENANT_ID "
1084 subnet_params+="--ip_version 6 "
1085 subnet_params+="--gateway $IPV6_PRIVATE_NETWORK_GATEWAY "
1086 subnet_params+="--name $IPV6_PRIVATE_SUBNET_NAME "
1087 subnet_params+="$NET_ID $FIXED_RANGE_V6 $ipv6_modes"
1088 local ipv6_subnet_id=$(neutron subnet-create $subnet_params | grep ' id ' | get_field 2)
1089 die_if_not_set $LINENO ipv6_subnet_id "Failure creating private IPv6 subnet for $TENANT_ID"
1090 echo $ipv6_subnet_id
1091}
1092
1093# Create public IPv4 subnet
1094function _neutron_create_public_subnet_v4 {
1095 local subnet_params+="--ip_version 4 "
1096 subnet_params+="${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} "
1097 subnet_params+="--gateway $PUBLIC_NETWORK_GATEWAY "
1098 subnet_params+="--name $PUBLIC_SUBNET_NAME "
1099 subnet_params+="$EXT_NET_ID $FLOATING_RANGE "
1100 subnet_params+="-- --enable_dhcp=False"
1101 local id_and_ext_gw_ip=$(neutron subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
1102 die_if_not_set $LINENO id_and_ext_gw_ip "Failure creating public IPv4 subnet"
1103 echo $id_and_ext_gw_ip
1104}
1105
1106# Create public IPv6 subnet
1107function _neutron_create_public_subnet_v6 {
1108 local subnet_params="--ip_version 6 "
1109 subnet_params+="--gateway $IPV6_PUBLIC_NETWORK_GATEWAY "
1110 subnet_params+="--name $IPV6_PUBLIC_SUBNET_NAME "
1111 subnet_params+="$EXT_NET_ID $IPV6_PUBLIC_RANGE "
1112 subnet_params+="-- --enable_dhcp=False"
1113 local ipv6_id_and_ext_gw_ip=$(neutron subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
1114 die_if_not_set $LINENO ipv6_id_and_ext_gw_ip "Failure creating an IPv6 public subnet"
1115 echo $ipv6_id_and_ext_gw_ip
1116}
1117
1118# Configure neutron router for IPv4 public access
1119function _neutron_configure_router_v4 {
1120 neutron router-interface-add $ROUTER_ID $SUBNET_ID
1121 # Create a public subnet on the external network
1122 local id_and_ext_gw_ip=$(_neutron_create_public_subnet_v4 $EXT_NET_ID)
1123 local ext_gw_ip=$(echo $id_and_ext_gw_ip | get_field 2)
1124 PUB_SUBNET_ID=$(echo $id_and_ext_gw_ip | get_field 5)
1125 # Configure the external network as the default router gateway
1126 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
1127
1128 # This logic is specific to using the l3-agent for layer 3
1129 if is_service_enabled q-l3; then
1130 # Configure and enable public bridge
1131 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
1132 local ext_gw_interface=$(_neutron_get_ext_gw_interface)
1133 local cidr_len=${FLOATING_RANGE#*/}
1134 sudo ip addr add $ext_gw_ip/$cidr_len dev $ext_gw_interface
1135 sudo ip link set $ext_gw_interface up
1136 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; }'`
1137 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
1138 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
1139 fi
1140 _neutron_set_router_id
1141 fi
1142}
1143
1144# Configure neutron router for IPv6 public access
1145function _neutron_configure_router_v6 {
1146 neutron router-interface-add $ROUTER_ID $IPV6_SUBNET_ID
1147 # Create a public subnet on the external network
1148 local ipv6_id_and_ext_gw_ip=$(_neutron_create_public_subnet_v6 $EXT_NET_ID)
1149 local ipv6_ext_gw_ip=$(echo $ipv6_id_and_ext_gw_ip | get_field 2)
1150 local ipv6_pub_subnet_id=$(echo $ipv6_id_and_ext_gw_ip | get_field 5)
1151
1152 # If the external network has not already been set as the default router
1153 # gateway when configuring an IPv4 public subnet, do so now
1154 if [[ "$IP_VERSION" == "6" ]]; then
1155 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
1156 fi
1157
1158 # This logic is specific to using the l3-agent for layer 3
1159 if is_service_enabled q-l3; then
1160 local ipv6_router_gw_port
1161 # Ensure IPv6 forwarding is enabled on the host
1162 sudo sysctl -w net.ipv6.conf.all.forwarding=1
1163 # Configure and enable public bridge
1164 if [[ "$IP_VERSION" = "6" ]]; then
1165 # Override global IPV6_ROUTER_GW_IP with the true value from neutron
1166 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; }'`
1167 die_if_not_set $LINENO IPV6_ROUTER_GW_IP "Failure retrieving IPV6_ROUTER_GW_IP"
1168 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; }'`
1169 die_if_not_set $LINENO ipv6_router_gw_port "Failure retrieving ipv6_router_gw_port"
1170 else
1171 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; }'`
1172 die_if_not_set $LINENO ipv6_router_gw_port "Failure retrieving ipv6_router_gw_port"
1173 fi
1174
1175 # The ovs_base_configure_l3_agent function flushes the public
1176 # bridge's ip addresses, so turn IPv6 support in the host off
1177 # and then on to recover the public bridge's link local address
1178 sudo sysctl -w net.ipv6.conf.${PUBLIC_BRIDGE}.disable_ipv6=1
1179 sudo sysctl -w net.ipv6.conf.${PUBLIC_BRIDGE}.disable_ipv6=0
1180 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
1181 local ext_gw_interface=$(_neutron_get_ext_gw_interface)
1182 local ipv6_cidr_len=${IPV6_PUBLIC_RANGE#*/}
1183
1184 # Define router_ns based on whether DVR is enabled
1185 local router_ns=qrouter
1186 if [[ "$Q_DVR_MODE" == "dvr_snat" ]]; then
1187 router_ns=snat
1188 fi
1189
1190 # Configure interface for public bridge
1191 sudo ip -6 addr add $ipv6_ext_gw_ip/$ipv6_cidr_len dev $ext_gw_interface
1192
1193 # Wait until layer 3 agent has configured the gateway port on
1194 # the public bridge, then add gateway address to the interface
1195 # TODO (john-davidge) Remove once l3-agent supports dual-stack
1196 if [[ "$IP_VERSION" == "4+6" ]]; then
1197 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
1198 die $LINENO "Timeout retrieving ROUTER_GW_IP"
1199 fi
1200 # Configure the gateway port with the public IPv6 adress
1201 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}
1202 # Add a default IPv6 route to the neutron router as the
1203 # l3-agent does not add one in the dual-stack case
1204 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}
1205 fi
1206 sudo ip -6 route add $FIXED_RANGE_V6 via $IPV6_ROUTER_GW_IP dev $ext_gw_interface
1207 fi
1208 _neutron_set_router_id
1209 fi
1210}
1211
1212# Explicitly set router id in l3 agent configuration
1213function _neutron_set_router_id {
1214 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
1215 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
1216 fi
1217}
1218
1219# Get ext_gw_interface depending on value of Q_USE_PUBLIC_VETH
1220function _neutron_get_ext_gw_interface {
1221 if [[ "$Q_USE_PUBLIC_VETH" == "True" ]]; then
1222 echo $Q_PUBLIC_VETH_EX
1223 else
1224 # Disable in-band as we are going to use local port
1225 # to communicate with VMs
1226 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
1227 other_config:disable-in-band=true
1228 echo $PUBLIC_BRIDGE
1229 fi
1230}
1231
Mark McClainb05c8762013-07-06 23:29:39 -04001232# Functions for Neutron Exercises
1233#--------------------------------
1234
Ian Wienandaee18c72014-02-21 15:35:08 +11001235function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001236 local from_net="$1"
1237 net_id=`_get_net_id $from_net`
1238 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}'`
1239 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1240}
1241
Ian Wienandaee18c72014-02-21 15:35:08 +11001242function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001243 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
1244 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
1245 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
1246 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
1247 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
1248 fi
1249}
1250
Ian Wienandaee18c72014-02-21 15:35:08 +11001251function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001252 delete_probe $PUBLIC_NETWORK_NAME
1253 delete_probe $PRIVATE_NETWORK_NAME
1254}
1255
Ian Wienandaee18c72014-02-21 15:35:08 +11001256function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -04001257 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
1258}
1259
Ian Wienandaee18c72014-02-21 15:35:08 +11001260function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001261 local from_net="$1"
1262 net_id=`_get_net_id $from_net`
1263 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`
1264 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1265}
1266
Ian Wienandaee18c72014-02-21 15:35:08 +11001267function _ping_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001268 local from_net=$1
1269 local ip=$2
1270 local timeout_sec=$3
1271 local expected=${4:-"True"}
1272 local check_command=""
1273 probe_cmd=`_get_probe_cmd_prefix $from_net`
1274 if [[ "$expected" = "True" ]]; then
1275 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1276 else
1277 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1278 fi
1279 if ! timeout $timeout_sec sh -c "$check_command"; then
1280 if [[ "$expected" = "True" ]]; then
1281 die $LINENO "[Fail] Couldn't ping server"
1282 else
1283 die $LINENO "[Fail] Could ping server"
1284 fi
1285 fi
1286}
1287
1288# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001289function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001290 local from_net=$1
1291 local key_file=$2
1292 local ip=$3
1293 local user=$4
1294 local timeout_sec=$5
1295 local probe_cmd = ""
1296 probe_cmd=`_get_probe_cmd_prefix $from_net`
1297 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
1298 die $LINENO "server didn't become ssh-able!"
1299 fi
1300}
1301
1302# Neutron 3rd party programs
1303#---------------------------
1304
1305# please refer to ``lib/neutron_thirdparty/README.md`` for details
1306NEUTRON_THIRD_PARTIES=""
1307for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001308 third_party=$(basename $f)
1309 if is_service_enabled $third_party; then
1310 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1311 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1312 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001313done
1314
Ian Wienandaee18c72014-02-21 15:35:08 +11001315function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001316 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1317 ${1}_${third_party}
1318 done
1319}
1320
1321# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001322function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001323 _neutron_third_party_do configure
1324}
1325
1326# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001327function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001328 _neutron_third_party_do init
1329}
1330
1331# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001332function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001333 _neutron_third_party_do install
1334}
1335
1336# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001337function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001338 _neutron_third_party_do start
1339}
1340
1341# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001342function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001343 _neutron_third_party_do stop
1344}
1345
armando-migliaccioef1e0802014-01-02 16:33:53 -08001346# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001347function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001348 _neutron_third_party_do check
1349}
1350
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001351function is_provider_network {
1352 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1353 return 0
1354 fi
1355 return 1
1356}
1357
Mark McClainb05c8762013-07-06 23:29:39 -04001358
1359# Restore xtrace
1360$XTRACE
1361
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001362# Tell emacs to use shell-script-mode
1363## Local variables:
1364## mode: shell-script
1365## End: