blob: 5ceeb62eb7b5a2e6b397a19409a46ae822ff5dc4 [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
88# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +000089Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -040090# Default Neutron Port
91Q_PORT=${Q_PORT:-9696}
92# Default Neutron Host
93Q_HOST=${Q_HOST:-$SERVICE_HOST}
94# Default admin username
95Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
96# Default auth strategy
97Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
98# Use namespace or not
99Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
100# RHEL's support for namespaces requires using veths with ovs
101Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
102Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
103# Meta data IP
104Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
105# Allow Overlapping IP among subnets
106Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
107# Use neutron-debug command
108Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
109# The name of the default q-l3 router
110Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Aaron Rosen4540d002013-10-24 13:59:33 -0700111# nova vif driver that all plugins should use
112NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500113Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
114Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800115VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
116VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700117
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400118## Provider Network Information
119PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
120
Tomoe Sugiharaafbc6312013-11-14 20:02:47 +0000121# The next two variables are configured by plugin
122# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
123#
124# The plugin supports L3.
125Q_L3_ENABLED=${Q_L3_ENABLED:-False}
126# L3 routers exist per tenant
127Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False}
Aaron Rosen4540d002013-10-24 13:59:33 -0700128
Mark McClainb05c8762013-07-06 23:29:39 -0400129# List of config file names in addition to the main plugin config file
130# See _configure_neutron_common() for details about setting it up
131declare -a Q_PLUGIN_EXTRA_CONF_FILES
132
Paul Michali746dcee2014-04-02 19:12:22 +0000133# List of (optional) config files for VPN device drivers to use with
134# the neutron-q-vpn agent
135declare -a Q_VPN_EXTRA_CONF_FILES
136
Mark McClainb05c8762013-07-06 23:29:39 -0400137
Dean Troyere2907b42014-02-26 17:35:37 -0600138Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
139if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
140 Q_RR_COMMAND="sudo"
141else
142 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
143 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400144fi
145
Dean Troyere2907b42014-02-26 17:35:37 -0600146# Provider Network Configurations
147# --------------------------------
148
149# The following variables control the Neutron openvswitch and
150# linuxbridge plugins' allocation of tenant networks and
151# availability of provider networks. If these are not configured
152# in ``localrc``, tenant networks will be local to the host (with no
153# remote connectivity), and no physical resources will be
154# available for the allocation of provider networks.
155
156# To use GRE tunnels for tenant networks, set to True in
157# ``localrc``. GRE tunnels are only supported by the openvswitch
158# plugin, and currently only on Ubuntu.
159ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False}
160
161# If using GRE tunnels for tenant networks, specify the range of
162# tunnel IDs from which tenant networks are allocated. Can be
163# overriden in ``localrc`` in necesssary.
Anant Patil3827dc02014-07-03 21:38:16 +0530164TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600165
166# To use VLANs for tenant networks, set to True in localrc. VLANs
167# are supported by the openvswitch and linuxbridge plugins, each
168# requiring additional configuration described below.
169ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
170
171# If using VLANs for tenant networks, set in ``localrc`` to specify
172# the range of VLAN VIDs from which tenant networks are
173# allocated. An external network switch must be configured to
174# trunk these VLANs between hosts for multi-host connectivity.
175#
176# Example: ``TENANT_VLAN_RANGE=1000:1999``
177TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
178
179# If using VLANs for tenant networks, or if using flat or VLAN
180# provider networks, set in ``localrc`` to the name of the physical
181# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
182# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
183# agent, as described below.
184#
185# Example: ``PHYSICAL_NETWORK=default``
186PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
187
188# With the openvswitch plugin, if using VLANs for tenant networks,
189# or if using flat or VLAN provider networks, set in ``localrc`` to
190# the name of the OVS bridge to use for the physical network. The
191# bridge will be created if it does not already exist, but a
192# physical interface must be manually added to the bridge as a
193# port for external connectivity.
194#
195# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
196OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
197
198# With the linuxbridge plugin, if using VLANs for tenant networks,
199# or if using flat or VLAN provider networks, set in ``localrc`` to
200# the name of the network interface to use for the physical
201# network.
202#
203# Example: ``LB_PHYSICAL_INTERFACE=eth1``
204LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
205
Edgar Magana6f335b92014-07-10 15:42:44 -0700206# When Neutron tunnels are enabled it is needed to specify the
207# IP address of the end point in the local server. This IP is set
208# by default to the same IP address that the HOST IP.
209# This variable can be used to specify a different end point IP address
210# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
211TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
212
Dean Troyere2907b42014-02-26 17:35:37 -0600213# With the openvswitch plugin, set to True in ``localrc`` to enable
214# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
215#
216# Example: ``OVS_ENABLE_TUNNELING=True``
217OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
218
Mark McClainb05c8762013-07-06 23:29:39 -0400219# Neutron plugin specific functions
220# ---------------------------------
221
222# Please refer to ``lib/neutron_plugins/README.md`` for details.
223source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
224
225# Agent loadbalancer service plugin functions
226# -------------------------------------------
227
228# Hardcoding for 1 service plugin for now
229source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
230
Emilien Macchi40546f72013-09-24 15:10:25 +0200231# Agent metering service plugin functions
232# -------------------------------------------
233
234# Hardcoding for 1 service plugin for now
235source $TOP_DIR/lib/neutron_plugins/services/metering
236
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700237# VPN service plugin functions
238# -------------------------------------------
239# Hardcoding for 1 service plugin for now
240source $TOP_DIR/lib/neutron_plugins/services/vpn
241
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700242# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100243# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700244source $TOP_DIR/lib/neutron_plugins/services/firewall
245
Mark McClainb05c8762013-07-06 23:29:39 -0400246# Use security group or not
247if has_neutron_plugin_security_group; then
248 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
249else
250 Q_USE_SECGROUP=False
251fi
252
Dean Troyer4237f592014-01-29 16:22:11 -0600253# Tell Tempest this project is present
254TEMPEST_SERVICES+=,neutron
255
256
Dean Troyere2907b42014-02-26 17:35:37 -0600257# Save trace setting
258XTRACE=$(set +o | grep xtrace)
259set +o xtrace
260
261
Mark McClainb05c8762013-07-06 23:29:39 -0400262# Functions
263# ---------
264
Dean Troyere4fa7212014-01-15 15:04:49 -0600265# Test if any Neutron services are enabled
266# is_neutron_enabled
267function is_neutron_enabled {
268 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
269 return 1
270}
271
Mark McClainb05c8762013-07-06 23:29:39 -0400272# configure_neutron()
273# Set common config for all neutron server and agents.
Ian Wienandaee18c72014-02-21 15:35:08 +1100274function configure_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400275 _configure_neutron_common
276 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
277
278 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
279 if is_service_enabled q-lbaas; then
280 _configure_neutron_lbaas
281 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200282 if is_service_enabled q-metering; then
283 _configure_neutron_metering
284 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700285 if is_service_enabled q-vpn; then
286 _configure_neutron_vpn
287 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700288 if is_service_enabled q-fwaas; then
289 _configure_neutron_fwaas
290 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000291 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400292 _configure_neutron_service
293 fi
294 if is_service_enabled q-agt; then
295 _configure_neutron_plugin_agent
296 fi
297 if is_service_enabled q-dhcp; then
298 _configure_neutron_dhcp_agent
299 fi
300 if is_service_enabled q-l3; then
301 _configure_neutron_l3_agent
302 fi
303 if is_service_enabled q-meta; then
304 _configure_neutron_metadata_agent
305 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400306 if is_service_enabled ceilometer; then
307 _configure_neutron_ceilometer_notifications
308 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400309
310 _configure_neutron_debug_command
311}
312
Ian Wienandaee18c72014-02-21 15:35:08 +1100313function create_nova_conf_neutron {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800314 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
Gary Kotton13d385e2014-06-17 23:24:53 -0700315 iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME"
316 iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD"
317 iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
318 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
319 iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME"
Bartosz Górski0abde392014-02-28 14:15:19 +0100320 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Gary Kotton13d385e2014-06-17 23:24:53 -0700321 iniset $NOVA_CONF neutron url "http://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400322
323 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
324 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400325 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800326 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400327 fi
328
329 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
330 neutron_plugin_create_nova_conf
331
Gary Kotton51c681d2014-04-22 01:40:56 -0700332 iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER"
Mark McClainb05c8762013-07-06 23:29:39 -0400333 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
334 if is_service_enabled q-meta; then
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800335 iniset $NOVA_CONF DEFAULT service_neutron_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400336 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800337
338 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
339 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400340}
341
Emilien Macchia677b7f2013-11-25 23:40:20 +0100342# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100343function create_neutron_cache_dir {
Emilien Macchia677b7f2013-11-25 23:40:20 +0100344 # Create cache dir
345 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
346 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
347 rm -f $NEUTRON_AUTH_CACHE_DIR/*
348}
349
Mark McClainb05c8762013-07-06 23:29:39 -0400350# create_neutron_accounts() - Set up common required neutron accounts
351
352# Tenant User Roles
353# ------------------------------------------------------------------
354# service neutron admin # if enabled
355
356# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100357function create_neutron_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400358
Steve Martinelli19685422014-01-24 13:02:26 -0600359 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
360 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Mark McClainb05c8762013-07-06 23:29:39 -0400361
362 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100363
364 NEUTRON_USER=$(get_or_create_user "neutron" \
Gael Chamoulaud6dd8a8b2014-07-22 01:12:12 +0200365 "$SERVICE_PASSWORD" $SERVICE_TENANT)
Bartosz Górski0abde392014-02-28 14:15:19 +0100366 get_or_add_user_role $ADMIN_ROLE $NEUTRON_USER $SERVICE_TENANT
367
Mark McClainb05c8762013-07-06 23:29:39 -0400368 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100369
370 NEUTRON_SERVICE=$(get_or_create_service "neutron" \
371 "network" "Neutron Service")
372 get_or_create_endpoint $NEUTRON_SERVICE \
373 "$REGION_NAME" \
374 "http://$SERVICE_HOST:9696/" \
375 "http://$SERVICE_HOST:9696/" \
376 "http://$SERVICE_HOST:9696/"
Mark McClainb05c8762013-07-06 23:29:39 -0400377 fi
378 fi
379}
380
Ian Wienandaee18c72014-02-21 15:35:08 +1100381function create_neutron_initial_network {
Steve Martinelli19685422014-01-24 13:02:26 -0600382 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500383 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400384
385 # Create a small network
386 # Since neutron command is executed in admin context at this point,
Dirk Mueller25049cd2014-01-09 13:53:52 +0100387 # ``--tenant-id`` needs to be specified.
Mark McClainb05c8762013-07-06 23:29:39 -0400388 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200389 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
390 die $LINENO "Neutron settings for baremetal not set.. exiting"
391 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400392 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
393 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
394 sudo ip addr del $IP dev $PUBLIC_INTERFACE
395 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
396 done
Dirk Mueller25049cd2014-01-09 13:53:52 +0100397 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 -0500398 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100399 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 -0500400 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400401 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200402 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400403 elif is_provider_network; then
404 die_if_not_set $LINENO SEGMENTATION_ID "A SEGMENTATION_ID is required to use provider networking"
405 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
Sean M. Collins21e6c622014-06-16 11:19:48 -0400406 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 -0400407 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 -0400408 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 -0400409 sudo ip link set $OVS_PHYSICAL_BRIDGE up
410 sudo ip link set br-int up
411 sudo ip link set $PUBLIC_INTERFACE up
Mark McClainb05c8762013-07-06 23:29:39 -0400412 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100413 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500414 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100415 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 -0500416 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400417 fi
418
419 if [[ "$Q_L3_ENABLED" == "True" ]]; then
420 # Create a router, and add the private subnet as one of its interfaces
421 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
422 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100423 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500424 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400425 else
426 # Plugin only supports creating a single router, which should be admin owned.
427 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500428 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400429 fi
430 neutron router-interface-add $ROUTER_ID $SUBNET_ID
431 # Create an external network, and a subnet. Configure the external network as router gw
432 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500433 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400434 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 -0500435 die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400436 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
437
438 if is_service_enabled q-l3; then
439 # logic is specific to using the l3-agent for l3
440 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
441 CIDR_LEN=${FLOATING_RANGE#*/}
442 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
443 sudo ip link set $PUBLIC_BRIDGE up
444 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 -0500445 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400446 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
447 fi
448 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
449 # Explicitly set router id in l3 agent configuration
450 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
451 fi
452 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400453 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400454}
455
456# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100457function init_neutron {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700458 recreate_database $Q_DB_NAME utf8
459 # Run Neutron db migrations
460 $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 -0400461}
462
463# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100464function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400465 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
466 setup_develop $NEUTRON_DIR
467}
468
469# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100470function install_neutronclient {
Mark McClainb05c8762013-07-06 23:29:39 -0400471 git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH
472 setup_develop $NEUTRONCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200473 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 -0400474}
475
476# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100477function install_neutron_agent_packages {
Mark McClainb05c8762013-07-06 23:29:39 -0400478 # install packages that are specific to plugin agent(s)
479 if is_service_enabled q-agt q-dhcp q-l3; then
480 neutron_plugin_install_agent_packages
481 fi
482
483 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400484 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400485 fi
486}
487
488# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100489function start_neutron_service_and_check {
Mark McClainb05c8762013-07-06 23:29:39 -0400490 # build config-file options
491 local cfg_file
492 local CFG_FILE_OPTIONS="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
493 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
Sean Dague3bdb9222013-10-22 08:36:16 -0400494 CFG_FILE_OPTIONS+=" --config-file /$cfg_file"
Mark McClainb05c8762013-07-06 23:29:39 -0400495 done
496 # Start the Neutron service
497 screen_it q-svc "cd $NEUTRON_DIR && python $NEUTRON_BIN_DIR/neutron-server $CFG_FILE_OPTIONS"
498 echo "Waiting for Neutron to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800499 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 -0400500 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400501 fi
502}
503
504# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100505function start_neutron_agents {
Mark McClainb05c8762013-07-06 23:29:39 -0400506 # Start up the neutron agents if enabled
507 screen_it q-agt "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
508 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 -0700509
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700510 L3_CONF_FILES="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
511
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400512 if is_provider_network; then
513 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
514 sudo ip link set $OVS_PHYSICAL_BRIDGE up
515 sudo ip link set br-int up
516 sudo ip link set $PUBLIC_INTERFACE up
517 fi
518
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700519 if is_service_enabled q-fwaas; then
520 L3_CONF_FILES="$L3_CONF_FILES --config-file $Q_FWAAS_CONF_FILE"
Adam Gandelmancf1ef232014-04-21 17:09:52 -0700521 VPN_CONF_FILES="$VPN_CONF_FILES --config-file $Q_FWAAS_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700522 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700523 if is_service_enabled q-vpn; then
Paul Michali746dcee2014-04-02 19:12:22 +0000524 screen_it q-vpn "cd $NEUTRON_DIR && $AGENT_VPN_BINARY $VPN_CONF_FILES"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700525 else
526 screen_it q-l3 "cd $NEUTRON_DIR && python $AGENT_L3_BINARY $L3_CONF_FILES"
527 fi
528
Mark McClainb05c8762013-07-06 23:29:39 -0400529 screen_it q-meta "cd $NEUTRON_DIR && python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
530
531 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
532 # For XenServer, start an agent for the domU openvswitch
533 screen_it q-domua "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
534 fi
535
536 if is_service_enabled q-lbaas; then
537 screen_it q-lbaas "cd $NEUTRON_DIR && python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
538 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200539
540 if is_service_enabled q-metering; then
541 screen_it q-metering "cd $NEUTRON_DIR && python $AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
542 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400543}
544
545# stop_neutron() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100546function stop_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400547 if is_service_enabled q-dhcp; then
548 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
549 [ ! -z "$pid" ] && sudo kill -9 $pid
550 fi
551 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100552 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400553 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900554
555 if is_service_enabled q-lbaas; then
556 neutron_lbaas_stop
557 fi
558 if is_service_enabled q-fwaas; then
559 neutron_fwaas_stop
560 fi
561 if is_service_enabled q-vpn; then
562 neutron_vpn_stop
563 fi
564 if is_service_enabled q-metering; then
565 neutron_metering_stop
566 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400567}
568
569# cleanup_neutron() - Remove residual data files, anything left over from previous
570# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100571function cleanup_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400572 if is_neutron_ovs_base_plugin; then
573 neutron_ovs_base_cleanup
574 fi
575
576 # delete all namespaces created by neutron
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900577 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|qlbaas)-[0-9a-f-]*'); do
Mark McClainb05c8762013-07-06 23:29:39 -0400578 sudo ip netns delete ${ns}
579 done
580}
581
582# _configure_neutron_common()
583# Set common config for all neutron server and agents.
584# This MUST be called before other ``_configure_neutron_*`` functions.
Ian Wienandaee18c72014-02-21 15:35:08 +1100585function _configure_neutron_common {
Mark McClainb05c8762013-07-06 23:29:39 -0400586 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
587 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
588 sudo mkdir -p $NEUTRON_CONF_DIR
589 fi
590 sudo chown $STACK_USER $NEUTRON_CONF_DIR
591
592 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
593
594 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
595 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
596 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
597 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100598 #
Mark McClainb05c8762013-07-06 23:29:39 -0400599 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
600 neutron_plugin_configure_common
601
sbauzae2c4ee22013-08-29 17:29:46 +0200602 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400603 die $LINENO "Neutron plugin not set.. exiting"
604 fi
605
606 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
607 mkdir -p /$Q_PLUGIN_CONF_PATH
608 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
609 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
610
611 iniset /$Q_PLUGIN_CONF_FILE database connection `database_connection_url $Q_DB_NAME`
612 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
613
614 # If addition config files are set, make sure their path name is set as well
615 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
616 die $LINENO "Neutron additional plugin config not set.. exiting"
617 fi
618
619 # If additional config files exist, copy them over to neutron configuration
620 # directory
621 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400622 local f
623 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
624 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400625 done
626 fi
627
Joe Gordonbee5c502013-08-30 13:48:08 -0400628 if [ "$VIRT_DRIVER" = 'fake' ]; then
629 # Disable arbitrary limits
630 iniset $NEUTRON_CONF quotas quota_network -1
631 iniset $NEUTRON_CONF quotas quota_subnet -1
632 iniset $NEUTRON_CONF quotas quota_port -1
633 iniset $NEUTRON_CONF quotas quota_security_group -1
634 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
635 fi
636
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700637 # Format logging
638 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800639 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700640 fi
641
Mark McClainb05c8762013-07-06 23:29:39 -0400642 _neutron_setup_rootwrap
643}
644
Ian Wienandaee18c72014-02-21 15:35:08 +1100645function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400646 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
647 return
648 fi
649
650 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
651
652 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
653 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
654 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400655 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
656
Mark McClainb05c8762013-07-06 23:29:39 -0400657 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
658
659 neutron_plugin_configure_debug_command
660}
661
Ian Wienandaee18c72014-02-21 15:35:08 +1100662function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400663 AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
664 Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
665
666 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
667
668 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500669 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400670 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
671 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
672
Kyle Mestery73b21912013-08-22 11:25:21 +0000673 # Define extra "DEFAULT" configuration options when q-dhcp is configured by
674 # defining the array ``Q_DHCP_EXTRA_DEFAULT_OPTS``.
675 # For Example: ``Q_DHCP_EXTRA_DEFAULT_OPTS=(foo=true bar=2)``
676 for I in "${Q_DHCP_EXTRA_DEFAULT_OPTS[@]}"; do
677 # Replace the first '=' with ' ' for iniset syntax
678 iniset $Q_DHCP_CONF_FILE DEFAULT ${I/=/ }
679 done
680
Mark McClainb05c8762013-07-06 23:29:39 -0400681 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
682
683 neutron_plugin_configure_dhcp_agent
684}
685
Ian Wienandaee18c72014-02-21 15:35:08 +1100686function _configure_neutron_l3_agent {
Paul Michali746dcee2014-04-02 19:12:22 +0000687 local cfg_file
Mark McClainb05c8762013-07-06 23:29:39 -0400688 Q_L3_ENABLED=True
689 # for l3-agent, only use per tenant router if we have namespaces
690 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700691
692 AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
Mark McClainb05c8762013-07-06 23:29:39 -0400693 Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
694
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700695 if is_service_enabled q-fwaas; then
696 Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
697 fi
698
Paul Michali746dcee2014-04-02 19:12:22 +0000699 if is_service_enabled q-vpn; then
700 Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
701 cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
702 VPN_CONF_FILES="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
703 for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
704 VPN_CONF_FILES+=" --config-file $cfg_file"
705 done
706 fi
707
Mark McClainb05c8762013-07-06 23:29:39 -0400708 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
709
710 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500711 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400712 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
713 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
714
Mark McClainb05c8762013-07-06 23:29:39 -0400715 _neutron_setup_interface_driver $Q_L3_CONF_FILE
716
717 neutron_plugin_configure_l3_agent
718}
719
Ian Wienandaee18c72014-02-21 15:35:08 +1100720function _configure_neutron_metadata_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400721 AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
722 Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
723
724 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
725
726 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500727 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400728 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
729 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
730
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000731 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT True True
Maru Newbybf10ac52013-08-10 21:27:54 +0000732
Mark McClainb05c8762013-07-06 23:29:39 -0400733}
734
Dina Belova58adaa62014-07-11 18:18:12 +0400735function _configure_neutron_ceilometer_notifications {
736 iniset $NEUTRON_CONF DEFAULT notification_driver neutron.openstack.common.notifier.rpc_notifier
737}
738
Ian Wienandaee18c72014-02-21 15:35:08 +1100739function _configure_neutron_lbaas {
Mark McClainb05c8762013-07-06 23:29:39 -0400740 neutron_agent_lbaas_configure_common
741 neutron_agent_lbaas_configure_agent
742}
743
Ian Wienandaee18c72014-02-21 15:35:08 +1100744function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200745 neutron_agent_metering_configure_common
746 neutron_agent_metering_configure_agent
747}
748
Ian Wienandaee18c72014-02-21 15:35:08 +1100749function _configure_neutron_fwaas {
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700750 neutron_fwaas_configure_common
751 neutron_fwaas_configure_driver
752}
753
Ian Wienandaee18c72014-02-21 15:35:08 +1100754function _configure_neutron_vpn {
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700755 neutron_vpn_install_agent_packages
756 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700757}
758
Mark McClainb05c8762013-07-06 23:29:39 -0400759# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
760# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100761function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400762 # Specify the default root helper prior to agent configuration to
763 # ensure that an agent's configuration can override the default
764 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
765 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500766 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400767
768 # Configure agent for plugin
769 neutron_plugin_configure_plugin_agent
770}
771
772# _configure_neutron_service() - Set config files for neutron service
773# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100774function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400775 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
776 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
777
778 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
779 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
780
Mark McClainb05c8762013-07-06 23:29:39 -0400781 # Update either configuration file with plugin
782 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
783
784 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
785 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
786 fi
787
788 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500789 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400790 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
791 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
792
793 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
794 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
795
Simon Pasquierca96b0a2013-07-09 16:59:12 +0200796 # Define extra "DEFAULT" configuration options when q-svc is configured by
797 # defining the array ``Q_SRV_EXTRA_DEFAULT_OPTS``.
798 # For Example: ``Q_SRV_EXTRA_DEFAULT_OPTS=(foo=true bar=2)``
799 for I in "${Q_SRV_EXTRA_DEFAULT_OPTS[@]}"; do
800 # Replace the first '=' with ' ' for iniset syntax
801 iniset $NEUTRON_CONF DEFAULT ${I/=/ }
802 done
803
Aaron Rosencea32b12014-03-04 16:20:14 -0800804 # Configuration for neutron notifations to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500805 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
806 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Aaron Rosencea32b12014-03-04 16:20:14 -0800807 iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
Dirk Mueller5ca261a2014-04-04 22:48:02 +0200808 iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800809 iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
810 ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
811 iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
812 iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
813
Mark McClainb05c8762013-07-06 23:29:39 -0400814 # Configure plugin
815 neutron_plugin_configure_service
816}
817
818# Utility Functions
819#------------------
820
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900821# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100822function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900823 local service_plugin_class=$1
824 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
825 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
826 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
827 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
828 fi
829}
830
Mark McClainb05c8762013-07-06 23:29:39 -0400831# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100832function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400833 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
834 return
835 fi
836 # Deploy new rootwrap filters files (owned by root).
837 # Wipe any existing ``rootwrap.d`` files first
838 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
839 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
840 sudo rm -rf $Q_CONF_ROOTWRAP_D
841 fi
842 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
843 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
844 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
845 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
846 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
847 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
848 # location moved in newer versions, prefer new location
849 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400850 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400851 else
Sean Dague3bdb9222013-10-22 08:36:16 -0400852 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400853 fi
854 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
855 sudo chown root:root $Q_RR_CONF_FILE
856 sudo chmod 0644 $Q_RR_CONF_FILE
857 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
858 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
859
860 # Set up the rootwrap sudoers for neutron
861 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100862 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400863 chmod 0440 $TEMPFILE
864 sudo chown root:root $TEMPFILE
865 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
866
867 # Update the root_helper
868 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
869}
870
871# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +1100872function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -0400873 local conf_file=$1
874 local section=$2
875 local use_auth_url=$3
Maru Newbybf10ac52013-08-10 21:27:54 +0000876 local skip_auth_cache=$4
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000877
878 iniset $conf_file $section auth_uri $KEYSTONE_SERVICE_URI
879 iniset $conf_file $section identity_uri $KEYSTONE_AUTH_URI
Mark McClainb05c8762013-07-06 23:29:39 -0400880 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
881 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
882 iniset $conf_file $section admin_password $SERVICE_PASSWORD
Maru Newbybf10ac52013-08-10 21:27:54 +0000883 if [[ -z $skip_auth_cache ]]; then
884 iniset $conf_file $section signing_dir $NEUTRON_AUTH_CACHE_DIR
885 # Create cache dir
Emilien Macchia677b7f2013-11-25 23:40:20 +0100886 create_neutron_cache_dir
Maru Newbybf10ac52013-08-10 21:27:54 +0000887 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400888}
889
Ian Wienandaee18c72014-02-21 15:35:08 +1100890function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -0400891
892 # ovs_use_veth needs to be set before the plugin configuration
893 # occurs to allow plugins to override the setting.
894 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
895
896 neutron_plugin_setup_interface_driver $1
897}
898
899# Functions for Neutron Exercises
900#--------------------------------
901
Ian Wienandaee18c72014-02-21 15:35:08 +1100902function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -0400903 local from_net="$1"
904 net_id=`_get_net_id $from_net`
905 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}'`
906 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
907}
908
Ian Wienandaee18c72014-02-21 15:35:08 +1100909function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -0400910 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
911 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
912 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
913 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
914 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
915 fi
916}
917
Ian Wienandaee18c72014-02-21 15:35:08 +1100918function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -0400919 delete_probe $PUBLIC_NETWORK_NAME
920 delete_probe $PRIVATE_NETWORK_NAME
921}
922
Ian Wienandaee18c72014-02-21 15:35:08 +1100923function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -0400924 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
925}
926
Ian Wienandaee18c72014-02-21 15:35:08 +1100927function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -0400928 local from_net="$1"
929 net_id=`_get_net_id $from_net`
930 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`
931 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
932}
933
Ian Wienandaee18c72014-02-21 15:35:08 +1100934function _ping_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400935 local from_net=$1
936 local ip=$2
937 local timeout_sec=$3
938 local expected=${4:-"True"}
939 local check_command=""
940 probe_cmd=`_get_probe_cmd_prefix $from_net`
941 if [[ "$expected" = "True" ]]; then
942 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
943 else
944 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
945 fi
946 if ! timeout $timeout_sec sh -c "$check_command"; then
947 if [[ "$expected" = "True" ]]; then
948 die $LINENO "[Fail] Couldn't ping server"
949 else
950 die $LINENO "[Fail] Could ping server"
951 fi
952 fi
953}
954
955# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +1100956function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400957 local from_net=$1
958 local key_file=$2
959 local ip=$3
960 local user=$4
961 local timeout_sec=$5
962 local probe_cmd = ""
963 probe_cmd=`_get_probe_cmd_prefix $from_net`
964 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
965 die $LINENO "server didn't become ssh-able!"
966 fi
967}
968
969# Neutron 3rd party programs
970#---------------------------
971
972# please refer to ``lib/neutron_thirdparty/README.md`` for details
973NEUTRON_THIRD_PARTIES=""
974for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -0400975 third_party=$(basename $f)
976 if is_service_enabled $third_party; then
977 source $TOP_DIR/lib/neutron_thirdparty/$third_party
978 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
979 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400980done
981
Ian Wienandaee18c72014-02-21 15:35:08 +1100982function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -0400983 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
984 ${1}_${third_party}
985 done
986}
987
988# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100989function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -0400990 _neutron_third_party_do configure
991}
992
993# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100994function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -0400995 _neutron_third_party_do init
996}
997
998# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100999function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001000 _neutron_third_party_do install
1001}
1002
1003# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001004function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001005 _neutron_third_party_do start
1006}
1007
1008# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001009function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001010 _neutron_third_party_do stop
1011}
1012
armando-migliaccioef1e0802014-01-02 16:33:53 -08001013# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001014function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001015 _neutron_third_party_do check
1016}
1017
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001018function is_provider_network {
1019 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1020 return 0
1021 fi
1022 return 1
1023}
1024
Mark McClainb05c8762013-07-06 23:29:39 -04001025
1026# Restore xtrace
1027$XTRACE
1028
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001029# Tell emacs to use shell-script-mode
1030## Local variables:
1031## mode: shell-script
1032## End: