blob: 5da7cfc34e96674de5053785e36887b6089f2597 [file] [log] [blame]
Mark McClainb05c8762013-07-06 23:29:39 -04001# lib/neutron
2# functions - funstions specific to neutron
3
4# Dependencies:
5# ``functions`` file
6# ``DEST`` must be defined
7
8# ``stack.sh`` calls the entry points in this order:
9#
10# install_neutron
11# install_neutronclient
12# install_neutron_agent_packages
13# install_neutron_third_party
14# configure_neutron
15# init_neutron
16# configure_neutron_third_party
17# init_neutron_third_party
18# start_neutron_third_party
19# create_nova_conf_neutron
20# start_neutron_service_and_check
21# create_neutron_initial_network
22# setup_neutron_debug
23# start_neutron_agents
24#
25# ``unstack.sh`` calls the entry points in this order:
26#
27# stop_neutron
28
29# Functions in lib/neutron are classified into the following categories:
30#
31# - entry points (called from stack.sh or unstack.sh)
32# - internal functions
33# - neutron exercises
34# - 3rd party programs
35
36
37# Neutron Networking
38# ------------------
39
40# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
41# to run Neutron on this host, make sure that q-svc is also in
42# ``ENABLED_SERVICES``.
43#
44# If you're planning to use the Neutron openvswitch plugin, set
45# ``Q_PLUGIN`` to "openvswitch" and make sure the q-agt service is enabled
46# in ``ENABLED_SERVICES``. If you're planning to use the Neutron
47# linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the
48# q-agt service is enabled in ``ENABLED_SERVICES``.
49#
50# See "Neutron Network Configuration" below for additional variables
51# that must be set in localrc for connectivity across hosts with
52# Neutron.
53#
54# With Neutron networking the NETWORK_MANAGER variable is ignored.
55#
56# To enable specific configuration options for either the Open vSwitch or
57# LinuxBridge plugin, please see the top level README file under the
58# Neutron section.
59
60# Save trace setting
61XTRACE=$(set +o | grep xtrace)
62set +o xtrace
63
64
65# Neutron Network Configuration
66# -----------------------------
67
68# Gateway and subnet defaults, in case they are not customized in localrc
69NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
70PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.225}
71PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
72PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
73
74# Set up default directories
75NEUTRON_DIR=$DEST/neutron
76NEUTRONCLIENT_DIR=$DEST/python-neutronclient
77NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
78
79# Support entry points installation of console scripts
80if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
81 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
82 else
83NEUTRON_BIN_DIR=$(get_python_exec_prefix)
84fi
85
86NEUTRON_CONF_DIR=/etc/neutron
87NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
88export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
89
90# Default Neutron Plugin
91Q_PLUGIN=${Q_PLUGIN:-openvswitch}
92# Default Neutron Port
93Q_PORT=${Q_PORT:-9696}
94# Default Neutron Host
95Q_HOST=${Q_HOST:-$SERVICE_HOST}
96# Default admin username
97Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
98# Default auth strategy
99Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
100# Use namespace or not
101Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
102# RHEL's support for namespaces requires using veths with ovs
103Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
104Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
105# Meta data IP
106Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
107# Allow Overlapping IP among subnets
108Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
109# Use neutron-debug command
110Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
111# The name of the default q-l3 router
112Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
113# List of config file names in addition to the main plugin config file
114# See _configure_neutron_common() for details about setting it up
115declare -a Q_PLUGIN_EXTRA_CONF_FILES
116
117if is_service_enabled neutron; then
118 Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
119 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
120 Q_RR_COMMAND="sudo"
121 else
122 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
123 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
124 fi
125
126 # Provider Network Configurations
127 # --------------------------------
128
129 # The following variables control the Neutron openvswitch and
130 # linuxbridge plugins' allocation of tenant networks and
131 # availability of provider networks. If these are not configured
132 # in ``localrc``, tenant networks will be local to the host (with no
133 # remote connectivity), and no physical resources will be
134 # available for the allocation of provider networks.
135
136 # To use GRE tunnels for tenant networks, set to True in
137 # ``localrc``. GRE tunnels are only supported by the openvswitch
138 # plugin, and currently only on Ubuntu.
139 ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False}
140
141 # If using GRE tunnels for tenant networks, specify the range of
142 # tunnel IDs from which tenant networks are allocated. Can be
143 # overriden in ``localrc`` in necesssary.
144 TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGE:-1:1000}
145
146 # To use VLANs for tenant networks, set to True in localrc. VLANs
147 # are supported by the openvswitch and linuxbridge plugins, each
148 # requiring additional configuration described below.
149 ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
150
151 # If using VLANs for tenant networks, set in ``localrc`` to specify
152 # the range of VLAN VIDs from which tenant networks are
153 # allocated. An external network switch must be configured to
154 # trunk these VLANs between hosts for multi-host connectivity.
155 #
156 # Example: ``TENANT_VLAN_RANGE=1000:1999``
157 TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
158
159 # If using VLANs for tenant networks, or if using flat or VLAN
160 # provider networks, set in ``localrc`` to the name of the physical
161 # network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
162 # openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
163 # agent, as described below.
164 #
165 # Example: ``PHYSICAL_NETWORK=default``
166 PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
167
168 # With the openvswitch plugin, if using VLANs for tenant networks,
169 # or if using flat or VLAN provider networks, set in ``localrc`` to
170 # the name of the OVS bridge to use for the physical network. The
171 # bridge will be created if it does not already exist, but a
172 # physical interface must be manually added to the bridge as a
173 # port for external connectivity.
174 #
175 # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
176 OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
177
178 # With the linuxbridge plugin, if using VLANs for tenant networks,
179 # or if using flat or VLAN provider networks, set in ``localrc`` to
180 # the name of the network interface to use for the physical
181 # network.
182 #
183 # Example: ``LB_PHYSICAL_INTERFACE=eth1``
184 LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
185
186 # With the openvswitch plugin, set to True in ``localrc`` to enable
187 # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
188 #
189 # Example: ``OVS_ENABLE_TUNNELING=True``
190 OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
191fi
192
193# Neutron plugin specific functions
194# ---------------------------------
195
196# Please refer to ``lib/neutron_plugins/README.md`` for details.
197source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
198
199# Agent loadbalancer service plugin functions
200# -------------------------------------------
201
202# Hardcoding for 1 service plugin for now
203source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
204
205# Use security group or not
206if has_neutron_plugin_security_group; then
207 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
208else
209 Q_USE_SECGROUP=False
210fi
211
212# Functions
213# ---------
214
215# configure_neutron()
216# Set common config for all neutron server and agents.
217function configure_neutron() {
218 _configure_neutron_common
219 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
220
221 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
222 if is_service_enabled q-lbaas; then
223 _configure_neutron_lbaas
224 fi
225 if is_service_enabled q-svc; then
226 _configure_neutron_service
227 fi
228 if is_service_enabled q-agt; then
229 _configure_neutron_plugin_agent
230 fi
231 if is_service_enabled q-dhcp; then
232 _configure_neutron_dhcp_agent
233 fi
234 if is_service_enabled q-l3; then
235 _configure_neutron_l3_agent
236 fi
237 if is_service_enabled q-meta; then
238 _configure_neutron_metadata_agent
239 fi
240
241 _configure_neutron_debug_command
242}
243
244function create_nova_conf_neutron() {
245 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.quantumv2.api.API"
246 iniset $NOVA_CONF DEFAULT quantum_admin_username "$Q_ADMIN_USERNAME"
247 iniset $NOVA_CONF DEFAULT quantum_admin_password "$SERVICE_PASSWORD"
248 iniset $NOVA_CONF DEFAULT quantum_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
249 iniset $NOVA_CONF DEFAULT quantum_auth_strategy "$Q_AUTH_STRATEGY"
250 iniset $NOVA_CONF DEFAULT quantum_admin_tenant_name "$SERVICE_TENANT_NAME"
251 iniset $NOVA_CONF DEFAULT quantum_url "http://$Q_HOST:$Q_PORT"
252
253 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
254 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
255 iniset $NOVA_CONF DEFAULT security_group_api quantum
256 fi
257
258 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
259 neutron_plugin_create_nova_conf
260
261 iniset $NOVA_CONF DEFAULT libvirt_vif_driver "$NOVA_VIF_DRIVER"
262 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
263 if is_service_enabled q-meta; then
264 iniset $NOVA_CONF DEFAULT service_quantum_metadata_proxy "True"
265 fi
266}
267
268# create_neutron_accounts() - Set up common required neutron accounts
269
270# Tenant User Roles
271# ------------------------------------------------------------------
272# service neutron admin # if enabled
273
274# Migrated from keystone_data.sh
275function create_neutron_accounts() {
276
277 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
278 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
279
280 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
281 NEUTRON_USER=$(keystone user-create \
282 --name=neutron \
283 --pass="$SERVICE_PASSWORD" \
284 --tenant_id $SERVICE_TENANT \
285 --email=neutron@example.com \
286 | grep " id " | get_field 2)
287 keystone user-role-add \
288 --tenant_id $SERVICE_TENANT \
289 --user_id $NEUTRON_USER \
290 --role_id $ADMIN_ROLE
291 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
292 NEUTRON_SERVICE=$(keystone service-create \
293 --name=neutron \
294 --type=network \
295 --description="Neutron Service" \
296 | grep " id " | get_field 2)
297 keystone endpoint-create \
298 --region RegionOne \
299 --service_id $NEUTRON_SERVICE \
300 --publicurl "http://$SERVICE_HOST:9696/" \
301 --adminurl "http://$SERVICE_HOST:9696/" \
302 --internalurl "http://$SERVICE_HOST:9696/"
303 fi
304 fi
305}
306
307function create_neutron_initial_network() {
308 TENANT_ID=$(keystone tenant-list | grep " demo " | get_field 1)
309
310 # Create a small network
311 # Since neutron command is executed in admin context at this point,
312 # ``--tenant_id`` needs to be specified.
313 if is_baremetal; then
314 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
315 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
316 sudo ip addr del $IP dev $PUBLIC_INTERFACE
317 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
318 done
319 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)
320 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)
321 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
322 else
323 NET_ID=$(neutron net-create --tenant_id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
324 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)
325 fi
326
327 if [[ "$Q_L3_ENABLED" == "True" ]]; then
328 # Create a router, and add the private subnet as one of its interfaces
329 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
330 # create a tenant-owned router.
331 ROUTER_ID=$(neutron router-create --tenant_id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
332 else
333 # Plugin only supports creating a single router, which should be admin owned.
334 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
335 fi
336 neutron router-interface-add $ROUTER_ID $SUBNET_ID
337 # Create an external network, and a subnet. Configure the external network as router gw
338 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
339 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)
340 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
341
342 if is_service_enabled q-l3; then
343 # logic is specific to using the l3-agent for l3
344 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
345 CIDR_LEN=${FLOATING_RANGE#*/}
346 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
347 sudo ip link set $PUBLIC_BRIDGE up
348 ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'`
349 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
350 fi
351 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
352 # Explicitly set router id in l3 agent configuration
353 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
354 fi
355 fi
356 fi
357}
358
359# init_neutron() - Initialize databases, etc.
360function init_neutron() {
361 :
362}
363
364# install_neutron() - Collect source and prepare
365function install_neutron() {
366 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
367 setup_develop $NEUTRON_DIR
368}
369
370# install_neutronclient() - Collect source and prepare
371function install_neutronclient() {
372 git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH
373 setup_develop $NEUTRONCLIENT_DIR
374}
375
376# install_neutron_agent_packages() - Collect source and prepare
377function install_neutron_agent_packages() {
378 # install packages that are specific to plugin agent(s)
379 if is_service_enabled q-agt q-dhcp q-l3; then
380 neutron_plugin_install_agent_packages
381 fi
382
383 if is_service_enabled q-lbaas; then
384 neutron_agent_lbaas_install_agent_packages
385 fi
386}
387
388# Start running processes, including screen
389function start_neutron_service_and_check() {
390 # build config-file options
391 local cfg_file
392 local CFG_FILE_OPTIONS="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
393 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
394 CFG_FILE_OPTIONS+=" --config-file /$cfg_file"
395 done
396 # Start the Neutron service
397 screen_it q-svc "cd $NEUTRON_DIR && python $NEUTRON_BIN_DIR/neutron-server $CFG_FILE_OPTIONS"
398 echo "Waiting for Neutron to start..."
399 if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then
400 die $LINENO "Neutron did not start"
401 fi
402}
403
404# Start running processes, including screen
405function start_neutron_agents() {
406 # Start up the neutron agents if enabled
407 screen_it q-agt "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
408 screen_it q-dhcp "cd $NEUTRON_DIR && python $AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file=$Q_DHCP_CONF_FILE"
409 screen_it q-l3 "cd $NEUTRON_DIR && python $AGENT_L3_BINARY --config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
410 screen_it q-meta "cd $NEUTRON_DIR && python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
411
412 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
413 # For XenServer, start an agent for the domU openvswitch
414 screen_it q-domua "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
415 fi
416
417 if is_service_enabled q-lbaas; then
418 screen_it q-lbaas "cd $NEUTRON_DIR && python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
419 fi
420}
421
422# stop_neutron() - Stop running processes (non-screen)
423function stop_neutron() {
424 if is_service_enabled q-dhcp; then
425 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
426 [ ! -z "$pid" ] && sudo kill -9 $pid
427 fi
428 if is_service_enabled q-meta; then
429 pid=$(ps aux | awk '/neutron-ns-metadata-proxy/ { print $2 }')
430 [ ! -z "$pid" ] && sudo kill -9 $pid
431 fi
432}
433
434# cleanup_neutron() - Remove residual data files, anything left over from previous
435# runs that a clean run would need to clean up
436function cleanup_neutron() {
437 if is_neutron_ovs_base_plugin; then
438 neutron_ovs_base_cleanup
439 fi
440
441 # delete all namespaces created by neutron
442 for ns in $(sudo ip netns list | grep -o -e qdhcp-[0-9a-f\-]* -e qrouter-[0-9a-f\-]*); do
443 sudo ip netns delete ${ns}
444 done
445}
446
447# _configure_neutron_common()
448# Set common config for all neutron server and agents.
449# This MUST be called before other ``_configure_neutron_*`` functions.
450function _configure_neutron_common() {
451 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
452 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
453 sudo mkdir -p $NEUTRON_CONF_DIR
454 fi
455 sudo chown $STACK_USER $NEUTRON_CONF_DIR
456
457 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
458
459 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
460 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
461 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
462 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
463 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
464 neutron_plugin_configure_common
465
466 if [[ $Q_PLUGIN_CONF_PATH == '' || $Q_PLUGIN_CONF_FILENAME == '' || $Q_PLUGIN_CLASS == '' ]]; then
467 die $LINENO "Neutron plugin not set.. exiting"
468 fi
469
470 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
471 mkdir -p /$Q_PLUGIN_CONF_PATH
472 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
473 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
474
475 iniset /$Q_PLUGIN_CONF_FILE database connection `database_connection_url $Q_DB_NAME`
476 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
477
478 # If addition config files are set, make sure their path name is set as well
479 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
480 die $LINENO "Neutron additional plugin config not set.. exiting"
481 fi
482
483 # If additional config files exist, copy them over to neutron configuration
484 # directory
485 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
486 mkdir -p /$Q_PLUGIN_EXTRA_CONF_PATH
487 local f
488 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
489 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
490 cp $NEUTRON_DIR/${Q_PLUGIN_EXTRA_CONF_FILES[$f]} /${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
491 done
492 fi
493
494 _neutron_setup_rootwrap
495}
496
497function _configure_neutron_debug_command() {
498 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
499 return
500 fi
501
502 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
503
504 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
505 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
506 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
507 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT root_helper "$Q_RR_COMMAND"
508 # Intermediate fix until Neutron patch lands and then line above will
509 # be cleaned.
510 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
511
512 _neutron_setup_keystone $NEUTRON_TEST_CONFIG_FILE DEFAULT set_auth_url
513 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
514
515 neutron_plugin_configure_debug_command
516}
517
518function _configure_neutron_dhcp_agent() {
519 AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
520 Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
521
522 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
523
524 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
525 iniset $Q_DHCP_CONF_FILE DEFAULT debug True
526 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
527 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
528
529 _neutron_setup_keystone $Q_DHCP_CONF_FILE DEFAULT set_auth_url
530 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
531
532 neutron_plugin_configure_dhcp_agent
533}
534
535function _configure_neutron_l3_agent() {
536 Q_L3_ENABLED=True
537 # for l3-agent, only use per tenant router if we have namespaces
538 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
539 AGENT_L3_BINARY="$NEUTRON_BIN_DIR/neutron-l3-agent"
540 Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
541
542 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
543
544 iniset $Q_L3_CONF_FILE DEFAULT verbose True
545 iniset $Q_L3_CONF_FILE DEFAULT debug True
546 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
547 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
548
549 _neutron_setup_keystone $Q_L3_CONF_FILE DEFAULT set_auth_url
550 _neutron_setup_interface_driver $Q_L3_CONF_FILE
551
552 neutron_plugin_configure_l3_agent
553}
554
555function _configure_neutron_metadata_agent() {
556 AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
557 Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
558
559 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
560
561 iniset $Q_META_CONF_FILE DEFAULT verbose True
562 iniset $Q_META_CONF_FILE DEFAULT debug True
563 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
564 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
565
566 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT set_auth_url
567}
568
569function _configure_neutron_lbaas() {
570 neutron_agent_lbaas_configure_common
571 neutron_agent_lbaas_configure_agent
572}
573
574# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
575# It is called when q-agt is enabled.
576function _configure_neutron_plugin_agent() {
577 # Specify the default root helper prior to agent configuration to
578 # ensure that an agent's configuration can override the default
579 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
580 iniset $NEUTRON_CONF DEFAULT verbose True
581 iniset $NEUTRON_CONF DEFAULT debug True
582
583 # Configure agent for plugin
584 neutron_plugin_configure_plugin_agent
585}
586
587# _configure_neutron_service() - Set config files for neutron service
588# It is called when q-svc is enabled.
589function _configure_neutron_service() {
590 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
591 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
592
593 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
594 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
595
596 if is_service_enabled $DATABASE_BACKENDS; then
597 recreate_database $Q_DB_NAME utf8
598 else
599 die $LINENO "A database must be enabled in order to use the $Q_PLUGIN Neutron plugin."
600 fi
601
602 # Update either configuration file with plugin
603 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
604
605 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
606 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
607 fi
608
609 iniset $NEUTRON_CONF DEFAULT verbose True
610 iniset $NEUTRON_CONF DEFAULT debug True
611 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
612 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
613
614 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
615 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
616
Simon Pasquierca96b0a2013-07-09 16:59:12 +0200617 # Define extra "DEFAULT" configuration options when q-svc is configured by
618 # defining the array ``Q_SRV_EXTRA_DEFAULT_OPTS``.
619 # For Example: ``Q_SRV_EXTRA_DEFAULT_OPTS=(foo=true bar=2)``
620 for I in "${Q_SRV_EXTRA_DEFAULT_OPTS[@]}"; do
621 # Replace the first '=' with ' ' for iniset syntax
622 iniset $NEUTRON_CONF DEFAULT ${I/=/ }
623 done
624
Mark McClainb05c8762013-07-06 23:29:39 -0400625 # Configure plugin
626 neutron_plugin_configure_service
627}
628
629# Utility Functions
630#------------------
631
632# _neutron_setup_rootwrap() - configure Neutron's rootwrap
633function _neutron_setup_rootwrap() {
634 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
635 return
636 fi
637 # Deploy new rootwrap filters files (owned by root).
638 # Wipe any existing ``rootwrap.d`` files first
639 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
640 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
641 sudo rm -rf $Q_CONF_ROOTWRAP_D
642 fi
643 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
644 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
645 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
646 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
647 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
648 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
649 # location moved in newer versions, prefer new location
650 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
651 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
652 else
653 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
654 fi
655 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
656 sudo chown root:root $Q_RR_CONF_FILE
657 sudo chmod 0644 $Q_RR_CONF_FILE
658 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
659 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
660
661 # Set up the rootwrap sudoers for neutron
662 TEMPFILE=`mktemp`
663 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
664 chmod 0440 $TEMPFILE
665 sudo chown root:root $TEMPFILE
666 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
667
668 # Update the root_helper
669 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
670}
671
672# Configures keystone integration for neutron service and agents
673function _neutron_setup_keystone() {
674 local conf_file=$1
675 local section=$2
676 local use_auth_url=$3
677 if [[ -n $use_auth_url ]]; then
678 iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0"
679 else
680 iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST
681 iniset $conf_file $section auth_port $KEYSTONE_AUTH_PORT
682 iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL
683 fi
684 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
685 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
686 iniset $conf_file $section admin_password $SERVICE_PASSWORD
687 iniset $conf_file $section signing_dir $NEUTRON_AUTH_CACHE_DIR
688 # Create cache dir
689 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
690 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
691 rm -f $NEUTRON_AUTH_CACHE_DIR/*
692}
693
694function _neutron_setup_interface_driver() {
695
696 # ovs_use_veth needs to be set before the plugin configuration
697 # occurs to allow plugins to override the setting.
698 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
699
700 neutron_plugin_setup_interface_driver $1
701}
702
703# Functions for Neutron Exercises
704#--------------------------------
705
706function delete_probe() {
707 local from_net="$1"
708 net_id=`_get_net_id $from_net`
709 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}'`
710 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
711}
712
713function setup_neutron_debug() {
714 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
715 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
716 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
717 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
718 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
719 fi
720}
721
722function teardown_neutron_debug() {
723 delete_probe $PUBLIC_NETWORK_NAME
724 delete_probe $PRIVATE_NETWORK_NAME
725}
726
727function _get_net_id() {
728 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
729}
730
731function _get_probe_cmd_prefix() {
732 local from_net="$1"
733 net_id=`_get_net_id $from_net`
734 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`
735 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
736}
737
738function _ping_check_neutron() {
739 local from_net=$1
740 local ip=$2
741 local timeout_sec=$3
742 local expected=${4:-"True"}
743 local check_command=""
744 probe_cmd=`_get_probe_cmd_prefix $from_net`
745 if [[ "$expected" = "True" ]]; then
746 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
747 else
748 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
749 fi
750 if ! timeout $timeout_sec sh -c "$check_command"; then
751 if [[ "$expected" = "True" ]]; then
752 die $LINENO "[Fail] Couldn't ping server"
753 else
754 die $LINENO "[Fail] Could ping server"
755 fi
756 fi
757}
758
759# ssh check
760function _ssh_check_neutron() {
761 local from_net=$1
762 local key_file=$2
763 local ip=$3
764 local user=$4
765 local timeout_sec=$5
766 local probe_cmd = ""
767 probe_cmd=`_get_probe_cmd_prefix $from_net`
768 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
769 die $LINENO "server didn't become ssh-able!"
770 fi
771}
772
773# Neutron 3rd party programs
774#---------------------------
775
776# please refer to ``lib/neutron_thirdparty/README.md`` for details
777NEUTRON_THIRD_PARTIES=""
778for f in $TOP_DIR/lib/neutron_thirdparty/*; do
779 third_party=$(basename $f)
780 if is_service_enabled $third_party; then
781 source $TOP_DIR/lib/neutron_thirdparty/$third_party
782 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
783 fi
784done
785
786function _neutron_third_party_do() {
787 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
788 ${1}_${third_party}
789 done
790}
791
792# configure_neutron_third_party() - Set config files, create data dirs, etc
793function configure_neutron_third_party() {
794 _neutron_third_party_do configure
795}
796
797# init_neutron_third_party() - Initialize databases, etc.
798function init_neutron_third_party() {
799 _neutron_third_party_do init
800}
801
802# install_neutron_third_party() - Collect source and prepare
803function install_neutron_third_party() {
804 _neutron_third_party_do install
805}
806
807# start_neutron_third_party() - Start running processes, including screen
808function start_neutron_third_party() {
809 _neutron_third_party_do start
810}
811
812# stop_neutron_third_party - Stop running processes (non-screen)
813function stop_neutron_third_party() {
814 _neutron_third_party_do stop
815}
816
817
818# Restore xtrace
819$XTRACE
820
821# Local variables:
822# mode: shell-script
823# End: