blob: 15c8f19179a6e23dbfa0c04fc08a9cc82e2cd6d5 [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.
Dean Troyer60e9c0a2012-12-06 15:52:52 -060055
Salvatore Orlandod6767d02012-08-31 04:55:20 -070056# Save trace setting
57XTRACE=$(set +o | grep xtrace)
58set +o xtrace
59
Dean Troyer60e9c0a2012-12-06 15:52:52 -060060
Akihiro MOTOKI66afb472012-12-21 15:34:13 +090061# Quantum Network Configuration
62# -----------------------------
Dean Troyer60e9c0a2012-12-06 15:52:52 -060063
64# Set up default directories
Nachi Ueno8bc21f62012-11-19 22:04:28 -080065QUANTUM_DIR=$DEST/quantum
Dean Troyer60e9c0a2012-12-06 15:52:52 -060066QUANTUMCLIENT_DIR=$DEST/python-quantumclient
Gary Kotton9343df12012-11-28 10:05:53 +000067QUANTUM_AUTH_CACHE_DIR=${QUANTUM_AUTH_CACHE_DIR:-/var/cache/quantum}
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070068
Dean Troyer60e9c0a2012-12-06 15:52:52 -060069QUANTUM_CONF_DIR=/etc/quantum
70QUANTUM_CONF=$QUANTUM_CONF_DIR/quantum.conf
71export QUANTUM_TEST_CONFIG_FILE=${QUANTUM_TEST_CONFIG_FILE:-"$QUANTUM_CONF_DIR/debug.ini"}
72
73# Default Quantum Plugin
74Q_PLUGIN=${Q_PLUGIN:-openvswitch}
75# Default Quantum Port
76Q_PORT=${Q_PORT:-9696}
77# Default Quantum Host
Jian Wenf28c9c72013-05-21 14:16:56 +080078Q_HOST=${Q_HOST:-$SERVICE_HOST}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060079# Default admin username
80Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-quantum}
81# Default auth strategy
82Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
83# Use namespace or not
84Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
Maru Newbyd7150e92013-04-23 06:16:11 +000085# RHEL's support for namespaces requires using veths with ovs
86Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060087Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
88# Meta data IP
Jian Wenf28c9c72013-05-21 14:16:56 +080089Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
Akihiro MOTOKI66afb472012-12-21 15:34:13 +090090# Allow Overlapping IP among subnets
Salvatore Orlandod1742fe2013-03-07 13:34:57 +010091Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060092# Use quantum-debug command
93Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
Maru Newby31c94ab2012-12-19 03:59:20 +000094# The name of the default q-l3 router
95Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Baodong (Robert) Li7a8d8522013-03-21 06:16:55 -070096# List of config file names in addition to the main plugin config file
97# See _configure_quantum_common() for details about setting it up
98declare -a Q_PLUGIN_EXTRA_CONF_FILES
Dean Troyer60e9c0a2012-12-06 15:52:52 -060099
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800100if is_service_enabled quantum; then
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600101 Q_RR_CONF_FILE=$QUANTUM_CONF_DIR/rootwrap.conf
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800102 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
103 Q_RR_COMMAND="sudo"
104 else
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800105 QUANTUM_ROOTWRAP=$(get_rootwrap_location quantum)
106 Q_RR_COMMAND="sudo $QUANTUM_ROOTWRAP $Q_RR_CONF_FILE"
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800107 fi
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800108
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900109 # Provider Network Configurations
110 # --------------------------------
111
112 # The following variables control the Quantum openvswitch and
113 # linuxbridge plugins' allocation of tenant networks and
114 # availability of provider networks. If these are not configured
Dean Troyer1a6d4492013-06-03 16:47:36 -0500115 # in ``localrc``, tenant networks will be local to the host (with no
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900116 # remote connectivity), and no physical resources will be
117 # available for the allocation of provider networks.
118
119 # To use GRE tunnels for tenant networks, set to True in
Dean Troyer1a6d4492013-06-03 16:47:36 -0500120 # ``localrc``. GRE tunnels are only supported by the openvswitch
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900121 # plugin, and currently only on Ubuntu.
122 ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False}
123
124 # If using GRE tunnels for tenant networks, specify the range of
125 # tunnel IDs from which tenant networks are allocated. Can be
Dean Troyer1a6d4492013-06-03 16:47:36 -0500126 # overriden in ``localrc`` in necesssary.
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900127 TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGE:-1:1000}
128
129 # To use VLANs for tenant networks, set to True in localrc. VLANs
130 # are supported by the openvswitch and linuxbridge plugins, each
131 # requiring additional configuration described below.
132 ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
133
Dean Troyer1a6d4492013-06-03 16:47:36 -0500134 # If using VLANs for tenant networks, set in ``localrc`` to specify
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900135 # the range of VLAN VIDs from which tenant networks are
136 # allocated. An external network switch must be configured to
137 # trunk these VLANs between hosts for multi-host connectivity.
138 #
139 # Example: ``TENANT_VLAN_RANGE=1000:1999``
140 TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
141
142 # If using VLANs for tenant networks, or if using flat or VLAN
Dean Troyer1a6d4492013-06-03 16:47:36 -0500143 # provider networks, set in ``localrc`` to the name of the physical
144 # network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
145 # openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900146 # agent, as described below.
147 #
148 # Example: ``PHYSICAL_NETWORK=default``
149 PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
150
151 # With the openvswitch plugin, if using VLANs for tenant networks,
Dean Troyer1a6d4492013-06-03 16:47:36 -0500152 # or if using flat or VLAN provider networks, set in ``localrc`` to
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900153 # the name of the OVS bridge to use for the physical network. The
154 # bridge will be created if it does not already exist, but a
155 # physical interface must be manually added to the bridge as a
156 # port for external connectivity.
157 #
158 # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
159 OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
160
161 # With the linuxbridge plugin, if using VLANs for tenant networks,
Dean Troyer1a6d4492013-06-03 16:47:36 -0500162 # or if using flat or VLAN provider networks, set in ``localrc`` to
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900163 # the name of the network interface to use for the physical
164 # network.
165 #
166 # Example: ``LB_PHYSICAL_INTERFACE=eth1``
167 LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
168
Dean Troyer1a6d4492013-06-03 16:47:36 -0500169 # With the openvswitch plugin, set to True in ``localrc`` to enable
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900170 # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
171 #
172 # Example: ``OVS_ENABLE_TUNNELING=True``
173 OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
174fi
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600175
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900176# Quantum plugin specific functions
177# ---------------------------------
Dean Troyer1a6d4492013-06-03 16:47:36 -0500178
179# Please refer to ``lib/quantum_plugins/README.md`` for details.
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900180source $TOP_DIR/lib/quantum_plugins/$Q_PLUGIN
181
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400182# Agent loadbalancer service plugin functions
183# -------------------------------------------
Dean Troyer1a6d4492013-06-03 16:47:36 -0500184
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400185# Hardcoding for 1 service plugin for now
Akihiro MOTOKIc07112a2013-03-22 16:35:38 +0900186source $TOP_DIR/lib/quantum_plugins/services/agent_loadbalancer
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400187
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +0900188# Use security group or not
189if has_quantum_plugin_security_group; then
190 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
191else
192 Q_USE_SECGROUP=False
193fi
194
Dean Troyercc6b4432013-04-08 15:38:03 -0500195# Functions
196# ---------
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600197
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900198# configure_quantum()
199# Set common config for all quantum server and agents.
200function configure_quantum() {
201 _configure_quantum_common
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900202 iniset_rpc_backend quantum $QUANTUM_CONF DEFAULT
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900203
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400204 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
205 if is_service_enabled q-lbaas; then
206 _configure_quantum_lbaas
207 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900208 if is_service_enabled q-svc; then
209 _configure_quantum_service
210 fi
211 if is_service_enabled q-agt; then
212 _configure_quantum_plugin_agent
213 fi
214 if is_service_enabled q-dhcp; then
215 _configure_quantum_dhcp_agent
216 fi
217 if is_service_enabled q-l3; then
218 _configure_quantum_l3_agent
219 fi
220 if is_service_enabled q-meta; then
221 _configure_quantum_metadata_agent
222 fi
223
224 _configure_quantum_debug_command
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900225}
226
227function create_nova_conf_quantum() {
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800228 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.quantumv2.api.API"
229 iniset $NOVA_CONF DEFAULT quantum_admin_username "$Q_ADMIN_USERNAME"
230 iniset $NOVA_CONF DEFAULT quantum_admin_password "$SERVICE_PASSWORD"
231 iniset $NOVA_CONF DEFAULT quantum_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
232 iniset $NOVA_CONF DEFAULT quantum_auth_strategy "$Q_AUTH_STRATEGY"
233 iniset $NOVA_CONF DEFAULT quantum_admin_tenant_name "$SERVICE_TENANT_NAME"
234 iniset $NOVA_CONF DEFAULT quantum_url "http://$Q_HOST:$Q_PORT"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900235
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +0900236 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
237 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
238 iniset $NOVA_CONF DEFAULT security_group_api quantum
239 fi
240
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900241 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
242 quantum_plugin_create_nova_conf
243
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800244 iniset $NOVA_CONF DEFAULT libvirt_vif_driver "$NOVA_VIF_DRIVER"
245 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900246 if is_service_enabled q-meta; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800247 iniset $NOVA_CONF DEFAULT service_quantum_metadata_proxy "True"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900248 fi
249}
250
251# create_quantum_accounts() - Set up common required quantum accounts
252
253# Tenant User Roles
254# ------------------------------------------------------------------
255# service quantum admin # if enabled
256
257# Migrated from keystone_data.sh
258function create_quantum_accounts() {
259
260 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
261 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
262
263 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
264 QUANTUM_USER=$(keystone user-create \
265 --name=quantum \
266 --pass="$SERVICE_PASSWORD" \
267 --tenant_id $SERVICE_TENANT \
268 --email=quantum@example.com \
269 | grep " id " | get_field 2)
270 keystone user-role-add \
271 --tenant_id $SERVICE_TENANT \
272 --user_id $QUANTUM_USER \
273 --role_id $ADMIN_ROLE
274 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
275 QUANTUM_SERVICE=$(keystone service-create \
276 --name=quantum \
277 --type=network \
278 --description="Quantum Service" \
279 | grep " id " | get_field 2)
280 keystone endpoint-create \
281 --region RegionOne \
282 --service_id $QUANTUM_SERVICE \
283 --publicurl "http://$SERVICE_HOST:9696/" \
284 --adminurl "http://$SERVICE_HOST:9696/" \
285 --internalurl "http://$SERVICE_HOST:9696/"
286 fi
287 fi
288}
289
290function create_quantum_initial_network() {
291 TENANT_ID=$(keystone tenant-list | grep " demo " | get_field 1)
292
293 # Create a small network
294 # Since quantum command is executed in admin context at this point,
295 # ``--tenant_id`` needs to be specified.
Devananda van der Veen37a8d152013-01-15 17:27:34 -0800296 if is_baremetal; then
297 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
298 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
299 sudo ip addr del $IP dev $PUBLIC_INTERFACE
300 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
301 done
302 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)
303 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)
304 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
305 else
306 NET_ID=$(quantum net-create --tenant_id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
307 SUBNET_ID=$(quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
308 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900309
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800310 if [[ "$Q_L3_ENABLED" == "True" ]]; then
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900311 # Create a router, and add the private subnet as one of its interfaces
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800312 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
313 # create a tenant-owned router.
Maru Newby31c94ab2012-12-19 03:59:20 +0000314 ROUTER_ID=$(quantum router-create --tenant_id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
315 else
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800316 # Plugin only supports creating a single router, which should be admin owned.
Maru Newby31c94ab2012-12-19 03:59:20 +0000317 ROUTER_ID=$(quantum router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
318 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900319 quantum router-interface-add $ROUTER_ID $SUBNET_ID
320 # Create an external network, and a subnet. Configure the external network as router gw
321 EXT_NET_ID=$(quantum net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
Stephen Ma8396d4f2013-02-18 05:32:59 -0800322 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 +0900323 quantum router-gateway-set $ROUTER_ID $EXT_NET_ID
324
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800325 if is_service_enabled q-l3; then
326 # logic is specific to using the l3-agent for l3
327 if is_quantum_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
328 CIDR_LEN=${FLOATING_RANGE#*/}
329 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
330 sudo ip link set $PUBLIC_BRIDGE up
331 ROUTER_GW_IP=`quantum port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'`
332 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
333 fi
334 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
335 # Explicitly set router id in l3 agent configuration
336 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
337 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900338 fi
339 fi
340}
341
342# init_quantum() - Initialize databases, etc.
343function init_quantum() {
344 :
345}
346
347# install_quantum() - Collect source and prepare
348function install_quantum() {
349 git_clone $QUANTUM_REPO $QUANTUM_DIR $QUANTUM_BRANCH
Dean Troyerfe51a902013-04-01 15:48:44 -0500350 setup_develop $QUANTUM_DIR
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900351}
352
353# install_quantumclient() - Collect source and prepare
354function install_quantumclient() {
355 git_clone $QUANTUMCLIENT_REPO $QUANTUMCLIENT_DIR $QUANTUMCLIENT_BRANCH
Dean Troyerfe51a902013-04-01 15:48:44 -0500356 setup_develop $QUANTUMCLIENT_DIR
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900357}
358
359# install_quantum_agent_packages() - Collect source and prepare
360function install_quantum_agent_packages() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900361 # install packages that is specific to plugin agent
362 quantum_plugin_install_agent_packages
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900363}
364
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900365# Start running processes, including screen
366function start_quantum_service_and_check() {
Baodong (Robert) Li7a8d8522013-03-21 06:16:55 -0700367 # build config-file options
368 local cfg_file
369 local CFG_FILE_OPTIONS="--config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
370 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
371 CFG_FILE_OPTIONS+=" --config-file /$cfg_file"
372 done
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900373 # Start the Quantum service
Baodong (Robert) Li7a8d8522013-03-21 06:16:55 -0700374 screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server $CFG_FILE_OPTIONS"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900375 echo "Waiting for Quantum to start..."
Aaron Rosen0ae742c2013-02-21 12:10:30 -0800376 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 -0800377 die $LINENO "Quantum did not start"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900378 fi
379}
380
381# Start running processes, including screen
382function start_quantum_agents() {
383 # Start up the quantum agents if enabled
Dean Troyer58ab9292013-03-19 15:39:47 -0500384 screen_it q-agt "cd $QUANTUM_DIR && python $AGENT_BINARY --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
385 screen_it q-dhcp "cd $QUANTUM_DIR && python $AGENT_DHCP_BINARY --config-file $QUANTUM_CONF --config-file=$Q_DHCP_CONF_FILE"
386 screen_it q-l3 "cd $QUANTUM_DIR && python $AGENT_L3_BINARY --config-file $QUANTUM_CONF --config-file=$Q_L3_CONF_FILE"
387 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 +0400388
Mate Lakatf652e0f2013-05-21 18:12:48 +0100389 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
390 # For XenServer, start an agent for the domU openvswitch
391 screen_it q-domua "cd $QUANTUM_DIR && python $AGENT_BINARY --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
392 fi
393
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400394 if is_service_enabled q-lbaas; then
Dean Troyer58ab9292013-03-19 15:39:47 -0500395 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 +0400396 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900397}
398
399# stop_quantum() - Stop running processes (non-screen)
400function stop_quantum() {
401 if is_service_enabled q-dhcp; then
402 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
403 [ ! -z "$pid" ] && sudo kill -9 $pid
404 fi
Jordan Pittier2ae6acf2013-05-08 19:14:29 +0200405 if is_service_enabled q-meta; then
406 pid=$(ps aux | awk '/quantum-ns-metadata-proxy/ { print $2 }')
407 [ ! -z "$pid" ] && sudo kill -9 $pid
408 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900409}
410
Dean Troyer995eb922013-03-07 16:11:40 -0600411# cleanup_quantum() - Remove residual data files, anything left over from previous
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900412# runs that a clean run would need to clean up
Dean Troyer995eb922013-03-07 16:11:40 -0600413function cleanup_quantum() {
JordanP614202f2013-05-16 11:16:13 +0200414 if is_quantum_ovs_base_plugin; then
415 quantum_ovs_base_cleanup
416 fi
417
418 # delete all namespaces created by quantum
419 for ns in $(sudo ip netns list | grep -o -e qdhcp-[0-9a-f\-]* -e qrouter-[0-9a-f\-]*); do
420 sudo ip netns delete ${ns}
421 done
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900422}
423
424# _configure_quantum_common()
425# Set common config for all quantum server and agents.
Dean Troyer1a6d4492013-06-03 16:47:36 -0500426# This MUST be called before other ``_configure_quantum_*`` functions.
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900427function _configure_quantum_common() {
428 # Put config files in ``QUANTUM_CONF_DIR`` for everyone to find
429 if [[ ! -d $QUANTUM_CONF_DIR ]]; then
430 sudo mkdir -p $QUANTUM_CONF_DIR
431 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100432 sudo chown $STACK_USER $QUANTUM_CONF_DIR
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900433
434 cp $QUANTUM_DIR/etc/quantum.conf $QUANTUM_CONF
435
Dean Troyer1a6d4492013-06-03 16:47:36 -0500436 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
437 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
438 # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
439 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
440 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900441 quantum_plugin_configure_common
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900442
443 if [[ $Q_PLUGIN_CONF_PATH == '' || $Q_PLUGIN_CONF_FILENAME == '' || $Q_PLUGIN_CLASS == '' ]]; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800444 die $LINENO "Quantum plugin not set.. exiting"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900445 fi
446
447 # If needed, move config file from ``$QUANTUM_DIR/etc/quantum`` to ``QUANTUM_CONF_DIR``
448 mkdir -p /$Q_PLUGIN_CONF_PATH
449 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
450 cp $QUANTUM_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
451
Attila Fazekas7e79d912013-03-03 12:23:04 +0100452 iniset /$Q_PLUGIN_CONF_FILE DATABASE sql_connection `database_connection_url $Q_DB_NAME`
mathieu-rohoncf9c10d2013-03-18 17:34:03 +0100453 iniset $QUANTUM_CONF DEFAULT state_path $DATA_DIR/quantum
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900454
Baodong (Robert) Li7a8d8522013-03-21 06:16:55 -0700455 # If addition config files are set, make sure their path name is set as well
456 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
457 die $LINENO "Quantum additional plugin config not set.. exiting"
458 fi
459
460 # If additional config files exist, copy them over to quantum configuration
461 # directory
462 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
463 mkdir -p /$Q_PLUGIN_EXTRA_CONF_PATH
464 local f
465 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
466 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
467 cp $QUANTUM_DIR/${Q_PLUGIN_EXTRA_CONF_FILES[$f]} /${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
468 done
469 fi
470
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900471 _quantum_setup_rootwrap
472}
473
474function _configure_quantum_debug_command() {
475 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
476 return
477 fi
478
479 cp $QUANTUM_DIR/etc/l3_agent.ini $QUANTUM_TEST_CONFIG_FILE
480
481 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT verbose False
482 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT debug False
483 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
484 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT root_helper "$Q_RR_COMMAND"
Gary Kottond9ca2b22013-01-30 13:52:43 +0000485 # Intermediate fix until Quantum patch lands and then line above will
486 # be cleaned.
487 iniset $QUANTUM_TEST_CONFIG_FILE AGENT root_helper "$Q_RR_COMMAND"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900488
489 _quantum_setup_keystone $QUANTUM_TEST_CONFIG_FILE DEFAULT set_auth_url
490 _quantum_setup_interface_driver $QUANTUM_TEST_CONFIG_FILE
491
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900492 quantum_plugin_configure_debug_command
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900493}
494
495function _configure_quantum_dhcp_agent() {
496 AGENT_DHCP_BINARY="$QUANTUM_DIR/bin/quantum-dhcp-agent"
497 Q_DHCP_CONF_FILE=$QUANTUM_CONF_DIR/dhcp_agent.ini
498
499 cp $QUANTUM_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
500
501 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
502 iniset $Q_DHCP_CONF_FILE DEFAULT debug True
503 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900504 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
505
506 _quantum_setup_keystone $Q_DHCP_CONF_FILE DEFAULT set_auth_url
507 _quantum_setup_interface_driver $Q_DHCP_CONF_FILE
508
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900509 quantum_plugin_configure_dhcp_agent
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900510}
511
512function _configure_quantum_l3_agent() {
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800513 Q_L3_ENABLED=True
514 # for l3-agent, only use per tenant router if we have namespaces
515 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900516 AGENT_L3_BINARY="$QUANTUM_DIR/bin/quantum-l3-agent"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900517 Q_L3_CONF_FILE=$QUANTUM_CONF_DIR/l3_agent.ini
518
519 cp $QUANTUM_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
520
521 iniset $Q_L3_CONF_FILE DEFAULT verbose True
522 iniset $Q_L3_CONF_FILE DEFAULT debug True
523 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900524 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
525
526 _quantum_setup_keystone $Q_L3_CONF_FILE DEFAULT set_auth_url
527 _quantum_setup_interface_driver $Q_L3_CONF_FILE
528
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900529 quantum_plugin_configure_l3_agent
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900530}
531
532function _configure_quantum_metadata_agent() {
533 AGENT_META_BINARY="$QUANTUM_DIR/bin/quantum-metadata-agent"
534 Q_META_CONF_FILE=$QUANTUM_CONF_DIR/metadata_agent.ini
535
536 cp $QUANTUM_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
537
538 iniset $Q_META_CONF_FILE DEFAULT verbose True
539 iniset $Q_META_CONF_FILE DEFAULT debug True
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900540 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
541 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
542
543 _quantum_setup_keystone $Q_META_CONF_FILE DEFAULT set_auth_url
544}
545
Dean Troyer1a6d4492013-06-03 16:47:36 -0500546function _configure_quantum_lbaas() {
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400547 quantum_agent_lbaas_install_agent_packages
548 quantum_agent_lbaas_configure_common
549 quantum_agent_lbaas_configure_agent
550}
551
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900552# _configure_quantum_plugin_agent() - Set config files for quantum plugin agent
553# It is called when q-agt is enabled.
554function _configure_quantum_plugin_agent() {
Maru Newby2298ca42012-10-25 23:46:42 +0000555 # Specify the default root helper prior to agent configuration to
Gary Kotton98e18e92013-01-28 14:26:56 +0000556 # ensure that an agent's configuration can override the default
Maru Newby2298ca42012-10-25 23:46:42 +0000557 iniset /$Q_PLUGIN_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
mathieu-rohon3ebb01a2013-04-09 15:09:07 +0200558 iniset $QUANTUM_CONF DEFAULT verbose True
559 iniset $QUANTUM_CONF DEFAULT debug True
Maru Newby2298ca42012-10-25 23:46:42 +0000560
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900561 # Configure agent for plugin
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900562 quantum_plugin_configure_plugin_agent
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900563}
564
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900565# _configure_quantum_service() - Set config files for quantum service
566# It is called when q-svc is enabled.
567function _configure_quantum_service() {
568 Q_API_PASTE_FILE=$QUANTUM_CONF_DIR/api-paste.ini
569 Q_POLICY_FILE=$QUANTUM_CONF_DIR/policy.json
570
571 cp $QUANTUM_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
572 cp $QUANTUM_DIR/etc/policy.json $Q_POLICY_FILE
573
574 if is_service_enabled $DATABASE_BACKENDS; then
575 recreate_database $Q_DB_NAME utf8
576 else
Nachi Ueno07115eb2013-02-26 12:38:18 -0800577 die $LINENO "A database must be enabled in order to use the $Q_PLUGIN Quantum plugin."
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900578 fi
579
580 # Update either configuration file with plugin
581 iniset $QUANTUM_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
582
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400583 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
584 iniset $QUANTUM_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
585 fi
586
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900587 iniset $QUANTUM_CONF DEFAULT verbose True
588 iniset $QUANTUM_CONF DEFAULT debug True
Salvatore Orlando3de02e82013-03-12 15:12:12 +0100589 iniset $QUANTUM_CONF DEFAULT policy_file $Q_POLICY_FILE
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900590 iniset $QUANTUM_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
591
592 iniset $QUANTUM_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
Akihiro MOTOKI712feb62013-02-11 23:45:19 +0900593 _quantum_setup_keystone $QUANTUM_CONF keystone_authtoken
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900594
595 # Configure plugin
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900596 quantum_plugin_configure_service
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900597}
598
599# Utility Functions
600#------------------
601
602# _quantum_setup_rootwrap() - configure Quantum's rootwrap
603function _quantum_setup_rootwrap() {
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800604 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
605 return
606 fi
607 # Deploy new rootwrap filters files (owned by root).
Dean Troyer1a6d4492013-06-03 16:47:36 -0500608 # Wipe any existing ``rootwrap.d`` files first
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600609 Q_CONF_ROOTWRAP_D=$QUANTUM_CONF_DIR/rootwrap.d
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800610 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
611 sudo rm -rf $Q_CONF_ROOTWRAP_D
612 fi
Dean Troyer1a6d4492013-06-03 16:47:36 -0500613 # Deploy filters to ``$QUANTUM_CONF_DIR/rootwrap.d``
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800614 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
615 cp -pr $QUANTUM_DIR/etc/quantum/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
616 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
617 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
Dean Troyer1a6d4492013-06-03 16:47:36 -0500618 # Set up ``rootwrap.conf``, pointing to ``$QUANTUM_CONF_DIR/rootwrap.d``
Dirk Mueller13aab252013-03-18 18:55:09 +0100619 # location moved in newer versions, prefer new location
620 if test -r $QUANTUM_DIR/etc/quantum/rootwrap.conf; then
621 sudo cp -p $QUANTUM_DIR/etc/quantum/rootwrap.conf $Q_RR_CONF_FILE
622 else
623 sudo cp -p $QUANTUM_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
624 fi
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800625 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
626 sudo chown root:root $Q_RR_CONF_FILE
627 sudo chmod 0644 $Q_RR_CONF_FILE
Dean Troyer1a6d4492013-06-03 16:47:36 -0500628 # Specify ``rootwrap.conf`` as first parameter to quantum-rootwrap
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800629 ROOTWRAP_SUDOER_CMD="$QUANTUM_ROOTWRAP $Q_RR_CONF_FILE *"
630
631 # Set up the rootwrap sudoers for quantum
632 TEMPFILE=`mktemp`
633 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
634 chmod 0440 $TEMPFILE
635 sudo chown root:root $TEMPFILE
636 sudo mv $TEMPFILE /etc/sudoers.d/quantum-rootwrap
Gary Kotton98e18e92013-01-28 14:26:56 +0000637
638 # Update the root_helper
639 iniset $QUANTUM_CONF AGENT root_helper "$Q_RR_COMMAND"
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800640}
641
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700642# Configures keystone integration for quantum service and agents
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900643function _quantum_setup_keystone() {
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700644 local conf_file=$1
645 local section=$2
646 local use_auth_url=$3
647 if [[ -n $use_auth_url ]]; then
648 iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0"
649 else
650 iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST
651 iniset $conf_file $section auth_port $KEYSTONE_AUTH_PORT
652 iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL
653 fi
654 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
655 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
656 iniset $conf_file $section admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900657 iniset $conf_file $section signing_dir $QUANTUM_AUTH_CACHE_DIR
658 # Create cache dir
659 sudo mkdir -p $QUANTUM_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100660 sudo chown $STACK_USER $QUANTUM_AUTH_CACHE_DIR
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800661 rm -f $QUANTUM_AUTH_CACHE_DIR/*
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700662}
663
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900664function _quantum_setup_interface_driver() {
Maru Newbyd7150e92013-04-23 06:16:11 +0000665
666 # ovs_use_veth needs to be set before the plugin configuration
667 # occurs to allow plugins to override the setting.
668 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
669
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900670 quantum_plugin_setup_interface_driver $1
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000671}
672
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900673# Functions for Quantum Exercises
674#--------------------------------
675
676function delete_probe() {
677 local from_net="$1"
678 net_id=`_get_net_id $from_net`
679 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}'`
680 quantum-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
681}
682
683function setup_quantum_debug() {
684 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
685 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +0900686 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 +0900687 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +0900688 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 +0000689 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900690}
691
692function teardown_quantum_debug() {
693 delete_probe $PUBLIC_NETWORK_NAME
694 delete_probe $PRIVATE_NETWORK_NAME
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000695}
696
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700697function _get_net_id() {
698 quantum --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
699}
700
701function _get_probe_cmd_prefix() {
702 local from_net="$1"
703 net_id=`_get_net_id $from_net`
704 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 -0800705 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700706}
707
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700708function _ping_check_quantum() {
709 local from_net=$1
710 local ip=$2
711 local timeout_sec=$3
712 local expected=${4:-"True"}
713 local check_command=""
714 probe_cmd=`_get_probe_cmd_prefix $from_net`
715 if [[ "$expected" = "True" ]]; then
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800716 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700717 else
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800718 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700719 fi
720 if ! timeout $timeout_sec sh -c "$check_command"; then
721 if [[ "$expected" = "True" ]]; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800722 die $LINENO "[Fail] Couldn't ping server"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700723 else
Nachi Ueno07115eb2013-02-26 12:38:18 -0800724 die $LINENO "[Fail] Could ping server"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700725 fi
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700726 fi
727}
728
729# ssh check
730function _ssh_check_quantum() {
731 local from_net=$1
732 local key_file=$2
733 local ip=$3
734 local user=$4
735 local timeout_sec=$5
736 local probe_cmd = ""
737 probe_cmd=`_get_probe_cmd_prefix $from_net`
Dean Troyercc6b4432013-04-08 15:38:03 -0500738 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 -0800739 die $LINENO "server didn't become ssh-able!"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700740 fi
741}
742
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900743# Quantum 3rd party programs
744#---------------------------
Dean Troyer1a6d4492013-06-03 16:47:36 -0500745
746# please refer to ``lib/quantum_thirdparty/README.md`` for details
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900747QUANTUM_THIRD_PARTIES=""
748for f in $TOP_DIR/lib/quantum_thirdparty/*; do
749 third_party=$(basename $f)
750 if is_service_enabled $third_party; then
751 source $TOP_DIR/lib/quantum_thirdparty/$third_party
752 QUANTUM_THIRD_PARTIES="$QUANTUM_THIRD_PARTIES,$third_party"
753 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900754done
755
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900756function _quantum_third_party_do() {
757 for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do
758 ${1}_${third_party}
759 done
760}
761
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900762# configure_quantum_third_party() - Set config files, create data dirs, etc
763function configure_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900764 _quantum_third_party_do configure
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700765}
766
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900767# init_quantum_third_party() - Initialize databases, etc.
768function init_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900769 _quantum_third_party_do init
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700770}
771
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900772# install_quantum_third_party() - Collect source and prepare
773function install_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900774 _quantum_third_party_do install
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900775}
776
777# start_quantum_third_party() - Start running processes, including screen
778function start_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900779 _quantum_third_party_do start
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900780}
781
782# stop_quantum_third_party - Stop running processes (non-screen)
783function stop_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900784 _quantum_third_party_do stop
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900785}
786
787
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700788# Restore xtrace
789$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400790
791# Local variables:
792# mode: shell-script
793# End: