blob: df276c71d5fba98259a84c743ad84452f7f49a21 [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
62# Save trace setting
63XTRACE=$(set +o | grep xtrace)
64set +o xtrace
65
66
67# Neutron Network Configuration
68# -----------------------------
69
70# Gateway and subnet defaults, in case they are not customized in localrc
71NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
Salvatore Orlando90234ac2013-11-25 05:44:10 -080072PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
Mark McClainb05c8762013-07-06 23:29:39 -040073PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
74PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
75
76# Set up default directories
77NEUTRON_DIR=$DEST/neutron
78NEUTRONCLIENT_DIR=$DEST/python-neutronclient
79NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
80
81# Support entry points installation of console scripts
82if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
83 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040084else
85 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040086fi
87
88NEUTRON_CONF_DIR=/etc/neutron
89NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
90export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
91
92# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +000093Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -040094# Default Neutron Port
95Q_PORT=${Q_PORT:-9696}
96# Default Neutron Host
97Q_HOST=${Q_HOST:-$SERVICE_HOST}
98# Default admin username
99Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
100# Default auth strategy
101Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
102# Use namespace or not
103Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
104# RHEL's support for namespaces requires using veths with ovs
105Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
106Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
107# Meta data IP
108Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
109# Allow Overlapping IP among subnets
110Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
111# Use neutron-debug command
112Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
113# The name of the default q-l3 router
114Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Aaron Rosen4540d002013-10-24 13:59:33 -0700115# nova vif driver that all plugins should use
116NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
117
Tomoe Sugiharaafbc6312013-11-14 20:02:47 +0000118# The next two variables are configured by plugin
119# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
120#
121# The plugin supports L3.
122Q_L3_ENABLED=${Q_L3_ENABLED:-False}
123# L3 routers exist per tenant
124Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False}
Aaron Rosen4540d002013-10-24 13:59:33 -0700125
Mark McClainb05c8762013-07-06 23:29:39 -0400126# List of config file names in addition to the main plugin config file
127# See _configure_neutron_common() for details about setting it up
128declare -a Q_PLUGIN_EXTRA_CONF_FILES
129
130if is_service_enabled neutron; then
131 Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
132 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
133 Q_RR_COMMAND="sudo"
134 else
135 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
136 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
137 fi
138
139 # Provider Network Configurations
140 # --------------------------------
141
142 # The following variables control the Neutron openvswitch and
143 # linuxbridge plugins' allocation of tenant networks and
144 # availability of provider networks. If these are not configured
145 # in ``localrc``, tenant networks will be local to the host (with no
146 # remote connectivity), and no physical resources will be
147 # available for the allocation of provider networks.
148
149 # To use GRE tunnels for tenant networks, set to True in
150 # ``localrc``. GRE tunnels are only supported by the openvswitch
151 # plugin, and currently only on Ubuntu.
152 ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False}
153
154 # If using GRE tunnels for tenant networks, specify the range of
155 # tunnel IDs from which tenant networks are allocated. Can be
156 # overriden in ``localrc`` in necesssary.
157 TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGE:-1:1000}
158
159 # To use VLANs for tenant networks, set to True in localrc. VLANs
160 # are supported by the openvswitch and linuxbridge plugins, each
161 # requiring additional configuration described below.
162 ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
163
164 # If using VLANs for tenant networks, set in ``localrc`` to specify
165 # the range of VLAN VIDs from which tenant networks are
166 # allocated. An external network switch must be configured to
167 # trunk these VLANs between hosts for multi-host connectivity.
168 #
169 # Example: ``TENANT_VLAN_RANGE=1000:1999``
170 TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
171
172 # If using VLANs for tenant networks, or if using flat or VLAN
173 # provider networks, set in ``localrc`` to the name of the physical
174 # network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
175 # openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
176 # agent, as described below.
177 #
178 # Example: ``PHYSICAL_NETWORK=default``
179 PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
180
181 # With the openvswitch plugin, if using VLANs for tenant networks,
182 # or if using flat or VLAN provider networks, set in ``localrc`` to
183 # the name of the OVS bridge to use for the physical network. The
184 # bridge will be created if it does not already exist, but a
185 # physical interface must be manually added to the bridge as a
186 # port for external connectivity.
187 #
188 # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
189 OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
190
191 # With the linuxbridge plugin, if using VLANs for tenant networks,
192 # or if using flat or VLAN provider networks, set in ``localrc`` to
193 # the name of the network interface to use for the physical
194 # network.
195 #
196 # Example: ``LB_PHYSICAL_INTERFACE=eth1``
197 LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
198
199 # With the openvswitch plugin, set to True in ``localrc`` to enable
200 # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
201 #
202 # Example: ``OVS_ENABLE_TUNNELING=True``
203 OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
204fi
205
206# Neutron plugin specific functions
207# ---------------------------------
208
209# Please refer to ``lib/neutron_plugins/README.md`` for details.
210source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
211
212# Agent loadbalancer service plugin functions
213# -------------------------------------------
214
215# Hardcoding for 1 service plugin for now
216source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
217
Emilien Macchi40546f72013-09-24 15:10:25 +0200218# Agent metering service plugin functions
219# -------------------------------------------
220
221# Hardcoding for 1 service plugin for now
222source $TOP_DIR/lib/neutron_plugins/services/metering
223
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700224# VPN service plugin functions
225# -------------------------------------------
226# Hardcoding for 1 service plugin for now
227source $TOP_DIR/lib/neutron_plugins/services/vpn
228
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700229# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100230# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700231source $TOP_DIR/lib/neutron_plugins/services/firewall
232
Mark McClainb05c8762013-07-06 23:29:39 -0400233# Use security group or not
234if has_neutron_plugin_security_group; then
235 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
236else
237 Q_USE_SECGROUP=False
238fi
239
Dean Troyer4237f592014-01-29 16:22:11 -0600240# Tell Tempest this project is present
241TEMPEST_SERVICES+=,neutron
242
243
Mark McClainb05c8762013-07-06 23:29:39 -0400244# Functions
245# ---------
246
Dean Troyere4fa7212014-01-15 15:04:49 -0600247# Test if any Neutron services are enabled
248# is_neutron_enabled
249function is_neutron_enabled {
250 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
251 return 1
252}
253
Mark McClainb05c8762013-07-06 23:29:39 -0400254# configure_neutron()
255# Set common config for all neutron server and agents.
256function configure_neutron() {
257 _configure_neutron_common
258 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
259
260 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
261 if is_service_enabled q-lbaas; then
262 _configure_neutron_lbaas
263 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200264 if is_service_enabled q-metering; then
265 _configure_neutron_metering
266 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700267 if is_service_enabled q-vpn; then
268 _configure_neutron_vpn
269 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700270 if is_service_enabled q-fwaas; then
271 _configure_neutron_fwaas
272 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400273 if is_service_enabled q-svc; then
274 _configure_neutron_service
275 fi
276 if is_service_enabled q-agt; then
277 _configure_neutron_plugin_agent
278 fi
279 if is_service_enabled q-dhcp; then
280 _configure_neutron_dhcp_agent
281 fi
282 if is_service_enabled q-l3; then
283 _configure_neutron_l3_agent
284 fi
285 if is_service_enabled q-meta; then
286 _configure_neutron_metadata_agent
287 fi
288
289 _configure_neutron_debug_command
290}
291
292function create_nova_conf_neutron() {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800293 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
294 iniset $NOVA_CONF DEFAULT neutron_admin_username "$Q_ADMIN_USERNAME"
295 iniset $NOVA_CONF DEFAULT neutron_admin_password "$SERVICE_PASSWORD"
296 iniset $NOVA_CONF DEFAULT neutron_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
297 iniset $NOVA_CONF DEFAULT neutron_auth_strategy "$Q_AUTH_STRATEGY"
298 iniset $NOVA_CONF DEFAULT neutron_admin_tenant_name "$SERVICE_TENANT_NAME"
299 iniset $NOVA_CONF DEFAULT neutron_region_name "RegionOne"
300 iniset $NOVA_CONF DEFAULT neutron_url "http://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400301
302 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
303 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400304 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800305 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400306 fi
307
308 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
309 neutron_plugin_create_nova_conf
310
311 iniset $NOVA_CONF DEFAULT libvirt_vif_driver "$NOVA_VIF_DRIVER"
312 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
313 if is_service_enabled q-meta; then
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800314 iniset $NOVA_CONF DEFAULT service_neutron_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400315 fi
316}
317
Emilien Macchia677b7f2013-11-25 23:40:20 +0100318# create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
319function create_neutron_cache_dir() {
320 # Create cache dir
321 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
322 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
323 rm -f $NEUTRON_AUTH_CACHE_DIR/*
324}
325
Mark McClainb05c8762013-07-06 23:29:39 -0400326# create_neutron_accounts() - Set up common required neutron accounts
327
328# Tenant User Roles
329# ------------------------------------------------------------------
330# service neutron admin # if enabled
331
332# Migrated from keystone_data.sh
333function create_neutron_accounts() {
334
Steve Martinelli19685422014-01-24 13:02:26 -0600335 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
336 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Mark McClainb05c8762013-07-06 23:29:39 -0400337
338 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600339 NEUTRON_USER=$(openstack user create \
340 neutron \
341 --password "$SERVICE_PASSWORD" \
342 --project $SERVICE_TENANT \
343 --email neutron@example.com \
Mark McClainb05c8762013-07-06 23:29:39 -0400344 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600345 openstack role add \
346 $ADMIN_ROLE \
347 --project $SERVICE_TENANT \
348 --user $NEUTRON_USER
Mark McClainb05c8762013-07-06 23:29:39 -0400349 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600350 NEUTRON_SERVICE=$(openstack service create \
351 neutron \
Mark McClainb05c8762013-07-06 23:29:39 -0400352 --type=network \
353 --description="Neutron Service" \
354 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600355 openstack endpoint create \
356 $NEUTRON_SERVICE \
Mark McClainb05c8762013-07-06 23:29:39 -0400357 --region RegionOne \
Mark McClainb05c8762013-07-06 23:29:39 -0400358 --publicurl "http://$SERVICE_HOST:9696/" \
359 --adminurl "http://$SERVICE_HOST:9696/" \
360 --internalurl "http://$SERVICE_HOST:9696/"
361 fi
362 fi
363}
364
365function create_neutron_initial_network() {
Steve Martinelli19685422014-01-24 13:02:26 -0600366 TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500367 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
Mark McClainb05c8762013-07-06 23:29:39 -0400368
369 # Create a small network
370 # Since neutron command is executed in admin context at this point,
Dirk Mueller25049cd2014-01-09 13:53:52 +0100371 # ``--tenant-id`` needs to be specified.
Mark McClainb05c8762013-07-06 23:29:39 -0400372 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200373 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
374 die $LINENO "Neutron settings for baremetal not set.. exiting"
375 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400376 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
377 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
378 sudo ip addr del $IP dev $PUBLIC_INTERFACE
379 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
380 done
Dirk Mueller25049cd2014-01-09 13:53:52 +0100381 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 -0500382 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100383 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 -0500384 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400385 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200386 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Mark McClainb05c8762013-07-06 23:29:39 -0400387 else
Dirk Mueller25049cd2014-01-09 13:53:52 +0100388 NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500389 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
Dirk Mueller25049cd2014-01-09 13:53:52 +0100390 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 -0500391 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
Mark McClainb05c8762013-07-06 23:29:39 -0400392 fi
393
394 if [[ "$Q_L3_ENABLED" == "True" ]]; then
395 # Create a router, and add the private subnet as one of its interfaces
396 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
397 # create a tenant-owned router.
Dirk Mueller25049cd2014-01-09 13:53:52 +0100398 ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500399 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400400 else
401 # Plugin only supports creating a single router, which should be admin owned.
402 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500403 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400404 fi
405 neutron router-interface-add $ROUTER_ID $SUBNET_ID
406 # Create an external network, and a subnet. Configure the external network as router gw
407 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500408 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400409 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 -0500410 die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400411 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
412
413 if is_service_enabled q-l3; then
414 # logic is specific to using the l3-agent for l3
415 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
416 CIDR_LEN=${FLOATING_RANGE#*/}
417 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
418 sudo ip link set $PUBLIC_BRIDGE up
419 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 -0500420 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Mark McClainb05c8762013-07-06 23:29:39 -0400421 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
422 fi
423 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
424 # Explicitly set router id in l3 agent configuration
425 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
426 fi
427 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400428 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400429}
430
431# init_neutron() - Initialize databases, etc.
432function init_neutron() {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700433 recreate_database $Q_DB_NAME utf8
434 # Run Neutron db migrations
435 $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 -0400436}
437
438# install_neutron() - Collect source and prepare
439function install_neutron() {
440 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
441 setup_develop $NEUTRON_DIR
442}
443
444# install_neutronclient() - Collect source and prepare
445function install_neutronclient() {
446 git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH
447 setup_develop $NEUTRONCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200448 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 -0400449}
450
451# install_neutron_agent_packages() - Collect source and prepare
452function install_neutron_agent_packages() {
453 # install packages that are specific to plugin agent(s)
454 if is_service_enabled q-agt q-dhcp q-l3; then
455 neutron_plugin_install_agent_packages
456 fi
457
458 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400459 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400460 fi
461}
462
463# Start running processes, including screen
464function start_neutron_service_and_check() {
465 # build config-file options
466 local cfg_file
467 local CFG_FILE_OPTIONS="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
468 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
Sean Dague3bdb9222013-10-22 08:36:16 -0400469 CFG_FILE_OPTIONS+=" --config-file /$cfg_file"
Mark McClainb05c8762013-07-06 23:29:39 -0400470 done
471 # Start the Neutron service
472 screen_it q-svc "cd $NEUTRON_DIR && python $NEUTRON_BIN_DIR/neutron-server $CFG_FILE_OPTIONS"
473 echo "Waiting for Neutron to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800474 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 -0400475 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400476 fi
477}
478
479# Start running processes, including screen
480function start_neutron_agents() {
481 # Start up the neutron agents if enabled
482 screen_it q-agt "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
483 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 -0700484
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700485 L3_CONF_FILES="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
486
487 if is_service_enabled q-fwaas; then
488 L3_CONF_FILES="$L3_CONF_FILES --config-file $Q_FWAAS_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700489 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700490 if is_service_enabled q-vpn; then
491 screen_it q-vpn "cd $NEUTRON_DIR && $AGENT_VPN_BINARY $L3_CONF_FILES"
492 else
493 screen_it q-l3 "cd $NEUTRON_DIR && python $AGENT_L3_BINARY $L3_CONF_FILES"
494 fi
495
Mark McClainb05c8762013-07-06 23:29:39 -0400496 screen_it q-meta "cd $NEUTRON_DIR && python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
497
498 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
499 # For XenServer, start an agent for the domU openvswitch
500 screen_it q-domua "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
501 fi
502
503 if is_service_enabled q-lbaas; then
504 screen_it q-lbaas "cd $NEUTRON_DIR && python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
505 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200506
507 if is_service_enabled q-metering; then
508 screen_it q-metering "cd $NEUTRON_DIR && python $AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
509 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400510}
511
512# stop_neutron() - Stop running processes (non-screen)
513function stop_neutron() {
514 if is_service_enabled q-dhcp; then
515 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
516 [ ! -z "$pid" ] && sudo kill -9 $pid
517 fi
518 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100519 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Mark McClainb05c8762013-07-06 23:29:39 -0400520 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900521
522 if is_service_enabled q-lbaas; then
523 neutron_lbaas_stop
524 fi
525 if is_service_enabled q-fwaas; then
526 neutron_fwaas_stop
527 fi
528 if is_service_enabled q-vpn; then
529 neutron_vpn_stop
530 fi
531 if is_service_enabled q-metering; then
532 neutron_metering_stop
533 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400534}
535
536# cleanup_neutron() - Remove residual data files, anything left over from previous
537# runs that a clean run would need to clean up
538function cleanup_neutron() {
539 if is_neutron_ovs_base_plugin; then
540 neutron_ovs_base_cleanup
541 fi
542
543 # delete all namespaces created by neutron
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900544 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|qlbaas)-[0-9a-f-]*'); do
Mark McClainb05c8762013-07-06 23:29:39 -0400545 sudo ip netns delete ${ns}
546 done
547}
548
549# _configure_neutron_common()
550# Set common config for all neutron server and agents.
551# This MUST be called before other ``_configure_neutron_*`` functions.
552function _configure_neutron_common() {
553 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
554 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
555 sudo mkdir -p $NEUTRON_CONF_DIR
556 fi
557 sudo chown $STACK_USER $NEUTRON_CONF_DIR
558
559 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
560
561 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
562 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
563 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
564 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100565 #
Mark McClainb05c8762013-07-06 23:29:39 -0400566 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
567 neutron_plugin_configure_common
568
sbauzae2c4ee22013-08-29 17:29:46 +0200569 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400570 die $LINENO "Neutron plugin not set.. exiting"
571 fi
572
573 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
574 mkdir -p /$Q_PLUGIN_CONF_PATH
575 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
576 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
577
578 iniset /$Q_PLUGIN_CONF_FILE database connection `database_connection_url $Q_DB_NAME`
579 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
580
581 # If addition config files are set, make sure their path name is set as well
582 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
583 die $LINENO "Neutron additional plugin config not set.. exiting"
584 fi
585
586 # If additional config files exist, copy them over to neutron configuration
587 # directory
588 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
589 mkdir -p /$Q_PLUGIN_EXTRA_CONF_PATH
590 local f
591 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
592 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
593 cp $NEUTRON_DIR/${Q_PLUGIN_EXTRA_CONF_FILES[$f]} /${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
594 done
595 fi
596
Joe Gordonbee5c502013-08-30 13:48:08 -0400597 if [ "$VIRT_DRIVER" = 'fake' ]; then
598 # Disable arbitrary limits
599 iniset $NEUTRON_CONF quotas quota_network -1
600 iniset $NEUTRON_CONF quotas quota_subnet -1
601 iniset $NEUTRON_CONF quotas quota_port -1
602 iniset $NEUTRON_CONF quotas quota_security_group -1
603 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
604 fi
605
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700606 # Format logging
607 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800608 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700609 fi
610
Mark McClainb05c8762013-07-06 23:29:39 -0400611 _neutron_setup_rootwrap
612}
613
614function _configure_neutron_debug_command() {
615 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
616 return
617 fi
618
619 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
620
621 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
622 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
623 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Mark McClainb05c8762013-07-06 23:29:39 -0400624 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
625
Mark McClainb05c8762013-07-06 23:29:39 -0400626 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
627
628 neutron_plugin_configure_debug_command
629}
630
631function _configure_neutron_dhcp_agent() {
632 AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
633 Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
634
635 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
636
637 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500638 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400639 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
640 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
641
Kyle Mestery73b21912013-08-22 11:25:21 +0000642 # Define extra "DEFAULT" configuration options when q-dhcp is configured by
643 # defining the array ``Q_DHCP_EXTRA_DEFAULT_OPTS``.
644 # For Example: ``Q_DHCP_EXTRA_DEFAULT_OPTS=(foo=true bar=2)``
645 for I in "${Q_DHCP_EXTRA_DEFAULT_OPTS[@]}"; do
646 # Replace the first '=' with ' ' for iniset syntax
647 iniset $Q_DHCP_CONF_FILE DEFAULT ${I/=/ }
648 done
649
Mark McClainb05c8762013-07-06 23:29:39 -0400650 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
651
652 neutron_plugin_configure_dhcp_agent
653}
654
655function _configure_neutron_l3_agent() {
656 Q_L3_ENABLED=True
657 # for l3-agent, only use per tenant router if we have namespaces
658 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700659
660 AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
Mark McClainb05c8762013-07-06 23:29:39 -0400661 Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
662
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700663 if is_service_enabled q-fwaas; then
664 Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
665 fi
666
Mark McClainb05c8762013-07-06 23:29:39 -0400667 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
668
669 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500670 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400671 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
672 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
673
Mark McClainb05c8762013-07-06 23:29:39 -0400674 _neutron_setup_interface_driver $Q_L3_CONF_FILE
675
676 neutron_plugin_configure_l3_agent
677}
678
679function _configure_neutron_metadata_agent() {
680 AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
681 Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
682
683 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
684
685 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500686 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400687 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
688 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
689
Yong Sheng Gong8535d8b2013-08-25 11:21:13 +0800690 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT True True True
Maru Newbybf10ac52013-08-10 21:27:54 +0000691
Mark McClainb05c8762013-07-06 23:29:39 -0400692}
693
694function _configure_neutron_lbaas() {
695 neutron_agent_lbaas_configure_common
696 neutron_agent_lbaas_configure_agent
697}
698
Emilien Macchi40546f72013-09-24 15:10:25 +0200699function _configure_neutron_metering() {
700 neutron_agent_metering_configure_common
701 neutron_agent_metering_configure_agent
702}
703
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700704function _configure_neutron_fwaas() {
705 neutron_fwaas_configure_common
706 neutron_fwaas_configure_driver
707}
708
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700709function _configure_neutron_vpn()
710{
711 neutron_vpn_install_agent_packages
712 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700713}
714
Mark McClainb05c8762013-07-06 23:29:39 -0400715# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
716# It is called when q-agt is enabled.
717function _configure_neutron_plugin_agent() {
718 # Specify the default root helper prior to agent configuration to
719 # ensure that an agent's configuration can override the default
720 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
721 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500722 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400723
724 # Configure agent for plugin
725 neutron_plugin_configure_plugin_agent
726}
727
728# _configure_neutron_service() - Set config files for neutron service
729# It is called when q-svc is enabled.
730function _configure_neutron_service() {
731 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
732 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
733
734 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
735 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
736
Mark McClainb05c8762013-07-06 23:29:39 -0400737 # Update either configuration file with plugin
738 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
739
740 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
741 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
742 fi
743
744 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500745 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400746 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
747 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
748
749 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
750 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
751
Simon Pasquierca96b0a2013-07-09 16:59:12 +0200752 # Define extra "DEFAULT" configuration options when q-svc is configured by
753 # defining the array ``Q_SRV_EXTRA_DEFAULT_OPTS``.
754 # For Example: ``Q_SRV_EXTRA_DEFAULT_OPTS=(foo=true bar=2)``
755 for I in "${Q_SRV_EXTRA_DEFAULT_OPTS[@]}"; do
756 # Replace the first '=' with ' ' for iniset syntax
757 iniset $NEUTRON_CONF DEFAULT ${I/=/ }
758 done
759
Mark McClainb05c8762013-07-06 23:29:39 -0400760 # Configure plugin
761 neutron_plugin_configure_service
762}
763
764# Utility Functions
765#------------------
766
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900767# _neutron_service_plugin_class_add() - add service plugin class
768function _neutron_service_plugin_class_add() {
769 local service_plugin_class=$1
770 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
771 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
772 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
773 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
774 fi
775}
776
Mark McClainb05c8762013-07-06 23:29:39 -0400777# _neutron_setup_rootwrap() - configure Neutron's rootwrap
778function _neutron_setup_rootwrap() {
779 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
780 return
781 fi
782 # Deploy new rootwrap filters files (owned by root).
783 # Wipe any existing ``rootwrap.d`` files first
784 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
785 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
786 sudo rm -rf $Q_CONF_ROOTWRAP_D
787 fi
788 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
789 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
790 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
791 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
792 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
793 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
794 # location moved in newer versions, prefer new location
795 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400796 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400797 else
Sean Dague3bdb9222013-10-22 08:36:16 -0400798 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400799 fi
800 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
801 sudo chown root:root $Q_RR_CONF_FILE
802 sudo chmod 0644 $Q_RR_CONF_FILE
803 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
804 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
805
806 # Set up the rootwrap sudoers for neutron
807 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100808 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400809 chmod 0440 $TEMPFILE
810 sudo chown root:root $TEMPFILE
811 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
812
813 # Update the root_helper
814 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
815}
816
817# Configures keystone integration for neutron service and agents
818function _neutron_setup_keystone() {
819 local conf_file=$1
820 local section=$2
821 local use_auth_url=$3
Maru Newbybf10ac52013-08-10 21:27:54 +0000822 local skip_auth_cache=$4
Yong Sheng Gong8535d8b2013-08-25 11:21:13 +0800823 local use_service_port=$5
824 local keystone_port=$KEYSTONE_AUTH_PORT
825 if [[ -n $use_service_port ]]; then
826 keystone_port=$KEYSTONE_SERVICE_PORT
827 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400828 if [[ -n $use_auth_url ]]; then
Yong Sheng Gong8535d8b2013-08-25 11:21:13 +0800829 iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$keystone_port/v2.0"
Mark McClainb05c8762013-07-06 23:29:39 -0400830 else
831 iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST
Yong Sheng Gong8535d8b2013-08-25 11:21:13 +0800832 iniset $conf_file $section auth_port $keystone_port
Mark McClainb05c8762013-07-06 23:29:39 -0400833 iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL
834 fi
835 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
836 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
837 iniset $conf_file $section admin_password $SERVICE_PASSWORD
Maru Newbybf10ac52013-08-10 21:27:54 +0000838 if [[ -z $skip_auth_cache ]]; then
839 iniset $conf_file $section signing_dir $NEUTRON_AUTH_CACHE_DIR
840 # Create cache dir
Emilien Macchia677b7f2013-11-25 23:40:20 +0100841 create_neutron_cache_dir
Maru Newbybf10ac52013-08-10 21:27:54 +0000842 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400843}
844
845function _neutron_setup_interface_driver() {
846
847 # ovs_use_veth needs to be set before the plugin configuration
848 # occurs to allow plugins to override the setting.
849 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
850
851 neutron_plugin_setup_interface_driver $1
852}
853
854# Functions for Neutron Exercises
855#--------------------------------
856
857function delete_probe() {
858 local from_net="$1"
859 net_id=`_get_net_id $from_net`
860 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}'`
861 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
862}
863
864function setup_neutron_debug() {
865 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
866 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
867 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
868 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
869 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
870 fi
871}
872
873function teardown_neutron_debug() {
874 delete_probe $PUBLIC_NETWORK_NAME
875 delete_probe $PRIVATE_NETWORK_NAME
876}
877
878function _get_net_id() {
879 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
880}
881
882function _get_probe_cmd_prefix() {
883 local from_net="$1"
884 net_id=`_get_net_id $from_net`
885 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`
886 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
887}
888
889function _ping_check_neutron() {
890 local from_net=$1
891 local ip=$2
892 local timeout_sec=$3
893 local expected=${4:-"True"}
894 local check_command=""
895 probe_cmd=`_get_probe_cmd_prefix $from_net`
896 if [[ "$expected" = "True" ]]; then
897 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
898 else
899 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
900 fi
901 if ! timeout $timeout_sec sh -c "$check_command"; then
902 if [[ "$expected" = "True" ]]; then
903 die $LINENO "[Fail] Couldn't ping server"
904 else
905 die $LINENO "[Fail] Could ping server"
906 fi
907 fi
908}
909
910# ssh check
911function _ssh_check_neutron() {
912 local from_net=$1
913 local key_file=$2
914 local ip=$3
915 local user=$4
916 local timeout_sec=$5
917 local probe_cmd = ""
918 probe_cmd=`_get_probe_cmd_prefix $from_net`
919 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
920 die $LINENO "server didn't become ssh-able!"
921 fi
922}
923
924# Neutron 3rd party programs
925#---------------------------
926
927# please refer to ``lib/neutron_thirdparty/README.md`` for details
928NEUTRON_THIRD_PARTIES=""
929for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -0400930 third_party=$(basename $f)
931 if is_service_enabled $third_party; then
932 source $TOP_DIR/lib/neutron_thirdparty/$third_party
933 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
934 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400935done
936
937function _neutron_third_party_do() {
938 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
939 ${1}_${third_party}
940 done
941}
942
943# configure_neutron_third_party() - Set config files, create data dirs, etc
944function configure_neutron_third_party() {
945 _neutron_third_party_do configure
946}
947
948# init_neutron_third_party() - Initialize databases, etc.
949function init_neutron_third_party() {
950 _neutron_third_party_do init
951}
952
953# install_neutron_third_party() - Collect source and prepare
954function install_neutron_third_party() {
955 _neutron_third_party_do install
956}
957
958# start_neutron_third_party() - Start running processes, including screen
959function start_neutron_third_party() {
960 _neutron_third_party_do start
961}
962
963# stop_neutron_third_party - Stop running processes (non-screen)
964function stop_neutron_third_party() {
965 _neutron_third_party_do stop
966}
967
armando-migliaccioef1e0802014-01-02 16:33:53 -0800968# check_neutron_third_party_integration() - Check that third party integration is sane
969function check_neutron_third_party_integration() {
970 _neutron_third_party_do check
971}
972
Mark McClainb05c8762013-07-06 23:29:39 -0400973
974# Restore xtrace
975$XTRACE
976
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100977# Tell emacs to use shell-script-mode
978## Local variables:
979## mode: shell-script
980## End: