blob: 788db537bd3a220dd223a92d5c6fc2f595726882 [file] [log] [blame]
Salvatore Orlandod6767d02012-08-31 04:55:20 -07001# lib/quantum
2# functions - funstions specific to quantum
3
Dean Troyer60e9c0a2012-12-06 15:52:52 -06004# Dependencies:
5# ``functions`` file
6# ``DEST`` must be defined
7
Akihiro MOTOKI66afb472012-12-21 15:34:13 +09008# ``stack.sh`` calls the entry points in this order:
9#
10# install_quantum
11# install_quantumclient
12# install_quantum_agent_packages
13# install_quantum_third_party
14# setup_quantum
15# setup_quantumclient
16# configure_quantum
17# init_quantum
18# configure_quantum_third_party
19# init_quantum_third_party
20# start_quantum_third_party
21# create_nova_conf_quantum
22# start_quantum_service_and_check
23# create_quantum_initial_network
24# setup_quantum_debug
25# start_quantum_agents
26#
27# ``unstack.sh`` calls the entry points in this order:
28#
29# stop_quantum
30
31# Functions in lib/quantum are classified into the following categories:
32#
33# - entry points (called from stack.sh or unstack.sh)
34# - internal functions
35# - quantum exercises
36# - 3rd party programs
37
Dean Troyer60e9c0a2012-12-06 15:52:52 -060038
39# Quantum Networking
40# ------------------
41
42# Make sure that quantum is enabled in ``ENABLED_SERVICES``. If you want
43# to run Quantum on this host, make sure that q-svc is also in
44# ``ENABLED_SERVICES``.
45#
46# If you're planning to use the Quantum 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 Quantum
49# linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the
50# q-agt service is enabled in ``ENABLED_SERVICES``.
51#
52# See "Quantum Network Configuration" below for additional variables
53# that must be set in localrc for connectivity across hosts with
54# Quantum.
55#
56# With Quantum networking the NET_MAN variable is ignored.
57
58
Salvatore Orlandod6767d02012-08-31 04:55:20 -070059# Save trace setting
60XTRACE=$(set +o | grep xtrace)
61set +o xtrace
62
Dean Troyer60e9c0a2012-12-06 15:52:52 -060063
Akihiro MOTOKI66afb472012-12-21 15:34:13 +090064# Quantum Network Configuration
65# -----------------------------
Dean Troyer60e9c0a2012-12-06 15:52:52 -060066
67# Set up default directories
Nachi Ueno8bc21f62012-11-19 22:04:28 -080068QUANTUM_DIR=$DEST/quantum
Dean Troyer60e9c0a2012-12-06 15:52:52 -060069QUANTUMCLIENT_DIR=$DEST/python-quantumclient
Gary Kotton9343df12012-11-28 10:05:53 +000070QUANTUM_AUTH_CACHE_DIR=${QUANTUM_AUTH_CACHE_DIR:-/var/cache/quantum}
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070071
Dean Troyer60e9c0a2012-12-06 15:52:52 -060072QUANTUM_CONF_DIR=/etc/quantum
73QUANTUM_CONF=$QUANTUM_CONF_DIR/quantum.conf
74export QUANTUM_TEST_CONFIG_FILE=${QUANTUM_TEST_CONFIG_FILE:-"$QUANTUM_CONF_DIR/debug.ini"}
75
76# Default Quantum Plugin
77Q_PLUGIN=${Q_PLUGIN:-openvswitch}
78# Default Quantum Port
79Q_PORT=${Q_PORT:-9696}
80# Default Quantum Host
81Q_HOST=${Q_HOST:-$HOST_IP}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060082# Default admin username
83Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-quantum}
84# Default auth strategy
85Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
86# Use namespace or not
87Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
88Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
89# Meta data IP
90Q_META_DATA_IP=${Q_META_DATA_IP:-$HOST_IP}
Akihiro MOTOKI66afb472012-12-21 15:34:13 +090091# Allow Overlapping IP among subnets
92Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-False}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060093# Use quantum-debug command
94Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
Maru Newby31c94ab2012-12-19 03:59:20 +000095# The name of the default q-l3 router
96Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060097
Nachi Ueno8bc21f62012-11-19 22:04:28 -080098if is_service_enabled quantum; then
Dean Troyer60e9c0a2012-12-06 15:52:52 -060099 Q_RR_CONF_FILE=$QUANTUM_CONF_DIR/rootwrap.conf
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800100 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
101 Q_RR_COMMAND="sudo"
102 else
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800103 QUANTUM_ROOTWRAP=$(get_rootwrap_location quantum)
104 Q_RR_COMMAND="sudo $QUANTUM_ROOTWRAP $Q_RR_CONF_FILE"
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800105 fi
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800106
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900107 # Provider Network Configurations
108 # --------------------------------
109
110 # The following variables control the Quantum openvswitch and
111 # linuxbridge plugins' allocation of tenant networks and
112 # availability of provider networks. If these are not configured
113 # in localrc, tenant networks will be local to the host (with no
114 # remote connectivity), and no physical resources will be
115 # available for the allocation of provider networks.
116
117 # To use GRE tunnels for tenant networks, set to True in
118 # localrc. GRE tunnels are only supported by the openvswitch
119 # plugin, and currently only on Ubuntu.
120 ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False}
121
122 # If using GRE tunnels for tenant networks, specify the range of
123 # tunnel IDs from which tenant networks are allocated. Can be
124 # overriden in localrc in necesssary.
125 TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGE:-1:1000}
126
127 # To use VLANs for tenant networks, set to True in localrc. VLANs
128 # are supported by the openvswitch and linuxbridge plugins, each
129 # requiring additional configuration described below.
130 ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
131
132 # If using VLANs for tenant networks, set in localrc to specify
133 # the range of VLAN VIDs from which tenant networks are
134 # allocated. An external network switch must be configured to
135 # trunk these VLANs between hosts for multi-host connectivity.
136 #
137 # Example: ``TENANT_VLAN_RANGE=1000:1999``
138 TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
139
140 # If using VLANs for tenant networks, or if using flat or VLAN
141 # provider networks, set in localrc to the name of the physical
142 # network, and also configure OVS_PHYSICAL_BRIDGE for the
143 # openvswitch agent or LB_PHYSICAL_INTERFACE for the linuxbridge
144 # agent, as described below.
145 #
146 # Example: ``PHYSICAL_NETWORK=default``
147 PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
148
149 # With the openvswitch plugin, if using VLANs for tenant networks,
150 # or if using flat or VLAN provider networks, set in localrc to
151 # the name of the OVS bridge to use for the physical network. The
152 # bridge will be created if it does not already exist, but a
153 # physical interface must be manually added to the bridge as a
154 # port for external connectivity.
155 #
156 # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
157 OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
158
159 # With the linuxbridge plugin, if using VLANs for tenant networks,
160 # or if using flat or VLAN provider networks, set in localrc to
161 # the name of the network interface to use for the physical
162 # network.
163 #
164 # Example: ``LB_PHYSICAL_INTERFACE=eth1``
165 LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
166
167 # With the openvswitch plugin, set to True in localrc to enable
168 # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
169 #
170 # Example: ``OVS_ENABLE_TUNNELING=True``
171 OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
172fi
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600173
174# Entry Points
175# ------------
176
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900177# configure_quantum()
178# Set common config for all quantum server and agents.
179function configure_quantum() {
180 _configure_quantum_common
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900181 iniset_rpc_backend quantum $QUANTUM_CONF DEFAULT
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900182
183 if is_service_enabled q-svc; then
184 _configure_quantum_service
185 fi
186 if is_service_enabled q-agt; then
187 _configure_quantum_plugin_agent
188 fi
189 if is_service_enabled q-dhcp; then
190 _configure_quantum_dhcp_agent
191 fi
192 if is_service_enabled q-l3; then
193 _configure_quantum_l3_agent
194 fi
195 if is_service_enabled q-meta; then
196 _configure_quantum_metadata_agent
197 fi
198
199 _configure_quantum_debug_command
200
201 _cleanup_quantum
202}
203
204function create_nova_conf_quantum() {
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800205 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.quantumv2.api.API"
206 iniset $NOVA_CONF DEFAULT quantum_admin_username "$Q_ADMIN_USERNAME"
207 iniset $NOVA_CONF DEFAULT quantum_admin_password "$SERVICE_PASSWORD"
208 iniset $NOVA_CONF DEFAULT quantum_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
209 iniset $NOVA_CONF DEFAULT quantum_auth_strategy "$Q_AUTH_STRATEGY"
210 iniset $NOVA_CONF DEFAULT quantum_admin_tenant_name "$SERVICE_TENANT_NAME"
211 iniset $NOVA_CONF DEFAULT quantum_url "http://$Q_HOST:$Q_PORT"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900212
213 if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
214 NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver"}
Maru Newby2298ca42012-10-25 23:46:42 +0000215 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
216 add_nova_opt "xenapi_vif_driver=nova.virt.xenapi.vif.XenAPIOpenVswitchDriver"
217 add_nova_opt "xenapi_ovs_integration_bridge=$FLAT_NETWORK_BRIDGE"
218 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900219 elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
220 NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.QuantumLinuxBridgeVIFDriver"}
221 elif [[ "$Q_PLUGIN" = "ryu" ]]; then
222 NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"quantum.plugins.ryu.nova.vif.LibvirtOpenVswitchOFPRyuDriver"}
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800223 iniset $NOVA_CONF DEFAULT libvirt_ovs_integration_bridge "$OVS_BRIDGE"
224 iniset $NOVA_CONF DEFAULT linuxnet_ovs_ryu_api_host "$RYU_API_HOST:$RYU_API_PORT"
225 iniset $NOVA_CONF DEFAULT libvirt_ovs_ryu_api_host "$RYU_API_HOST:$RYU_API_PORT"
Sumit Naiksatam4b26d312013-01-04 10:32:54 -0800226 elif [[ "$Q_PLUGIN" = "bigswitch_floodlight" ]]; then
227 NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver"}
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900228 fi
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800229 iniset $NOVA_CONF DEFAULT libvirt_vif_driver "$NOVA_VIF_DRIVER"
230 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900231 if is_service_enabled q-meta; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800232 iniset $NOVA_CONF DEFAULT service_quantum_metadata_proxy "True"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900233 fi
234}
235
236# create_quantum_accounts() - Set up common required quantum accounts
237
238# Tenant User Roles
239# ------------------------------------------------------------------
240# service quantum admin # if enabled
241
242# Migrated from keystone_data.sh
243function create_quantum_accounts() {
244
245 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
246 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
247
248 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
249 QUANTUM_USER=$(keystone user-create \
250 --name=quantum \
251 --pass="$SERVICE_PASSWORD" \
252 --tenant_id $SERVICE_TENANT \
253 --email=quantum@example.com \
254 | grep " id " | get_field 2)
255 keystone user-role-add \
256 --tenant_id $SERVICE_TENANT \
257 --user_id $QUANTUM_USER \
258 --role_id $ADMIN_ROLE
259 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
260 QUANTUM_SERVICE=$(keystone service-create \
261 --name=quantum \
262 --type=network \
263 --description="Quantum Service" \
264 | grep " id " | get_field 2)
265 keystone endpoint-create \
266 --region RegionOne \
267 --service_id $QUANTUM_SERVICE \
268 --publicurl "http://$SERVICE_HOST:9696/" \
269 --adminurl "http://$SERVICE_HOST:9696/" \
270 --internalurl "http://$SERVICE_HOST:9696/"
271 fi
272 fi
273}
274
275function create_quantum_initial_network() {
276 TENANT_ID=$(keystone tenant-list | grep " demo " | get_field 1)
277
278 # Create a small network
279 # Since quantum command is executed in admin context at this point,
280 # ``--tenant_id`` needs to be specified.
281 NET_ID=$(quantum net-create --tenant_id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
282 SUBNET_ID=$(quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
283
284 if is_service_enabled q-l3; then
285 # Create a router, and add the private subnet as one of its interfaces
Maru Newby31c94ab2012-12-19 03:59:20 +0000286 if [[ "$Q_USE_NAMESPACE" == "True" ]]; then
287 # If namespaces are enabled, create a tenant-owned router.
288 ROUTER_ID=$(quantum router-create --tenant_id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
289 else
290 # If namespaces are disabled, the L3 agent can only target
291 # a single router, which should not be tenant-owned.
292 ROUTER_ID=$(quantum router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
293 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900294 quantum router-interface-add $ROUTER_ID $SUBNET_ID
295 # Create an external network, and a subnet. Configure the external network as router gw
296 EXT_NET_ID=$(quantum net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
297 EXT_GW_IP=$(quantum subnet-create --ip_version 4 $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2)
298 quantum router-gateway-set $ROUTER_ID $EXT_NET_ID
299
300 if is_quantum_ovs_base_plugin "$Q_PLUGIN" && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
301 CIDR_LEN=${FLOATING_RANGE#*/}
302 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
303 sudo ip link set $PUBLIC_BRIDGE up
304 ROUTER_GW_IP=`quantum port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'`
305 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
306 fi
307 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
308 # Explicitly set router id in l3 agent configuration
309 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
310 fi
311 fi
312}
313
314# init_quantum() - Initialize databases, etc.
315function init_quantum() {
316 :
317}
318
319# install_quantum() - Collect source and prepare
320function install_quantum() {
321 git_clone $QUANTUM_REPO $QUANTUM_DIR $QUANTUM_BRANCH
322}
323
324# install_quantumclient() - Collect source and prepare
325function install_quantumclient() {
326 git_clone $QUANTUMCLIENT_REPO $QUANTUMCLIENT_DIR $QUANTUMCLIENT_BRANCH
327}
328
329# install_quantum_agent_packages() - Collect source and prepare
330function install_quantum_agent_packages() {
331 if is_quantum_ovs_base_plugin "$Q_PLUGIN"; then
332 # Install deps
333 # FIXME add to ``files/apts/quantum``, but don't install if not needed!
334 if is_ubuntu; then
335 kernel_version=`cat /proc/version | cut -d " " -f3`
336 install_package make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms linux-headers-$kernel_version
337 else
338 ### FIXME(dtroyer): Find RPMs for OpenVSwitch
339 echo "OpenVSwitch packages need to be located"
340 # Fedora does not started OVS by default
341 restart_service openvswitch
342 fi
343 elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
344 install_package bridge-utils
345 fi
346}
347
348function is_quantum_ovs_base_plugin() {
349 local plugin=$1
Sumit Naiksatam4b26d312013-01-04 10:32:54 -0800350 if [[ ",openvswitch,ryu,bigswitch_floodlight," =~ ,${plugin}, ]]; then
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900351 return 0
352 fi
353 return 1
354}
355
356function setup_quantum() {
357 setup_develop $QUANTUM_DIR
358}
359
360function setup_quantumclient() {
361 setup_develop $QUANTUMCLIENT_DIR
362}
363
364# Start running processes, including screen
365function start_quantum_service_and_check() {
366 # Start the Quantum service
367 screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
368 echo "Waiting for Quantum to start..."
369 if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://127.0.0.1:9696; do sleep 1; done"; then
370 echo "Quantum did not start"
371 exit 1
372 fi
373}
374
375# Start running processes, including screen
376function start_quantum_agents() {
377 # Start up the quantum agents if enabled
378 screen_it q-agt "python $AGENT_BINARY --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
379 screen_it q-dhcp "python $AGENT_DHCP_BINARY --config-file $QUANTUM_CONF --config-file=$Q_DHCP_CONF_FILE"
380 screen_it q-meta "python $AGENT_META_BINARY --config-file $QUANTUM_CONF --config-file=$Q_META_CONF_FILE"
381 screen_it q-l3 "python $AGENT_L3_BINARY --config-file $QUANTUM_CONF --config-file=$Q_L3_CONF_FILE"
382}
383
384# stop_quantum() - Stop running processes (non-screen)
385function stop_quantum() {
386 if is_service_enabled q-dhcp; then
387 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
388 [ ! -z "$pid" ] && sudo kill -9 $pid
389 fi
390}
391
392# _cleanup_quantum() - Remove residual data files, anything left over from previous
393# runs that a clean run would need to clean up
394function _cleanup_quantum() {
395 :
396}
397
398# _configure_quantum_common()
399# Set common config for all quantum server and agents.
400# This MUST be called before other _configure_quantum_* functions.
401function _configure_quantum_common() {
402 # Put config files in ``QUANTUM_CONF_DIR`` for everyone to find
403 if [[ ! -d $QUANTUM_CONF_DIR ]]; then
404 sudo mkdir -p $QUANTUM_CONF_DIR
405 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100406 sudo chown $STACK_USER $QUANTUM_CONF_DIR
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900407
408 cp $QUANTUM_DIR/etc/quantum.conf $QUANTUM_CONF
409
410 if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
411 Q_PLUGIN_CONF_PATH=etc/quantum/plugins/openvswitch
412 Q_PLUGIN_CONF_FILENAME=ovs_quantum_plugin.ini
413 Q_DB_NAME="ovs_quantum"
414 Q_PLUGIN_CLASS="quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2"
415 elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
416 Q_PLUGIN_CONF_PATH=etc/quantum/plugins/linuxbridge
417 Q_PLUGIN_CONF_FILENAME=linuxbridge_conf.ini
418 Q_DB_NAME="quantum_linux_bridge"
419 Q_PLUGIN_CLASS="quantum.plugins.linuxbridge.lb_quantum_plugin.LinuxBridgePluginV2"
420 elif [[ "$Q_PLUGIN" = "ryu" ]]; then
421 Q_PLUGIN_CONF_PATH=etc/quantum/plugins/ryu
422 Q_PLUGIN_CONF_FILENAME=ryu.ini
423 Q_DB_NAME="ovs_quantum"
424 Q_PLUGIN_CLASS="quantum.plugins.ryu.ryu_quantum_plugin.RyuQuantumPluginV2"
Sumit Naiksatam4b26d312013-01-04 10:32:54 -0800425 elif [[ "$Q_PLUGIN" = "bigswitch_floodlight" ]]; then
426 Q_PLUGIN_CONF_PATH=etc/quantum/plugins/bigswitch
427 Q_PLUGIN_CONF_FILENAME=restproxy.ini
428 Q_DB_NAME="restproxy_quantum"
429 Q_PLUGIN_CLASS="quantum.plugins.bigswitch.plugin.QuantumRestProxyV2"
430 BS_FL_CONTROLLERS_PORT=${BS_FL_CONTROLLERS_PORT:-localhost:80}
431 BS_FL_CONTROLLER_TIMEOUT=${BS_FL_CONTROLLER_TIMEOUT:-10}
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900432 fi
433
434 if [[ $Q_PLUGIN_CONF_PATH == '' || $Q_PLUGIN_CONF_FILENAME == '' || $Q_PLUGIN_CLASS == '' ]]; then
435 echo "Quantum plugin not set.. exiting"
436 exit 1
437 fi
438
439 # If needed, move config file from ``$QUANTUM_DIR/etc/quantum`` to ``QUANTUM_CONF_DIR``
440 mkdir -p /$Q_PLUGIN_CONF_PATH
441 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
442 cp $QUANTUM_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
443
444 database_connection_url dburl $Q_DB_NAME
445 iniset /$Q_PLUGIN_CONF_FILE DATABASE sql_connection $dburl
446 unset dburl
447
448 _quantum_setup_rootwrap
449}
450
451function _configure_quantum_debug_command() {
452 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
453 return
454 fi
455
456 cp $QUANTUM_DIR/etc/l3_agent.ini $QUANTUM_TEST_CONFIG_FILE
457
458 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT verbose False
459 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT debug False
460 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
461 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT root_helper "$Q_RR_COMMAND"
462
463 _quantum_setup_keystone $QUANTUM_TEST_CONFIG_FILE DEFAULT set_auth_url
464 _quantum_setup_interface_driver $QUANTUM_TEST_CONFIG_FILE
465
466 if is_quantum_ovs_base_plugin "$Q_PLUGIN"; then
467 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
468 elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
469 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT external_network_bridge ''
470 fi
471
472 if [[ "$Q_PLUGIN" = "ryu" ]]; then
473 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT ryu_api_host $RYU_API_HOST:$RYU_API_PORT
474 fi
475}
476
477function _configure_quantum_dhcp_agent() {
478 AGENT_DHCP_BINARY="$QUANTUM_DIR/bin/quantum-dhcp-agent"
479 Q_DHCP_CONF_FILE=$QUANTUM_CONF_DIR/dhcp_agent.ini
480
481 cp $QUANTUM_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
482
483 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
484 iniset $Q_DHCP_CONF_FILE DEFAULT debug True
485 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
486 iniset $Q_DHCP_CONF_FILE DEFAULT state_path $DATA_DIR/quantum
487 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
488
489 _quantum_setup_keystone $Q_DHCP_CONF_FILE DEFAULT set_auth_url
490 _quantum_setup_interface_driver $Q_DHCP_CONF_FILE
491
492 if [[ "$Q_PLUGIN" = "ryu" ]]; then
493 iniset $Q_DHCP_CONF_FILE DEFAULT ryu_api_host $RYU_API_HOST:$RYU_API_PORT
494 fi
495}
496
497function _configure_quantum_l3_agent() {
498 AGENT_L3_BINARY="$QUANTUM_DIR/bin/quantum-l3-agent"
499 PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex}
500 Q_L3_CONF_FILE=$QUANTUM_CONF_DIR/l3_agent.ini
501
502 cp $QUANTUM_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
503
504 iniset $Q_L3_CONF_FILE DEFAULT verbose True
505 iniset $Q_L3_CONF_FILE DEFAULT debug True
506 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
507 iniset $Q_L3_CONF_FILE DEFAULT state_path $DATA_DIR/quantum
508 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
509
510 _quantum_setup_keystone $Q_L3_CONF_FILE DEFAULT set_auth_url
511 _quantum_setup_interface_driver $Q_L3_CONF_FILE
512
513 if is_quantum_ovs_base_plugin "$Q_PLUGIN"; then
514 iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
515 _quantum_setup_external_bridge $PUBLIC_BRIDGE
516 elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
517 iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge ''
518 fi
519
520 if [[ "$Q_PLUGIN" = "ryu" ]]; then
521 iniset $Q_L3_CONF_FILE DEFAULT ryu_api_host $RYU_API_HOST:$RYU_API_PORT
522 fi
523}
524
525function _configure_quantum_metadata_agent() {
526 AGENT_META_BINARY="$QUANTUM_DIR/bin/quantum-metadata-agent"
527 Q_META_CONF_FILE=$QUANTUM_CONF_DIR/metadata_agent.ini
528
529 cp $QUANTUM_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
530
531 iniset $Q_META_CONF_FILE DEFAULT verbose True
532 iniset $Q_META_CONF_FILE DEFAULT debug True
533 iniset $Q_META_CONF_FILE DEFAULT state_path $DATA_DIR/quantum
534 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
535 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
536
537 _quantum_setup_keystone $Q_META_CONF_FILE DEFAULT set_auth_url
538}
539
540# _configure_quantum_plugin_agent() - Set config files for quantum plugin agent
541# It is called when q-agt is enabled.
542function _configure_quantum_plugin_agent() {
Maru Newby2298ca42012-10-25 23:46:42 +0000543
544 # Specify the default root helper prior to agent configuration to
545 # ensure that an agent's configuration can override the default.
546 iniset /$Q_PLUGIN_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
547
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900548 # Configure agent for plugin
549 if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
550 _configure_quantum_plugin_agent_openvswitch
551 elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
552 _configure_quantum_plugin_agent_linuxbridge
553 elif [[ "$Q_PLUGIN" = "ryu" ]]; then
554 _configure_quantum_plugin_agent_ryu
555 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900556}
557
558function _configure_quantum_plugin_agent_linuxbridge() {
559 # Setup physical network interface mappings. Override
560 # ``LB_VLAN_RANGES`` and ``LB_INTERFACE_MAPPINGS`` in ``localrc`` for more
561 # complex physical network configurations.
562 if [[ "$LB_INTERFACE_MAPPINGS" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]] && [[ "$LB_PHYSICAL_INTERFACE" != "" ]]; then
563 LB_INTERFACE_MAPPINGS=$PHYSICAL_NETWORK:$LB_PHYSICAL_INTERFACE
564 fi
565 if [[ "$LB_INTERFACE_MAPPINGS" != "" ]]; then
566 iniset /$Q_PLUGIN_CONF_FILE LINUX_BRIDGE physical_interface_mappings $LB_INTERFACE_MAPPINGS
567 fi
568 AGENT_BINARY="$QUANTUM_DIR/bin/quantum-linuxbridge-agent"
569}
570
571function _configure_quantum_plugin_agent_openvswitch() {
572 # Setup integration bridge
573 OVS_BRIDGE=${OVS_BRIDGE:-br-int}
574 _quantum_setup_ovs_bridge $OVS_BRIDGE
575
576 # Setup agent for tunneling
577 if [[ "$OVS_ENABLE_TUNNELING" = "True" ]]; then
578 # Verify tunnels are supported
579 # REVISIT - also check kernel module support for GRE and patch ports
580 OVS_VERSION=`ovs-vsctl --version | head -n 1 | awk '{print $4;}'`
581 if [ $OVS_VERSION \< "1.4" ] && ! is_service_enabled q-svc ; then
582 echo "You are running OVS version $OVS_VERSION."
583 echo "OVS 1.4+ is required for tunneling between multiple hosts."
584 exit 1
585 fi
586 iniset /$Q_PLUGIN_CONF_FILE OVS enable_tunneling True
587 iniset /$Q_PLUGIN_CONF_FILE OVS local_ip $HOST_IP
588 fi
589
590 # Setup physical network bridge mappings. Override
591 # ``OVS_VLAN_RANGES`` and ``OVS_BRIDGE_MAPPINGS`` in ``localrc`` for more
592 # complex physical network configurations.
593 if [[ "$OVS_BRIDGE_MAPPINGS" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]] && [[ "$OVS_PHYSICAL_BRIDGE" != "" ]]; then
594 OVS_BRIDGE_MAPPINGS=$PHYSICAL_NETWORK:$OVS_PHYSICAL_BRIDGE
595
596 # Configure bridge manually with physical interface as port for multi-node
597 sudo ovs-vsctl --no-wait -- --may-exist add-br $OVS_PHYSICAL_BRIDGE
598 fi
599 if [[ "$OVS_BRIDGE_MAPPINGS" != "" ]]; then
600 iniset /$Q_PLUGIN_CONF_FILE OVS bridge_mappings $OVS_BRIDGE_MAPPINGS
601 fi
602 AGENT_BINARY="$QUANTUM_DIR/bin/quantum-openvswitch-agent"
Maru Newby2298ca42012-10-25 23:46:42 +0000603
604 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
605 # Nova will always be installed along with quantum for a domU
606 # devstack install, so it should be safe to rely on nova.conf
607 # for xenapi configuration.
608 Q_RR_DOM0_COMMAND="$QUANTUM_DIR/bin/quantum-rootwrap-dom0 $NOVA_CONF"
609 # Under XS/XCP, the ovs agent needs to target the dom0
610 # integration bridge. This is enabled by using a root wrapper
611 # that executes commands on dom0 via a XenAPI plugin.
612 iniset /$Q_PLUGIN_CONF_FILE AGENT root_helper "$Q_RR_DOM0_COMMAND"
613
614 # FLAT_NETWORK_BRIDGE is the dom0 integration bridge. To
615 # ensure the bridge lacks direct connectivity, set
616 # VM_VLAN=-1;VM_DEV=invalid in localrc
617 iniset /$Q_PLUGIN_CONF_FILE OVS integration_bridge $FLAT_NETWORK_BRIDGE
618
619 # The ovs agent needs to ensure that the ports associated with
620 # a given network share the same local vlan tag. On
621 # single-node XS/XCP, this requires monitoring both the dom0
622 # bridge, where VM's are attached, and the domU bridge, where
623 # dhcp servers are attached.
624 if is_service_enabled q-dhcp; then
625 iniset /$Q_PLUGIN_CONF_FILE OVS domu_integration_bridge $OVS_BRIDGE
626 # DomU will use the regular rootwrap
627 iniset /$Q_PLUGIN_CONF_FILE AGENT domu_root_helper "$Q_RR_COMMAND"
628 # Plug the vm interface into the domU integration bridge.
629 sudo ip addr flush dev $GUEST_INTERFACE_DEFAULT
630 sudo ip link set $OVS_BRIDGE up
631 # Assign the VM IP only if it has been set explicitly
632 if [[ "$VM_IP" != "" ]]; then
633 sudo ip addr add $VM_IP dev $OVS_BRIDGE
634 fi
635 sudo ovs-vsctl add-port $OVS_BRIDGE $GUEST_INTERFACE_DEFAULT
636 fi
637 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900638}
639
640function _configure_quantum_plugin_agent_ryu() {
641 # Set up integration bridge
642 OVS_BRIDGE=${OVS_BRIDGE:-br-int}
643 _quantum_setup_ovs_bridge $OVS_BRIDGE
644 if [ -n "$RYU_INTERNAL_INTERFACE" ]; then
645 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_BRIDGE $RYU_INTERNAL_INTERFACE
646 fi
647 AGENT_BINARY="$QUANTUM_DIR/quantum/plugins/ryu/agent/ryu_quantum_agent.py"
648}
649
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900650# _configure_quantum_service() - Set config files for quantum service
651# It is called when q-svc is enabled.
652function _configure_quantum_service() {
653 Q_API_PASTE_FILE=$QUANTUM_CONF_DIR/api-paste.ini
654 Q_POLICY_FILE=$QUANTUM_CONF_DIR/policy.json
655
656 cp $QUANTUM_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
657 cp $QUANTUM_DIR/etc/policy.json $Q_POLICY_FILE
658
659 if is_service_enabled $DATABASE_BACKENDS; then
660 recreate_database $Q_DB_NAME utf8
661 else
662 echo "A database must be enabled in order to use the $Q_PLUGIN Quantum plugin."
663 exit 1
664 fi
665
666 # Update either configuration file with plugin
667 iniset $QUANTUM_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
668
669 iniset $QUANTUM_CONF DEFAULT verbose True
670 iniset $QUANTUM_CONF DEFAULT debug True
671 iniset $QUANTUM_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
672
673 iniset $QUANTUM_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
674 _quantum_setup_keystone $Q_API_PASTE_FILE filter:authtoken
675
676 # Configure plugin
677 if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
678 if [[ "$ENABLE_TENANT_TUNNELS" = "True" ]]; then
679 iniset /$Q_PLUGIN_CONF_FILE OVS tenant_network_type gre
680 iniset /$Q_PLUGIN_CONF_FILE OVS tunnel_id_ranges $TENANT_TUNNEL_RANGES
681 elif [[ "$ENABLE_TENANT_VLANS" = "True" ]]; then
682 iniset /$Q_PLUGIN_CONF_FILE OVS tenant_network_type vlan
683 else
684 echo "WARNING - The openvswitch plugin is using local tenant networks, with no connectivity between hosts."
685 fi
686
687 # Override ``OVS_VLAN_RANGES`` and ``OVS_BRIDGE_MAPPINGS`` in ``localrc``
688 # for more complex physical network configurations.
689 if [[ "$OVS_VLAN_RANGES" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]]; then
690 OVS_VLAN_RANGES=$PHYSICAL_NETWORK
691 if [[ "$TENANT_VLAN_RANGE" != "" ]]; then
692 OVS_VLAN_RANGES=$OVS_VLAN_RANGES:$TENANT_VLAN_RANGE
693 fi
694 fi
695 if [[ "$OVS_VLAN_RANGES" != "" ]]; then
696 iniset /$Q_PLUGIN_CONF_FILE OVS network_vlan_ranges $OVS_VLAN_RANGES
697 fi
698
699 # Enable tunnel networks if selected
700 if [[ $OVS_ENABLE_TUNNELING = "True" ]]; then
701 iniset /$Q_PLUGIN_CONF_FILE OVS enable_tunneling True
702 fi
703 elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
704 if [[ "$ENABLE_TENANT_VLANS" = "True" ]]; then
705 iniset /$Q_PLUGIN_CONF_FILE VLANS tenant_network_type vlan
706 else
707 echo "WARNING - The linuxbridge plugin is using local tenant networks, with no connectivity between hosts."
708 fi
709
710 # Override ``LB_VLAN_RANGES`` and ``LB_INTERFACE_MAPPINGS`` in ``localrc``
711 # for more complex physical network configurations.
712 if [[ "$LB_VLAN_RANGES" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]]; then
713 LB_VLAN_RANGES=$PHYSICAL_NETWORK
714 if [[ "$TENANT_VLAN_RANGE" != "" ]]; then
715 LB_VLAN_RANGES=$LB_VLAN_RANGES:$TENANT_VLAN_RANGE
716 fi
717 fi
718 if [[ "$LB_VLAN_RANGES" != "" ]]; then
719 iniset /$Q_PLUGIN_CONF_FILE VLANS network_vlan_ranges $LB_VLAN_RANGES
720 fi
721 elif [[ "$Q_PLUGIN" = "ryu" ]]; then
722 iniset /$Q_PLUGIN_CONF_FILE OVS openflow_controller $RYU_OFP_HOST:$RYU_OFP_PORT
723 iniset /$Q_PLUGIN_CONF_FILE OVS openflow_rest_api $RYU_API_HOST:$RYU_API_PORT
Sumit Naiksatam4b26d312013-01-04 10:32:54 -0800724 elif [[ "$Q_PLUGIN" = "bigswitch_floodlight" ]]; then
725 iniset /$Q_PLUGIN_CONF_FILE RESTPROXY servers $BS_FL_CONTROLLERS_PORT
726 iniset /$Q_PLUGIN_CONF_FILE RESTPROXY servertimeout $BS_FL_CONTROLLER_TIMEOUT
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900727 fi
728}
729
730# Utility Functions
731#------------------
732
733# _quantum_setup_rootwrap() - configure Quantum's rootwrap
734function _quantum_setup_rootwrap() {
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800735 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
736 return
737 fi
738 # Deploy new rootwrap filters files (owned by root).
739 # Wipe any existing rootwrap.d files first
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600740 Q_CONF_ROOTWRAP_D=$QUANTUM_CONF_DIR/rootwrap.d
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800741 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
742 sudo rm -rf $Q_CONF_ROOTWRAP_D
743 fi
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600744 # Deploy filters to $QUANTUM_CONF_DIR/rootwrap.d
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800745 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
746 cp -pr $QUANTUM_DIR/etc/quantum/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
747 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
748 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600749 # Set up rootwrap.conf, pointing to $QUANTUM_CONF_DIR/rootwrap.d
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800750 sudo cp -p $QUANTUM_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
751 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
752 sudo chown root:root $Q_RR_CONF_FILE
753 sudo chmod 0644 $Q_RR_CONF_FILE
754 # Specify rootwrap.conf as first parameter to quantum-rootwrap
755 ROOTWRAP_SUDOER_CMD="$QUANTUM_ROOTWRAP $Q_RR_CONF_FILE *"
756
757 # Set up the rootwrap sudoers for quantum
758 TEMPFILE=`mktemp`
759 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
760 chmod 0440 $TEMPFILE
761 sudo chown root:root $TEMPFILE
762 sudo mv $TEMPFILE /etc/sudoers.d/quantum-rootwrap
763}
764
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700765# Configures keystone integration for quantum service and agents
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900766function _quantum_setup_keystone() {
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700767 local conf_file=$1
768 local section=$2
769 local use_auth_url=$3
770 if [[ -n $use_auth_url ]]; then
771 iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0"
772 else
773 iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST
774 iniset $conf_file $section auth_port $KEYSTONE_AUTH_PORT
775 iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL
776 fi
777 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
778 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
779 iniset $conf_file $section admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900780 iniset $conf_file $section signing_dir $QUANTUM_AUTH_CACHE_DIR
781 # Create cache dir
782 sudo mkdir -p $QUANTUM_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100783 sudo chown $STACK_USER $QUANTUM_AUTH_CACHE_DIR
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800784 rm -f $QUANTUM_AUTH_CACHE_DIR/*
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700785}
786
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900787function _quantum_setup_ovs_bridge() {
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700788 local bridge=$1
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900789 quantum-ovs-cleanup --ovs_integration_bridge $bridge
790 sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700791 sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge
792}
793
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900794function _quantum_setup_interface_driver() {
795 local conf_file=$1
796 if [[ "$Q_PLUGIN" == "openvswitch" ]]; then
797 iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver
798 elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
799 iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.BridgeInterfaceDriver
800 elif [[ "$Q_PLUGIN" = "ryu" ]]; then
801 iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.RyuInterfaceDriver
Sumit Naiksatam4b26d312013-01-04 10:32:54 -0800802 elif [[ "$Q_PLUGIN" = "bigswitch_floodlight" ]]; then
803 iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900804 fi
805}
806
807function _quantum_setup_external_bridge() {
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000808 local bridge=$1
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900809 quantum-ovs-cleanup --external_network_bridge $bridge
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000810 sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000811 # ensure no IP is configured on the public bridge
812 sudo ip addr flush dev $bridge
813}
814
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900815# Functions for Quantum Exercises
816#--------------------------------
817
818function delete_probe() {
819 local from_net="$1"
820 net_id=`_get_net_id $from_net`
821 probe_id=`quantum-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}'`
822 quantum-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
823}
824
825function setup_quantum_debug() {
826 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
827 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
828 quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create $public_net_id
829 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
830 quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create $private_net_id
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000831 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900832}
833
834function teardown_quantum_debug() {
835 delete_probe $PUBLIC_NETWORK_NAME
836 delete_probe $PRIVATE_NETWORK_NAME
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000837}
838
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700839function _get_net_id() {
840 quantum --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
841}
842
843function _get_probe_cmd_prefix() {
844 local from_net="$1"
845 net_id=`_get_net_id $from_net`
846 probe_id=`quantum-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`
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800847 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700848}
849
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700850function _ping_check_quantum() {
851 local from_net=$1
852 local ip=$2
853 local timeout_sec=$3
854 local expected=${4:-"True"}
855 local check_command=""
856 probe_cmd=`_get_probe_cmd_prefix $from_net`
857 if [[ "$expected" = "True" ]]; then
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800858 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700859 else
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800860 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700861 fi
862 if ! timeout $timeout_sec sh -c "$check_command"; then
863 if [[ "$expected" = "True" ]]; then
864 echo "[Fail] Couldn't ping server"
865 else
866 echo "[Fail] Could ping server"
867 fi
868 exit 1
869 fi
870}
871
872# ssh check
873function _ssh_check_quantum() {
874 local from_net=$1
875 local key_file=$2
876 local ip=$3
877 local user=$4
878 local timeout_sec=$5
879 local probe_cmd = ""
880 probe_cmd=`_get_probe_cmd_prefix $from_net`
881 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
882 echo "server didn't become ssh-able!"
883 exit 1
884 fi
885}
886
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900887# Quantum 3rd party programs
888#---------------------------
889# A comma-separated list of 3rd party programs
Sumit Naiksatam4b26d312013-01-04 10:32:54 -0800890QUANTUM_THIRD_PARTIES="ryu,bigswitch_floodlight"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900891for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do
892 source lib/$third_party
893done
894
895# configure_quantum_third_party() - Set config files, create data dirs, etc
896function configure_quantum_third_party() {
897 for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do
898 if is_service_enabled $third_party; then
899 configure_${third_party}
900 fi
901 done
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700902}
903
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900904# init_quantum_third_party() - Initialize databases, etc.
905function init_quantum_third_party() {
906 for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do
907 if is_service_enabled $third_party; then
908 init_${third_party}
909 fi
910 done
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700911}
912
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900913# install_quantum_third_party() - Collect source and prepare
914function install_quantum_third_party() {
915 for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do
916 if is_service_enabled $third_party; then
917 install_${third_party}
918 fi
919 done
920}
921
922# start_quantum_third_party() - Start running processes, including screen
923function start_quantum_third_party() {
924 for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do
925 if is_service_enabled $third_party; then
926 start_${third_party}
927 fi
928 done
929}
930
931# stop_quantum_third_party - Stop running processes (non-screen)
932function stop_quantum_third_party() {
933 for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do
934 if is_service_enabled $third_party; then
935 stop_${third_party}
936 fi
937 done
938}
939
940
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700941# Restore xtrace
942$XTRACE