blob: 17ffce7cb52afd4c326810def9d82d6288ee3f87 [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
Kevin Benton66b361b2017-06-13 00:31:01 -070031# NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values:
32# - False (default) : Run neutron under Eventlet
33# - True : Run neutron under uwsgi
34# TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable
35# enough
Jens Harbott3492fee2018-11-30 13:57:17 +000036NEUTRON_DEPLOY_MOD_WSGI=$(trueorfalse False NEUTRON_DEPLOY_MOD_WSGI)
Sean M. Collins2a242512016-05-03 09:03:09 -040037NEUTRON_AGENT=${NEUTRON_AGENT:-openvswitch}
38NEUTRON_DIR=$DEST/neutron
Ian Wienand1f82f432017-10-04 09:51:02 +110039NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
Sean M. Collins2a242512016-05-03 09:03:09 -040040
Brian Haley9aaa5292017-09-20 14:23:05 -040041NEUTRON_DISTRIBUTED_ROUTING=$(trueorfalse False NEUTRON_DISTRIBUTED_ROUTING)
42# Distributed Virtual Router (DVR) configuration
43# Can be:
44# - ``legacy`` - No DVR functionality
45# - ``dvr_snat`` - Controller or single node DVR
46# - ``dvr`` - Compute node in multi-node DVR
47# - ``dvr_no_external`` - Compute node in multi-node DVR, no external network
48#
49# Default is 'dvr_snat' since it can handle both DVR and legacy routers
50NEUTRON_DVR_MODE=${NEUTRON_DVR_MODE:-dvr_snat}
51
Sean M. Collins2a242512016-05-03 09:03:09 -040052NEUTRON_BIN_DIR=$(get_python_exec_prefix)
53NEUTRON_DHCP_BINARY="neutron-dhcp-agent"
54
55NEUTRON_CONF_DIR=/etc/neutron
56NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
57NEUTRON_META_CONF=$NEUTRON_CONF_DIR/metadata_agent.ini
58
59NEUTRON_DHCP_CONF=$NEUTRON_CONF_DIR/dhcp_agent.ini
60NEUTRON_L3_CONF=$NEUTRON_CONF_DIR/l3_agent.ini
61NEUTRON_AGENT_CONF=$NEUTRON_CONF_DIR/
Josh8f721622018-02-01 09:45:47 +020062NEUTRON_CREATE_INITIAL_NETWORKS=${NEUTRON_CREATE_INITIAL_NETWORKS:-True}
Sean M. Collins2a242512016-05-03 09:03:09 -040063
64NEUTRON_STATE_PATH=${NEUTRON_STATE_PATH:=$DATA_DIR/neutron}
Ian Wienand1f82f432017-10-04 09:51:02 +110065NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
Sean M. Collins2a242512016-05-03 09:03:09 -040066
Kevin Benton66b361b2017-06-13 00:31:01 -070067NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
68
Sean M. Collins2a242512016-05-03 09:03:09 -040069# By default, use the ML2 plugin
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +090070NEUTRON_CORE_PLUGIN=${NEUTRON_CORE_PLUGIN:-ml2}
71NEUTRON_CORE_PLUGIN_CONF_FILENAME=${NEUTRON_CORE_PLUGIN_CONF_FILENAME:-ml2_conf.ini}
72NEUTRON_CORE_PLUGIN_CONF_PATH=$NEUTRON_CONF_DIR/plugins/$NEUTRON_CORE_PLUGIN
73NEUTRON_CORE_PLUGIN_CONF=$NEUTRON_CORE_PLUGIN_CONF_PATH/$NEUTRON_CORE_PLUGIN_CONF_FILENAME
Sean M. Collins2a242512016-05-03 09:03:09 -040074
Ihar Hrachyshkabf697f52017-02-23 12:09:01 +000075NEUTRON_METERING_AGENT_CONF_FILENAME=${NEUTRON_METERING_AGENT_CONF_FILENAME:-metering_agent.ini}
76NEUTRON_METERING_AGENT_CONF=$NEUTRON_CONF_DIR/$NEUTRON_METERING_AGENT_CONF_FILENAME
77
Sean M. Collins2a242512016-05-03 09:03:09 -040078NEUTRON_AGENT_BINARY=${NEUTRON_AGENT_BINARY:-neutron-$NEUTRON_AGENT-agent}
79NEUTRON_L3_BINARY=${NEUTRON_L3_BINARY:-neutron-l3-agent}
80NEUTRON_META_BINARY=${NEUTRON_META_BINARY:-neutron-metadata-agent}
Ihar Hrachyshkabf697f52017-02-23 12:09:01 +000081NEUTRON_METERING_BINARY=${NEUTRON_METERING_BINARY:-neutron-metering-agent}
Sean M. Collins2a242512016-05-03 09:03:09 -040082
83# Public facing bits
Sean Daguef3b2f4c2017-04-13 10:11:48 -040084if is_service_enabled tls-proxy; then
Sean M. Collins2a242512016-05-03 09:03:09 -040085 NEUTRON_SERVICE_PROTOCOL="https"
86fi
87NEUTRON_SERVICE_HOST=${NEUTRON_SERVICE_HOST:-$SERVICE_HOST}
88NEUTRON_SERVICE_PORT=${NEUTRON_SERVICE_PORT:-9696}
89NEUTRON_SERVICE_PORT_INT=${NEUTRON_SERVICE_PORT_INT:-19696}
90NEUTRON_SERVICE_PROTOCOL=${NEUTRON_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
91
92NEUTRON_AUTH_STRATEGY=${NEUTRON_AUTH_STRATEGY:-keystone}
93NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
94NEUTRON_ROOTWRAP_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +000095NEUTRON_ROOTWRAP_CMD="$NEUTRON_ROOTWRAP $NEUTRON_ROOTWRAP_CONF_FILE"
96NEUTRON_ROOTWRAP_DAEMON_CMD="$NEUTRON_ROOTWRAP-daemon $NEUTRON_ROOTWRAP_CONF_FILE"
Sean M. Collins2a242512016-05-03 09:03:09 -040097
Ihar Hrachyshka615e1152017-02-23 10:41:51 +000098# This is needed because _neutron_ovs_base_configure_l3_agent uses it to create
99# an external network bridge
100PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex}
101PUBLIC_BRIDGE_MTU=${PUBLIC_BRIDGE_MTU:-1500}
102
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900103# Additional neutron api config files
Sean Dagueafef8bf2017-03-06 14:07:23 -0500104declare -a -g _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900105
Sean M. Collins2a242512016-05-03 09:03:09 -0400106# Functions
107# ---------
108
109# Test if any Neutron services are enabled
110# is_neutron_enabled
111function is_neutron_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700112 [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1
Sean M. Collins2a242512016-05-03 09:03:09 -0400113 [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
114 return 1
115}
116
117# Test if any Neutron services are enabled
118# is_neutron_enabled
119function is_neutron_legacy_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700120 [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1
Sean M. Collins2a242512016-05-03 09:03:09 -0400121 [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
122 return 1
123}
124
YAMAMOTO Takashic74315e2016-07-21 17:49:43 +0900125if is_neutron_legacy_enabled; then
126 source $TOP_DIR/lib/neutron-legacy
127fi
128
Sean M. Collins2a242512016-05-03 09:03:09 -0400129# cleanup_neutron() - Remove residual data files, anything left over from previous
130# runs that a clean run would need to clean up
131function cleanup_neutron_new {
132 source $TOP_DIR/lib/neutron_plugins/${NEUTRON_AGENT}_agent
133 if is_neutron_ovs_base_plugin; then
134 neutron_ovs_base_cleanup
135 fi
136
137 if [[ $NEUTRON_AGENT == "linuxbridge" ]]; then
138 neutron_lb_cleanup
139 fi
140 # delete all namespaces created by neutron
141 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|qlbaas|fip|snat)-[0-9a-f-]*'); do
142 sudo ip netns delete ${ns}
143 done
144}
145
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000146# configure_root_helper_options() - Configure agent rootwrap helper options
147function configure_root_helper_options {
148 local conffile=$1
149 iniset $conffile agent root_helper "sudo $NEUTRON_ROOTWRAP_CMD"
150 iniset $conffile agent root_helper_daemon "sudo $NEUTRON_ROOTWRAP_DAEMON_CMD"
151}
152
Sean M. Collins2a242512016-05-03 09:03:09 -0400153# configure_neutron() - Set config files, create data dirs, etc
154function configure_neutron_new {
155 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
156
157 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
158
159 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
160
161 configure_neutron_rootwrap
162
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900163 mkdir -p $NEUTRON_CORE_PLUGIN_CONF_PATH
Sean M. Collins2a242512016-05-03 09:03:09 -0400164
YAMAMOTO Takashi1df17c92017-05-01 17:00:42 +0900165 # NOTE(yamamoto): A decomposed plugin should prepare the config file in
166 # its devstack plugin.
167 if [ -f $NEUTRON_DIR/etc/neutron/plugins/$NEUTRON_CORE_PLUGIN/$NEUTRON_CORE_PLUGIN_CONF_FILENAME.sample ]; then
168 cp $NEUTRON_DIR/etc/neutron/plugins/$NEUTRON_CORE_PLUGIN/$NEUTRON_CORE_PLUGIN_CONF_FILENAME.sample $NEUTRON_CORE_PLUGIN_CONF
169 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400170
171 iniset $NEUTRON_CONF database connection `database_connection_url neutron`
172 iniset $NEUTRON_CONF DEFAULT state_path $NEUTRON_STATE_PATH
173 iniset $NEUTRON_CONF oslo_concurrency lock_path $NEUTRON_STATE_PATH/lock
174 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
175
Gary Kottond2ef6152016-09-20 04:12:11 -0700176 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean M. Collinsfbba3b92016-05-12 11:17:53 -0400177
Sean M. Collins5394cc12016-05-11 15:03:38 -0400178 iniset_rpc_backend neutron $NEUTRON_CONF
179
Sean M. Collins2a242512016-05-03 09:03:09 -0400180 # Neutron API server & Neutron plugin
181 if is_service_enabled neutron-api; then
182 local policy_file=$NEUTRON_CONF_DIR/policy.json
Sean M. Collins2a242512016-05-03 09:03:09 -0400183 # Allow neutron user to administer neutron to match neutron account
Akihiro Motoki80769c52018-11-23 05:18:40 +0900184 # NOTE(amotoki): This is required for nova works correctly with neutron.
185 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
186 cp $NEUTRON_DIR/etc/policy.json $policy_file
187 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $policy_file
188 else
189 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $policy_file
190 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400191
192 cp $NEUTRON_DIR/etc/api-paste.ini $NEUTRON_CONF_DIR/api-paste.ini
193
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900194 iniset $NEUTRON_CONF DEFAULT core_plugin $NEUTRON_CORE_PLUGIN
Sean M. Collins2a242512016-05-03 09:03:09 -0400195
Sean M. Collins2a242512016-05-03 09:03:09 -0400196 iniset $NEUTRON_CONF DEFAULT policy_file $policy_file
197 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips True
Brian Haley9aaa5292017-09-20 14:23:05 -0400198 iniset $NEUTRON_CONF DEFAULT router_distributed $NEUTRON_DISTRIBUTED_ROUTING
Sean M. Collins2a242512016-05-03 09:03:09 -0400199
200 iniset $NEUTRON_CONF DEFAULT auth_strategy $NEUTRON_AUTH_STRATEGY
Ian Wienand1f82f432017-10-04 09:51:02 +1100201 configure_auth_token_middleware $NEUTRON_CONF neutron $NEUTRON_AUTH_CACHE_DIR keystone_authtoken
202 configure_auth_token_middleware $NEUTRON_CONF nova $NEUTRON_AUTH_CACHE_DIR nova
Sean M. Collins2a242512016-05-03 09:03:09 -0400203
204 # Configure VXLAN
205 # TODO(sc68cal) not hardcode?
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900206 iniset $NEUTRON_CORE_PLUGIN_CONF ml2 tenant_network_types vxlan
Brian Haley9aaa5292017-09-20 14:23:05 -0400207
208 local mech_drivers="openvswitch"
209 if [[ "$NEUTRON_DISTRIBUTED_ROUTING" = "True" ]]; then
210 mech_drivers+=",l2population"
211 else
212 mech_drivers+=",linuxbridge"
213 fi
214 iniset $NEUTRON_CORE_PLUGIN_CONF ml2 mechanism_drivers $mech_drivers
215
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900216 iniset $NEUTRON_CORE_PLUGIN_CONF ml2_type_vxlan vni_ranges 1001:2000
Sean M. Collinsedcb7e52016-12-15 11:29:28 -0500217 iniset $NEUTRON_CORE_PLUGIN_CONF ml2_type_flat flat_networks public
Matt Riedemannc9c9d312016-09-15 20:33:22 -0400218 if [[ "$NEUTRON_PORT_SECURITY" = "True" ]]; then
Ihar Hrachyshkaf511c362017-03-07 06:31:49 +0000219 neutron_ml2_extension_driver_add port_security
Matt Riedemannc9c9d312016-09-15 20:33:22 -0400220 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400221 fi
222
223 # Neutron OVS or LB agent
224 if is_service_enabled neutron-agent; then
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900225 iniset $NEUTRON_CORE_PLUGIN_CONF agent tunnel_types vxlan
226 iniset $NEUTRON_CORE_PLUGIN_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000227 configure_root_helper_options $NEUTRON_CORE_PLUGIN_CONF
Sean M. Collins2a242512016-05-03 09:03:09 -0400228
229 # Configure the neutron agent
230 if [[ $NEUTRON_AGENT == "linuxbridge" ]]; then
Sean M. Collinsedcb7e52016-12-15 11:29:28 -0500231 iniset $NEUTRON_CORE_PLUGIN_CONF securitygroup firewall_driver iptables
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900232 iniset $NEUTRON_CORE_PLUGIN_CONF vxlan local_ip $HOST_IP
Jakub Libosvara99ab702018-05-14 16:12:52 +0200233 elif [[ $NEUTRON_AGENT == "openvswitch" ]]; then
234 iniset $NEUTRON_CORE_PLUGIN_CONF securitygroup firewall_driver openvswitch
YAMAMOTO Takashi4a55d2a2016-08-24 15:30:09 +0900235 iniset $NEUTRON_CORE_PLUGIN_CONF ovs local_ip $HOST_IP
Brian Haley9aaa5292017-09-20 14:23:05 -0400236
237 if [[ "$NEUTRON_DISTRIBUTED_ROUTING" = "True" ]]; then
238 iniset $NEUTRON_CORE_PLUGIN_CONF agent l2_population True
239 iniset $NEUTRON_CORE_PLUGIN_CONF agent enable_distributed_routing True
Swaminathan Vasudevan9bf7e262019-05-02 13:45:46 -0700240 iniset $NEUTRON_CORE_PLUGIN_CONF agent arp_responder True
Brian Haley9aaa5292017-09-20 14:23:05 -0400241 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400242 fi
Ihar Hrachyshkab3a210f2016-09-29 13:26:30 +0000243
Denis Buliga0bf75a42017-02-06 16:56:46 +0200244 if ! running_in_container; then
245 enable_kernel_bridge_firewall
246 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400247 fi
248
249 # DHCP Agent
250 if is_service_enabled neutron-dhcp; then
251 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $NEUTRON_DHCP_CONF
252
Gary Kottond2ef6152016-09-20 04:12:11 -0700253 iniset $NEUTRON_DHCP_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean Dague78801c12016-08-04 14:10:07 -0400254 # make it so we have working DNS from guests
255 iniset $NEUTRON_DHCP_CONF DEFAULT dnsmasq_local_resolv True
256
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000257 configure_root_helper_options $NEUTRON_DHCP_CONF
Sean M. Collins2a242512016-05-03 09:03:09 -0400258 iniset $NEUTRON_DHCP_CONF DEFAULT interface_driver $NEUTRON_AGENT
259 neutron_plugin_configure_dhcp_agent $NEUTRON_DHCP_CONF
260 fi
261
262 if is_service_enabled neutron-l3; then
263 cp $NEUTRON_DIR/etc/l3_agent.ini.sample $NEUTRON_L3_CONF
264 iniset $NEUTRON_L3_CONF DEFAULT interface_driver $NEUTRON_AGENT
YAMAMOTO Takashid9ec4202016-07-21 16:14:52 +0900265 neutron_service_plugin_class_add router
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000266 configure_root_helper_options $NEUTRON_L3_CONF
Gary Kottond2ef6152016-09-20 04:12:11 -0700267 iniset $NEUTRON_L3_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean M. Collins2a242512016-05-03 09:03:09 -0400268 neutron_plugin_configure_l3_agent $NEUTRON_L3_CONF
Ihar Hrachyshkae3915932017-02-24 06:24:47 +0000269
270 # Configure the neutron agent to serve external network ports
271 if [[ $NEUTRON_AGENT == "linuxbridge" ]]; then
272 iniset $NEUTRON_CORE_PLUGIN_CONF linux_bridge bridge_mappings "$PUBLIC_NETWORK_NAME:$PUBLIC_BRIDGE"
273 else
274 iniset $NEUTRON_CORE_PLUGIN_CONF ovs bridge_mappings "$PUBLIC_NETWORK_NAME:$PUBLIC_BRIDGE"
275 fi
Brian Haley9aaa5292017-09-20 14:23:05 -0400276
277 if [[ "$NEUTRON_DISTRIBUTED_ROUTING" = "True" ]]; then
278 iniset $NEUTRON_L3_CONF DEFAULT agent_mode $NEUTRON_DVR_MODE
279 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400280 fi
281
282 # Metadata
Sean M. Collins1cd28282016-05-11 15:07:19 -0400283 if is_service_enabled neutron-metadata-agent; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400284 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $NEUTRON_META_CONF
285
Gary Kottond2ef6152016-09-20 04:12:11 -0700286 iniset $NEUTRON_META_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Ken'ichi Ohmichi2da019f2017-10-11 09:57:25 -0700287 iniset $NEUTRON_META_CONF DEFAULT nova_metadata_host $SERVICE_HOST
Armando Migliaccio06f2ea22017-02-02 16:47:00 -0800288 iniset $NEUTRON_META_CONF DEFAULT metadata_workers $API_WORKERS
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000289 # TODO(ihrachys) do we really need to set rootwrap for metadata agent?
290 configure_root_helper_options $NEUTRON_META_CONF
Sean M. Collins2a242512016-05-03 09:03:09 -0400291
292 # TODO(dtroyer): remove the v2.0 hard code below
Sean Daguec13b8a12017-04-20 06:54:51 -0400293 iniset $NEUTRON_META_CONF DEFAULT auth_url $KEYSTONE_SERVICE_URI
Ian Wienand1f82f432017-10-04 09:51:02 +1100294 configure_auth_token_middleware $NEUTRON_META_CONF neutron $NEUTRON_AUTH_CACHE_DIR DEFAULT
Sean M. Collins2a242512016-05-03 09:03:09 -0400295 fi
296
297 # Format logging
Sean Dague27f66e92017-05-02 09:08:17 -0400298 setup_logging $NEUTRON_CONF
Sean M. Collins2a242512016-05-03 09:03:09 -0400299
Kevin Benton66b361b2017-06-13 00:31:01 -0700300 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400301 # Set the service port for a proxy to take the original
302 iniset $NEUTRON_CONF DEFAULT bind_port "$NEUTRON_SERVICE_PORT_INT"
Jens Harbott411c34d2017-08-29 14:40:26 +0000303 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
Sean M. Collins2a242512016-05-03 09:03:09 -0400304 fi
305
Sean M. Collins8063fee2016-05-24 11:27:36 -0700306 # Metering
307 if is_service_enabled neutron-metering; then
Ihar Hrachyshkabf697f52017-02-23 12:09:01 +0000308 cp $NEUTRON_DIR/etc/metering_agent.ini.sample $NEUTRON_METERING_AGENT_CONF
YAMAMOTO Takashid9ec4202016-07-21 16:14:52 +0900309 neutron_service_plugin_class_add metering
Sean M. Collins8063fee2016-05-24 11:27:36 -0700310 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400311}
312
313# configure_neutron_rootwrap() - configure Neutron's rootwrap
314function configure_neutron_rootwrap {
Sean M. Collins2a242512016-05-03 09:03:09 -0400315 # Deploy new rootwrap filters files (owned by root).
316 # Wipe any existing rootwrap.d files first
317 if [[ -d $NEUTRON_CONF_DIR/rootwrap.d ]]; then
318 sudo rm -rf $NEUTRON_CONF_DIR/rootwrap.d
319 fi
320
321 # Deploy filters to /etc/neutron/rootwrap.d
322 sudo install -d -o root -g root -m 755 $NEUTRON_CONF_DIR/rootwrap.d
323 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.d/*.filters $NEUTRON_CONF_DIR/rootwrap.d
324
325 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
326 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $NEUTRON_CONF_DIR
327 sudo sed -e "s:^filters_path=.*$:filters_path=$NEUTRON_CONF_DIR/rootwrap.d:" -i $NEUTRON_CONF_DIR/rootwrap.conf
328
329 # Set up the rootwrap sudoers for Neutron
330 tempfile=`mktemp`
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000331 echo "$STACK_USER ALL=(root) NOPASSWD: $NEUTRON_ROOTWRAP_CMD *" >$tempfile
332 echo "$STACK_USER ALL=(root) NOPASSWD: $NEUTRON_ROOTWRAP_DAEMON_CMD" >>$tempfile
Sean M. Collins2a242512016-05-03 09:03:09 -0400333 chmod 0440 $tempfile
334 sudo chown root:root $tempfile
335 sudo mv $tempfile /etc/sudoers.d/neutron-rootwrap
336}
337
338# Make Neutron-required changes to nova.conf
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100339# Takes a single optional argument which is the config file to update,
340# if not passed $NOVA_CONF is used.
Sean M. Collins2a242512016-05-03 09:03:09 -0400341function configure_neutron_nova_new {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100342 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400343 iniset $conf DEFAULT use_neutron True
344 iniset $conf neutron auth_type "password"
345 iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
346 iniset $conf neutron username neutron
347 iniset $conf neutron password "$SERVICE_PASSWORD"
348 iniset $conf neutron user_domain_name "Default"
349 iniset $conf neutron project_name "$SERVICE_TENANT_NAME"
350 iniset $conf neutron project_domain_name "Default"
351 iniset $conf neutron auth_strategy $NEUTRON_AUTH_STRATEGY
352 iniset $conf neutron region_name "$REGION_NAME"
Sean M. Collins2a242512016-05-03 09:03:09 -0400353
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400354 iniset $conf DEFAULT firewall_driver nova.virt.firewall.NoopFirewallDriver
Sean M. Collins2a242512016-05-03 09:03:09 -0400355
Gary Kotton88f85582016-08-14 06:55:42 -0700356 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400357 neutron_plugin_create_nova_conf $conf
Gary Kotton88f85582016-08-14 06:55:42 -0700358
Sean M. Collins1cd28282016-05-11 15:07:19 -0400359 if is_service_enabled neutron-metadata-agent; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400360 iniset $conf neutron service_metadata_proxy "True"
Sean M. Collins2a242512016-05-03 09:03:09 -0400361 fi
362
363}
364
365# Tenant User Roles
366# ------------------------------------------------------------------
367# service neutron admin # if enabled
368
369# create_neutron_accounts() - Create required service accounts
370function create_neutron_accounts_new {
Kevin Benton66b361b2017-06-13 00:31:01 -0700371 local neutron_url
372
373 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
374 neutron_url=$NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST/networking/
375 else
376 neutron_url=$NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST:$NEUTRON_SERVICE_PORT/
377 fi
378
379
Sean M. Collins2a242512016-05-03 09:03:09 -0400380 if [[ "$ENABLED_SERVICES" =~ "neutron-api" ]]; then
381
382 create_service_user "neutron"
383
384 neutron_service=$(get_or_create_service "neutron" \
385 "network" "Neutron Service")
386 get_or_create_endpoint $neutron_service \
Kevin Benton66b361b2017-06-13 00:31:01 -0700387 "$REGION_NAME" "$neutron_url"
Sean M. Collins2a242512016-05-03 09:03:09 -0400388 fi
389}
390
Ian Wienand1f82f432017-10-04 09:51:02 +1100391# create_neutron_cache_dir() - Part of the init_neutron() process
392function create_neutron_cache_dir {
393 # Create cache dir
394 sudo install -d -o $STACK_USER $NEUTRON_AUTH_CACHE_DIR
395 rm -f $NEUTRON_AUTH_CACHE_DIR/*
396}
397
Sean M. Collins2a242512016-05-03 09:03:09 -0400398# init_neutron() - Initialize databases, etc.
399function init_neutron_new {
400
401 recreate_database neutron
402
Clark Boylan633dbc32017-06-14 12:09:21 -0700403 time_start "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400404 # Run Neutron db migrations
Ihar Hrachyshka19f4b3f2017-02-23 20:44:18 +0000405 $NEUTRON_BIN_DIR/neutron-db-manage upgrade heads
Clark Boylan633dbc32017-06-14 12:09:21 -0700406 time_stop "dbsync"
Ian Wienand1f82f432017-10-04 09:51:02 +1100407
408 create_neutron_cache_dir
Sean M. Collins2a242512016-05-03 09:03:09 -0400409}
410
411# install_neutron() - Collect source and prepare
412function install_neutron_new {
413 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
414 setup_develop $NEUTRON_DIR
415
416 # Install neutron-lib from git so we make sure we're testing
417 # the latest code.
418 if use_library_from_git "neutron-lib"; then
419 git_clone_by_name "neutron-lib"
420 setup_dev_lib "neutron-lib"
421 fi
422
423 # L3 service requires radvd
424 if is_service_enabled neutron-l3; then
425 install_package radvd
426 fi
427
428 if is_service_enabled neutron-agent neutron-dhcp neutron-l3; then
429 #TODO(sc68cal) - kind of ugly
430 source $TOP_DIR/lib/neutron_plugins/${NEUTRON_AGENT}_agent
431 neutron_plugin_install_agent_packages
432 fi
433
434}
435
436# install_neutronclient() - Collect source and prepare
437function install_neutronclient {
438 if use_library_from_git "python-neutronclient"; then
439 git_clone_by_name "python-neutronclient"
440 setup_dev_lib "python-neutronclient"
441 sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-neutronclient"]}/tools/,/etc/bash_completion.d/}neutron.bash_completion
442 fi
443}
444
445# start_neutron_api() - Start the API process ahead of other things
446function start_neutron_api {
447 local service_port=$NEUTRON_SERVICE_PORT
448 local service_protocol=$NEUTRON_SERVICE_PROTOCOL
Kevin Benton66b361b2017-06-13 00:31:01 -0700449 local neutron_url
Sean M. Collins2a242512016-05-03 09:03:09 -0400450 if is_service_enabled tls-proxy; then
451 service_port=$NEUTRON_SERVICE_PORT_INT
452 service_protocol="http"
453 fi
454
YAMAMOTO Takashied887d82017-02-22 14:21:33 -0500455 local opts=""
456 opts+=" --config-file $NEUTRON_CONF"
457 opts+=" --config-file $NEUTRON_CORE_PLUGIN_CONF"
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900458 local cfg_file
459 for cfg_file in ${_NEUTRON_SERVER_EXTRA_CONF_FILES_ABS[@]}; do
460 opts+=" --config-file $cfg_file"
461 done
462
Kevin Benton66b361b2017-06-13 00:31:01 -0700463 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
464 run_process neutron-api "$NEUTRON_BIN_DIR/uwsgi --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
465 neutron_url=$service_protocol://$NEUTRON_SERVICE_HOST/networking/
466 enable_service neutron-rpc-server
467 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $opts"
468 else
469 # Start the Neutron service
470 # TODO(sc68cal) Stop hard coding this
471 run_process neutron-api "$NEUTRON_BIN_DIR/neutron-server $opts"
472 neutron_url=$service_protocol://$NEUTRON_SERVICE_HOST:$service_port
473 # Start proxy if enabled
474 if is_service_enabled tls-proxy; then
475 start_tls_proxy neutron '*' $NEUTRON_SERVICE_PORT $NEUTRON_SERVICE_HOST $NEUTRON_SERVICE_PORT_INT
476 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400477 fi
478
Kevin Benton66b361b2017-06-13 00:31:01 -0700479 if ! wait_for_service $SERVICE_TIMEOUT $neutron_url; then
480 die $LINENO "neutron-api did not start"
Sean M. Collins2a242512016-05-03 09:03:09 -0400481 fi
482}
483
Sean Dague0eebeb42017-08-30 14:16:58 -0400484# start_neutron() - Start running processes
Sean M. Collins2a242512016-05-03 09:03:09 -0400485function start_neutron_new {
Sean M. Collins2a242512016-05-03 09:03:09 -0400486 # Start up the neutron agents if enabled
487 # TODO(sc68cal) Make this pluggable so different DevStack plugins for different Neutron plugins
488 # can resolve the $NEUTRON_AGENT_BINARY
489 if is_service_enabled neutron-agent; then
Ihar Hrachyshka19f4b3f2017-02-23 20:44:18 +0000490 # TODO(ihrachys) stop loading ml2_conf.ini into agents, instead load agent specific files
491 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 -0400492 fi
493 if is_service_enabled neutron-dhcp; then
494 neutron_plugin_configure_dhcp_agent $NEUTRON_DHCP_CONF
Ihar Hrachyshka19f4b3f2017-02-23 20:44:18 +0000495 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 -0400496 fi
497 if is_service_enabled neutron-l3; then
Ihar Hrachyshka19f4b3f2017-02-23 20:44:18 +0000498 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 +0900499 fi
Josh8f721622018-02-01 09:45:47 +0200500 if is_service_enabled neutron-api && [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" == "True" ]]; then
YAMAMOTO Takashi07edde12016-10-19 19:21:00 +0000501 # XXX(sc68cal) - Here's where plugins can wire up their own networks instead
502 # of the code in lib/neutron_plugins/services/l3
503 if type -p neutron_plugin_create_initial_networks > /dev/null; then
504 neutron_plugin_create_initial_networks
505 else
506 # XXX(sc68cal) Load up the built in Neutron networking code and build a topology
507 source $TOP_DIR/lib/neutron_plugins/services/l3
508 # Create the networks using servic
509 create_neutron_initial_network
510 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400511 fi
Sean M. Collins1cd28282016-05-11 15:07:19 -0400512 if is_service_enabled neutron-metadata-agent; then
Ihar Hrachyshka19f4b3f2017-02-23 20:44:18 +0000513 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 -0400514 fi
Sean M. Collins8063fee2016-05-24 11:27:36 -0700515
516 if is_service_enabled neutron-metering; then
Ihar Hrachyshka868746b2017-09-13 15:44:18 -0600517 run_process neutron-metering "$NEUTRON_BIN_DIR/$NEUTRON_METERING_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_METERING_AGENT_CONF"
Sean M. Collins8063fee2016-05-24 11:27:36 -0700518 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400519}
520
Sean Dague0eebeb42017-08-30 14:16:58 -0400521# stop_neutron() - Stop running processes
Sean M. Collins2a242512016-05-03 09:03:09 -0400522function stop_neutron_new {
523 for serv in neutron-api neutron-agent neutron-l3; do
524 stop_process $serv
525 done
526
Kevin Benton66b361b2017-06-13 00:31:01 -0700527 if is_service_enabled neutron-rpc-server; then
528 stop_process neutron-rpc-server
529 fi
530
Sean M. Collins2a242512016-05-03 09:03:09 -0400531 if is_service_enabled neutron-dhcp; then
532 stop_process neutron-dhcp
533 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
534 [ ! -z "$pid" ] && sudo kill -9 $pid
535 fi
536
Sean M. Collins1cd28282016-05-11 15:07:19 -0400537 if is_service_enabled neutron-metadata-agent; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400538 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Sean M. Collins1cd28282016-05-11 15:07:19 -0400539 stop_process neutron-metadata-agent
Sean M. Collins2a242512016-05-03 09:03:09 -0400540 fi
541}
542
YAMAMOTO Takashid9ec4202016-07-21 16:14:52 +0900543# neutron_service_plugin_class_add() - add service plugin class
544function neutron_service_plugin_class_add_new {
545 local service_plugin_class=$1
546 local plugins=""
547
548 plugins=$(iniget $NEUTRON_CONF DEFAULT service_plugins)
YAMAMOTO Takashi84e45c92017-02-22 14:25:14 -0500549 if [ $plugins ]; then
550 plugins+=","
551 fi
552 plugins+="${service_plugin_class}"
YAMAMOTO Takashid9ec4202016-07-21 16:14:52 +0900553 iniset $NEUTRON_CONF DEFAULT service_plugins $plugins
554}
555
Ihar Hrachyshkaf511c362017-03-07 06:31:49 +0000556function _neutron_ml2_extension_driver_add {
557 local driver=$1
558 local drivers=""
559
560 drivers=$(iniget $NEUTRON_CORE_PLUGIN_CONF ml2 extension_drivers)
561 if [ $drivers ]; then
562 drivers+=","
563 fi
564 drivers+="${driver}"
565 iniset $NEUTRON_CORE_PLUGIN_CONF ml2 extension_drivers $drivers
566}
567
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900568function neutron_server_config_add_new {
569 _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS+=($1)
570}
571
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -0500572# neutron_deploy_rootwrap_filters() - deploy rootwrap filters
573function neutron_deploy_rootwrap_filters_new {
574 local srcdir=$1
575 sudo install -d -o root -g root -m 755 $NEUTRON_CONF_DIR/rootwrap.d
576 sudo install -o root -g root -m 644 $srcdir/etc/neutron/rootwrap.d/*.filters $NEUTRON_CONF_DIR/rootwrap.d
577}
578
Sean M. Collins2a242512016-05-03 09:03:09 -0400579# Dispatch functions
580# These are needed for compatibility between the old and new implementations
581# where there are function name overlaps. These will be removed when
582# neutron-legacy is removed.
583# TODO(sc68cal) Remove when neutron-legacy is no more.
584function cleanup_neutron {
Kevin Benton66b361b2017-06-13 00:31:01 -0700585 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
586 stop_process neutron-api
587 stop_process neutron-rpc-server
588 remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api"
589 sudo rm -f $(apache_site_config_for neutron-api)
590 fi
591
Sean M. Collins2a242512016-05-03 09:03:09 -0400592 if is_neutron_legacy_enabled; then
593 # Call back to old function
594 cleanup_mutnauq "$@"
595 else
596 cleanup_neutron_new "$@"
597 fi
598}
599
600function configure_neutron {
601 if is_neutron_legacy_enabled; then
602 # Call back to old function
603 configure_mutnauq "$@"
604 else
605 configure_neutron_new "$@"
606 fi
Kevin Benton66b361b2017-06-13 00:31:01 -0700607
608 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
609 write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api" "/networking"
610 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400611}
612
613function configure_neutron_nova {
614 if is_neutron_legacy_enabled; then
615 # Call back to old function
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400616 create_nova_conf_neutron $NOVA_CONF
617 if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
618 for i in $(seq 1 $NOVA_NUM_CELLS); do
619 local conf
620 conf=$(conductor_conf $i)
621 create_nova_conf_neutron $conf
622 done
623 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400624 else
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400625 configure_neutron_nova_new $NOVA_CONF
626 if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
627 for i in $(seq 1 $NOVA_NUM_CELLS); do
628 local conf
629 conf=$(conductor_conf $i)
630 configure_neutron_nova_new $conf
631 done
632 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400633 fi
634}
635
636function create_neutron_accounts {
637 if is_neutron_legacy_enabled; then
638 # Call back to old function
639 create_mutnauq_accounts "$@"
640 else
641 create_neutron_accounts_new "$@"
642 fi
643}
644
645function init_neutron {
646 if is_neutron_legacy_enabled; then
647 # Call back to old function
648 init_mutnauq "$@"
649 else
650 init_neutron_new "$@"
651 fi
652}
653
654function install_neutron {
655 if is_neutron_legacy_enabled; then
656 # Call back to old function
657 install_mutnauq "$@"
658 else
659 install_neutron_new "$@"
660 fi
661}
662
YAMAMOTO Takashid9ec4202016-07-21 16:14:52 +0900663function neutron_service_plugin_class_add {
664 if is_neutron_legacy_enabled; then
665 # Call back to old function
666 _neutron_service_plugin_class_add "$@"
667 else
668 neutron_service_plugin_class_add_new "$@"
669 fi
670}
671
Ihar Hrachyshkaf511c362017-03-07 06:31:49 +0000672function neutron_ml2_extension_driver_add {
673 if is_neutron_legacy_enabled; then
674 # Call back to old function
675 _neutron_ml2_extension_driver_add_old "$@"
676 else
677 _neutron_ml2_extension_driver_add "$@"
678 fi
679}
680
YAMAMOTO Takashic74315e2016-07-21 17:49:43 +0900681function install_neutron_agent_packages {
682 if is_neutron_legacy_enabled; then
683 # Call back to old function
684 install_neutron_agent_packages_mutnauq "$@"
685 else
686 :
687 fi
688}
689
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900690function neutron_server_config_add {
691 if is_neutron_legacy_enabled; then
692 # Call back to old function
693 mutnauq_server_config_add "$@"
694 else
695 neutron_server_config_add_new "$@"
696 fi
697}
698
Sean M. Collins2a242512016-05-03 09:03:09 -0400699function start_neutron {
700 if is_neutron_legacy_enabled; then
701 # Call back to old function
702 start_mutnauq_l2_agent "$@"
703 start_mutnauq_other_agents "$@"
704 else
705 start_neutron_new "$@"
706 fi
707}
708
709function stop_neutron {
710 if is_neutron_legacy_enabled; then
711 # Call back to old function
712 stop_mutnauq "$@"
713 else
714 stop_neutron_new "$@"
715 fi
716}
717
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -0500718function neutron_deploy_rootwrap_filters {
719 if is_neutron_legacy_enabled; then
720 # Call back to old function
721 _neutron_deploy_rootwrap_filters "$@"
722 else
723 neutron_deploy_rootwrap_filters_new "$@"
724 fi
725}
726
Sean M. Collins2a242512016-05-03 09:03:09 -0400727# Restore xtrace
728$XTRACE