blob: 573fd6fbb0f5881a826bcc41b82c16fbd70fa20a [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
23# - create_neutron_initial_network
24# - setup_neutron_debug
25# - start_neutron_agents
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
Mark McClainb05c8762013-07-06 23:29:39 -040030
31# Functions in lib/neutron are classified into the following categories:
32#
33# - entry points (called from stack.sh or unstack.sh)
34# - internal functions
35# - neutron exercises
36# - 3rd party programs
37
38
39# Neutron Networking
40# ------------------
41
42# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
43# to run Neutron on this host, make sure that q-svc is also in
44# ``ENABLED_SERVICES``.
45#
46# If you're planning to use the Neutron openvswitch plugin, set
47# ``Q_PLUGIN`` to "openvswitch" and make sure the q-agt service is enabled
48# in ``ENABLED_SERVICES``. If you're planning to use the Neutron
49# linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the
50# q-agt service is enabled in ``ENABLED_SERVICES``.
51#
52# See "Neutron Network Configuration" below for additional variables
53# that must be set in localrc for connectivity across hosts with
54# Neutron.
55#
56# With Neutron networking the NETWORK_MANAGER variable is ignored.
57#
58# To enable specific configuration options for either the Open vSwitch or
59# LinuxBridge plugin, please see the top level README file under the
60# Neutron section.
61
Mark McClainb05c8762013-07-06 23:29:39 -040062
63# Neutron Network Configuration
64# -----------------------------
65
66# Gateway and subnet defaults, in case they are not customized in localrc
67NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
Salvatore Orlando90234ac2013-11-25 05:44:10 -080068PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
Mark McClainb05c8762013-07-06 23:29:39 -040069PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
70PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
71
72# Set up default directories
73NEUTRON_DIR=$DEST/neutron
74NEUTRONCLIENT_DIR=$DEST/python-neutronclient
75NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
76
77# Support entry points installation of console scripts
78if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
79 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040080else
81 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040082fi
83
84NEUTRON_CONF_DIR=/etc/neutron
85NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
86export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
87
Henry Gessau0fc1cc22014-07-06 22:54:34 -040088# Default name for Neutron database
89Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -040090# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +000091Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -040092# Default Neutron Port
93Q_PORT=${Q_PORT:-9696}
94# Default Neutron Host
95Q_HOST=${Q_HOST:-$SERVICE_HOST}
96# Default admin username
97Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
98# Default auth strategy
99Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
100# Use namespace or not
101Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
102# RHEL's support for namespaces requires using veths with ovs
103Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
104Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
105# Meta data IP
106Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
107# Allow Overlapping IP among subnets
108Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
109# Use neutron-debug command
110Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
111# The name of the default q-l3 router
112Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Aaron Rosen4540d002013-10-24 13:59:33 -0700113# nova vif driver that all plugins should use
114NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500115Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
116Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800117VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
118VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700119
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400120## Provider Network Information
121PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
122
Tomoe Sugiharaafbc6312013-11-14 20:02:47 +0000123# The next two variables are configured by plugin
124# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
125#
126# The plugin supports L3.
127Q_L3_ENABLED=${Q_L3_ENABLED:-False}
128# L3 routers exist per tenant
129Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False}
Aaron Rosen4540d002013-10-24 13:59:33 -0700130
Mark McClainb05c8762013-07-06 23:29:39 -0400131# List of config file names in addition to the main plugin config file
132# See _configure_neutron_common() for details about setting it up
133declare -a Q_PLUGIN_EXTRA_CONF_FILES
134
Paul Michali746dcee2014-04-02 19:12:22 +0000135# List of (optional) config files for VPN device drivers to use with
136# the neutron-q-vpn agent
137declare -a Q_VPN_EXTRA_CONF_FILES
138
Mark McClainb05c8762013-07-06 23:29:39 -0400139
Dean Troyere2907b42014-02-26 17:35:37 -0600140Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
141if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
142 Q_RR_COMMAND="sudo"
143else
144 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
145 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400146fi
147
Brian Haleyeea76212014-06-27 11:45:50 -0400148
149# Distributed Virtual Router (DVR) configuration
150# Can be:
151# legacy - No DVR functionality
152# dvr_snat - Controller or single node DVR
153# dvr - Compute node in multi-node DVR
154Q_DVR_MODE=${Q_DVR_MODE:-legacy}
155if [[ "$Q_DVR_MODE" != "legacy" ]]; then
156 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
157fi
158
Dean Troyere2907b42014-02-26 17:35:37 -0600159# Provider Network Configurations
160# --------------------------------
161
162# The following variables control the Neutron openvswitch and
163# linuxbridge plugins' allocation of tenant networks and
164# availability of provider networks. If these are not configured
165# in ``localrc``, tenant networks will be local to the host (with no
166# remote connectivity), and no physical resources will be
167# available for the allocation of provider networks.
168
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200169# To disable tunnels (GRE or VXLAN) for tenant networks,
170# set to False in ``local.conf``.
171# GRE tunnels are only supported by the openvswitch.
172ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600173
174# If using GRE tunnels for tenant networks, specify the range of
175# tunnel IDs from which tenant networks are allocated. Can be
176# overriden in ``localrc`` in necesssary.
Anant Patil3827dc02014-07-03 21:38:16 +0530177TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600178
179# To use VLANs for tenant networks, set to True in localrc. VLANs
180# are supported by the openvswitch and linuxbridge plugins, each
181# requiring additional configuration described below.
182ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
183
184# If using VLANs for tenant networks, set in ``localrc`` to specify
185# the range of VLAN VIDs from which tenant networks are
186# allocated. An external network switch must be configured to
187# trunk these VLANs between hosts for multi-host connectivity.
188#
189# Example: ``TENANT_VLAN_RANGE=1000:1999``
190TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
191
192# If using VLANs for tenant networks, or if using flat or VLAN
193# provider networks, set in ``localrc`` to the name of the physical
194# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
195# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
196# agent, as described below.
197#
198# Example: ``PHYSICAL_NETWORK=default``
199PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
200
201# With the openvswitch plugin, if using VLANs for tenant networks,
202# or if using flat or VLAN provider networks, set in ``localrc`` to
203# the name of the OVS bridge to use for the physical network. The
204# bridge will be created if it does not already exist, but a
205# physical interface must be manually added to the bridge as a
206# port for external connectivity.
207#
208# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
209OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
210
211# With the linuxbridge plugin, if using VLANs for tenant networks,
212# or if using flat or VLAN provider networks, set in ``localrc`` to
213# the name of the network interface to use for the physical
214# network.
215#
216# Example: ``LB_PHYSICAL_INTERFACE=eth1``
217LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
218
Edgar Magana6f335b92014-07-10 15:42:44 -0700219# When Neutron tunnels are enabled it is needed to specify the
220# IP address of the end point in the local server. This IP is set
221# by default to the same IP address that the HOST IP.
222# This variable can be used to specify a different end point IP address
223# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
224TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
225
Dean Troyere2907b42014-02-26 17:35:37 -0600226# With the openvswitch plugin, set to True in ``localrc`` to enable
227# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
228#
229# Example: ``OVS_ENABLE_TUNNELING=True``
230OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
231
Tan Lin27a196e2014-10-31 15:44:34 +0800232# Use DHCP agent for providing metadata service in the case of
233# without L3 agent (No Route Agent), set to True in localrc.
234ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
235
236# Add a static route as dhcp option, so the request to 169.254.169.254
237# will be able to reach through a route(DHCP agent)
238# This option require ENABLE_ISOLATED_METADATA = True
239ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
Mark McClainb05c8762013-07-06 23:29:39 -0400240# Neutron plugin specific functions
241# ---------------------------------
242
243# Please refer to ``lib/neutron_plugins/README.md`` for details.
244source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
245
246# Agent loadbalancer service plugin functions
247# -------------------------------------------
248
249# Hardcoding for 1 service plugin for now
250source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
251
Emilien Macchi40546f72013-09-24 15:10:25 +0200252# Agent metering service plugin functions
253# -------------------------------------------
254
255# Hardcoding for 1 service plugin for now
256source $TOP_DIR/lib/neutron_plugins/services/metering
257
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700258# VPN service plugin functions
259# -------------------------------------------
260# Hardcoding for 1 service plugin for now
261source $TOP_DIR/lib/neutron_plugins/services/vpn
262
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700263# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100264# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700265source $TOP_DIR/lib/neutron_plugins/services/firewall
266
Mark McClainb05c8762013-07-06 23:29:39 -0400267# Use security group or not
268if has_neutron_plugin_security_group; then
269 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
270else
271 Q_USE_SECGROUP=False
272fi
273
Dean Troyer4237f592014-01-29 16:22:11 -0600274# Tell Tempest this project is present
275TEMPEST_SERVICES+=,neutron
276
277
Dean Troyere2907b42014-02-26 17:35:37 -0600278# Save trace setting
279XTRACE=$(set +o | grep xtrace)
280set +o xtrace
281
282
Mark McClainb05c8762013-07-06 23:29:39 -0400283# Functions
284# ---------
285
Dean Troyere4fa7212014-01-15 15:04:49 -0600286# Test if any Neutron services are enabled
287# is_neutron_enabled
288function is_neutron_enabled {
289 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
290 return 1
291}
292
Mark McClainb05c8762013-07-06 23:29:39 -0400293# configure_neutron()
294# Set common config for all neutron server and agents.
Ian Wienandaee18c72014-02-21 15:35:08 +1100295function configure_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400296 _configure_neutron_common
297 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
298
299 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
300 if is_service_enabled q-lbaas; then
301 _configure_neutron_lbaas
302 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200303 if is_service_enabled q-metering; then
304 _configure_neutron_metering
305 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700306 if is_service_enabled q-vpn; then
307 _configure_neutron_vpn
308 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700309 if is_service_enabled q-fwaas; then
310 _configure_neutron_fwaas
311 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000312 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400313 _configure_neutron_service
314 fi
315 if is_service_enabled q-agt; then
316 _configure_neutron_plugin_agent
317 fi
318 if is_service_enabled q-dhcp; then
319 _configure_neutron_dhcp_agent
320 fi
321 if is_service_enabled q-l3; then
322 _configure_neutron_l3_agent
323 fi
324 if is_service_enabled q-meta; then
325 _configure_neutron_metadata_agent
326 fi
327
Brian Haleyeea76212014-06-27 11:45:50 -0400328 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
329 _configure_dvr
330 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400331 if is_service_enabled ceilometer; then
332 _configure_neutron_ceilometer_notifications
333 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400334
335 _configure_neutron_debug_command
336}
337
Ian Wienandaee18c72014-02-21 15:35:08 +1100338function create_nova_conf_neutron {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800339 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
Gary Kotton13d385e2014-06-17 23:24:53 -0700340 iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME"
341 iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD"
342 iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
343 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
344 iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME"
Bartosz Górski0abde392014-02-28 14:15:19 +0100345 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Gary Kotton13d385e2014-06-17 23:24:53 -0700346 iniset $NOVA_CONF neutron url "http://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400347
348 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
349 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400350 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800351 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400352 fi
353
354 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
355 neutron_plugin_create_nova_conf
356
Gary Kotton51c681d2014-04-22 01:40:56 -0700357 iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER"
Mark McClainb05c8762013-07-06 23:29:39 -0400358 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
359 if is_service_enabled q-meta; then
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800360 iniset $NOVA_CONF DEFAULT service_neutron_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400361 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800362
363 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
364 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400365}
366
Emilien Macchia677b7f2013-11-25 23:40:20 +0100367# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100368function create_neutron_cache_dir {
Emilien Macchia677b7f2013-11-25 23:40:20 +0100369 # Create cache dir
370 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
371 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
372 rm -f $NEUTRON_AUTH_CACHE_DIR/*
373}
374
Mark McClainb05c8762013-07-06 23:29:39 -0400375# create_neutron_accounts() - Set up common required neutron accounts
376
377# Tenant User Roles
378# ------------------------------------------------------------------
379# service neutron admin # if enabled
380
381# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100382function create_neutron_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400383
Steve Martinelli19685422014-01-24 13:02:26 -0600384 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
385 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Mark McClainb05c8762013-07-06 23:29:39 -0400386
387 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100388
389 NEUTRON_USER=$(get_or_create_user "neutron" \
Gael Chamoulaud6dd8a8b2014-07-22 01:12:12 +0200390 "$SERVICE_PASSWORD" $SERVICE_TENANT)
Bartosz Górski0abde392014-02-28 14:15:19 +0100391 get_or_add_user_role $ADMIN_ROLE $NEUTRON_USER $SERVICE_TENANT
392
Mark McClainb05c8762013-07-06 23:29:39 -0400393 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100394
395 NEUTRON_SERVICE=$(get_or_create_service "neutron" \
396 "network" "Neutron Service")
397 get_or_create_endpoint $NEUTRON_SERVICE \
398 "$REGION_NAME" \
Aaron Rosen186119c2014-07-25 15:35:09 -0700399 "http://$SERVICE_HOST:$Q_PORT/" \
400 "http://$SERVICE_HOST:$Q_PORT/" \
401 "http://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400402 fi
403 fi
404}
405
Ian Wienandaee18c72014-02-21 15:35:08 +1100406function create_neutron_initial_network {
Steve Martinelli19685422014-01-24 13:02:26 -0600407 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500408 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400409
410 # Create a small network
411 # Since neutron command is executed in admin context at this point,
Dirk Mueller25049cd2014-01-09 13:53:52 +0100412 # ``--tenant-id`` needs to be specified.
Mark McClainb05c8762013-07-06 23:29:39 -0400413 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200414 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
415 die $LINENO "Neutron settings for baremetal not set.. exiting"
416 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400417 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
418 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
419 sudo ip addr del $IP dev $PUBLIC_INTERFACE
420 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
421 done
Dirk Mueller25049cd2014-01-09 13:53:52 +0100422 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 -0500423 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100424 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 -0500425 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400426 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200427 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400428 elif is_provider_network; then
429 die_if_not_set $LINENO SEGMENTATION_ID "A SEGMENTATION_ID is required to use provider networking"
430 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
Sean M. Collins21e6c622014-06-16 11:19:48 -0400431 NET_ID=$(neutron net-create $PHYSICAL_NETWORK --tenant_id $TENANT_ID --provider:network_type $PROVIDER_NETWORK_TYPE --provider:physical_network "$PHYSICAL_NETWORK" --provider:segmentation_id "$SEGMENTATION_ID" --shared | grep ' id ' | get_field 2)
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400432 SUBNET_ID=$(neutron subnet-create --tenant_id $TENANT_ID --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --name $PROVIDER_SUBNET_NAME $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
Sean M. Collinse13fd602014-05-14 17:01:53 -0400433 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 -0400434 sudo ip link set $OVS_PHYSICAL_BRIDGE up
435 sudo ip link set br-int up
436 sudo ip link set $PUBLIC_INTERFACE up
Mark McClainb05c8762013-07-06 23:29:39 -0400437 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100438 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500439 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100440 SUBNET_ID=$(neutron subnet-create --tenant-id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY --name $PRIVATE_SUBNET_NAME $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500441 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400442 fi
443
444 if [[ "$Q_L3_ENABLED" == "True" ]]; then
445 # Create a router, and add the private subnet as one of its interfaces
446 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
447 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100448 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500449 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400450 else
451 # Plugin only supports creating a single router, which should be admin owned.
452 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500453 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400454 fi
455 neutron router-interface-add $ROUTER_ID $SUBNET_ID
456 # Create an external network, and a subnet. Configure the external network as router gw
457 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500458 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400459 EXT_GW_IP=$(neutron subnet-create --ip_version 4 ${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} --gateway $PUBLIC_NETWORK_GATEWAY --name $PUBLIC_SUBNET_NAME $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500460 die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400461 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
462
463 if is_service_enabled q-l3; then
464 # logic is specific to using the l3-agent for l3
465 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
466 CIDR_LEN=${FLOATING_RANGE#*/}
467 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
468 sudo ip link set $PUBLIC_BRIDGE up
469 ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'`
DennyZhang23178a92013-10-22 17:07:32 -0500470 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400471 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
472 fi
473 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
474 # Explicitly set router id in l3 agent configuration
475 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
476 fi
477 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400478 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400479}
480
481# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100482function init_neutron {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700483 recreate_database $Q_DB_NAME utf8
484 # Run Neutron db migrations
485 $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 -0400486}
487
488# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100489function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400490 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
491 setup_develop $NEUTRON_DIR
492}
493
494# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100495function install_neutronclient {
Mark McClainb05c8762013-07-06 23:29:39 -0400496 git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH
497 setup_develop $NEUTRONCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200498 sudo install -D -m 0644 -o $STACK_USER {$NEUTRONCLIENT_DIR/tools/,/etc/bash_completion.d/}neutron.bash_completion
Mark McClainb05c8762013-07-06 23:29:39 -0400499}
500
501# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100502function install_neutron_agent_packages {
Mark McClainb05c8762013-07-06 23:29:39 -0400503 # install packages that are specific to plugin agent(s)
504 if is_service_enabled q-agt q-dhcp q-l3; then
505 neutron_plugin_install_agent_packages
506 fi
507
508 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400509 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400510 fi
511}
512
513# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100514function start_neutron_service_and_check {
Mark McClainb05c8762013-07-06 23:29:39 -0400515 # build config-file options
516 local cfg_file
517 local CFG_FILE_OPTIONS="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
518 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
Sean Dague3bdb9222013-10-22 08:36:16 -0400519 CFG_FILE_OPTIONS+=" --config-file /$cfg_file"
Mark McClainb05c8762013-07-06 23:29:39 -0400520 done
521 # Start the Neutron service
522 screen_it q-svc "cd $NEUTRON_DIR && python $NEUTRON_BIN_DIR/neutron-server $CFG_FILE_OPTIONS"
523 echo "Waiting for Neutron to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800524 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400525 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400526 fi
527}
528
529# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100530function start_neutron_agents {
Mark McClainb05c8762013-07-06 23:29:39 -0400531 # Start up the neutron agents if enabled
532 screen_it q-agt "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
533 screen_it q-dhcp "cd $NEUTRON_DIR && python $AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file=$Q_DHCP_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700534
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700535 L3_CONF_FILES="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
536
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400537 if is_provider_network; then
538 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
539 sudo ip link set $OVS_PHYSICAL_BRIDGE up
540 sudo ip link set br-int up
541 sudo ip link set $PUBLIC_INTERFACE up
542 fi
543
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700544 if is_service_enabled q-fwaas; then
545 L3_CONF_FILES="$L3_CONF_FILES --config-file $Q_FWAAS_CONF_FILE"
Adam Gandelmancf1ef232014-04-21 17:09:52 -0700546 VPN_CONF_FILES="$VPN_CONF_FILES --config-file $Q_FWAAS_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700547 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700548 if is_service_enabled q-vpn; then
Paul Michali746dcee2014-04-02 19:12:22 +0000549 screen_it q-vpn "cd $NEUTRON_DIR && $AGENT_VPN_BINARY $VPN_CONF_FILES"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700550 else
551 screen_it q-l3 "cd $NEUTRON_DIR && python $AGENT_L3_BINARY $L3_CONF_FILES"
552 fi
553
Mark McClainb05c8762013-07-06 23:29:39 -0400554 screen_it q-meta "cd $NEUTRON_DIR && python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
555
556 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
557 # For XenServer, start an agent for the domU openvswitch
558 screen_it q-domua "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
559 fi
560
561 if is_service_enabled q-lbaas; then
562 screen_it q-lbaas "cd $NEUTRON_DIR && python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
563 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200564
565 if is_service_enabled q-metering; then
566 screen_it q-metering "cd $NEUTRON_DIR && python $AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
567 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400568}
569
570# stop_neutron() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100571function stop_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400572 if is_service_enabled q-dhcp; then
573 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
574 [ ! -z "$pid" ] && sudo kill -9 $pid
575 fi
576 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100577 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400578 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900579
580 if is_service_enabled q-lbaas; then
581 neutron_lbaas_stop
582 fi
583 if is_service_enabled q-fwaas; then
584 neutron_fwaas_stop
585 fi
586 if is_service_enabled q-vpn; then
587 neutron_vpn_stop
588 fi
589 if is_service_enabled q-metering; then
590 neutron_metering_stop
591 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400592}
593
594# cleanup_neutron() - Remove residual data files, anything left over from previous
595# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100596function cleanup_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400597 if is_neutron_ovs_base_plugin; then
598 neutron_ovs_base_cleanup
599 fi
600
601 # delete all namespaces created by neutron
Brian Haleyeea76212014-06-27 11:45:50 -0400602 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 -0400603 sudo ip netns delete ${ns}
604 done
605}
606
607# _configure_neutron_common()
608# Set common config for all neutron server and agents.
609# This MUST be called before other ``_configure_neutron_*`` functions.
Ian Wienandaee18c72014-02-21 15:35:08 +1100610function _configure_neutron_common {
Mark McClainb05c8762013-07-06 23:29:39 -0400611 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
612 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
613 sudo mkdir -p $NEUTRON_CONF_DIR
614 fi
615 sudo chown $STACK_USER $NEUTRON_CONF_DIR
616
617 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
618
619 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
620 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
621 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
622 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100623 #
Mark McClainb05c8762013-07-06 23:29:39 -0400624 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
625 neutron_plugin_configure_common
626
sbauzae2c4ee22013-08-29 17:29:46 +0200627 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400628 die $LINENO "Neutron plugin not set.. exiting"
629 fi
630
631 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
632 mkdir -p /$Q_PLUGIN_CONF_PATH
633 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
634 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
635
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200636 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400637 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
638
639 # If addition config files are set, make sure their path name is set as well
640 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
641 die $LINENO "Neutron additional plugin config not set.. exiting"
642 fi
643
644 # If additional config files exist, copy them over to neutron configuration
645 # directory
646 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400647 local f
648 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
649 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400650 done
651 fi
652
Joe Gordonbee5c502013-08-30 13:48:08 -0400653 if [ "$VIRT_DRIVER" = 'fake' ]; then
654 # Disable arbitrary limits
655 iniset $NEUTRON_CONF quotas quota_network -1
656 iniset $NEUTRON_CONF quotas quota_subnet -1
657 iniset $NEUTRON_CONF quotas quota_port -1
658 iniset $NEUTRON_CONF quotas quota_security_group -1
659 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
660 fi
661
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700662 # Format logging
663 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800664 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700665 fi
666
Mark McClainb05c8762013-07-06 23:29:39 -0400667 _neutron_setup_rootwrap
668}
669
Ian Wienandaee18c72014-02-21 15:35:08 +1100670function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400671 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
672 return
673 fi
674
675 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
676
677 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
678 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
679 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400680 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
681
Mark McClainb05c8762013-07-06 23:29:39 -0400682 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
683
684 neutron_plugin_configure_debug_command
685}
686
Ian Wienandaee18c72014-02-21 15:35:08 +1100687function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400688 AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
689 Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
690
691 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
692
693 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500694 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400695 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
696 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
697
Tan Lin27a196e2014-10-31 15:44:34 +0800698 if ! is_service_enabled q-l3; then
699 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
700 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
701 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
702 else
703 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
704 die "$LINENO" "Enable isolated metadata is a must for metadata network"
705 fi
706 fi
707 fi
708
Mark McClainb05c8762013-07-06 23:29:39 -0400709 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
710
711 neutron_plugin_configure_dhcp_agent
712}
713
Ian Wienandaee18c72014-02-21 15:35:08 +1100714function _configure_neutron_l3_agent {
Paul Michali746dcee2014-04-02 19:12:22 +0000715 local cfg_file
Mark McClainb05c8762013-07-06 23:29:39 -0400716 Q_L3_ENABLED=True
717 # for l3-agent, only use per tenant router if we have namespaces
718 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700719
720 AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
Mark McClainb05c8762013-07-06 23:29:39 -0400721 Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
722
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700723 if is_service_enabled q-fwaas; then
724 Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
725 fi
726
Paul Michali746dcee2014-04-02 19:12:22 +0000727 if is_service_enabled q-vpn; then
728 Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
729 cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
730 VPN_CONF_FILES="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
731 for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
732 VPN_CONF_FILES+=" --config-file $cfg_file"
733 done
734 fi
735
Mark McClainb05c8762013-07-06 23:29:39 -0400736 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
737
738 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500739 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400740 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
741 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
742
Mark McClainb05c8762013-07-06 23:29:39 -0400743 _neutron_setup_interface_driver $Q_L3_CONF_FILE
744
745 neutron_plugin_configure_l3_agent
746}
747
Ian Wienandaee18c72014-02-21 15:35:08 +1100748function _configure_neutron_metadata_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400749 AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
750 Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
751
752 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
753
754 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500755 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400756 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
757 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
758
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000759 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT True True
Maru Newbybf10ac52013-08-10 21:27:54 +0000760
Mark McClainb05c8762013-07-06 23:29:39 -0400761}
762
Dina Belova58adaa62014-07-11 18:18:12 +0400763function _configure_neutron_ceilometer_notifications {
764 iniset $NEUTRON_CONF DEFAULT notification_driver neutron.openstack.common.notifier.rpc_notifier
765}
766
Ian Wienandaee18c72014-02-21 15:35:08 +1100767function _configure_neutron_lbaas {
Mark McClainb05c8762013-07-06 23:29:39 -0400768 neutron_agent_lbaas_configure_common
769 neutron_agent_lbaas_configure_agent
770}
771
Ian Wienandaee18c72014-02-21 15:35:08 +1100772function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200773 neutron_agent_metering_configure_common
774 neutron_agent_metering_configure_agent
775}
776
Ian Wienandaee18c72014-02-21 15:35:08 +1100777function _configure_neutron_fwaas {
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700778 neutron_fwaas_configure_common
779 neutron_fwaas_configure_driver
780}
781
Ian Wienandaee18c72014-02-21 15:35:08 +1100782function _configure_neutron_vpn {
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700783 neutron_vpn_install_agent_packages
784 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700785}
786
Brian Haleyeea76212014-06-27 11:45:50 -0400787function _configure_dvr {
788 iniset $NEUTRON_CONF DEFAULT router_distributed True
789 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
790}
791
792
Mark McClainb05c8762013-07-06 23:29:39 -0400793# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
794# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100795function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400796 # Specify the default root helper prior to agent configuration to
797 # ensure that an agent's configuration can override the default
798 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
799 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500800 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400801
802 # Configure agent for plugin
803 neutron_plugin_configure_plugin_agent
804}
805
806# _configure_neutron_service() - Set config files for neutron service
807# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100808function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400809 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
810 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
811
812 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
813 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
814
Mark McClainb05c8762013-07-06 23:29:39 -0400815 # Update either configuration file with plugin
816 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
817
818 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
819 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
820 fi
821
822 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500823 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400824 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
825 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
826
827 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
828 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
829
Aaron Rosencea32b12014-03-04 16:20:14 -0800830 # Configuration for neutron notifations to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500831 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
832 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Aaron Rosencea32b12014-03-04 16:20:14 -0800833 iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
Dirk Mueller5ca261a2014-04-04 22:48:02 +0200834 iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800835 iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
836 ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
837 iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
838 iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
839
Mark McClainb05c8762013-07-06 23:29:39 -0400840 # Configure plugin
841 neutron_plugin_configure_service
842}
843
844# Utility Functions
845#------------------
846
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900847# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100848function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900849 local service_plugin_class=$1
850 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
851 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
852 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
853 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
854 fi
855}
856
Mark McClainb05c8762013-07-06 23:29:39 -0400857# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100858function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400859 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
860 return
861 fi
862 # Deploy new rootwrap filters files (owned by root).
863 # Wipe any existing ``rootwrap.d`` files first
864 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
865 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
866 sudo rm -rf $Q_CONF_ROOTWRAP_D
867 fi
868 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
869 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
870 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
871 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
872 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
873 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
874 # location moved in newer versions, prefer new location
875 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400876 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400877 else
Sean Dague3bdb9222013-10-22 08:36:16 -0400878 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400879 fi
880 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
881 sudo chown root:root $Q_RR_CONF_FILE
882 sudo chmod 0644 $Q_RR_CONF_FILE
883 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
884 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
885
886 # Set up the rootwrap sudoers for neutron
887 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100888 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400889 chmod 0440 $TEMPFILE
890 sudo chown root:root $TEMPFILE
891 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
892
893 # Update the root_helper
894 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
895}
896
897# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +1100898function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -0400899 local conf_file=$1
900 local section=$2
901 local use_auth_url=$3
Maru Newbybf10ac52013-08-10 21:27:54 +0000902 local skip_auth_cache=$4
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000903
904 iniset $conf_file $section auth_uri $KEYSTONE_SERVICE_URI
905 iniset $conf_file $section identity_uri $KEYSTONE_AUTH_URI
Mark McClainb05c8762013-07-06 23:29:39 -0400906 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
907 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
908 iniset $conf_file $section admin_password $SERVICE_PASSWORD
Maru Newbybf10ac52013-08-10 21:27:54 +0000909 if [[ -z $skip_auth_cache ]]; then
910 iniset $conf_file $section signing_dir $NEUTRON_AUTH_CACHE_DIR
911 # Create cache dir
Emilien Macchia677b7f2013-11-25 23:40:20 +0100912 create_neutron_cache_dir
Maru Newbybf10ac52013-08-10 21:27:54 +0000913 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400914}
915
Ian Wienandaee18c72014-02-21 15:35:08 +1100916function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -0400917
918 # ovs_use_veth needs to be set before the plugin configuration
919 # occurs to allow plugins to override the setting.
920 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
921
922 neutron_plugin_setup_interface_driver $1
923}
924
925# Functions for Neutron Exercises
926#--------------------------------
927
Ian Wienandaee18c72014-02-21 15:35:08 +1100928function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -0400929 local from_net="$1"
930 net_id=`_get_net_id $from_net`
931 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}'`
932 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
933}
934
Ian Wienandaee18c72014-02-21 15:35:08 +1100935function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -0400936 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
937 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
938 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
939 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
940 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
941 fi
942}
943
Ian Wienandaee18c72014-02-21 15:35:08 +1100944function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -0400945 delete_probe $PUBLIC_NETWORK_NAME
946 delete_probe $PRIVATE_NETWORK_NAME
947}
948
Ian Wienandaee18c72014-02-21 15:35:08 +1100949function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -0400950 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
951}
952
Ian Wienandaee18c72014-02-21 15:35:08 +1100953function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -0400954 local from_net="$1"
955 net_id=`_get_net_id $from_net`
956 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`
957 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
958}
959
Ian Wienandaee18c72014-02-21 15:35:08 +1100960function _ping_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400961 local from_net=$1
962 local ip=$2
963 local timeout_sec=$3
964 local expected=${4:-"True"}
965 local check_command=""
966 probe_cmd=`_get_probe_cmd_prefix $from_net`
967 if [[ "$expected" = "True" ]]; then
968 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
969 else
970 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
971 fi
972 if ! timeout $timeout_sec sh -c "$check_command"; then
973 if [[ "$expected" = "True" ]]; then
974 die $LINENO "[Fail] Couldn't ping server"
975 else
976 die $LINENO "[Fail] Could ping server"
977 fi
978 fi
979}
980
981# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +1100982function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400983 local from_net=$1
984 local key_file=$2
985 local ip=$3
986 local user=$4
987 local timeout_sec=$5
988 local probe_cmd = ""
989 probe_cmd=`_get_probe_cmd_prefix $from_net`
990 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
991 die $LINENO "server didn't become ssh-able!"
992 fi
993}
994
995# Neutron 3rd party programs
996#---------------------------
997
998# please refer to ``lib/neutron_thirdparty/README.md`` for details
999NEUTRON_THIRD_PARTIES=""
1000for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001001 third_party=$(basename $f)
1002 if is_service_enabled $third_party; then
1003 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1004 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1005 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001006done
1007
Ian Wienandaee18c72014-02-21 15:35:08 +11001008function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001009 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1010 ${1}_${third_party}
1011 done
1012}
1013
1014# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001015function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001016 _neutron_third_party_do configure
1017}
1018
1019# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001020function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001021 _neutron_third_party_do init
1022}
1023
1024# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001025function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001026 _neutron_third_party_do install
1027}
1028
1029# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001030function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001031 _neutron_third_party_do start
1032}
1033
1034# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001035function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001036 _neutron_third_party_do stop
1037}
1038
armando-migliaccioef1e0802014-01-02 16:33:53 -08001039# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001040function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001041 _neutron_third_party_do check
1042}
1043
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001044function is_provider_network {
1045 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1046 return 0
1047 fi
1048 return 1
1049}
1050
Mark McClainb05c8762013-07-06 23:29:39 -04001051
1052# Restore xtrace
1053$XTRACE
1054
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001055# Tell emacs to use shell-script-mode
1056## Local variables:
1057## mode: shell-script
1058## End: