blob: 1c01d05e5f18905257cd1b7416b79ed82baab0dd [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
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
20# - create_nova_conf_neutron
21# - start_neutron_service_and_check
22# - create_neutron_initial_network
23# - setup_neutron_debug
24# - start_neutron_agents
Mark McClainb05c8762013-07-06 23:29:39 -040025#
26# ``unstack.sh`` calls the entry points in this order:
27#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010028# - stop_neutron
Mark McClainb05c8762013-07-06 23:29:39 -040029
30# Functions in lib/neutron are classified into the following categories:
31#
32# - entry points (called from stack.sh or unstack.sh)
33# - internal functions
34# - neutron exercises
35# - 3rd party programs
36
37
38# Neutron Networking
39# ------------------
40
41# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
42# to run Neutron on this host, make sure that q-svc is also in
43# ``ENABLED_SERVICES``.
44#
45# If you're planning to use the Neutron openvswitch plugin, set
46# ``Q_PLUGIN`` to "openvswitch" and make sure the q-agt service is enabled
47# in ``ENABLED_SERVICES``. If you're planning to use the Neutron
48# linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the
49# q-agt service is enabled in ``ENABLED_SERVICES``.
50#
51# See "Neutron Network Configuration" below for additional variables
52# that must be set in localrc for connectivity across hosts with
53# Neutron.
54#
55# With Neutron networking the NETWORK_MANAGER variable is ignored.
56#
57# To enable specific configuration options for either the Open vSwitch or
58# LinuxBridge plugin, please see the top level README file under the
59# Neutron section.
60
61# Save trace setting
62XTRACE=$(set +o | grep xtrace)
63set +o xtrace
64
65
66# Neutron Network Configuration
67# -----------------------------
68
69# Gateway and subnet defaults, in case they are not customized in localrc
70NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
71PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.225}
72PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
73PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
74
75# Set up default directories
76NEUTRON_DIR=$DEST/neutron
77NEUTRONCLIENT_DIR=$DEST/python-neutronclient
78NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
79
80# Support entry points installation of console scripts
81if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
82 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040083else
84 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040085fi
86
87NEUTRON_CONF_DIR=/etc/neutron
88NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
89export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
90
91# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +000092Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -040093# Default Neutron Port
94Q_PORT=${Q_PORT:-9696}
95# Default Neutron Host
96Q_HOST=${Q_HOST:-$SERVICE_HOST}
97# Default admin username
98Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
99# Default auth strategy
100Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
101# Use namespace or not
102Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
103# RHEL's support for namespaces requires using veths with ovs
104Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
105Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
106# Meta data IP
107Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
108# Allow Overlapping IP among subnets
109Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
110# Use neutron-debug command
111Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
112# The name of the default q-l3 router
113Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Aaron Rosen4540d002013-10-24 13:59:33 -0700114# nova vif driver that all plugins should use
115NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
116
117
Mark McClainb05c8762013-07-06 23:29:39 -0400118# List of config file names in addition to the main plugin config file
119# See _configure_neutron_common() for details about setting it up
120declare -a Q_PLUGIN_EXTRA_CONF_FILES
121
122if is_service_enabled neutron; then
123 Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
124 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
125 Q_RR_COMMAND="sudo"
126 else
127 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
128 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
129 fi
130
131 # Provider Network Configurations
132 # --------------------------------
133
134 # The following variables control the Neutron openvswitch and
135 # linuxbridge plugins' allocation of tenant networks and
136 # availability of provider networks. If these are not configured
137 # in ``localrc``, tenant networks will be local to the host (with no
138 # remote connectivity), and no physical resources will be
139 # available for the allocation of provider networks.
140
141 # To use GRE tunnels for tenant networks, set to True in
142 # ``localrc``. GRE tunnels are only supported by the openvswitch
143 # plugin, and currently only on Ubuntu.
144 ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False}
145
146 # If using GRE tunnels for tenant networks, specify the range of
147 # tunnel IDs from which tenant networks are allocated. Can be
148 # overriden in ``localrc`` in necesssary.
149 TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGE:-1:1000}
150
151 # To use VLANs for tenant networks, set to True in localrc. VLANs
152 # are supported by the openvswitch and linuxbridge plugins, each
153 # requiring additional configuration described below.
154 ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
155
156 # If using VLANs for tenant networks, set in ``localrc`` to specify
157 # the range of VLAN VIDs from which tenant networks are
158 # allocated. An external network switch must be configured to
159 # trunk these VLANs between hosts for multi-host connectivity.
160 #
161 # Example: ``TENANT_VLAN_RANGE=1000:1999``
162 TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
163
164 # If using VLANs for tenant networks, or if using flat or VLAN
165 # provider networks, set in ``localrc`` to the name of the physical
166 # network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
167 # openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
168 # agent, as described below.
169 #
170 # Example: ``PHYSICAL_NETWORK=default``
171 PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
172
173 # With the openvswitch plugin, if using VLANs for tenant networks,
174 # or if using flat or VLAN provider networks, set in ``localrc`` to
175 # the name of the OVS bridge to use for the physical network. The
176 # bridge will be created if it does not already exist, but a
177 # physical interface must be manually added to the bridge as a
178 # port for external connectivity.
179 #
180 # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
181 OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
182
183 # With the linuxbridge plugin, if using VLANs for tenant networks,
184 # or if using flat or VLAN provider networks, set in ``localrc`` to
185 # the name of the network interface to use for the physical
186 # network.
187 #
188 # Example: ``LB_PHYSICAL_INTERFACE=eth1``
189 LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
190
191 # With the openvswitch plugin, set to True in ``localrc`` to enable
192 # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
193 #
194 # Example: ``OVS_ENABLE_TUNNELING=True``
195 OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
196fi
197
198# Neutron plugin specific functions
199# ---------------------------------
200
201# Please refer to ``lib/neutron_plugins/README.md`` for details.
202source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
203
204# Agent loadbalancer service plugin functions
205# -------------------------------------------
206
207# Hardcoding for 1 service plugin for now
208source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
209
Emilien Macchi40546f72013-09-24 15:10:25 +0200210# Agent metering service plugin functions
211# -------------------------------------------
212
213# Hardcoding for 1 service plugin for now
214source $TOP_DIR/lib/neutron_plugins/services/metering
215
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700216# VPN service plugin functions
217# -------------------------------------------
218# Hardcoding for 1 service plugin for now
219source $TOP_DIR/lib/neutron_plugins/services/vpn
220
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700221# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100222# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700223source $TOP_DIR/lib/neutron_plugins/services/firewall
224
Mark McClainb05c8762013-07-06 23:29:39 -0400225# Use security group or not
226if has_neutron_plugin_security_group; then
227 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
228else
229 Q_USE_SECGROUP=False
230fi
231
232# Functions
233# ---------
234
235# configure_neutron()
236# Set common config for all neutron server and agents.
237function configure_neutron() {
238 _configure_neutron_common
239 iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
240
241 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
242 if is_service_enabled q-lbaas; then
243 _configure_neutron_lbaas
244 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200245 if is_service_enabled q-metering; then
246 _configure_neutron_metering
247 fi
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700248 if is_service_enabled q-vpn; then
249 _configure_neutron_vpn
250 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700251 if is_service_enabled q-fwaas; then
252 _configure_neutron_fwaas
253 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400254 if is_service_enabled q-svc; then
255 _configure_neutron_service
256 fi
257 if is_service_enabled q-agt; then
258 _configure_neutron_plugin_agent
259 fi
260 if is_service_enabled q-dhcp; then
261 _configure_neutron_dhcp_agent
262 fi
263 if is_service_enabled q-l3; then
264 _configure_neutron_l3_agent
265 fi
266 if is_service_enabled q-meta; then
267 _configure_neutron_metadata_agent
268 fi
269
270 _configure_neutron_debug_command
271}
272
273function create_nova_conf_neutron() {
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800274 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
275 iniset $NOVA_CONF DEFAULT neutron_admin_username "$Q_ADMIN_USERNAME"
276 iniset $NOVA_CONF DEFAULT neutron_admin_password "$SERVICE_PASSWORD"
277 iniset $NOVA_CONF DEFAULT neutron_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
278 iniset $NOVA_CONF DEFAULT neutron_auth_strategy "$Q_AUTH_STRATEGY"
279 iniset $NOVA_CONF DEFAULT neutron_admin_tenant_name "$SERVICE_TENANT_NAME"
280 iniset $NOVA_CONF DEFAULT neutron_region_name "RegionOne"
281 iniset $NOVA_CONF DEFAULT neutron_url "http://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400282
283 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
284 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400285 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800286 iniset $NOVA_CONF DEFAULT security_group_api neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400287 fi
288
289 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
290 neutron_plugin_create_nova_conf
291
292 iniset $NOVA_CONF DEFAULT libvirt_vif_driver "$NOVA_VIF_DRIVER"
293 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
294 if is_service_enabled q-meta; then
Yong Sheng Gong032e4542013-08-25 10:21:10 +0800295 iniset $NOVA_CONF DEFAULT service_neutron_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400296 fi
297}
298
299# create_neutron_accounts() - Set up common required neutron accounts
300
301# Tenant User Roles
302# ------------------------------------------------------------------
303# service neutron admin # if enabled
304
305# Migrated from keystone_data.sh
306function create_neutron_accounts() {
307
308 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
309 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
310
311 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
312 NEUTRON_USER=$(keystone user-create \
313 --name=neutron \
314 --pass="$SERVICE_PASSWORD" \
315 --tenant_id $SERVICE_TENANT \
316 --email=neutron@example.com \
317 | grep " id " | get_field 2)
318 keystone user-role-add \
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200319 --tenant-id $SERVICE_TENANT \
320 --user-id $NEUTRON_USER \
321 --role-id $ADMIN_ROLE
Mark McClainb05c8762013-07-06 23:29:39 -0400322 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
323 NEUTRON_SERVICE=$(keystone service-create \
324 --name=neutron \
325 --type=network \
326 --description="Neutron Service" \
327 | grep " id " | get_field 2)
328 keystone endpoint-create \
329 --region RegionOne \
330 --service_id $NEUTRON_SERVICE \
331 --publicurl "http://$SERVICE_HOST:9696/" \
332 --adminurl "http://$SERVICE_HOST:9696/" \
333 --internalurl "http://$SERVICE_HOST:9696/"
334 fi
335 fi
336}
337
338function create_neutron_initial_network() {
339 TENANT_ID=$(keystone tenant-list | grep " demo " | get_field 1)
340
341 # Create a small network
342 # Since neutron command is executed in admin context at this point,
343 # ``--tenant_id`` needs to be specified.
344 if is_baremetal; then
sbauzae2c4ee22013-08-29 17:29:46 +0200345 if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
346 die $LINENO "Neutron settings for baremetal not set.. exiting"
347 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400348 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
349 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
350 sudo ip addr del $IP dev $PUBLIC_INTERFACE
351 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
352 done
353 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)
354 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)
355 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
sbauzae2c4ee22013-08-29 17:29:46 +0200356 sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
Mark McClainb05c8762013-07-06 23:29:39 -0400357 else
358 NET_ID=$(neutron net-create --tenant_id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
359 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)
360 fi
361
362 if [[ "$Q_L3_ENABLED" == "True" ]]; then
363 # Create a router, and add the private subnet as one of its interfaces
364 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
365 # create a tenant-owned router.
366 ROUTER_ID=$(neutron router-create --tenant_id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
367 else
368 # Plugin only supports creating a single router, which should be admin owned.
369 ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
370 fi
371 neutron router-interface-add $ROUTER_ID $SUBNET_ID
372 # Create an external network, and a subnet. Configure the external network as router gw
373 EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
374 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)
375 neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
376
377 if is_service_enabled q-l3; then
378 # logic is specific to using the l3-agent for l3
379 if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
380 CIDR_LEN=${FLOATING_RANGE#*/}
381 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
382 sudo ip link set $PUBLIC_BRIDGE up
383 ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'`
384 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
385 fi
386 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
387 # Explicitly set router id in l3 agent configuration
388 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
389 fi
390 fi
Sean Dague3bdb9222013-10-22 08:36:16 -0400391 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400392}
393
394# init_neutron() - Initialize databases, etc.
395function init_neutron() {
Salvatore Orlandodd649882013-08-05 08:56:17 -0700396 recreate_database $Q_DB_NAME utf8
397 # Run Neutron db migrations
398 $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 -0400399}
400
401# install_neutron() - Collect source and prepare
402function install_neutron() {
403 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
404 setup_develop $NEUTRON_DIR
405}
406
407# install_neutronclient() - Collect source and prepare
408function install_neutronclient() {
409 git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH
410 setup_develop $NEUTRONCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200411 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 -0400412}
413
414# install_neutron_agent_packages() - Collect source and prepare
415function install_neutron_agent_packages() {
416 # install packages that are specific to plugin agent(s)
417 if is_service_enabled q-agt q-dhcp q-l3; then
418 neutron_plugin_install_agent_packages
419 fi
420
421 if is_service_enabled q-lbaas; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400422 neutron_agent_lbaas_install_agent_packages
Mark McClainb05c8762013-07-06 23:29:39 -0400423 fi
424}
425
426# Start running processes, including screen
427function start_neutron_service_and_check() {
428 # build config-file options
429 local cfg_file
430 local CFG_FILE_OPTIONS="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
431 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
Sean Dague3bdb9222013-10-22 08:36:16 -0400432 CFG_FILE_OPTIONS+=" --config-file /$cfg_file"
Mark McClainb05c8762013-07-06 23:29:39 -0400433 done
434 # Start the Neutron service
435 screen_it q-svc "cd $NEUTRON_DIR && python $NEUTRON_BIN_DIR/neutron-server $CFG_FILE_OPTIONS"
436 echo "Waiting for Neutron to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800437 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 -0400438 die $LINENO "Neutron did not start"
Mark McClainb05c8762013-07-06 23:29:39 -0400439 fi
440}
441
442# Start running processes, including screen
443function start_neutron_agents() {
444 # Start up the neutron agents if enabled
445 screen_it q-agt "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
446 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 -0700447
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700448 L3_CONF_FILES="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
449
450 if is_service_enabled q-fwaas; then
451 L3_CONF_FILES="$L3_CONF_FILES --config-file $Q_FWAAS_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700452 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700453 if is_service_enabled q-vpn; then
454 screen_it q-vpn "cd $NEUTRON_DIR && $AGENT_VPN_BINARY $L3_CONF_FILES"
455 else
456 screen_it q-l3 "cd $NEUTRON_DIR && python $AGENT_L3_BINARY $L3_CONF_FILES"
457 fi
458
Mark McClainb05c8762013-07-06 23:29:39 -0400459 screen_it q-meta "cd $NEUTRON_DIR && python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
460
461 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
462 # For XenServer, start an agent for the domU openvswitch
463 screen_it q-domua "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
464 fi
465
466 if is_service_enabled q-lbaas; then
467 screen_it q-lbaas "cd $NEUTRON_DIR && python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
468 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200469
470 if is_service_enabled q-metering; then
471 screen_it q-metering "cd $NEUTRON_DIR && python $AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
472 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400473}
474
475# stop_neutron() - Stop running processes (non-screen)
476function stop_neutron() {
477 if is_service_enabled q-dhcp; then
478 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
479 [ ! -z "$pid" ] && sudo kill -9 $pid
480 fi
481 if is_service_enabled q-meta; then
482 pid=$(ps aux | awk '/neutron-ns-metadata-proxy/ { print $2 }')
483 [ ! -z "$pid" ] && sudo kill -9 $pid
484 fi
485}
486
487# cleanup_neutron() - Remove residual data files, anything left over from previous
488# runs that a clean run would need to clean up
489function cleanup_neutron() {
490 if is_neutron_ovs_base_plugin; then
491 neutron_ovs_base_cleanup
492 fi
493
494 # delete all namespaces created by neutron
495 for ns in $(sudo ip netns list | grep -o -e qdhcp-[0-9a-f\-]* -e qrouter-[0-9a-f\-]*); do
496 sudo ip netns delete ${ns}
497 done
498}
499
500# _configure_neutron_common()
501# Set common config for all neutron server and agents.
502# This MUST be called before other ``_configure_neutron_*`` functions.
503function _configure_neutron_common() {
504 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
505 if [[ ! -d $NEUTRON_CONF_DIR ]]; then
506 sudo mkdir -p $NEUTRON_CONF_DIR
507 fi
508 sudo chown $STACK_USER $NEUTRON_CONF_DIR
509
510 cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
511
512 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
513 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
514 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
515 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100516 #
Mark McClainb05c8762013-07-06 23:29:39 -0400517 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
518 neutron_plugin_configure_common
519
sbauzae2c4ee22013-08-29 17:29:46 +0200520 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400521 die $LINENO "Neutron plugin not set.. exiting"
522 fi
523
524 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
525 mkdir -p /$Q_PLUGIN_CONF_PATH
526 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
527 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
528
529 iniset /$Q_PLUGIN_CONF_FILE database connection `database_connection_url $Q_DB_NAME`
530 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
531
532 # If addition config files are set, make sure their path name is set as well
533 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
534 die $LINENO "Neutron additional plugin config not set.. exiting"
535 fi
536
537 # If additional config files exist, copy them over to neutron configuration
538 # directory
539 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
540 mkdir -p /$Q_PLUGIN_EXTRA_CONF_PATH
541 local f
542 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
543 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
544 cp $NEUTRON_DIR/${Q_PLUGIN_EXTRA_CONF_FILES[$f]} /${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
545 done
546 fi
547
Joe Gordonbee5c502013-08-30 13:48:08 -0400548 if [ "$VIRT_DRIVER" = 'fake' ]; then
549 # Disable arbitrary limits
550 iniset $NEUTRON_CONF quotas quota_network -1
551 iniset $NEUTRON_CONF quotas quota_subnet -1
552 iniset $NEUTRON_CONF quotas quota_port -1
553 iniset $NEUTRON_CONF quotas quota_security_group -1
554 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
555 fi
556
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700557 # Format logging
558 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800559 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700560 fi
561
Mark McClainb05c8762013-07-06 23:29:39 -0400562 _neutron_setup_rootwrap
563}
564
565function _configure_neutron_debug_command() {
566 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
567 return
568 fi
569
570 cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
571
572 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
573 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
574 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
575 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT root_helper "$Q_RR_COMMAND"
576 # Intermediate fix until Neutron patch lands and then line above will
577 # be cleaned.
578 iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
579
Mark McClainb05c8762013-07-06 23:29:39 -0400580 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
581
582 neutron_plugin_configure_debug_command
583}
584
585function _configure_neutron_dhcp_agent() {
586 AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
587 Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
588
589 cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
590
591 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500592 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400593 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
594 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
595
Kyle Mestery73b21912013-08-22 11:25:21 +0000596 # Define extra "DEFAULT" configuration options when q-dhcp is configured by
597 # defining the array ``Q_DHCP_EXTRA_DEFAULT_OPTS``.
598 # For Example: ``Q_DHCP_EXTRA_DEFAULT_OPTS=(foo=true bar=2)``
599 for I in "${Q_DHCP_EXTRA_DEFAULT_OPTS[@]}"; do
600 # Replace the first '=' with ' ' for iniset syntax
601 iniset $Q_DHCP_CONF_FILE DEFAULT ${I/=/ }
602 done
603
Mark McClainb05c8762013-07-06 23:29:39 -0400604 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
605
606 neutron_plugin_configure_dhcp_agent
607}
608
609function _configure_neutron_l3_agent() {
610 Q_L3_ENABLED=True
611 # for l3-agent, only use per tenant router if we have namespaces
612 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700613
614 AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
Mark McClainb05c8762013-07-06 23:29:39 -0400615 Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
616
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700617 if is_service_enabled q-fwaas; then
618 Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
619 fi
620
Mark McClainb05c8762013-07-06 23:29:39 -0400621 cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
622
623 iniset $Q_L3_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500624 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400625 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
626 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
627
Mark McClainb05c8762013-07-06 23:29:39 -0400628 _neutron_setup_interface_driver $Q_L3_CONF_FILE
629
630 neutron_plugin_configure_l3_agent
631}
632
633function _configure_neutron_metadata_agent() {
634 AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
635 Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
636
637 cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
638
639 iniset $Q_META_CONF_FILE DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500640 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400641 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
642 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
643
Yong Sheng Gong8535d8b2013-08-25 11:21:13 +0800644 _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT True True True
Maru Newbybf10ac52013-08-10 21:27:54 +0000645
Mark McClainb05c8762013-07-06 23:29:39 -0400646}
647
648function _configure_neutron_lbaas() {
649 neutron_agent_lbaas_configure_common
650 neutron_agent_lbaas_configure_agent
651}
652
Emilien Macchi40546f72013-09-24 15:10:25 +0200653function _configure_neutron_metering() {
654 neutron_agent_metering_configure_common
655 neutron_agent_metering_configure_agent
656}
657
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700658function _configure_neutron_fwaas() {
659 neutron_fwaas_configure_common
660 neutron_fwaas_configure_driver
661}
662
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700663function _configure_neutron_vpn()
664{
665 neutron_vpn_install_agent_packages
666 neutron_vpn_configure_common
Nachi Ueno69b3ff62013-06-07 10:28:33 -0700667}
668
Mark McClainb05c8762013-07-06 23:29:39 -0400669# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
670# It is called when q-agt is enabled.
671function _configure_neutron_plugin_agent() {
672 # Specify the default root helper prior to agent configuration to
673 # ensure that an agent's configuration can override the default
674 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
675 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500676 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400677
678 # Configure agent for plugin
679 neutron_plugin_configure_plugin_agent
680}
681
682# _configure_neutron_service() - Set config files for neutron service
683# It is called when q-svc is enabled.
684function _configure_neutron_service() {
685 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
686 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
687
688 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
689 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
690
Mark McClainb05c8762013-07-06 23:29:39 -0400691 # Update either configuration file with plugin
692 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
693
694 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
695 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
696 fi
697
698 iniset $NEUTRON_CONF DEFAULT verbose True
Ben Nemec03997942013-08-10 09:56:16 -0500699 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400700 iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
701 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
702
703 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
704 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
705
Simon Pasquierca96b0a2013-07-09 16:59:12 +0200706 # Define extra "DEFAULT" configuration options when q-svc is configured by
707 # defining the array ``Q_SRV_EXTRA_DEFAULT_OPTS``.
708 # For Example: ``Q_SRV_EXTRA_DEFAULT_OPTS=(foo=true bar=2)``
709 for I in "${Q_SRV_EXTRA_DEFAULT_OPTS[@]}"; do
710 # Replace the first '=' with ' ' for iniset syntax
711 iniset $NEUTRON_CONF DEFAULT ${I/=/ }
712 done
713
Mark McClainb05c8762013-07-06 23:29:39 -0400714 # Configure plugin
715 neutron_plugin_configure_service
716}
717
718# Utility Functions
719#------------------
720
721# _neutron_setup_rootwrap() - configure Neutron's rootwrap
722function _neutron_setup_rootwrap() {
723 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
724 return
725 fi
726 # Deploy new rootwrap filters files (owned by root).
727 # Wipe any existing ``rootwrap.d`` files first
728 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
729 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
730 sudo rm -rf $Q_CONF_ROOTWRAP_D
731 fi
732 # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
733 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
734 cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
735 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
736 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
737 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
738 # location moved in newer versions, prefer new location
739 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Sean Dague3bdb9222013-10-22 08:36:16 -0400740 sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400741 else
Sean Dague3bdb9222013-10-22 08:36:16 -0400742 sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400743 fi
744 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
745 sudo chown root:root $Q_RR_CONF_FILE
746 sudo chmod 0644 $Q_RR_CONF_FILE
747 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
748 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
749
750 # Set up the rootwrap sudoers for neutron
751 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100752 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400753 chmod 0440 $TEMPFILE
754 sudo chown root:root $TEMPFILE
755 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
756
757 # Update the root_helper
758 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
759}
760
761# Configures keystone integration for neutron service and agents
762function _neutron_setup_keystone() {
763 local conf_file=$1
764 local section=$2
765 local use_auth_url=$3
Maru Newbybf10ac52013-08-10 21:27:54 +0000766 local skip_auth_cache=$4
Yong Sheng Gong8535d8b2013-08-25 11:21:13 +0800767 local use_service_port=$5
768 local keystone_port=$KEYSTONE_AUTH_PORT
769 if [[ -n $use_service_port ]]; then
770 keystone_port=$KEYSTONE_SERVICE_PORT
771 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400772 if [[ -n $use_auth_url ]]; then
Yong Sheng Gong8535d8b2013-08-25 11:21:13 +0800773 iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$keystone_port/v2.0"
Mark McClainb05c8762013-07-06 23:29:39 -0400774 else
775 iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST
Yong Sheng Gong8535d8b2013-08-25 11:21:13 +0800776 iniset $conf_file $section auth_port $keystone_port
Mark McClainb05c8762013-07-06 23:29:39 -0400777 iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL
778 fi
779 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
780 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
781 iniset $conf_file $section admin_password $SERVICE_PASSWORD
Maru Newbybf10ac52013-08-10 21:27:54 +0000782 if [[ -z $skip_auth_cache ]]; then
783 iniset $conf_file $section signing_dir $NEUTRON_AUTH_CACHE_DIR
784 # Create cache dir
785 sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
786 sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
787 rm -f $NEUTRON_AUTH_CACHE_DIR/*
788 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400789}
790
791function _neutron_setup_interface_driver() {
792
793 # ovs_use_veth needs to be set before the plugin configuration
794 # occurs to allow plugins to override the setting.
795 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
796
797 neutron_plugin_setup_interface_driver $1
798}
799
800# Functions for Neutron Exercises
801#--------------------------------
802
803function delete_probe() {
804 local from_net="$1"
805 net_id=`_get_net_id $from_net`
806 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}'`
807 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
808}
809
810function setup_neutron_debug() {
811 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
812 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
813 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
814 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
815 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
816 fi
817}
818
819function teardown_neutron_debug() {
820 delete_probe $PUBLIC_NETWORK_NAME
821 delete_probe $PRIVATE_NETWORK_NAME
822}
823
824function _get_net_id() {
825 neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
826}
827
828function _get_probe_cmd_prefix() {
829 local from_net="$1"
830 net_id=`_get_net_id $from_net`
831 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`
832 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
833}
834
835function _ping_check_neutron() {
836 local from_net=$1
837 local ip=$2
838 local timeout_sec=$3
839 local expected=${4:-"True"}
840 local check_command=""
841 probe_cmd=`_get_probe_cmd_prefix $from_net`
842 if [[ "$expected" = "True" ]]; then
843 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
844 else
845 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
846 fi
847 if ! timeout $timeout_sec sh -c "$check_command"; then
848 if [[ "$expected" = "True" ]]; then
849 die $LINENO "[Fail] Couldn't ping server"
850 else
851 die $LINENO "[Fail] Could ping server"
852 fi
853 fi
854}
855
856# ssh check
857function _ssh_check_neutron() {
858 local from_net=$1
859 local key_file=$2
860 local ip=$3
861 local user=$4
862 local timeout_sec=$5
863 local probe_cmd = ""
864 probe_cmd=`_get_probe_cmd_prefix $from_net`
865 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
866 die $LINENO "server didn't become ssh-able!"
867 fi
868}
869
870# Neutron 3rd party programs
871#---------------------------
872
873# please refer to ``lib/neutron_thirdparty/README.md`` for details
874NEUTRON_THIRD_PARTIES=""
875for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -0400876 third_party=$(basename $f)
877 if is_service_enabled $third_party; then
878 source $TOP_DIR/lib/neutron_thirdparty/$third_party
879 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
880 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400881done
882
883function _neutron_third_party_do() {
884 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
885 ${1}_${third_party}
886 done
887}
888
889# configure_neutron_third_party() - Set config files, create data dirs, etc
890function configure_neutron_third_party() {
891 _neutron_third_party_do configure
892}
893
894# init_neutron_third_party() - Initialize databases, etc.
895function init_neutron_third_party() {
896 _neutron_third_party_do init
897}
898
899# install_neutron_third_party() - Collect source and prepare
900function install_neutron_third_party() {
901 _neutron_third_party_do install
902}
903
904# start_neutron_third_party() - Start running processes, including screen
905function start_neutron_third_party() {
906 _neutron_third_party_do start
907}
908
909# stop_neutron_third_party - Stop running processes (non-screen)
910function stop_neutron_third_party() {
911 _neutron_third_party_do stop
912}
913
914
915# Restore xtrace
916$XTRACE
917
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100918# Tell emacs to use shell-script-mode
919## Local variables:
920## mode: shell-script
921## End: