blob: f16937c6844e4286a7e1a29c275f071aeb9d823f [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
Akihiro MOTOKI66afb472012-12-21 15:34:13 +090014# configure_quantum
15# init_quantum
16# configure_quantum_third_party
17# init_quantum_third_party
18# start_quantum_third_party
19# create_nova_conf_quantum
20# start_quantum_service_and_check
21# create_quantum_initial_network
22# setup_quantum_debug
23# start_quantum_agents
24#
25# ``unstack.sh`` calls the entry points in this order:
26#
27# stop_quantum
28
29# Functions in lib/quantum are classified into the following categories:
30#
31# - entry points (called from stack.sh or unstack.sh)
32# - internal functions
33# - quantum exercises
34# - 3rd party programs
35
Dean Troyer60e9c0a2012-12-06 15:52:52 -060036
37# Quantum Networking
38# ------------------
39
40# Make sure that quantum is enabled in ``ENABLED_SERVICES``. If you want
41# to run Quantum on this host, make sure that q-svc is also in
42# ``ENABLED_SERVICES``.
43#
44# If you're planning to use the Quantum 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 Quantum
47# linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the
48# q-agt service is enabled in ``ENABLED_SERVICES``.
49#
50# See "Quantum Network Configuration" below for additional variables
51# that must be set in localrc for connectivity across hosts with
52# Quantum.
53#
Dean Troyerb3236912013-03-17 15:17:05 -050054# With Quantum networking the NETWORK_MANAGER variable is ignored.
Kyle Mesteryebfac642013-05-17 15:20:56 -050055#
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# Quantum section.
Dean Troyer60e9c0a2012-12-06 15:52:52 -060059
Salvatore Orlandod6767d02012-08-31 04:55:20 -070060# Save trace setting
61XTRACE=$(set +o | grep xtrace)
62set +o xtrace
63
Dean Troyer60e9c0a2012-12-06 15:52:52 -060064
Akihiro MOTOKI66afb472012-12-21 15:34:13 +090065# Quantum Network Configuration
66# -----------------------------
Dean Troyer60e9c0a2012-12-06 15:52:52 -060067
68# Set up default directories
Nachi Ueno8bc21f62012-11-19 22:04:28 -080069QUANTUM_DIR=$DEST/quantum
Dean Troyer60e9c0a2012-12-06 15:52:52 -060070QUANTUMCLIENT_DIR=$DEST/python-quantumclient
Gary Kotton9343df12012-11-28 10:05:53 +000071QUANTUM_AUTH_CACHE_DIR=${QUANTUM_AUTH_CACHE_DIR:-/var/cache/quantum}
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070072
Dean Troyer60e9c0a2012-12-06 15:52:52 -060073QUANTUM_CONF_DIR=/etc/quantum
74QUANTUM_CONF=$QUANTUM_CONF_DIR/quantum.conf
75export QUANTUM_TEST_CONFIG_FILE=${QUANTUM_TEST_CONFIG_FILE:-"$QUANTUM_CONF_DIR/debug.ini"}
76
77# Default Quantum Plugin
78Q_PLUGIN=${Q_PLUGIN:-openvswitch}
79# Default Quantum Port
80Q_PORT=${Q_PORT:-9696}
81# Default Quantum Host
Jian Wenf28c9c72013-05-21 14:16:56 +080082Q_HOST=${Q_HOST:-$SERVICE_HOST}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060083# Default admin username
84Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-quantum}
85# Default auth strategy
86Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
87# Use namespace or not
88Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
Maru Newbyd7150e92013-04-23 06:16:11 +000089# RHEL's support for namespaces requires using veths with ovs
90Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060091Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
92# Meta data IP
Jian Wenf28c9c72013-05-21 14:16:56 +080093Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
Akihiro MOTOKI66afb472012-12-21 15:34:13 +090094# Allow Overlapping IP among subnets
Salvatore Orlandod1742fe2013-03-07 13:34:57 +010095Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060096# Use quantum-debug command
97Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
Maru Newby31c94ab2012-12-19 03:59:20 +000098# The name of the default q-l3 router
99Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Baodong (Robert) Li7a8d8522013-03-21 06:16:55 -0700100# List of config file names in addition to the main plugin config file
101# See _configure_quantum_common() for details about setting it up
102declare -a Q_PLUGIN_EXTRA_CONF_FILES
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600103
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800104if is_service_enabled quantum; then
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600105 Q_RR_CONF_FILE=$QUANTUM_CONF_DIR/rootwrap.conf
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800106 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
107 Q_RR_COMMAND="sudo"
108 else
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800109 QUANTUM_ROOTWRAP=$(get_rootwrap_location quantum)
110 Q_RR_COMMAND="sudo $QUANTUM_ROOTWRAP $Q_RR_CONF_FILE"
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800111 fi
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800112
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900113 # Provider Network Configurations
114 # --------------------------------
115
116 # The following variables control the Quantum openvswitch and
117 # linuxbridge plugins' allocation of tenant networks and
118 # availability of provider networks. If these are not configured
Dean Troyer1a6d4492013-06-03 16:47:36 -0500119 # in ``localrc``, tenant networks will be local to the host (with no
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900120 # remote connectivity), and no physical resources will be
121 # available for the allocation of provider networks.
122
123 # To use GRE tunnels for tenant networks, set to True in
Dean Troyer1a6d4492013-06-03 16:47:36 -0500124 # ``localrc``. GRE tunnels are only supported by the openvswitch
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900125 # plugin, and currently only on Ubuntu.
126 ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False}
127
128 # If using GRE tunnels for tenant networks, specify the range of
129 # tunnel IDs from which tenant networks are allocated. Can be
Dean Troyer1a6d4492013-06-03 16:47:36 -0500130 # overriden in ``localrc`` in necesssary.
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900131 TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGE:-1:1000}
132
133 # To use VLANs for tenant networks, set to True in localrc. VLANs
134 # are supported by the openvswitch and linuxbridge plugins, each
135 # requiring additional configuration described below.
136 ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
137
Dean Troyer1a6d4492013-06-03 16:47:36 -0500138 # If using VLANs for tenant networks, set in ``localrc`` to specify
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900139 # the range of VLAN VIDs from which tenant networks are
140 # allocated. An external network switch must be configured to
141 # trunk these VLANs between hosts for multi-host connectivity.
142 #
143 # Example: ``TENANT_VLAN_RANGE=1000:1999``
144 TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
145
146 # If using VLANs for tenant networks, or if using flat or VLAN
Dean Troyer1a6d4492013-06-03 16:47:36 -0500147 # provider networks, set in ``localrc`` to the name of the physical
148 # network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
149 # openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900150 # agent, as described below.
151 #
152 # Example: ``PHYSICAL_NETWORK=default``
153 PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
154
155 # With the openvswitch plugin, if using VLANs for tenant networks,
Dean Troyer1a6d4492013-06-03 16:47:36 -0500156 # or if using flat or VLAN provider networks, set in ``localrc`` to
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900157 # the name of the OVS bridge to use for the physical network. The
158 # bridge will be created if it does not already exist, but a
159 # physical interface must be manually added to the bridge as a
160 # port for external connectivity.
161 #
162 # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
163 OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
164
165 # With the linuxbridge plugin, if using VLANs for tenant networks,
Dean Troyer1a6d4492013-06-03 16:47:36 -0500166 # or if using flat or VLAN provider networks, set in ``localrc`` to
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900167 # the name of the network interface to use for the physical
168 # network.
169 #
170 # Example: ``LB_PHYSICAL_INTERFACE=eth1``
171 LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
172
Dean Troyer1a6d4492013-06-03 16:47:36 -0500173 # With the openvswitch plugin, set to True in ``localrc`` to enable
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900174 # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
175 #
176 # Example: ``OVS_ENABLE_TUNNELING=True``
177 OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
178fi
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600179
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900180# Quantum plugin specific functions
181# ---------------------------------
Dean Troyer1a6d4492013-06-03 16:47:36 -0500182
183# Please refer to ``lib/quantum_plugins/README.md`` for details.
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900184source $TOP_DIR/lib/quantum_plugins/$Q_PLUGIN
185
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400186# Agent loadbalancer service plugin functions
187# -------------------------------------------
Dean Troyer1a6d4492013-06-03 16:47:36 -0500188
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400189# Hardcoding for 1 service plugin for now
Eugene Nikanorovb7196172013-06-13 22:11:42 +0400190source $TOP_DIR/lib/quantum_plugins/services/loadbalancer
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400191
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +0900192# Use security group or not
193if has_quantum_plugin_security_group; then
194 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
195else
196 Q_USE_SECGROUP=False
197fi
198
Dean Troyercc6b4432013-04-08 15:38:03 -0500199# Functions
200# ---------
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600201
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900202# configure_quantum()
203# Set common config for all quantum server and agents.
204function configure_quantum() {
205 _configure_quantum_common
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900206 iniset_rpc_backend quantum $QUANTUM_CONF DEFAULT
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900207
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400208 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
209 if is_service_enabled q-lbaas; then
210 _configure_quantum_lbaas
211 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900212 if is_service_enabled q-svc; then
213 _configure_quantum_service
214 fi
215 if is_service_enabled q-agt; then
216 _configure_quantum_plugin_agent
217 fi
218 if is_service_enabled q-dhcp; then
219 _configure_quantum_dhcp_agent
220 fi
221 if is_service_enabled q-l3; then
222 _configure_quantum_l3_agent
223 fi
224 if is_service_enabled q-meta; then
225 _configure_quantum_metadata_agent
226 fi
227
228 _configure_quantum_debug_command
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900229}
230
231function create_nova_conf_quantum() {
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800232 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.quantumv2.api.API"
233 iniset $NOVA_CONF DEFAULT quantum_admin_username "$Q_ADMIN_USERNAME"
234 iniset $NOVA_CONF DEFAULT quantum_admin_password "$SERVICE_PASSWORD"
235 iniset $NOVA_CONF DEFAULT quantum_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
236 iniset $NOVA_CONF DEFAULT quantum_auth_strategy "$Q_AUTH_STRATEGY"
237 iniset $NOVA_CONF DEFAULT quantum_admin_tenant_name "$SERVICE_TENANT_NAME"
238 iniset $NOVA_CONF DEFAULT quantum_url "http://$Q_HOST:$Q_PORT"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900239
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +0900240 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
241 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
242 iniset $NOVA_CONF DEFAULT security_group_api quantum
243 fi
244
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900245 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
246 quantum_plugin_create_nova_conf
247
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800248 iniset $NOVA_CONF DEFAULT libvirt_vif_driver "$NOVA_VIF_DRIVER"
249 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900250 if is_service_enabled q-meta; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800251 iniset $NOVA_CONF DEFAULT service_quantum_metadata_proxy "True"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900252 fi
253}
254
255# create_quantum_accounts() - Set up common required quantum accounts
256
257# Tenant User Roles
258# ------------------------------------------------------------------
259# service quantum admin # if enabled
260
261# Migrated from keystone_data.sh
262function create_quantum_accounts() {
263
264 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
265 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
266
267 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
268 QUANTUM_USER=$(keystone user-create \
269 --name=quantum \
270 --pass="$SERVICE_PASSWORD" \
271 --tenant_id $SERVICE_TENANT \
272 --email=quantum@example.com \
273 | grep " id " | get_field 2)
274 keystone user-role-add \
275 --tenant_id $SERVICE_TENANT \
276 --user_id $QUANTUM_USER \
277 --role_id $ADMIN_ROLE
278 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
279 QUANTUM_SERVICE=$(keystone service-create \
280 --name=quantum \
281 --type=network \
282 --description="Quantum Service" \
283 | grep " id " | get_field 2)
284 keystone endpoint-create \
285 --region RegionOne \
286 --service_id $QUANTUM_SERVICE \
287 --publicurl "http://$SERVICE_HOST:9696/" \
288 --adminurl "http://$SERVICE_HOST:9696/" \
289 --internalurl "http://$SERVICE_HOST:9696/"
290 fi
291 fi
292}
293
294function create_quantum_initial_network() {
295 TENANT_ID=$(keystone tenant-list | grep " demo " | get_field 1)
296
297 # Create a small network
298 # Since quantum command is executed in admin context at this point,
299 # ``--tenant_id`` needs to be specified.
Devananda van der Veen37a8d152013-01-15 17:27:34 -0800300 if is_baremetal; then
301 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
302 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
303 sudo ip addr del $IP dev $PUBLIC_INTERFACE
304 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
305 done
306 NET_ID=$(quantum net-create $PHYSICAL_NETWORK --tenant_id $TENANT_ID --provider:network_type flat --provider:physical_network "$PHYSICAL_NETWORK" | grep ' id ' | get_field 2)
307 SUBNET_ID=$(quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
308 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
309 else
310 NET_ID=$(quantum net-create --tenant_id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
311 SUBNET_ID=$(quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
312 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900313
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800314 if [[ "$Q_L3_ENABLED" == "True" ]]; then
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900315 # Create a router, and add the private subnet as one of its interfaces
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800316 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
317 # create a tenant-owned router.
Maru Newby31c94ab2012-12-19 03:59:20 +0000318 ROUTER_ID=$(quantum router-create --tenant_id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
319 else
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800320 # Plugin only supports creating a single router, which should be admin owned.
Maru Newby31c94ab2012-12-19 03:59:20 +0000321 ROUTER_ID=$(quantum router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
322 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900323 quantum router-interface-add $ROUTER_ID $SUBNET_ID
324 # Create an external network, and a subnet. Configure the external network as router gw
325 EXT_NET_ID=$(quantum net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
Stephen Ma8396d4f2013-02-18 05:32:59 -0800326 EXT_GW_IP=$(quantum subnet-create --ip_version 4 ${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2)
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900327 quantum router-gateway-set $ROUTER_ID $EXT_NET_ID
328
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800329 if is_service_enabled q-l3; then
330 # logic is specific to using the l3-agent for l3
331 if is_quantum_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
332 CIDR_LEN=${FLOATING_RANGE#*/}
333 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
334 sudo ip link set $PUBLIC_BRIDGE up
335 ROUTER_GW_IP=`quantum port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'`
336 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
337 fi
338 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
339 # Explicitly set router id in l3 agent configuration
340 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
341 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900342 fi
343 fi
344}
345
346# init_quantum() - Initialize databases, etc.
347function init_quantum() {
348 :
349}
350
351# install_quantum() - Collect source and prepare
352function install_quantum() {
353 git_clone $QUANTUM_REPO $QUANTUM_DIR $QUANTUM_BRANCH
Dean Troyerfe51a902013-04-01 15:48:44 -0500354 setup_develop $QUANTUM_DIR
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900355}
356
357# install_quantumclient() - Collect source and prepare
358function install_quantumclient() {
359 git_clone $QUANTUMCLIENT_REPO $QUANTUMCLIENT_DIR $QUANTUMCLIENT_BRANCH
Dean Troyerfe51a902013-04-01 15:48:44 -0500360 setup_develop $QUANTUMCLIENT_DIR
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900361}
362
363# install_quantum_agent_packages() - Collect source and prepare
364function install_quantum_agent_packages() {
armando-migliaccio84984872013-06-11 13:50:59 -0700365 # install packages that are specific to plugin agent(s)
366 if is_service_enabled q-agt q-dhcp q-l3; then
367 quantum_plugin_install_agent_packages
368 fi
369
370 if is_service_enabled q-lbaas; then
371 quantum_agent_lbaas_install_agent_packages
372 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900373}
374
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900375# Start running processes, including screen
376function start_quantum_service_and_check() {
Baodong (Robert) Li7a8d8522013-03-21 06:16:55 -0700377 # build config-file options
378 local cfg_file
379 local CFG_FILE_OPTIONS="--config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
380 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
381 CFG_FILE_OPTIONS+=" --config-file /$cfg_file"
382 done
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900383 # Start the Quantum service
Baodong (Robert) Li7a8d8522013-03-21 06:16:55 -0700384 screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server $CFG_FILE_OPTIONS"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900385 echo "Waiting for Quantum to start..."
Aaron Rosen0ae742c2013-02-21 12:10:30 -0800386 if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800387 die $LINENO "Quantum did not start"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900388 fi
389}
390
391# Start running processes, including screen
392function start_quantum_agents() {
393 # Start up the quantum agents if enabled
Dean Troyer58ab9292013-03-19 15:39:47 -0500394 screen_it q-agt "cd $QUANTUM_DIR && python $AGENT_BINARY --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
395 screen_it q-dhcp "cd $QUANTUM_DIR && python $AGENT_DHCP_BINARY --config-file $QUANTUM_CONF --config-file=$Q_DHCP_CONF_FILE"
396 screen_it q-l3 "cd $QUANTUM_DIR && python $AGENT_L3_BINARY --config-file $QUANTUM_CONF --config-file=$Q_L3_CONF_FILE"
397 screen_it q-meta "cd $QUANTUM_DIR && python $AGENT_META_BINARY --config-file $QUANTUM_CONF --config-file=$Q_META_CONF_FILE"
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400398
Mate Lakatf652e0f2013-05-21 18:12:48 +0100399 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
400 # For XenServer, start an agent for the domU openvswitch
401 screen_it q-domua "cd $QUANTUM_DIR && python $AGENT_BINARY --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
402 fi
403
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400404 if is_service_enabled q-lbaas; then
Dean Troyer58ab9292013-03-19 15:39:47 -0500405 screen_it q-lbaas "cd $QUANTUM_DIR && python $AGENT_LBAAS_BINARY --config-file $QUANTUM_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400406 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900407}
408
409# stop_quantum() - Stop running processes (non-screen)
410function stop_quantum() {
411 if is_service_enabled q-dhcp; then
412 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
413 [ ! -z "$pid" ] && sudo kill -9 $pid
414 fi
Jordan Pittier2ae6acf2013-05-08 19:14:29 +0200415 if is_service_enabled q-meta; then
416 pid=$(ps aux | awk '/quantum-ns-metadata-proxy/ { print $2 }')
417 [ ! -z "$pid" ] && sudo kill -9 $pid
418 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900419}
420
Dean Troyer995eb922013-03-07 16:11:40 -0600421# cleanup_quantum() - Remove residual data files, anything left over from previous
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900422# runs that a clean run would need to clean up
Dean Troyer995eb922013-03-07 16:11:40 -0600423function cleanup_quantum() {
JordanP614202f2013-05-16 11:16:13 +0200424 if is_quantum_ovs_base_plugin; then
425 quantum_ovs_base_cleanup
426 fi
427
428 # delete all namespaces created by quantum
429 for ns in $(sudo ip netns list | grep -o -e qdhcp-[0-9a-f\-]* -e qrouter-[0-9a-f\-]*); do
430 sudo ip netns delete ${ns}
431 done
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900432}
433
434# _configure_quantum_common()
435# Set common config for all quantum server and agents.
Dean Troyer1a6d4492013-06-03 16:47:36 -0500436# This MUST be called before other ``_configure_quantum_*`` functions.
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900437function _configure_quantum_common() {
438 # Put config files in ``QUANTUM_CONF_DIR`` for everyone to find
439 if [[ ! -d $QUANTUM_CONF_DIR ]]; then
440 sudo mkdir -p $QUANTUM_CONF_DIR
441 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100442 sudo chown $STACK_USER $QUANTUM_CONF_DIR
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900443
444 cp $QUANTUM_DIR/etc/quantum.conf $QUANTUM_CONF
445
Dean Troyer1a6d4492013-06-03 16:47:36 -0500446 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
447 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
448 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
449 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
450 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900451 quantum_plugin_configure_common
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900452
453 if [[ $Q_PLUGIN_CONF_PATH == '' || $Q_PLUGIN_CONF_FILENAME == '' || $Q_PLUGIN_CLASS == '' ]]; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800454 die $LINENO "Quantum plugin not set.. exiting"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900455 fi
456
457 # If needed, move config file from ``$QUANTUM_DIR/etc/quantum`` to ``QUANTUM_CONF_DIR``
458 mkdir -p /$Q_PLUGIN_CONF_PATH
459 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
460 cp $QUANTUM_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
461
Gary Kottond42634f2013-06-24 09:26:55 +0000462 iniset /$Q_PLUGIN_CONF_FILE database connection `database_connection_url $Q_DB_NAME`
mathieu-rohoncf9c10d2013-03-18 17:34:03 +0100463 iniset $QUANTUM_CONF DEFAULT state_path $DATA_DIR/quantum
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900464
Baodong (Robert) Li7a8d8522013-03-21 06:16:55 -0700465 # If addition config files are set, make sure their path name is set as well
466 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
467 die $LINENO "Quantum additional plugin config not set.. exiting"
468 fi
469
470 # If additional config files exist, copy them over to quantum configuration
471 # directory
472 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
473 mkdir -p /$Q_PLUGIN_EXTRA_CONF_PATH
474 local f
475 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
476 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
477 cp $QUANTUM_DIR/${Q_PLUGIN_EXTRA_CONF_FILES[$f]} /${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
478 done
479 fi
480
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900481 _quantum_setup_rootwrap
482}
483
484function _configure_quantum_debug_command() {
485 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
486 return
487 fi
488
489 cp $QUANTUM_DIR/etc/l3_agent.ini $QUANTUM_TEST_CONFIG_FILE
490
491 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT verbose False
492 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT debug False
493 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
494 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT root_helper "$Q_RR_COMMAND"
Gary Kottond9ca2b22013-01-30 13:52:43 +0000495 # Intermediate fix until Quantum patch lands and then line above will
496 # be cleaned.
Gary Kottond42634f2013-06-24 09:26:55 +0000497 iniset $QUANTUM_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900498
499 _quantum_setup_keystone $QUANTUM_TEST_CONFIG_FILE DEFAULT set_auth_url
500 _quantum_setup_interface_driver $QUANTUM_TEST_CONFIG_FILE
501
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900502 quantum_plugin_configure_debug_command
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900503}
504
505function _configure_quantum_dhcp_agent() {
506 AGENT_DHCP_BINARY="$QUANTUM_DIR/bin/quantum-dhcp-agent"
507 Q_DHCP_CONF_FILE=$QUANTUM_CONF_DIR/dhcp_agent.ini
508
509 cp $QUANTUM_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
510
511 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
512 iniset $Q_DHCP_CONF_FILE DEFAULT debug True
513 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900514 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
515
516 _quantum_setup_keystone $Q_DHCP_CONF_FILE DEFAULT set_auth_url
517 _quantum_setup_interface_driver $Q_DHCP_CONF_FILE
518
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900519 quantum_plugin_configure_dhcp_agent
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900520}
521
522function _configure_quantum_l3_agent() {
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800523 Q_L3_ENABLED=True
524 # for l3-agent, only use per tenant router if we have namespaces
525 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900526 AGENT_L3_BINARY="$QUANTUM_DIR/bin/quantum-l3-agent"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900527 Q_L3_CONF_FILE=$QUANTUM_CONF_DIR/l3_agent.ini
528
529 cp $QUANTUM_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
530
531 iniset $Q_L3_CONF_FILE DEFAULT verbose True
532 iniset $Q_L3_CONF_FILE DEFAULT debug True
533 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900534 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
535
536 _quantum_setup_keystone $Q_L3_CONF_FILE DEFAULT set_auth_url
537 _quantum_setup_interface_driver $Q_L3_CONF_FILE
538
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900539 quantum_plugin_configure_l3_agent
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900540}
541
542function _configure_quantum_metadata_agent() {
543 AGENT_META_BINARY="$QUANTUM_DIR/bin/quantum-metadata-agent"
544 Q_META_CONF_FILE=$QUANTUM_CONF_DIR/metadata_agent.ini
545
546 cp $QUANTUM_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
547
548 iniset $Q_META_CONF_FILE DEFAULT verbose True
549 iniset $Q_META_CONF_FILE DEFAULT debug True
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900550 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
551 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
552
553 _quantum_setup_keystone $Q_META_CONF_FILE DEFAULT set_auth_url
554}
555
Dean Troyer1a6d4492013-06-03 16:47:36 -0500556function _configure_quantum_lbaas() {
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400557 quantum_agent_lbaas_configure_common
558 quantum_agent_lbaas_configure_agent
559}
560
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900561# _configure_quantum_plugin_agent() - Set config files for quantum plugin agent
562# It is called when q-agt is enabled.
563function _configure_quantum_plugin_agent() {
Maru Newby2298ca42012-10-25 23:46:42 +0000564 # Specify the default root helper prior to agent configuration to
Gary Kotton98e18e92013-01-28 14:26:56 +0000565 # ensure that an agent's configuration can override the default
Gary Kottond42634f2013-06-24 09:26:55 +0000566 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
mathieu-rohon3ebb01a2013-04-09 15:09:07 +0200567 iniset $QUANTUM_CONF DEFAULT verbose True
568 iniset $QUANTUM_CONF DEFAULT debug True
Maru Newby2298ca42012-10-25 23:46:42 +0000569
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900570 # Configure agent for plugin
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900571 quantum_plugin_configure_plugin_agent
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900572}
573
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900574# _configure_quantum_service() - Set config files for quantum service
575# It is called when q-svc is enabled.
576function _configure_quantum_service() {
577 Q_API_PASTE_FILE=$QUANTUM_CONF_DIR/api-paste.ini
578 Q_POLICY_FILE=$QUANTUM_CONF_DIR/policy.json
579
580 cp $QUANTUM_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
581 cp $QUANTUM_DIR/etc/policy.json $Q_POLICY_FILE
582
583 if is_service_enabled $DATABASE_BACKENDS; then
584 recreate_database $Q_DB_NAME utf8
585 else
Nachi Ueno07115eb2013-02-26 12:38:18 -0800586 die $LINENO "A database must be enabled in order to use the $Q_PLUGIN Quantum plugin."
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900587 fi
588
589 # Update either configuration file with plugin
590 iniset $QUANTUM_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
591
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400592 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
593 iniset $QUANTUM_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
594 fi
595
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900596 iniset $QUANTUM_CONF DEFAULT verbose True
597 iniset $QUANTUM_CONF DEFAULT debug True
Salvatore Orlando3de02e82013-03-12 15:12:12 +0100598 iniset $QUANTUM_CONF DEFAULT policy_file $Q_POLICY_FILE
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900599 iniset $QUANTUM_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
600
601 iniset $QUANTUM_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
Akihiro MOTOKI712feb62013-02-11 23:45:19 +0900602 _quantum_setup_keystone $QUANTUM_CONF keystone_authtoken
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900603
604 # Configure plugin
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900605 quantum_plugin_configure_service
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900606}
607
608# Utility Functions
609#------------------
610
611# _quantum_setup_rootwrap() - configure Quantum's rootwrap
612function _quantum_setup_rootwrap() {
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800613 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
614 return
615 fi
616 # Deploy new rootwrap filters files (owned by root).
Dean Troyer1a6d4492013-06-03 16:47:36 -0500617 # Wipe any existing ``rootwrap.d`` files first
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600618 Q_CONF_ROOTWRAP_D=$QUANTUM_CONF_DIR/rootwrap.d
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800619 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
620 sudo rm -rf $Q_CONF_ROOTWRAP_D
621 fi
Dean Troyer1a6d4492013-06-03 16:47:36 -0500622 # Deploy filters to ``$QUANTUM_CONF_DIR/rootwrap.d``
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800623 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
624 cp -pr $QUANTUM_DIR/etc/quantum/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
625 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
626 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
Dean Troyer1a6d4492013-06-03 16:47:36 -0500627 # Set up ``rootwrap.conf``, pointing to ``$QUANTUM_CONF_DIR/rootwrap.d``
Dirk Mueller13aab252013-03-18 18:55:09 +0100628 # location moved in newer versions, prefer new location
629 if test -r $QUANTUM_DIR/etc/quantum/rootwrap.conf; then
630 sudo cp -p $QUANTUM_DIR/etc/quantum/rootwrap.conf $Q_RR_CONF_FILE
631 else
632 sudo cp -p $QUANTUM_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
633 fi
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800634 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
635 sudo chown root:root $Q_RR_CONF_FILE
636 sudo chmod 0644 $Q_RR_CONF_FILE
Dean Troyer1a6d4492013-06-03 16:47:36 -0500637 # Specify ``rootwrap.conf`` as first parameter to quantum-rootwrap
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800638 ROOTWRAP_SUDOER_CMD="$QUANTUM_ROOTWRAP $Q_RR_CONF_FILE *"
639
640 # Set up the rootwrap sudoers for quantum
641 TEMPFILE=`mktemp`
642 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
643 chmod 0440 $TEMPFILE
644 sudo chown root:root $TEMPFILE
645 sudo mv $TEMPFILE /etc/sudoers.d/quantum-rootwrap
Gary Kotton98e18e92013-01-28 14:26:56 +0000646
647 # Update the root_helper
Gary Kottond42634f2013-06-24 09:26:55 +0000648 iniset $QUANTUM_CONF agent root_helper "$Q_RR_COMMAND"
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800649}
650
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700651# Configures keystone integration for quantum service and agents
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900652function _quantum_setup_keystone() {
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700653 local conf_file=$1
654 local section=$2
655 local use_auth_url=$3
656 if [[ -n $use_auth_url ]]; then
657 iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0"
658 else
659 iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST
660 iniset $conf_file $section auth_port $KEYSTONE_AUTH_PORT
661 iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL
662 fi
663 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
664 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
665 iniset $conf_file $section admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900666 iniset $conf_file $section signing_dir $QUANTUM_AUTH_CACHE_DIR
667 # Create cache dir
668 sudo mkdir -p $QUANTUM_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100669 sudo chown $STACK_USER $QUANTUM_AUTH_CACHE_DIR
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800670 rm -f $QUANTUM_AUTH_CACHE_DIR/*
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700671}
672
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900673function _quantum_setup_interface_driver() {
Maru Newbyd7150e92013-04-23 06:16:11 +0000674
675 # ovs_use_veth needs to be set before the plugin configuration
676 # occurs to allow plugins to override the setting.
677 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
678
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900679 quantum_plugin_setup_interface_driver $1
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000680}
681
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900682# Functions for Quantum Exercises
683#--------------------------------
684
685function delete_probe() {
686 local from_net="$1"
687 net_id=`_get_net_id $from_net`
688 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}'`
689 quantum-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
690}
691
692function setup_quantum_debug() {
693 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
694 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +0900695 quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900696 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +0900697 quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000698 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900699}
700
701function teardown_quantum_debug() {
702 delete_probe $PUBLIC_NETWORK_NAME
703 delete_probe $PRIVATE_NETWORK_NAME
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000704}
705
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700706function _get_net_id() {
707 quantum --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
708}
709
710function _get_probe_cmd_prefix() {
711 local from_net="$1"
712 net_id=`_get_net_id $from_net`
713 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 -0800714 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700715}
716
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700717function _ping_check_quantum() {
718 local from_net=$1
719 local ip=$2
720 local timeout_sec=$3
721 local expected=${4:-"True"}
722 local check_command=""
723 probe_cmd=`_get_probe_cmd_prefix $from_net`
724 if [[ "$expected" = "True" ]]; then
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800725 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700726 else
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800727 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700728 fi
729 if ! timeout $timeout_sec sh -c "$check_command"; then
730 if [[ "$expected" = "True" ]]; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800731 die $LINENO "[Fail] Couldn't ping server"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700732 else
Nachi Ueno07115eb2013-02-26 12:38:18 -0800733 die $LINENO "[Fail] Could ping server"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700734 fi
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700735 fi
736}
737
738# ssh check
739function _ssh_check_quantum() {
740 local from_net=$1
741 local key_file=$2
742 local ip=$3
743 local user=$4
744 local timeout_sec=$5
745 local probe_cmd = ""
746 probe_cmd=`_get_probe_cmd_prefix $from_net`
Dean Troyercc6b4432013-04-08 15:38:03 -0500747 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
Nachi Ueno07115eb2013-02-26 12:38:18 -0800748 die $LINENO "server didn't become ssh-able!"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700749 fi
750}
751
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900752# Quantum 3rd party programs
753#---------------------------
Dean Troyer1a6d4492013-06-03 16:47:36 -0500754
755# please refer to ``lib/quantum_thirdparty/README.md`` for details
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900756QUANTUM_THIRD_PARTIES=""
757for f in $TOP_DIR/lib/quantum_thirdparty/*; do
758 third_party=$(basename $f)
759 if is_service_enabled $third_party; then
760 source $TOP_DIR/lib/quantum_thirdparty/$third_party
761 QUANTUM_THIRD_PARTIES="$QUANTUM_THIRD_PARTIES,$third_party"
762 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900763done
764
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900765function _quantum_third_party_do() {
766 for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do
767 ${1}_${third_party}
768 done
769}
770
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900771# configure_quantum_third_party() - Set config files, create data dirs, etc
772function configure_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900773 _quantum_third_party_do configure
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700774}
775
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900776# init_quantum_third_party() - Initialize databases, etc.
777function init_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900778 _quantum_third_party_do init
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700779}
780
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900781# install_quantum_third_party() - Collect source and prepare
782function install_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900783 _quantum_third_party_do install
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900784}
785
786# start_quantum_third_party() - Start running processes, including screen
787function start_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900788 _quantum_third_party_do start
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900789}
790
791# stop_quantum_third_party - Stop running processes (non-screen)
792function stop_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900793 _quantum_third_party_do stop
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900794}
795
796
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700797# Restore xtrace
798$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400799
800# Local variables:
801# mode: shell-script
802# End: