blob: 5b3ac9f42efe297daafc5ae776a76bf096fa75d4 [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#
Mark McClainb05c8762013-07-06 23:29:39 -040046# See "Neutron Network Configuration" below for additional variables
47# that must be set in localrc for connectivity across hosts with
48# Neutron.
49#
50# With Neutron networking the NETWORK_MANAGER variable is ignored.
Mark McClainb05c8762013-07-06 23:29:39 -040051
Mark McClainb05c8762013-07-06 23:29:39 -040052
53# Neutron Network Configuration
54# -----------------------------
55
56# Gateway and subnet defaults, in case they are not customized in localrc
57NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
Salvatore Orlando90234ac2013-11-25 05:44:10 -080058PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
Mark McClainb05c8762013-07-06 23:29:39 -040059PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
60PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
61
Rob Crittenden18d47782014-03-19 17:47:42 -040062if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then
63 Q_PROTOCOL="https"
64fi
65
66
Mark McClainb05c8762013-07-06 23:29:39 -040067# Set up default directories
68NEUTRON_DIR=$DEST/neutron
69NEUTRONCLIENT_DIR=$DEST/python-neutronclient
70NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
71
72# Support entry points installation of console scripts
73if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
74 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040075else
76 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040077fi
78
79NEUTRON_CONF_DIR=/etc/neutron
80NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
81export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
82
Adam Gandelman7614d212014-08-11 14:27:50 -070083# Agent binaries. Note, binary paths for other agents are set in per-service
84# scripts in lib/neutron_plugins/services/
85AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
86AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
87AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
88
89# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
90# loaded from per-plugin scripts in lib/neutron_plugins/
91Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
92Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
93Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
94Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
95Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
96
Henry Gessau0fc1cc22014-07-06 22:54:34 -040097# Default name for Neutron database
98Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -040099# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000100Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400101# Default Neutron Port
102Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400103# Default Neutron Internal Port when using TLS proxy
104Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400105# Default Neutron Host
106Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400107# Default protocol
108Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Mark McClainb05c8762013-07-06 23:29:39 -0400109# Default admin username
110Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
111# Default auth strategy
112Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
113# Use namespace or not
114Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
115# RHEL's support for namespaces requires using veths with ovs
116Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
117Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
118# Meta data IP
119Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
120# Allow Overlapping IP among subnets
121Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
122# Use neutron-debug command
123Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
124# The name of the default q-l3 router
125Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Aaron Rosen4540d002013-10-24 13:59:33 -0700126# nova vif driver that all plugins should use
127NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500128Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
129Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800130VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
131VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700132
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400133## Provider Network Information
134PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
135
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900136# Use flat providernet for public network
137#
138# If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network
139# for external interface of neutron l3-agent. In that case,
140# PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900141# used for the network. In case of ofagent, you should add the
142# corresponding entry to your OFAGENT_PHYSICAL_INTERFACE_MAPPINGS.
143# For openvswitch agent, you should add the corresponding entry to
144# your OVS_BRIDGE_MAPPINGS.
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900145#
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900146# eg. (ofagent)
147# Q_USE_PROVIDERNET_FOR_PUBLIC=True
148# Q_USE_PUBLIC_VETH=True
149# PUBLIC_PHYSICAL_NETWORK=public
150# OFAGENT_PHYSICAL_INTERFACE_MAPPINGS=public:veth-pub-int
151#
152# eg. (openvswitch agent)
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900153# Q_USE_PROVIDERNET_FOR_PUBLIC=True
154# PUBLIC_PHYSICAL_NETWORK=public
155# OVS_BRIDGE_MAPPINGS=public:br-ex
156Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-False}
157PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public}
158
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900159# If Q_USE_PUBLIC_VETH=True, create and use a veth pair instead of
160# PUBLIC_BRIDGE. This is intended to be used with
161# Q_USE_PROVIDERNET_FOR_PUBLIC=True.
162Q_USE_PUBLIC_VETH=${Q_USE_PUBLIC_VETH:-False}
163Q_PUBLIC_VETH_EX=${Q_PUBLIC_VETH_EX:-veth-pub-ex}
164Q_PUBLIC_VETH_INT=${Q_PUBLIC_VETH_INT:-veth-pub-int}
165
Tomoe Sugiharaafbc6312013-11-14 20:02:47 +0000166# The next two variables are configured by plugin
167# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
168#
169# The plugin supports L3.
170Q_L3_ENABLED=${Q_L3_ENABLED:-False}
171# L3 routers exist per tenant
172Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False}
Aaron Rosen4540d002013-10-24 13:59:33 -0700173
Mark McClainb05c8762013-07-06 23:29:39 -0400174# List of config file names in addition to the main plugin config file
175# See _configure_neutron_common() for details about setting it up
176declare -a Q_PLUGIN_EXTRA_CONF_FILES
177
Paul Michali746dcee2014-04-02 19:12:22 +0000178# List of (optional) config files for VPN device drivers to use with
179# the neutron-q-vpn agent
180declare -a Q_VPN_EXTRA_CONF_FILES
181
Mark McClainb05c8762013-07-06 23:29:39 -0400182
Dean Troyere2907b42014-02-26 17:35:37 -0600183Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
184if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
185 Q_RR_COMMAND="sudo"
186else
187 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
188 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400189fi
190
Brian Haleyeea76212014-06-27 11:45:50 -0400191
192# Distributed Virtual Router (DVR) configuration
193# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500194# - ``legacy`` - No DVR functionality
195# - ``dvr_snat`` - Controller or single node DVR
196# - ``dvr`` - Compute node in multi-node DVR
197#
Brian Haleyeea76212014-06-27 11:45:50 -0400198Q_DVR_MODE=${Q_DVR_MODE:-legacy}
199if [[ "$Q_DVR_MODE" != "legacy" ]]; then
200 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
201fi
202
Dean Troyere2907b42014-02-26 17:35:37 -0600203# Provider Network Configurations
204# --------------------------------
205
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900206# The following variables control the Neutron ML2 plugins' allocation
207# of tenant networks and availability of provider networks. If these
208# are not configured in ``localrc``, tenant networks will be local to
209# the host (with no remote connectivity), and no physical resources
210# will be available for the allocation of provider networks.
Dean Troyere2907b42014-02-26 17:35:37 -0600211
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200212# To disable tunnels (GRE or VXLAN) for tenant networks,
213# set to False in ``local.conf``.
214# GRE tunnels are only supported by the openvswitch.
215ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600216
217# If using GRE tunnels for tenant networks, specify the range of
218# tunnel IDs from which tenant networks are allocated. Can be
219# overriden in ``localrc`` in necesssary.
Anant Patil3827dc02014-07-03 21:38:16 +0530220TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600221
222# To use VLANs for tenant networks, set to True in localrc. VLANs
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900223# are supported by the ML2 plugins, requiring additional configuration
224# described below.
Dean Troyere2907b42014-02-26 17:35:37 -0600225ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
226
227# If using VLANs for tenant networks, set in ``localrc`` to specify
228# the range of VLAN VIDs from which tenant networks are
229# allocated. An external network switch must be configured to
230# trunk these VLANs between hosts for multi-host connectivity.
231#
232# Example: ``TENANT_VLAN_RANGE=1000:1999``
233TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
234
235# If using VLANs for tenant networks, or if using flat or VLAN
236# provider networks, set in ``localrc`` to the name of the physical
237# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
238# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
239# agent, as described below.
240#
241# Example: ``PHYSICAL_NETWORK=default``
242PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
243
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900244# With the openvswitch agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600245# or if using flat or VLAN provider networks, set in ``localrc`` to
246# the name of the OVS bridge to use for the physical network. The
247# bridge will be created if it does not already exist, but a
248# physical interface must be manually added to the bridge as a
249# port for external connectivity.
250#
251# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
252OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
253
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900254# With the linuxbridge agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600255# or if using flat or VLAN provider networks, set in ``localrc`` to
256# the name of the network interface to use for the physical
257# network.
258#
259# Example: ``LB_PHYSICAL_INTERFACE=eth1``
260LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
261
Edgar Magana6f335b92014-07-10 15:42:44 -0700262# When Neutron tunnels are enabled it is needed to specify the
263# IP address of the end point in the local server. This IP is set
264# by default to the same IP address that the HOST IP.
265# This variable can be used to specify a different end point IP address
266# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
267TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
268
Dean Troyere2907b42014-02-26 17:35:37 -0600269# With the openvswitch plugin, set to True in ``localrc`` to enable
270# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
271#
272# Example: ``OVS_ENABLE_TUNNELING=True``
273OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
274
Mark McClainb05c8762013-07-06 23:29:39 -0400275# Neutron plugin specific functions
276# ---------------------------------
277
278# Please refer to ``lib/neutron_plugins/README.md`` for details.
279source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
280
281# Agent loadbalancer service plugin functions
282# -------------------------------------------
283
284# Hardcoding for 1 service plugin for now
285source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
286
Emilien Macchi40546f72013-09-24 15:10:25 +0200287# Agent metering service plugin functions
288# -------------------------------------------
289
290# Hardcoding for 1 service plugin for now
291source $TOP_DIR/lib/neutron_plugins/services/metering
292
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700293# VPN service plugin functions
294# -------------------------------------------
295# Hardcoding for 1 service plugin for now
296source $TOP_DIR/lib/neutron_plugins/services/vpn
297
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700298# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100299# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700300source $TOP_DIR/lib/neutron_plugins/services/firewall
301
Mark McClainb05c8762013-07-06 23:29:39 -0400302# Use security group or not
303if has_neutron_plugin_security_group; then
304 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
305else
306 Q_USE_SECGROUP=False
307fi
308
Dean Troyer4237f592014-01-29 16:22:11 -0600309# Tell Tempest this project is present
310TEMPEST_SERVICES+=,neutron
311
312
Dean Troyere2907b42014-02-26 17:35:37 -0600313# Save trace setting
314XTRACE=$(set +o | grep xtrace)
315set +o xtrace
316
317
Mark McClainb05c8762013-07-06 23:29:39 -0400318# Functions
319# ---------
320
Adam Gandelman7614d212014-08-11 14:27:50 -0700321function _determine_config_server {
322 local cfg_file
323 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
324 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
325 opts+=" --config-file /$cfg_file"
326 done
327 echo "$opts"
328}
329
330function _determine_config_vpn {
331 local cfg_file
332 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
333 if is_service_enabled q-fwaas; then
334 opts+=" --config-file $Q_FWAAS_CONF_FILE"
335 fi
336 for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
337 opts+=" --config-file $cfg_file"
338 done
339 echo "$opts"
340
341}
342
343function _determine_config_l3 {
344 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
345 if is_service_enabled q-fwaas; then
346 opts+=" --config-file $Q_FWAAS_CONF_FILE"
347 fi
348 echo "$opts"
349}
350
351# For services and agents that require it, dynamically construct a list of
352# --config-file arguments that are passed to the binary.
353function determine_config_files {
354 local opts=""
355 case "$1" in
356 "neutron-server") opts="$(_determine_config_server)" ;;
357 "neutron-vpn-agent") opts="$(_determine_config_vpn)" ;;
358 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
359 esac
360 if [ -z "$opts" ] ; then
361 die $LINENO "Could not determine config files for $1."
362 fi
363 echo "$opts"
364}
365
Dean Troyere4fa7212014-01-15 15:04:49 -0600366# Test if any Neutron services are enabled
367# is_neutron_enabled
368function is_neutron_enabled {
369 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
370 return 1
371}
372
Mark McClainb05c8762013-07-06 23:29:39 -0400373# configure_neutron()
374# Set common config for all neutron server and agents.
Ian Wienandaee18c72014-02-21 15:35:08 +1100375function configure_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400376 _configure_neutron_common
377 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
378
379 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
380 if is_service_enabled q-lbaas; then
381 _configure_neutron_lbaas
382 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200383 if is_service_enabled q-metering; then
384 _configure_neutron_metering
385 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700386 if is_service_enabled q-vpn; then
387 _configure_neutron_vpn
388 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700389 if is_service_enabled q-fwaas; then
390 _configure_neutron_fwaas
391 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000392 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400393 _configure_neutron_service
394 fi
395 if is_service_enabled q-agt; then
396 _configure_neutron_plugin_agent
397 fi
398 if is_service_enabled q-dhcp; then
399 _configure_neutron_dhcp_agent
400 fi
401 if is_service_enabled q-l3; then
402 _configure_neutron_l3_agent
403 fi
404 if is_service_enabled q-meta; then
405 _configure_neutron_metadata_agent
406 fi
407
Brian Haleyeea76212014-06-27 11:45:50 -0400408 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
409 _configure_dvr
410 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400411 if is_service_enabled ceilometer; then
412 _configure_neutron_ceilometer_notifications
413 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400414
415 _configure_neutron_debug_command
416}
417
Ian Wienandaee18c72014-02-21 15:35:08 +1100418function create_nova_conf_neutron {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800419 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
Gary Kotton13d385e2014-06-17 23:24:53 -0700420 iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME"
421 iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD"
422 iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
423 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
424 iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME"
Bartosz Górski0abde392014-02-28 14:15:19 +0100425 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Rob Crittenden18d47782014-03-19 17:47:42 -0400426 iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400427
428 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
429 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400430 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800431 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400432 fi
433
434 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
435 neutron_plugin_create_nova_conf
436
Gary Kotton51c681d2014-04-22 01:40:56 -0700437 iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER"
Mark McClainb05c8762013-07-06 23:29:39 -0400438 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
439 if is_service_enabled q-meta; then
Gary Kottondd745502014-08-11 23:38:47 -0700440 iniset $NOVA_CONF neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400441 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800442
443 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
444 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400445}
446
Emilien Macchia677b7f2013-11-25 23:40:20 +0100447# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100448function create_neutron_cache_dir {
Emilien Macchia677b7f2013-11-25 23:40:20 +0100449 # Create cache dir
450 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
451 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
452 rm -f $NEUTRON_AUTH_CACHE_DIR/*
453}
454
Mark McClainb05c8762013-07-06 23:29:39 -0400455# create_neutron_accounts() - Set up common required neutron accounts
456
457# Tenant User Roles
458# ------------------------------------------------------------------
459# service neutron admin # if enabled
460
461# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100462function create_neutron_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400463
Dean Troyer188493d2014-07-25 15:54:11 -0500464 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700465 local service_role=$(openstack role list | awk "/ service / { print \$2 }")
Mark McClainb05c8762013-07-06 23:29:39 -0400466
467 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100468
Dean Troyer188493d2014-07-25 15:54:11 -0500469 local neutron_user=$(get_or_create_user "neutron" \
470 "$SERVICE_PASSWORD" $service_tenant)
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700471 get_or_add_user_role $service_role $neutron_user $service_tenant
Bartosz Górski0abde392014-02-28 14:15:19 +0100472
Mark McClainb05c8762013-07-06 23:29:39 -0400473 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100474
Dean Troyer188493d2014-07-25 15:54:11 -0500475 local neutron_service=$(get_or_create_service "neutron" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100476 "network" "Neutron Service")
Dean Troyer188493d2014-07-25 15:54:11 -0500477 get_or_create_endpoint $neutron_service \
Bartosz Górski0abde392014-02-28 14:15:19 +0100478 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400479 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
480 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
481 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400482 fi
483 fi
484}
485
Ian Wienandaee18c72014-02-21 15:35:08 +1100486function create_neutron_initial_network {
Steve Martinelli19685422014-01-24 13:02:26 -0600487 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500488 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400489
490 # Create a small network
491 # Since neutron command is executed in admin context at this point,
Dirk Mueller25049cd2014-01-09 13:53:52 +0100492 # ``--tenant-id`` needs to be specified.
Mark McClainb05c8762013-07-06 23:29:39 -0400493 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200494 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
495 die $LINENO "Neutron settings for baremetal not set.. exiting"
496 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400497 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
498 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
499 sudo ip addr del $IP dev $PUBLIC_INTERFACE
500 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
501 done
Dirk Mueller25049cd2014-01-09 13:53:52 +0100502 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 -0500503 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100504 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 -0500505 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400506 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200507 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400508 elif is_provider_network; then
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900509 die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400510 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
Satoru Moriyaaf9b2512014-09-01 20:43:08 +0900511 NET_ID=$(neutron net-create $PHYSICAL_NETWORK --tenant_id $TENANT_ID --provider:network_type $PROVIDER_NETWORK_TYPE --provider:physical_network "$PHYSICAL_NETWORK" ${SEGMENTATION_ID:+--provider:segmentation_id $SEGMENTATION_ID} --shared | grep ' id ' | get_field 2)
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400512 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 -0400513 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 -0400514 sudo ip link set $OVS_PHYSICAL_BRIDGE up
515 sudo ip link set br-int up
516 sudo ip link set $PUBLIC_INTERFACE up
Mark McClainb05c8762013-07-06 23:29:39 -0400517 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100518 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500519 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100520 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 -0500521 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400522 fi
523
524 if [[ "$Q_L3_ENABLED" == "True" ]]; then
525 # Create a router, and add the private subnet as one of its interfaces
526 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
527 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100528 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500529 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400530 else
531 # Plugin only supports creating a single router, which should be admin owned.
532 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500533 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400534 fi
535 neutron router-interface-add $ROUTER_ID $SUBNET_ID
536 # Create an external network, and a subnet. Configure the external network as router gw
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +0900537 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
538 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True --provider:network_type=flat --provider:physical_network=${PUBLIC_PHYSICAL_NETWORK} | grep ' id ' | get_field 2)
539 else
540 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
541 fi
DennyZhang23178a92013-10-22 17:07:32 -0500542 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400543 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 -0500544 die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400545 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
546
547 if is_service_enabled q-l3; then
548 # logic is specific to using the l3-agent for l3
549 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900550 local ext_gw_interface
551
552 if [[ "$Q_USE_PUBLIC_VETH" = "True" ]]; then
553 ext_gw_interface=$Q_PUBLIC_VETH_EX
554 else
555 # Disable in-band as we are going to use local port
556 # to communicate with VMs
557 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
558 other_config:disable-in-band=true
559 ext_gw_interface=$PUBLIC_BRIDGE
560 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400561 CIDR_LEN=${FLOATING_RANGE#*/}
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900562 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $ext_gw_interface
563 sudo ip link set $ext_gw_interface up
Mark McClainb05c8762013-07-06 23:29:39 -0400564 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 -0500565 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400566 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
567 fi
568 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
569 # Explicitly set router id in l3 agent configuration
570 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
571 fi
572 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400573 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400574}
575
576# init_neutron() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100577function init_neutron {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700578 recreate_database $Q_DB_NAME utf8
579 # Run Neutron db migrations
580 $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 -0400581}
582
583# install_neutron() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100584function install_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400585 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
586 setup_develop $NEUTRON_DIR
587}
588
589# install_neutronclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100590function install_neutronclient {
Mark McClainb05c8762013-07-06 23:29:39 -0400591 git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH
592 setup_develop $NEUTRONCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200593 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 -0400594}
595
596# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100597function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400598 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
599 if is_service_enabled q-l3; then
600 install_package radvd
601 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400602 # install packages that are specific to plugin agent(s)
603 if is_service_enabled q-agt q-dhcp q-l3; then
604 neutron_plugin_install_agent_packages
605 fi
606
607 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400608 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400609 fi
610}
611
612# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100613function start_neutron_service_and_check {
Adam Gandelman7614d212014-08-11 14:27:50 -0700614 local cfg_file_options="$(determine_config_files neutron-server)"
Rob Crittenden18d47782014-03-19 17:47:42 -0400615 local service_port=$Q_PORT
616 local service_protocol=$Q_PROTOCOL
617 if is_service_enabled tls-proxy; then
618 service_port=$Q_PORT_INT
619 service_protocol="http"
620 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400621 # Start the Neutron service
Chris Dent2f27a0e2014-09-09 13:46:02 +0100622 run_process q-svc "python $NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400623 echo "Waiting for Neutron to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400624 if is_ssl_enabled_service "neutron"; then
625 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
626 fi
627 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget ${ssl_ca} --no-proxy -q -O- $service_protocol://$Q_HOST:$service_port; do sleep 1; done"; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400628 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400629 fi
Rob Crittenden18d47782014-03-19 17:47:42 -0400630 # Start proxy if enabled
631 if is_service_enabled tls-proxy; then
632 start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT &
633 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400634}
635
636# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100637function start_neutron_agents {
Mark McClainb05c8762013-07-06 23:29:39 -0400638 # Start up the neutron agents if enabled
Chris Dent2f27a0e2014-09-09 13:46:02 +0100639 run_process q-agt "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
640 run_process q-dhcp "python $AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file=$Q_DHCP_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700641
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400642 if is_provider_network; then
643 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
644 sudo ip link set $OVS_PHYSICAL_BRIDGE up
645 sudo ip link set br-int up
646 sudo ip link set $PUBLIC_INTERFACE up
647 fi
648
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700649 if is_service_enabled q-vpn; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100650 run_process q-vpn "$AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700651 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100652 run_process q-l3 "python $AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700653 fi
654
Chris Dent2f27a0e2014-09-09 13:46:02 +0100655 run_process q-meta "python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400656
657 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
658 # For XenServer, start an agent for the domU openvswitch
Chris Dent2f27a0e2014-09-09 13:46:02 +0100659 run_process q-domua "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
Mark McClainb05c8762013-07-06 23:29:39 -0400660 fi
661
662 if is_service_enabled q-lbaas; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100663 run_process q-lbaas "python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400664 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200665
666 if is_service_enabled q-metering; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100667 run_process q-metering "python $AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
Emilien Macchi40546f72013-09-24 15:10:25 +0200668 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400669}
670
671# stop_neutron() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100672function stop_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400673 if is_service_enabled q-dhcp; then
674 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
675 [ ! -z "$pid" ] && sudo kill -9 $pid
676 fi
677 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100678 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400679 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900680
681 if is_service_enabled q-lbaas; then
682 neutron_lbaas_stop
683 fi
684 if is_service_enabled q-fwaas; then
685 neutron_fwaas_stop
686 fi
687 if is_service_enabled q-vpn; then
688 neutron_vpn_stop
689 fi
690 if is_service_enabled q-metering; then
691 neutron_metering_stop
692 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400693}
694
695# cleanup_neutron() - Remove residual data files, anything left over from previous
696# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100697function cleanup_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400698 if is_neutron_ovs_base_plugin; then
699 neutron_ovs_base_cleanup
700 fi
701
702 # delete all namespaces created by neutron
Brian Haleyeea76212014-06-27 11:45:50 -0400703 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 -0400704 sudo ip netns delete ${ns}
705 done
706}
707
708# _configure_neutron_common()
709# Set common config for all neutron server and agents.
710# This MUST be called before other ``_configure_neutron_*`` functions.
Ian Wienandaee18c72014-02-21 15:35:08 +1100711function _configure_neutron_common {
Mark McClainb05c8762013-07-06 23:29:39 -0400712 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
713 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
714 sudo mkdir -p $NEUTRON_CONF_DIR
715 fi
716 sudo chown $STACK_USER $NEUTRON_CONF_DIR
717
718 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
719
720 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
721 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
722 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
723 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100724 #
Mark McClainb05c8762013-07-06 23:29:39 -0400725 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
726 neutron_plugin_configure_common
727
sbauzae2c4ee22013-08-29 17:29:46 +0200728 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400729 die $LINENO "Neutron plugin not set.. exiting"
730 fi
731
732 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
733 mkdir -p /$Q_PLUGIN_CONF_PATH
734 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
735 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
736
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200737 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400738 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
739
740 # If addition config files are set, make sure their path name is set as well
741 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
742 die $LINENO "Neutron additional plugin config not set.. exiting"
743 fi
744
745 # If additional config files exist, copy them over to neutron configuration
746 # directory
747 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400748 local f
749 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
750 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400751 done
752 fi
753
Joe Gordonbee5c502013-08-30 13:48:08 -0400754 if [ "$VIRT_DRIVER" = 'fake' ]; then
755 # Disable arbitrary limits
756 iniset $NEUTRON_CONF quotas quota_network -1
757 iniset $NEUTRON_CONF quotas quota_subnet -1
758 iniset $NEUTRON_CONF quotas quota_port -1
759 iniset $NEUTRON_CONF quotas quota_security_group -1
760 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
761 fi
762
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700763 # Format logging
764 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800765 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700766 fi
767
Rob Crittenden18d47782014-03-19 17:47:42 -0400768 if is_service_enabled tls-proxy; then
769 # Set the service port for a proxy to take the original
770 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
771 fi
772
773 if is_ssl_enabled_service "nova"; then
774 iniset $NEUTRON_CONF DEFAULT nova_ca_certificates_file "$SSL_BUNDLE_FILE"
775 fi
776
777 if is_ssl_enabled_service "neutron"; then
778 ensure_certificates NEUTRON
779
780 iniset $NEUTRON_CONF DEFAULT use_ssl True
781 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
782 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
783 fi
784
Mark McClainb05c8762013-07-06 23:29:39 -0400785 _neutron_setup_rootwrap
786}
787
Ian Wienandaee18c72014-02-21 15:35:08 +1100788function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400789 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
790 return
791 fi
792
793 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
794
795 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
796 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
797 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400798 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
799
Mark McClainb05c8762013-07-06 23:29:39 -0400800 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
801
802 neutron_plugin_configure_debug_command
803}
804
Ian Wienandaee18c72014-02-21 15:35:08 +1100805function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400806
807 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
808
809 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500810 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400811 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
812 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
813
Mark McClainb05c8762013-07-06 23:29:39 -0400814 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
815
816 neutron_plugin_configure_dhcp_agent
817}
818
Ian Wienandaee18c72014-02-21 15:35:08 +1100819function _configure_neutron_l3_agent {
Paul Michali746dcee2014-04-02 19:12:22 +0000820 local cfg_file
Mark McClainb05c8762013-07-06 23:29:39 -0400821 Q_L3_ENABLED=True
822 # for l3-agent, only use per tenant router if we have namespaces
823 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700824
Paul Michali746dcee2014-04-02 19:12:22 +0000825 if is_service_enabled q-vpn; then
Paul Michali746dcee2014-04-02 19:12:22 +0000826 cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
Paul Michali746dcee2014-04-02 19:12:22 +0000827 fi
828
Mark McClainb05c8762013-07-06 23:29:39 -0400829 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
830
831 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500832 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400833 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
834 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
835
Mark McClainb05c8762013-07-06 23:29:39 -0400836 _neutron_setup_interface_driver $Q_L3_CONF_FILE
837
838 neutron_plugin_configure_l3_agent
839}
840
Ian Wienandaee18c72014-02-21 15:35:08 +1100841function _configure_neutron_metadata_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400842 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
843
844 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500845 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400846 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
847 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
848
Brant Knudson05952372014-09-19 17:22:22 -0500849 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT
Maru Newbybf10ac52013-08-10 21:27:54 +0000850
Mark McClainb05c8762013-07-06 23:29:39 -0400851}
852
Dina Belova58adaa62014-07-11 18:18:12 +0400853function _configure_neutron_ceilometer_notifications {
JordanPd4d4a342014-09-15 09:26:53 +0000854 iniset $NEUTRON_CONF DEFAULT notification_driver messaging
Dina Belova58adaa62014-07-11 18:18:12 +0400855}
856
Ian Wienandaee18c72014-02-21 15:35:08 +1100857function _configure_neutron_lbaas {
Mark McClainb05c8762013-07-06 23:29:39 -0400858 neutron_agent_lbaas_configure_common
859 neutron_agent_lbaas_configure_agent
860}
861
Ian Wienandaee18c72014-02-21 15:35:08 +1100862function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200863 neutron_agent_metering_configure_common
864 neutron_agent_metering_configure_agent
865}
866
Ian Wienandaee18c72014-02-21 15:35:08 +1100867function _configure_neutron_fwaas {
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700868 neutron_fwaas_configure_common
869 neutron_fwaas_configure_driver
870}
871
Ian Wienandaee18c72014-02-21 15:35:08 +1100872function _configure_neutron_vpn {
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700873 neutron_vpn_install_agent_packages
874 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700875}
876
Brian Haleyeea76212014-06-27 11:45:50 -0400877function _configure_dvr {
878 iniset $NEUTRON_CONF DEFAULT router_distributed True
879 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
880}
881
882
Mark McClainb05c8762013-07-06 23:29:39 -0400883# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
884# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100885function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400886 # Specify the default root helper prior to agent configuration to
887 # ensure that an agent's configuration can override the default
888 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
889 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500890 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400891
892 # Configure agent for plugin
893 neutron_plugin_configure_plugin_agent
894}
895
896# _configure_neutron_service() - Set config files for neutron service
897# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100898function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400899 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
900 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
901
902 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
903 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
904
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700905 # allow neutron user to administer neutron to match neutron account
906 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
907
Mark McClainb05c8762013-07-06 23:29:39 -0400908 # Update either configuration file with plugin
909 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
910
911 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
912 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
913 fi
914
915 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500916 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400917 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
918 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
919
920 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
921 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
922
Aaron Rosencea32b12014-03-04 16:20:14 -0800923 # Configuration for neutron notifations to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500924 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
925 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Aaron Rosencea32b12014-03-04 16:20:14 -0800926 iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
Dirk Mueller5ca261a2014-04-04 22:48:02 +0200927 iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800928 iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
929 ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
930 iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
931 iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
932
Mark McClainb05c8762013-07-06 23:29:39 -0400933 # Configure plugin
934 neutron_plugin_configure_service
935}
936
937# Utility Functions
938#------------------
939
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900940# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100941function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900942 local service_plugin_class=$1
943 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
944 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
945 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
946 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
947 fi
948}
949
Mark McClainb05c8762013-07-06 23:29:39 -0400950# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100951function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400952 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
953 return
954 fi
955 # Deploy new rootwrap filters files (owned by root).
956 # Wipe any existing ``rootwrap.d`` files first
957 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
958 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
959 sudo rm -rf $Q_CONF_ROOTWRAP_D
960 fi
961 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
962 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
963 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
964 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
965 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
966 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
967 # location moved in newer versions, prefer new location
968 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400969 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400970 else
Sean Dague3bdb9222013-10-22 08:36:16 -0400971 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400972 fi
973 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
974 sudo chown root:root $Q_RR_CONF_FILE
975 sudo chmod 0644 $Q_RR_CONF_FILE
976 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
977 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
978
979 # Set up the rootwrap sudoers for neutron
980 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100981 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400982 chmod 0440 $TEMPFILE
983 sudo chown root:root $TEMPFILE
984 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
985
986 # Update the root_helper
987 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
988}
989
990# Configures keystone integration for neutron service and agents
Ian Wienandaee18c72014-02-21 15:35:08 +1100991function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -0400992 local conf_file=$1
993 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000994
Brant Knudson05952372014-09-19 17:22:22 -0500995 create_neutron_cache_dir
996 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -0400997}
998
Ian Wienandaee18c72014-02-21 15:35:08 +1100999function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -04001000
1001 # ovs_use_veth needs to be set before the plugin configuration
1002 # occurs to allow plugins to override the setting.
1003 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1004
1005 neutron_plugin_setup_interface_driver $1
1006}
1007
1008# Functions for Neutron Exercises
1009#--------------------------------
1010
Ian Wienandaee18c72014-02-21 15:35:08 +11001011function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001012 local from_net="$1"
1013 net_id=`_get_net_id $from_net`
1014 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}'`
1015 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1016}
1017
Ian Wienandaee18c72014-02-21 15:35:08 +11001018function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001019 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
1020 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
1021 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
1022 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
1023 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
1024 fi
1025}
1026
Ian Wienandaee18c72014-02-21 15:35:08 +11001027function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001028 delete_probe $PUBLIC_NETWORK_NAME
1029 delete_probe $PRIVATE_NETWORK_NAME
1030}
1031
Ian Wienandaee18c72014-02-21 15:35:08 +11001032function _get_net_id {
Mark McClainb05c8762013-07-06 23:29:39 -04001033 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
1034}
1035
Ian Wienandaee18c72014-02-21 15:35:08 +11001036function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001037 local from_net="$1"
1038 net_id=`_get_net_id $from_net`
1039 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`
1040 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1041}
1042
Ian Wienandaee18c72014-02-21 15:35:08 +11001043function _ping_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001044 local from_net=$1
1045 local ip=$2
1046 local timeout_sec=$3
1047 local expected=${4:-"True"}
1048 local check_command=""
1049 probe_cmd=`_get_probe_cmd_prefix $from_net`
1050 if [[ "$expected" = "True" ]]; then
1051 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1052 else
1053 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1054 fi
1055 if ! timeout $timeout_sec sh -c "$check_command"; then
1056 if [[ "$expected" = "True" ]]; then
1057 die $LINENO "[Fail] Couldn't ping server"
1058 else
1059 die $LINENO "[Fail] Could ping server"
1060 fi
1061 fi
1062}
1063
1064# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001065function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001066 local from_net=$1
1067 local key_file=$2
1068 local ip=$3
1069 local user=$4
1070 local timeout_sec=$5
1071 local probe_cmd = ""
1072 probe_cmd=`_get_probe_cmd_prefix $from_net`
1073 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
1074 die $LINENO "server didn't become ssh-able!"
1075 fi
1076}
1077
1078# Neutron 3rd party programs
1079#---------------------------
1080
1081# please refer to ``lib/neutron_thirdparty/README.md`` for details
1082NEUTRON_THIRD_PARTIES=""
1083for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001084 third_party=$(basename $f)
1085 if is_service_enabled $third_party; then
1086 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1087 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1088 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001089done
1090
Ian Wienandaee18c72014-02-21 15:35:08 +11001091function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001092 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1093 ${1}_${third_party}
1094 done
1095}
1096
1097# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001098function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001099 _neutron_third_party_do configure
1100}
1101
1102# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001103function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001104 _neutron_third_party_do init
1105}
1106
1107# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001108function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001109 _neutron_third_party_do install
1110}
1111
1112# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001113function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001114 _neutron_third_party_do start
1115}
1116
1117# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001118function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001119 _neutron_third_party_do stop
1120}
1121
armando-migliaccioef1e0802014-01-02 16:33:53 -08001122# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001123function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001124 _neutron_third_party_do check
1125}
1126
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -04001127function is_provider_network {
1128 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
1129 return 0
1130 fi
1131 return 1
1132}
1133
Mark McClainb05c8762013-07-06 23:29:39 -04001134
1135# Restore xtrace
1136$XTRACE
1137
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001138# Tell emacs to use shell-script-mode
1139## Local variables:
1140## mode: shell-script
1141## End: