blob: ab005a9a010c66e170bfcc221be40b7f4a488c4f [file] [log] [blame]
Sean M. Collins2a242512016-05-03 09:03:09 -04001#!/bin/bash
2#
3# lib/neutron
4# Install and start **Neutron** network services
5
6# Dependencies:
7#
8# ``functions`` file
9# ``DEST`` must be defined
10
11# ``stack.sh`` calls the entry points in this order:
12#
13# - is_XXXX_enabled
14# - install_XXXX
15# - configure_XXXX
16# - init_XXXX
17# - start_XXXX
18# - stop_XXXX
19# - cleanup_XXXX
20
21# Save trace setting
22XTRACE=$(set +o | grep xtrace)
23set +o xtrace
24
25# Defaults
26# --------
27
28# Set up default directories
29GITDIR["python-neutronclient"]=$DEST/python-neutronclient
30
31NEUTRON_AGENT=${NEUTRON_AGENT:-openvswitch}
32NEUTRON_DIR=$DEST/neutron
33NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
34
35NEUTRON_BIN_DIR=$(get_python_exec_prefix)
36NEUTRON_DHCP_BINARY="neutron-dhcp-agent"
37
38NEUTRON_CONF_DIR=/etc/neutron
39NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
40NEUTRON_META_CONF=$NEUTRON_CONF_DIR/metadata_agent.ini
41
42NEUTRON_DHCP_CONF=$NEUTRON_CONF_DIR/dhcp_agent.ini
43NEUTRON_L3_CONF=$NEUTRON_CONF_DIR/l3_agent.ini
44NEUTRON_AGENT_CONF=$NEUTRON_CONF_DIR/
45
46NEUTRON_STATE_PATH=${NEUTRON_STATE_PATH:=$DATA_DIR/neutron}
47NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
48
49# By default, use the ML2 plugin
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +090050NEUTRON_CORE_PLUGIN=${NEUTRON_CORE_PLUGIN:-ml2}
51NEUTRON_CORE_PLUGIN_CONF_FILENAME=${NEUTRON_CORE_PLUGIN_CONF_FILENAME:-ml2_conf.ini}
52NEUTRON_CORE_PLUGIN_CONF_PATH=$NEUTRON_CONF_DIR/plugins/$NEUTRON_CORE_PLUGIN
53NEUTRON_CORE_PLUGIN_CONF=$NEUTRON_CORE_PLUGIN_CONF_PATH/$NEUTRON_CORE_PLUGIN_CONF_FILENAME
Sean M. Collins2a242512016-05-03 09:03:09 -040054
55NEUTRON_AGENT_BINARY=${NEUTRON_AGENT_BINARY:-neutron-$NEUTRON_AGENT-agent}
56NEUTRON_L3_BINARY=${NEUTRON_L3_BINARY:-neutron-l3-agent}
57NEUTRON_META_BINARY=${NEUTRON_META_BINARY:-neutron-metadata-agent}
58
59# Public facing bits
60if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then
61 NEUTRON_SERVICE_PROTOCOL="https"
62fi
63NEUTRON_SERVICE_HOST=${NEUTRON_SERVICE_HOST:-$SERVICE_HOST}
64NEUTRON_SERVICE_PORT=${NEUTRON_SERVICE_PORT:-9696}
65NEUTRON_SERVICE_PORT_INT=${NEUTRON_SERVICE_PORT_INT:-19696}
66NEUTRON_SERVICE_PROTOCOL=${NEUTRON_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
67
68NEUTRON_AUTH_STRATEGY=${NEUTRON_AUTH_STRATEGY:-keystone}
69NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
70NEUTRON_ROOTWRAP_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
71NEUTRON_ROOTWRAP_DAEMON_CMD="sudo $NEUTRON_ROOTWRAP-daemon $NEUTRON_ROOTWRAP_CONF_FILE"
72
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +090073# Additional neutron api config files
74declare -a _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS
75
Sean M. Collins2a242512016-05-03 09:03:09 -040076# Functions
77# ---------
78
79# Test if any Neutron services are enabled
80# is_neutron_enabled
81function is_neutron_enabled {
82 [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
83 return 1
84}
85
86# Test if any Neutron services are enabled
87# is_neutron_enabled
88function is_neutron_legacy_enabled {
89 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
90 return 1
91}
92
YAMAMOTO Takashic74315e2016-07-21 17:49:43 +090093if is_neutron_legacy_enabled; then
94 source $TOP_DIR/lib/neutron-legacy
95fi
96
Sean M. Collins2a242512016-05-03 09:03:09 -040097# cleanup_neutron() - Remove residual data files, anything left over from previous
98# runs that a clean run would need to clean up
99function cleanup_neutron_new {
100 source $TOP_DIR/lib/neutron_plugins/${NEUTRON_AGENT}_agent
101 if is_neutron_ovs_base_plugin; then
102 neutron_ovs_base_cleanup
103 fi
104
105 if [[ $NEUTRON_AGENT == "linuxbridge" ]]; then
106 neutron_lb_cleanup
107 fi
108 # delete all namespaces created by neutron
109 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|qlbaas|fip|snat)-[0-9a-f-]*'); do
110 sudo ip netns delete ${ns}
111 done
112}
113
114# configure_neutron() - Set config files, create data dirs, etc
115function configure_neutron_new {
116 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
117
118 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
119
120 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
121
122 configure_neutron_rootwrap
123
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900124 mkdir -p $NEUTRON_CORE_PLUGIN_CONF_PATH
Sean M. Collins2a242512016-05-03 09:03:09 -0400125
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900126 cp $NEUTRON_DIR/etc/neutron/plugins/$NEUTRON_CORE_PLUGIN/$NEUTRON_CORE_PLUGIN_CONF_FILENAME.sample $NEUTRON_CORE_PLUGIN_CONF
Sean M. Collins2a242512016-05-03 09:03:09 -0400127
128 iniset $NEUTRON_CONF database connection `database_connection_url neutron`
129 iniset $NEUTRON_CONF DEFAULT state_path $NEUTRON_STATE_PATH
130 iniset $NEUTRON_CONF oslo_concurrency lock_path $NEUTRON_STATE_PATH/lock
131 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
132
Gary Kottond2ef6152016-09-20 04:12:11 -0700133 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean M. Collinsfbba3b92016-05-12 11:17:53 -0400134
Sean M. Collins5394cc12016-05-11 15:03:38 -0400135 iniset_rpc_backend neutron $NEUTRON_CONF
136
Sean M. Collins2a242512016-05-03 09:03:09 -0400137 # Neutron API server & Neutron plugin
138 if is_service_enabled neutron-api; then
139 local policy_file=$NEUTRON_CONF_DIR/policy.json
140 cp $NEUTRON_DIR/etc/policy.json $policy_file
141 # Allow neutron user to administer neutron to match neutron account
142 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $policy_file
143
144 cp $NEUTRON_DIR/etc/api-paste.ini $NEUTRON_CONF_DIR/api-paste.ini
145
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900146 iniset $NEUTRON_CONF DEFAULT core_plugin $NEUTRON_CORE_PLUGIN
Sean M. Collins2a242512016-05-03 09:03:09 -0400147
Sean M. Collins2a242512016-05-03 09:03:09 -0400148 iniset $NEUTRON_CONF DEFAULT policy_file $policy_file
149 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips True
150
151 iniset $NEUTRON_CONF DEFAULT auth_strategy $NEUTRON_AUTH_STRATEGY
152 configure_auth_token_middleware $NEUTRON_CONF neutron $NEUTRON_AUTH_CACHE_DIR keystone_authtoken
Ihar Hrachyshka0ce4ba92017-02-24 05:13:53 +0000153 configure_auth_token_middleware $NEUTRON_CONF nova $NEUTRON_AUTH_CACHE_DIR nova
Sean M. Collins2a242512016-05-03 09:03:09 -0400154
155 # Configure VXLAN
156 # TODO(sc68cal) not hardcode?
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900157 iniset $NEUTRON_CORE_PLUGIN_CONF ml2 tenant_network_types vxlan
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900158 iniset $NEUTRON_CORE_PLUGIN_CONF ml2 mechanism_drivers openvswitch,linuxbridge
159 iniset $NEUTRON_CORE_PLUGIN_CONF ml2_type_vxlan vni_ranges 1001:2000
Sean M. Collinsedcb7e52016-12-15 11:29:28 -0500160 iniset $NEUTRON_CORE_PLUGIN_CONF ml2_type_flat flat_networks public
Matt Riedemannc9c9d312016-09-15 20:33:22 -0400161 if [[ "$NEUTRON_PORT_SECURITY" = "True" ]]; then
162 iniset $NEUTRON_CORE_PLUGIN_CONF ml2 extension_drivers port_security
163 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400164 fi
165
166 # Neutron OVS or LB agent
167 if is_service_enabled neutron-agent; then
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900168 iniset $NEUTRON_CORE_PLUGIN_CONF agent tunnel_types vxlan
169 iniset $NEUTRON_CORE_PLUGIN_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean M. Collins2a242512016-05-03 09:03:09 -0400170
171 # Configure the neutron agent
172 if [[ $NEUTRON_AGENT == "linuxbridge" ]]; then
Sean M. Collinsedcb7e52016-12-15 11:29:28 -0500173 iniset $NEUTRON_CORE_PLUGIN_CONF securitygroup firewall_driver iptables
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900174 iniset $NEUTRON_CORE_PLUGIN_CONF vxlan local_ip $HOST_IP
Sean M. Collins2a242512016-05-03 09:03:09 -0400175 else
Sean M. Collinsedcb7e52016-12-15 11:29:28 -0500176 iniset $NEUTRON_CORE_PLUGIN_CONF securitygroup firewall_driver iptables_hybrid
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900177 iniset $NEUTRON_CORE_PLUGIN_CONF ovs local_ip $HOST_IP
Sean M. Collins2a242512016-05-03 09:03:09 -0400178 fi
Ihar Hrachyshkab3a210f2016-09-29 13:26:30 +0000179
Denis Buliga0bf75a42017-02-06 16:56:46 +0200180 if ! running_in_container; then
181 enable_kernel_bridge_firewall
182 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400183 fi
184
185 # DHCP Agent
186 if is_service_enabled neutron-dhcp; then
187 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $NEUTRON_DHCP_CONF
188
Gary Kottond2ef6152016-09-20 04:12:11 -0700189 iniset $NEUTRON_DHCP_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean Dague78801c12016-08-04 14:10:07 -0400190 # make it so we have working DNS from guests
191 iniset $NEUTRON_DHCP_CONF DEFAULT dnsmasq_local_resolv True
192
Sean M. Collins2a242512016-05-03 09:03:09 -0400193 iniset $NEUTRON_DHCP_CONF agent root_helper_daemon "$NEUTRON_ROOTWRAP_DAEMON_CMD"
194 iniset $NEUTRON_DHCP_CONF DEFAULT interface_driver $NEUTRON_AGENT
195 neutron_plugin_configure_dhcp_agent $NEUTRON_DHCP_CONF
196 fi
197
198 if is_service_enabled neutron-l3; then
199 cp $NEUTRON_DIR/etc/l3_agent.ini.sample $NEUTRON_L3_CONF
200 iniset $NEUTRON_L3_CONF DEFAULT interface_driver $NEUTRON_AGENT
YAMAMOTO Takashid9ec4202016-07-21 16:14:52 +0900201 neutron_service_plugin_class_add router
Sean M. Collins2a242512016-05-03 09:03:09 -0400202 iniset $NEUTRON_L3_CONF agent root_helper_daemon "$NEUTRON_ROOTWRAP_DAEMON_CMD"
Gary Kottond2ef6152016-09-20 04:12:11 -0700203 iniset $NEUTRON_L3_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean M. Collins2a242512016-05-03 09:03:09 -0400204 neutron_plugin_configure_l3_agent $NEUTRON_L3_CONF
205 fi
206
207 # Metadata
Sean M. Collins1cd28282016-05-11 15:07:19 -0400208 if is_service_enabled neutron-metadata-agent; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400209 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $NEUTRON_META_CONF
210
Gary Kottond2ef6152016-09-20 04:12:11 -0700211 iniset $NEUTRON_META_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean M. Collins2a242512016-05-03 09:03:09 -0400212 iniset $NEUTRON_META_CONF DEFAULT nova_metadata_ip $SERVICE_HOST
Armando Migliaccio06f2ea22017-02-02 16:47:00 -0800213 iniset $NEUTRON_META_CONF DEFAULT metadata_workers $API_WORKERS
Sean M. Collins2a242512016-05-03 09:03:09 -0400214 iniset $NEUTRON_META_CONF agent root_helper_daemon "$NEUTRON_ROOTWRAP_DAEMON_CMD"
215
216 # TODO(dtroyer): remove the v2.0 hard code below
217 iniset $NEUTRON_META_CONF DEFAULT auth_url $KEYSTONE_SERVICE_URI/v2.0
218 configure_auth_token_middleware $NEUTRON_META_CONF neutron $NEUTRON_AUTH_CACHE_DIR DEFAULT
219 fi
220
221 # Format logging
222 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
223 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
224 else
225 # Show user_name and project_name by default
226 iniset $NEUTRON_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s] %(instance)s%(message)s"
227 fi
228
229 if is_service_enabled tls-proxy; then
230 # Set the service port for a proxy to take the original
231 iniset $NEUTRON_CONF DEFAULT bind_port "$NEUTRON_SERVICE_PORT_INT"
232 fi
233
Sean M. Collins2a242512016-05-03 09:03:09 -0400234 if is_ssl_enabled_service "neutron"; then
235 ensure_certificates NEUTRON
236
237 iniset $NEUTRON_CONF DEFAULT use_ssl True
238 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
239 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
240 fi
241
Sean M. Collins8063fee2016-05-24 11:27:36 -0700242 # Metering
243 if is_service_enabled neutron-metering; then
Sean M. Collins60f394a2016-06-17 16:15:30 -0400244 source $TOP_DIR/lib/neutron_plugins/services/metering
Sean M. Collins8063fee2016-05-24 11:27:36 -0700245 neutron_agent_metering_configure_common
246 neutron_agent_metering_configure_agent
YAMAMOTO Takashid9ec4202016-07-21 16:14:52 +0900247 neutron_service_plugin_class_add metering
Sean M. Collins8063fee2016-05-24 11:27:36 -0700248 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400249}
250
251# configure_neutron_rootwrap() - configure Neutron's rootwrap
252function configure_neutron_rootwrap {
253 # Set the paths of certain binaries
254 neutron_rootwrap=$(get_rootwrap_location neutron)
255
256 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
257 local rootwrap_sudoer_cmd="${neutron_rootwrap} $NEUTRON_CONF_DIR/rootwrap.conf"
258
259 # Deploy new rootwrap filters files (owned by root).
260 # Wipe any existing rootwrap.d files first
261 if [[ -d $NEUTRON_CONF_DIR/rootwrap.d ]]; then
262 sudo rm -rf $NEUTRON_CONF_DIR/rootwrap.d
263 fi
264
265 # Deploy filters to /etc/neutron/rootwrap.d
266 sudo install -d -o root -g root -m 755 $NEUTRON_CONF_DIR/rootwrap.d
267 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.d/*.filters $NEUTRON_CONF_DIR/rootwrap.d
268
269 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
270 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $NEUTRON_CONF_DIR
271 sudo sed -e "s:^filters_path=.*$:filters_path=$NEUTRON_CONF_DIR/rootwrap.d:" -i $NEUTRON_CONF_DIR/rootwrap.conf
272
273 # Set up the rootwrap sudoers for Neutron
274 tempfile=`mktemp`
275 echo "$STACK_USER ALL=(root) NOPASSWD: $rootwrap_sudoer_cmd *" >$tempfile
276 chmod 0440 $tempfile
277 sudo chown root:root $tempfile
278 sudo mv $tempfile /etc/sudoers.d/neutron-rootwrap
279}
280
281# Make Neutron-required changes to nova.conf
282function configure_neutron_nova_new {
283 iniset $NOVA_CONF DEFAULT use_neutron True
284 iniset $NOVA_CONF neutron auth_type "password"
Brant Knudsonc2c89e42017-02-23 20:15:47 -0600285 iniset $NOVA_CONF neutron auth_url "$KEYSTONE_SERVICE_URI/v3"
Sean M. Collins2a242512016-05-03 09:03:09 -0400286 iniset $NOVA_CONF neutron username neutron
287 iniset $NOVA_CONF neutron password "$SERVICE_PASSWORD"
288 iniset $NOVA_CONF neutron user_domain_name "Default"
289 iniset $NOVA_CONF neutron project_name "$SERVICE_TENANT_NAME"
290 iniset $NOVA_CONF neutron project_domain_name "Default"
291 iniset $NOVA_CONF neutron auth_strategy $NEUTRON_AUTH_STRATEGY
292 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
293 iniset $NOVA_CONF neutron url $NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST:$NEUTRON_SERVICE_PORT
294
295 iniset $NOVA_CONF DEFAULT firewall_driver nova.virt.firewall.NoopFirewallDriver
296
Gary Kotton88f85582016-08-14 06:55:42 -0700297 # optionally set options in nova_conf
298 neutron_plugin_create_nova_conf
299
Sean M. Collins1cd28282016-05-11 15:07:19 -0400300 if is_service_enabled neutron-metadata-agent; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400301 iniset $NOVA_CONF neutron service_metadata_proxy "True"
302 fi
303
304}
305
306# Tenant User Roles
307# ------------------------------------------------------------------
308# service neutron admin # if enabled
309
310# create_neutron_accounts() - Create required service accounts
311function create_neutron_accounts_new {
312 if [[ "$ENABLED_SERVICES" =~ "neutron-api" ]]; then
313
314 create_service_user "neutron"
315
316 neutron_service=$(get_or_create_service "neutron" \
317 "network" "Neutron Service")
318 get_or_create_endpoint $neutron_service \
319 "$REGION_NAME" \
Sean M. Collins2a242512016-05-03 09:03:09 -0400320 "$NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST:$NEUTRON_SERVICE_PORT/"
321 fi
322}
323
324# create_neutron_cache_dir() - Part of the init_neutron() process
325function create_neutron_cache_dir {
326 # Create cache dir
327 sudo install -d -o $STACK_USER $NEUTRON_AUTH_CACHE_DIR
328 rm -f $NEUTRON_AUTH_CACHE_DIR/*
329}
330
331# init_neutron() - Initialize databases, etc.
332function init_neutron_new {
333
334 recreate_database neutron
335
336 # Run Neutron db migrations
Ihar Hrachyshka19f4b3f2017-02-23 20:44:18 +0000337 $NEUTRON_BIN_DIR/neutron-db-manage upgrade heads
Sean M. Collins2a242512016-05-03 09:03:09 -0400338
339 create_neutron_cache_dir
340}
341
342# install_neutron() - Collect source and prepare
343function install_neutron_new {
344 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
345 setup_develop $NEUTRON_DIR
346
347 # Install neutron-lib from git so we make sure we're testing
348 # the latest code.
349 if use_library_from_git "neutron-lib"; then
350 git_clone_by_name "neutron-lib"
351 setup_dev_lib "neutron-lib"
352 fi
353
354 # L3 service requires radvd
355 if is_service_enabled neutron-l3; then
356 install_package radvd
357 fi
358
359 if is_service_enabled neutron-agent neutron-dhcp neutron-l3; then
360 #TODO(sc68cal) - kind of ugly
361 source $TOP_DIR/lib/neutron_plugins/${NEUTRON_AGENT}_agent
362 neutron_plugin_install_agent_packages
363 fi
364
365}
366
367# install_neutronclient() - Collect source and prepare
368function install_neutronclient {
369 if use_library_from_git "python-neutronclient"; then
370 git_clone_by_name "python-neutronclient"
371 setup_dev_lib "python-neutronclient"
372 sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-neutronclient"]}/tools/,/etc/bash_completion.d/}neutron.bash_completion
373 fi
374}
375
376# start_neutron_api() - Start the API process ahead of other things
377function start_neutron_api {
378 local service_port=$NEUTRON_SERVICE_PORT
379 local service_protocol=$NEUTRON_SERVICE_PROTOCOL
380 if is_service_enabled tls-proxy; then
381 service_port=$NEUTRON_SERVICE_PORT_INT
382 service_protocol="http"
383 fi
384
YAMAMOTO Takashied887d82017-02-22 14:21:33 -0500385 local opts=""
386 opts+=" --config-file $NEUTRON_CONF"
387 opts+=" --config-file $NEUTRON_CORE_PLUGIN_CONF"
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900388 local cfg_file
389 for cfg_file in ${_NEUTRON_SERVER_EXTRA_CONF_FILES_ABS[@]}; do
390 opts+=" --config-file $cfg_file"
391 done
392
Sean M. Collins2a242512016-05-03 09:03:09 -0400393 # Start the Neutron service
394 # TODO(sc68cal) Stop hard coding this
YAMAMOTO Takashied887d82017-02-22 14:21:33 -0500395 run_process neutron-api "$NEUTRON_BIN_DIR/neutron-server $opts"
Sean M. Collins2a242512016-05-03 09:03:09 -0400396
397 if is_ssl_enabled_service "neutron"; then
398 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
399 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $service_protocol://$NEUTRON_SERVICE_HOST:$service_port"
400 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
401 else
402 if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$NEUTRON_SERVICE_HOST:$service_port; then
403 die $LINENO "neutron-api did not start"
404 fi
405 fi
406
407
408 # Start proxy if enabled
409 if is_service_enabled tls-proxy; then
Gregory Haynes4b49e402016-08-31 18:19:51 -0700410 start_tls_proxy neutron '*' $NEUTRON_SERVICE_PORT $NEUTRON_SERVICE_HOST $NEUTRON_SERVICE_PORT_INT
Sean M. Collins2a242512016-05-03 09:03:09 -0400411 fi
412}
413
414# start_neutron() - Start running processes, including screen
415function start_neutron_new {
Sean M. Collins2a242512016-05-03 09:03:09 -0400416 # Start up the neutron agents if enabled
417 # TODO(sc68cal) Make this pluggable so different DevStack plugins for different Neutron plugins
418 # can resolve the $NEUTRON_AGENT_BINARY
419 if is_service_enabled neutron-agent; then
Ihar Hrachyshka19f4b3f2017-02-23 20:44:18 +0000420 # TODO(ihrachys) stop loading ml2_conf.ini into agents, instead load agent specific files
421 run_process neutron-agent "$NEUTRON_BIN_DIR/$NEUTRON_AGENT_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_CORE_PLUGIN_CONF"
Sean M. Collins2a242512016-05-03 09:03:09 -0400422 fi
423 if is_service_enabled neutron-dhcp; then
424 neutron_plugin_configure_dhcp_agent $NEUTRON_DHCP_CONF
Ihar Hrachyshka19f4b3f2017-02-23 20:44:18 +0000425 run_process neutron-dhcp "$NEUTRON_BIN_DIR/$NEUTRON_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_DHCP_CONF"
Sean M. Collins2a242512016-05-03 09:03:09 -0400426 fi
427 if is_service_enabled neutron-l3; then
Ihar Hrachyshka19f4b3f2017-02-23 20:44:18 +0000428 run_process neutron-l3 "$NEUTRON_BIN_DIR/$NEUTRON_L3_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_L3_CONF"
YAMAMOTO Takashic07170a2016-07-20 19:44:05 +0900429 fi
YAMAMOTO Takashi07edde12016-10-19 19:21:00 +0000430 if is_service_enabled neutron-api; then
431 # XXX(sc68cal) - Here's where plugins can wire up their own networks instead
432 # of the code in lib/neutron_plugins/services/l3
433 if type -p neutron_plugin_create_initial_networks > /dev/null; then
434 neutron_plugin_create_initial_networks
435 else
436 # XXX(sc68cal) Load up the built in Neutron networking code and build a topology
437 source $TOP_DIR/lib/neutron_plugins/services/l3
438 # Create the networks using servic
439 create_neutron_initial_network
440 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400441 fi
Sean M. Collins1cd28282016-05-11 15:07:19 -0400442 if is_service_enabled neutron-metadata-agent; then
Ihar Hrachyshka19f4b3f2017-02-23 20:44:18 +0000443 run_process neutron-metadata-agent "$NEUTRON_BIN_DIR/$NEUTRON_META_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_META_CONF"
Sean M. Collins2a242512016-05-03 09:03:09 -0400444 fi
Sean M. Collins8063fee2016-05-24 11:27:36 -0700445
446 if is_service_enabled neutron-metering; then
447 run_process neutron-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
448 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400449}
450
451# stop_neutron() - Stop running processes (non-screen)
452function stop_neutron_new {
453 for serv in neutron-api neutron-agent neutron-l3; do
454 stop_process $serv
455 done
456
457 if is_service_enabled neutron-dhcp; then
458 stop_process neutron-dhcp
459 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
460 [ ! -z "$pid" ] && sudo kill -9 $pid
461 fi
462
Sean M. Collins1cd28282016-05-11 15:07:19 -0400463 if is_service_enabled neutron-metadata-agent; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400464 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Sean M. Collins1cd28282016-05-11 15:07:19 -0400465 stop_process neutron-metadata-agent
Sean M. Collins2a242512016-05-03 09:03:09 -0400466 fi
467}
468
YAMAMOTO Takashid9ec4202016-07-21 16:14:52 +0900469# neutron_service_plugin_class_add() - add service plugin class
470function neutron_service_plugin_class_add_new {
471 local service_plugin_class=$1
472 local plugins=""
473
474 plugins=$(iniget $NEUTRON_CONF DEFAULT service_plugins)
YAMAMOTO Takashi84e45c92017-02-22 14:25:14 -0500475 if [ $plugins ]; then
476 plugins+=","
477 fi
478 plugins+="${service_plugin_class}"
YAMAMOTO Takashid9ec4202016-07-21 16:14:52 +0900479 iniset $NEUTRON_CONF DEFAULT service_plugins $plugins
480}
481
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900482function neutron_server_config_add_new {
483 _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS+=($1)
484}
485
Sean M. Collins2a242512016-05-03 09:03:09 -0400486# Dispatch functions
487# These are needed for compatibility between the old and new implementations
488# where there are function name overlaps. These will be removed when
489# neutron-legacy is removed.
490# TODO(sc68cal) Remove when neutron-legacy is no more.
491function cleanup_neutron {
492 if is_neutron_legacy_enabled; then
493 # Call back to old function
494 cleanup_mutnauq "$@"
495 else
496 cleanup_neutron_new "$@"
497 fi
498}
499
500function configure_neutron {
501 if is_neutron_legacy_enabled; then
502 # Call back to old function
503 configure_mutnauq "$@"
504 else
505 configure_neutron_new "$@"
506 fi
507}
508
509function configure_neutron_nova {
510 if is_neutron_legacy_enabled; then
511 # Call back to old function
512 create_nova_conf_neutron "$@"
513 else
514 configure_neutron_nova_new "$@"
515 fi
516}
517
518function create_neutron_accounts {
519 if is_neutron_legacy_enabled; then
520 # Call back to old function
521 create_mutnauq_accounts "$@"
522 else
523 create_neutron_accounts_new "$@"
524 fi
525}
526
527function init_neutron {
528 if is_neutron_legacy_enabled; then
529 # Call back to old function
530 init_mutnauq "$@"
531 else
532 init_neutron_new "$@"
533 fi
534}
535
536function install_neutron {
537 if is_neutron_legacy_enabled; then
538 # Call back to old function
539 install_mutnauq "$@"
540 else
541 install_neutron_new "$@"
542 fi
543}
544
YAMAMOTO Takashid9ec4202016-07-21 16:14:52 +0900545function neutron_service_plugin_class_add {
546 if is_neutron_legacy_enabled; then
547 # Call back to old function
548 _neutron_service_plugin_class_add "$@"
549 else
550 neutron_service_plugin_class_add_new "$@"
551 fi
552}
553
YAMAMOTO Takashic74315e2016-07-21 17:49:43 +0900554function install_neutron_agent_packages {
555 if is_neutron_legacy_enabled; then
556 # Call back to old function
557 install_neutron_agent_packages_mutnauq "$@"
558 else
559 :
560 fi
561}
562
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900563function neutron_server_config_add {
564 if is_neutron_legacy_enabled; then
565 # Call back to old function
566 mutnauq_server_config_add "$@"
567 else
568 neutron_server_config_add_new "$@"
569 fi
570}
571
Sean M. Collins2a242512016-05-03 09:03:09 -0400572function start_neutron {
573 if is_neutron_legacy_enabled; then
574 # Call back to old function
575 start_mutnauq_l2_agent "$@"
576 start_mutnauq_other_agents "$@"
577 else
578 start_neutron_new "$@"
579 fi
580}
581
582function stop_neutron {
583 if is_neutron_legacy_enabled; then
584 # Call back to old function
585 stop_mutnauq "$@"
586 else
587 stop_neutron_new "$@"
588 fi
589}
590
591# Restore xtrace
592$XTRACE