| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 | # | 
|  | 3 | # lib/neutron | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 4 | # functions - functions specific to neutron | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 5 |  | 
|  | 6 | # Dependencies: | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 7 | # ``functions`` file | 
|  | 8 | # ``DEST`` must be defined | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 9 | # ``STACK_USER`` must be defined | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 10 |  | 
|  | 11 | # ``stack.sh`` calls the entry points in this order: | 
|  | 12 | # | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 13 | # - install_neutron_agent_packages | 
|  | 14 | # - install_neutronclient | 
|  | 15 | # - install_neutron | 
|  | 16 | # - install_neutron_third_party | 
|  | 17 | # - configure_neutron | 
|  | 18 | # - init_neutron | 
|  | 19 | # - configure_neutron_third_party | 
|  | 20 | # - init_neutron_third_party | 
|  | 21 | # - start_neutron_third_party | 
|  | 22 | # - create_nova_conf_neutron | 
|  | 23 | # - configure_neutron_after_post_config | 
|  | 24 | # - start_neutron_service_and_check | 
|  | 25 | # - check_neutron_third_party_integration | 
|  | 26 | # - start_neutron_agents | 
|  | 27 | # - create_neutron_initial_network | 
|  | 28 | # | 
|  | 29 | # ``unstack.sh`` calls the entry points in this order: | 
|  | 30 | # | 
|  | 31 | # - stop_neutron | 
|  | 32 | # - stop_neutron_third_party | 
|  | 33 | # - cleanup_neutron | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 34 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 35 | # Functions in lib/neutron are classified into the following categories: | 
|  | 36 | # | 
|  | 37 | # - entry points (called from stack.sh or unstack.sh) | 
|  | 38 | # - internal functions | 
|  | 39 | # - neutron exercises | 
|  | 40 | # - 3rd party programs | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 41 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 42 |  | 
|  | 43 | # Neutron Networking | 
|  | 44 | # ------------------ | 
|  | 45 |  | 
|  | 46 | # Make sure that neutron is enabled in ``ENABLED_SERVICES``.  If you want | 
|  | 47 | # to run Neutron on this host, make sure that q-svc is also in | 
|  | 48 | # ``ENABLED_SERVICES``. | 
|  | 49 | # | 
|  | 50 | # See "Neutron Network Configuration" below for additional variables | 
|  | 51 | # that must be set in localrc for connectivity across hosts with | 
|  | 52 | # Neutron. | 
|  | 53 |  | 
|  | 54 | # Settings | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 55 | # -------- | 
|  | 56 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 57 |  | 
|  | 58 | # Neutron Network Configuration | 
|  | 59 | # ----------------------------- | 
|  | 60 |  | 
|  | 61 | if is_service_enabled tls-proxy; then | 
|  | 62 | Q_PROTOCOL="https" | 
|  | 63 | fi | 
|  | 64 |  | 
|  | 65 |  | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 66 | # Set up default directories | 
|  | 67 | GITDIR["python-neutronclient"]=$DEST/python-neutronclient | 
|  | 68 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 69 |  | 
|  | 70 | NEUTRON_DIR=$DEST/neutron | 
|  | 71 | NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas | 
|  | 72 |  | 
|  | 73 | # Support entry points installation of console scripts | 
|  | 74 | if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then | 
|  | 75 | NEUTRON_BIN_DIR=$NEUTRON_DIR/bin | 
|  | 76 | else | 
|  | 77 | NEUTRON_BIN_DIR=$(get_python_exec_prefix) | 
|  | 78 | fi | 
|  | 79 |  | 
|  | 80 | NEUTRON_CONF_DIR=/etc/neutron | 
|  | 81 | NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf | 
|  | 82 | export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"} | 
|  | 83 |  | 
| Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 84 | # NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values: | 
|  | 85 | # - False (default) : Run neutron under Eventlet | 
|  | 86 | # - True : Run neutron under uwsgi | 
|  | 87 | # TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable | 
|  | 88 | # enough | 
| Jens Harbott | 3492fee | 2018-11-30 13:57:17 +0000 | [diff] [blame] | 89 | NEUTRON_DEPLOY_MOD_WSGI=$(trueorfalse False NEUTRON_DEPLOY_MOD_WSGI) | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 90 |  | 
|  | 91 | NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 92 |  | 
| Slawek Kaplonski | 24b65ad | 2021-06-22 15:31:46 +0200 | [diff] [blame] | 93 | # If NEUTRON_ENFORCE_SCOPE == True, it will set "enforce_scope" | 
|  | 94 | # and "enforce_new_defaults" to True in the Neutron's config to enforce usage | 
|  | 95 | # of the new RBAC policies and scopes. | 
|  | 96 | NEUTRON_ENFORCE_SCOPE=$(trueorfalse False NEUTRON_ENFORCE_SCOPE) | 
|  | 97 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 98 | # Agent binaries.  Note, binary paths for other agents are set in per-service | 
|  | 99 | # scripts in lib/neutron_plugins/services/ | 
|  | 100 | AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent" | 
|  | 101 | AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"} | 
|  | 102 | AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent" | 
| Brian Haley | 9aaa529 | 2017-09-20 14:23:05 -0400 | [diff] [blame] | 103 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 104 | # Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and | 
|  | 105 | # loaded from per-plugin  scripts in lib/neutron_plugins/ | 
|  | 106 | Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini | 
|  | 107 | # NOTE(slaweq): NEUTRON_DHCP_CONF is used e.g. in neutron repository, | 
|  | 108 | # it was previously defined in the lib/neutron module which is now deleted. | 
|  | 109 | NEUTRON_DHCP_CONF=$Q_DHCP_CONF_FILE | 
|  | 110 | Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini | 
|  | 111 | # NOTE(slaweq): NEUTRON_L3_CONF is used e.g. in neutron repository, | 
|  | 112 | # it was previously defined in the lib/neutron module which is now deleted. | 
|  | 113 | NEUTRON_L3_CONF=$Q_L3_CONF_FILE | 
|  | 114 | Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 115 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 116 | # Default name for Neutron database | 
|  | 117 | Q_DB_NAME=${Q_DB_NAME:-neutron} | 
|  | 118 | # Default Neutron Plugin | 
|  | 119 | Q_PLUGIN=${Q_PLUGIN:-ml2} | 
|  | 120 | # Default Neutron Port | 
|  | 121 | Q_PORT=${Q_PORT:-9696} | 
|  | 122 | # Default Neutron Internal Port when using TLS proxy | 
|  | 123 | Q_PORT_INT=${Q_PORT_INT:-19696} | 
|  | 124 | # Default Neutron Host | 
|  | 125 | Q_HOST=${Q_HOST:-$SERVICE_HOST} | 
|  | 126 | # Default protocol | 
|  | 127 | Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL} | 
|  | 128 | # Default listen address | 
|  | 129 | Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)} | 
|  | 130 | # Default admin username | 
|  | 131 | Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron} | 
|  | 132 | # Default auth strategy | 
|  | 133 | Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone} | 
|  | 134 | # RHEL's support for namespaces requires using veths with ovs | 
|  | 135 | Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False} | 
|  | 136 | Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True} | 
|  | 137 | Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON) | 
|  | 138 | # Meta data IP | 
|  | 139 | Q_META_DATA_IP=${Q_META_DATA_IP:-$(ipv6_unquote $SERVICE_HOST)} | 
|  | 140 | # Allow Overlapping IP among subnets | 
|  | 141 | Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True} | 
|  | 142 | Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True} | 
|  | 143 | Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True} | 
|  | 144 | VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True} | 
|  | 145 | VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300} | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 146 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 147 | # Allow to skip stopping of OVN services | 
|  | 148 | SKIP_STOP_OVN=${SKIP_STOP_OVN:-False} | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 149 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 150 | # The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES. | 
|  | 151 | # /etc/neutron is assumed by many of devstack plugins.  Do not change. | 
|  | 152 | _Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron | 
| Julia Kreger | 6e5b138 | 2019-01-09 17:00:45 -0800 | [diff] [blame] | 153 |  | 
| Slawek Kaplonski | 1a21ccb | 2022-07-08 21:57:45 +0200 | [diff] [blame] | 154 | # The name of the service in the endpoint URL | 
|  | 155 | NEUTRON_ENDPOINT_SERVICE_NAME=${NEUTRON_ENDPOINT_SERVICE_NAME-"networking"} | 
|  | 156 | if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" && -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then | 
|  | 157 | NEUTRON_ENDPOINT_SERVICE_NAME="networking" | 
|  | 158 | fi | 
|  | 159 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 160 | # List of config file names in addition to the main plugin config file | 
|  | 161 | # To add additional plugin config files, use ``neutron_server_config_add`` | 
|  | 162 | # utility function.  For example: | 
|  | 163 | # | 
|  | 164 | #    ``neutron_server_config_add file1`` | 
|  | 165 | # | 
|  | 166 | # These config files are relative to ``/etc/neutron``.  The above | 
|  | 167 | # example would specify ``--config-file /etc/neutron/file1`` for | 
|  | 168 | # neutron server. | 
|  | 169 | declare -a -g Q_PLUGIN_EXTRA_CONF_FILES | 
| Julia Kreger | 6e5b138 | 2019-01-09 17:00:45 -0800 | [diff] [blame] | 170 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 171 | # same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path. | 
|  | 172 | declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS | 
|  | 173 |  | 
|  | 174 |  | 
|  | 175 | Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf | 
|  | 176 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then | 
|  | 177 | Q_RR_COMMAND="sudo" | 
|  | 178 | else | 
|  | 179 | NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron) | 
|  | 180 | Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE" | 
|  | 181 | if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then | 
|  | 182 | Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE" | 
|  | 183 | fi | 
|  | 184 | fi | 
|  | 185 |  | 
|  | 186 |  | 
|  | 187 | # Distributed Virtual Router (DVR) configuration | 
|  | 188 | # Can be: | 
|  | 189 | # - ``legacy``   - No DVR functionality | 
|  | 190 | # - ``dvr_snat`` - Controller or single node DVR | 
|  | 191 | # - ``dvr``      - Compute node in multi-node DVR | 
|  | 192 | # - ``dvr_no_external`` - Compute node in multi-node DVR, no external network | 
|  | 193 | # | 
|  | 194 | Q_DVR_MODE=${Q_DVR_MODE:-legacy} | 
|  | 195 | if [[ "$Q_DVR_MODE" != "legacy" ]]; then | 
|  | 196 | Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population | 
|  | 197 | fi | 
|  | 198 |  | 
|  | 199 | # Provider Network Configurations | 
|  | 200 | # -------------------------------- | 
|  | 201 |  | 
|  | 202 | # The following variables control the Neutron ML2 plugins' allocation | 
|  | 203 | # of tenant networks and availability of provider networks. If these | 
|  | 204 | # are not configured in ``localrc``, tenant networks will be local to | 
|  | 205 | # the host (with no remote connectivity), and no physical resources | 
|  | 206 | # will be available for the allocation of provider networks. | 
|  | 207 |  | 
|  | 208 | # To disable tunnels (GRE or VXLAN) for tenant networks, | 
|  | 209 | # set to False in ``local.conf``. | 
|  | 210 | # GRE tunnels are only supported by the openvswitch. | 
|  | 211 | ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True} | 
|  | 212 |  | 
|  | 213 | # If using GRE, VXLAN or GENEVE tunnels for tenant networks, | 
|  | 214 | # specify the range of IDs from which tenant networks are | 
|  | 215 | # allocated. Can be overridden in ``localrc`` if necessary. | 
|  | 216 | TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000} | 
|  | 217 |  | 
|  | 218 | # To use VLANs for tenant networks, set to True in localrc. VLANs | 
|  | 219 | # are supported by the ML2 plugins, requiring additional configuration | 
|  | 220 | # described below. | 
|  | 221 | ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False} | 
|  | 222 |  | 
|  | 223 | # If using VLANs for tenant networks, set in ``localrc`` to specify | 
|  | 224 | # the range of VLAN VIDs from which tenant networks are | 
|  | 225 | # allocated. An external network switch must be configured to | 
|  | 226 | # trunk these VLANs between hosts for multi-host connectivity. | 
|  | 227 | # | 
|  | 228 | # Example: ``TENANT_VLAN_RANGE=1000:1999`` | 
|  | 229 | TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-} | 
|  | 230 |  | 
|  | 231 | # If using VLANs for tenant networks, or if using flat or VLAN | 
|  | 232 | # provider networks, set in ``localrc`` to the name of the physical | 
|  | 233 | # network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the | 
|  | 234 | # openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge | 
|  | 235 | # agent, as described below. | 
|  | 236 | # | 
|  | 237 | # Example: ``PHYSICAL_NETWORK=default`` | 
|  | 238 | PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public} | 
|  | 239 |  | 
|  | 240 | # With the openvswitch agent, if using VLANs for tenant networks, | 
|  | 241 | # or if using flat or VLAN provider networks, set in ``localrc`` to | 
|  | 242 | # the name of the OVS bridge to use for the physical network. The | 
|  | 243 | # bridge will be created if it does not already exist, but a | 
|  | 244 | # physical interface must be manually added to the bridge as a | 
|  | 245 | # port for external connectivity. | 
|  | 246 | # | 
|  | 247 | # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1`` | 
|  | 248 | OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex} | 
|  | 249 |  | 
|  | 250 | # With the linuxbridge agent, if using VLANs for tenant networks, | 
|  | 251 | # or if using flat or VLAN provider networks, set in ``localrc`` to | 
|  | 252 | # the name of the network interface to use for the physical | 
|  | 253 | # network. | 
|  | 254 | # | 
|  | 255 | # Example: ``LB_PHYSICAL_INTERFACE=eth1`` | 
|  | 256 | if [[ $Q_AGENT == "linuxbridge" && -z ${LB_PHYSICAL_INTERFACE} ]]; then | 
|  | 257 | default_route_dev=$( (ip route; ip -6 route) | grep ^default | head -n 1 | awk '{print $5}') | 
|  | 258 | die_if_not_set $LINENO default_route_dev "Failure retrieving default route device" | 
|  | 259 | LB_PHYSICAL_INTERFACE=$default_route_dev | 
|  | 260 | fi | 
|  | 261 |  | 
|  | 262 | # With the openvswitch plugin, set to True in ``localrc`` to enable | 
|  | 263 | # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False. | 
|  | 264 | # | 
|  | 265 | # Example: ``OVS_ENABLE_TUNNELING=True`` | 
|  | 266 | OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS} | 
|  | 267 |  | 
|  | 268 | # Use DHCP agent for providing metadata service in the case of | 
|  | 269 | # without L3 agent (No Route Agent), set to True in localrc. | 
|  | 270 | ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False} | 
|  | 271 |  | 
|  | 272 | # Add a static route as dhcp option, so the request to 169.254.169.254 | 
|  | 273 | # will be able to reach through a route(DHCP agent) | 
|  | 274 | # This option require ENABLE_ISOLATED_METADATA = True | 
|  | 275 | ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False} | 
|  | 276 | # Neutron plugin specific functions | 
|  | 277 | # --------------------------------- | 
|  | 278 |  | 
|  | 279 | # Please refer to ``lib/neutron_plugins/README.md`` for details. | 
|  | 280 | if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then | 
|  | 281 | source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN | 
|  | 282 | fi | 
|  | 283 |  | 
|  | 284 | # Agent metering service plugin functions | 
|  | 285 | # ------------------------------------------- | 
|  | 286 |  | 
|  | 287 | # Hardcoding for 1 service plugin for now | 
|  | 288 | source $TOP_DIR/lib/neutron_plugins/services/metering | 
|  | 289 |  | 
|  | 290 | # L3 Service functions | 
|  | 291 | source $TOP_DIR/lib/neutron_plugins/services/l3 | 
|  | 292 |  | 
|  | 293 | # Additional Neutron service plugins | 
|  | 294 | source $TOP_DIR/lib/neutron_plugins/services/placement | 
|  | 295 | source $TOP_DIR/lib/neutron_plugins/services/trunk | 
|  | 296 | source $TOP_DIR/lib/neutron_plugins/services/qos | 
| elajkat | a84b209 | 2021-11-17 11:52:56 +0100 | [diff] [blame] | 297 | source $TOP_DIR/lib/neutron_plugins/services/segments | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 298 |  | 
|  | 299 | # Use security group or not | 
|  | 300 | if has_neutron_plugin_security_group; then | 
|  | 301 | Q_USE_SECGROUP=${Q_USE_SECGROUP:-True} | 
|  | 302 | else | 
|  | 303 | Q_USE_SECGROUP=False | 
|  | 304 | fi | 
|  | 305 |  | 
| Harald Jensås | 16ac21f | 2023-08-31 15:06:52 +0200 | [diff] [blame] | 306 | # OVN_BRIDGE_MAPPINGS - ovn-bridge-mappings | 
|  | 307 | # NOTE(hjensas): Initialize after sourcing neutron_plugins/services/l3 | 
|  | 308 | # which initialize PUBLIC_BRIDGE. | 
|  | 309 | OVN_BRIDGE_MAPPINGS=${OVN_BRIDGE_MAPPINGS:-$PHYSICAL_NETWORK:$PUBLIC_BRIDGE} | 
|  | 310 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 311 | # Save trace setting | 
|  | 312 | _XTRACE_NEUTRON=$(set +o | grep xtrace) | 
|  | 313 | set +o xtrace | 
|  | 314 |  | 
| YAMAMOTO Takashi | eede9dd | 2016-07-15 10:27:53 +0900 | [diff] [blame] | 315 |  | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 316 | # Functions | 
|  | 317 | # --------- | 
|  | 318 |  | 
|  | 319 | # Test if any Neutron services are enabled | 
|  | 320 | # is_neutron_enabled | 
|  | 321 | function is_neutron_enabled { | 
| Clark Boylan | 902158b | 2017-05-30 14:11:09 -0700 | [diff] [blame] | 322 | [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1 | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 323 | [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0 | 
|  | 324 | return 1 | 
|  | 325 | } | 
|  | 326 |  | 
|  | 327 | # Test if any Neutron services are enabled | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 328 | # TODO(slaweq): this is not really needed now and we should remove it as soon | 
|  | 329 | # as it will not be called from any other Devstack plugins, like e.g. Neutron | 
|  | 330 | # plugin | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 331 | function is_neutron_legacy_enabled { | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 332 | return 0 | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 333 | } | 
|  | 334 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 335 | function _determine_config_server { | 
|  | 336 | if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then | 
|  | 337 | if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then | 
|  | 338 | deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated" | 
|  | 339 | else | 
|  | 340 | die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated" | 
|  | 341 | fi | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 342 | fi | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 343 | if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then | 
|  | 344 | deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated.  Use neutron_server_config_add instead." | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 345 | fi | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 346 | for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do | 
|  | 347 | _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file) | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 348 | done | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 349 |  | 
|  | 350 | local cfg_file | 
|  | 351 | local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE" | 
|  | 352 | for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do | 
|  | 353 | opts+=" --config-file $cfg_file" | 
|  | 354 | done | 
|  | 355 | echo "$opts" | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 356 | } | 
|  | 357 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 358 | function _determine_config_l3 { | 
|  | 359 | local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE" | 
|  | 360 | echo "$opts" | 
| Ihar Hrachyshka | e65ab4a | 2017-02-24 17:47:55 +0000 | [diff] [blame] | 361 | } | 
|  | 362 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 363 | # For services and agents that require it, dynamically construct a list of | 
|  | 364 | # --config-file arguments that are passed to the binary. | 
|  | 365 | function determine_config_files { | 
|  | 366 | local opts="" | 
|  | 367 | case "$1" in | 
|  | 368 | "neutron-server") opts="$(_determine_config_server)" ;; | 
|  | 369 | "neutron-l3-agent") opts="$(_determine_config_l3)" ;; | 
|  | 370 | esac | 
|  | 371 | if [ -z "$opts" ] ; then | 
|  | 372 | die $LINENO "Could not determine config files for $1." | 
| YAMAMOTO Takashi | 1df17c9 | 2017-05-01 17:00:42 +0900 | [diff] [blame] | 373 | fi | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 374 | echo "$opts" | 
|  | 375 | } | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 376 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 377 | # configure_neutron() | 
|  | 378 | # Set common config for all neutron server and agents. | 
|  | 379 | function configure_neutron { | 
|  | 380 | _configure_neutron_common | 
| Sean M. Collins | 5394cc1 | 2016-05-11 15:03:38 -0400 | [diff] [blame] | 381 | iniset_rpc_backend neutron $NEUTRON_CONF | 
|  | 382 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 383 | if is_service_enabled q-metering neutron-metering; then | 
|  | 384 | _configure_neutron_metering | 
|  | 385 | fi | 
|  | 386 | if is_service_enabled q-agt neutron-agent; then | 
|  | 387 | _configure_neutron_plugin_agent | 
|  | 388 | fi | 
|  | 389 | if is_service_enabled q-dhcp neutron-dhcp; then | 
|  | 390 | _configure_neutron_dhcp_agent | 
|  | 391 | fi | 
|  | 392 | if is_service_enabled q-l3 neutron-l3; then | 
|  | 393 | _configure_neutron_l3_agent | 
|  | 394 | fi | 
|  | 395 | if is_service_enabled q-meta neutron-metadata-agent; then | 
|  | 396 | _configure_neutron_metadata_agent | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 397 | fi | 
|  | 398 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 399 | if [[ "$Q_DVR_MODE" != "legacy" ]]; then | 
|  | 400 | _configure_dvr | 
|  | 401 | fi | 
|  | 402 | if is_service_enabled ceilometer; then | 
|  | 403 | _configure_neutron_ceilometer_notifications | 
|  | 404 | fi | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 405 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 406 | if [[ $Q_AGENT == "ovn" ]]; then | 
|  | 407 | configure_ovn | 
|  | 408 | configure_ovn_plugin | 
|  | 409 | fi | 
| Brian Haley | 9aaa529 | 2017-09-20 14:23:05 -0400 | [diff] [blame] | 410 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 411 | # Configure Neutron's advanced services | 
|  | 412 | if is_service_enabled q-placement neutron-placement; then | 
|  | 413 | configure_placement_extension | 
|  | 414 | fi | 
|  | 415 | if is_service_enabled q-trunk neutron-trunk; then | 
|  | 416 | configure_trunk_extension | 
|  | 417 | fi | 
|  | 418 | if is_service_enabled q-qos neutron-qos; then | 
|  | 419 | configure_qos | 
|  | 420 | if is_service_enabled q-l3 neutron-l3; then | 
|  | 421 | configure_l3_agent_extension_fip_qos | 
|  | 422 | configure_l3_agent_extension_gateway_ip_qos | 
| Denis Buliga | 0bf75a4 | 2017-02-06 16:56:46 +0200 | [diff] [blame] | 423 | fi | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 424 | fi | 
| elajkat | a84b209 | 2021-11-17 11:52:56 +0100 | [diff] [blame] | 425 | if is_service_enabled neutron-segments; then | 
|  | 426 | configure_placement_neutron | 
|  | 427 | configure_segments_extension | 
|  | 428 | fi | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 429 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 430 | # Finally configure Neutron server and core plugin | 
|  | 431 | if is_service_enabled q-agt neutron-agent q-svc neutron-api; then | 
|  | 432 | _configure_neutron_service | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 433 | fi | 
|  | 434 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 435 | iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS" | 
|  | 436 | # devstack is not a tool for running uber scale OpenStack | 
|  | 437 | # clouds, therefore running without a dedicated RPC worker | 
|  | 438 | # for state reports is more than adequate. | 
|  | 439 | iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0 | 
| Ihar Hrachyshka | e391593 | 2017-02-24 06:24:47 +0000 | [diff] [blame] | 440 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 441 | if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then | 
|  | 442 | write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api" "/networking" | 
| Sean M. Collins | 8063fee | 2016-05-24 11:27:36 -0700 | [diff] [blame] | 443 | fi | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 444 | } | 
|  | 445 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 446 | function configure_neutron_nova { | 
|  | 447 | create_nova_conf_neutron $NOVA_CONF | 
|  | 448 | if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then | 
|  | 449 | for i in $(seq 1 $NOVA_NUM_CELLS); do | 
|  | 450 | local conf | 
|  | 451 | conf=$(conductor_conf $i) | 
|  | 452 | create_nova_conf_neutron $conf | 
|  | 453 | done | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 454 | fi | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 455 | } | 
|  | 456 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 457 | function create_nova_conf_neutron { | 
| Lucas Alvares Gomes | e638593 | 2018-06-28 11:00:28 +0100 | [diff] [blame] | 458 | local conf=${1:-$NOVA_CONF} | 
| Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 459 | iniset $conf neutron auth_type "password" | 
|  | 460 | iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI" | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 461 | iniset $conf neutron username "$Q_ADMIN_USERNAME" | 
| Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 462 | iniset $conf neutron password "$SERVICE_PASSWORD" | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 463 | iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME" | 
|  | 464 | iniset $conf neutron project_name "$SERVICE_PROJECT_NAME" | 
|  | 465 | iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME" | 
|  | 466 | iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY" | 
| Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 467 | iniset $conf neutron region_name "$REGION_NAME" | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 468 |  | 
| Gary Kotton | 88f8558 | 2016-08-14 06:55:42 -0700 | [diff] [blame] | 469 | # optionally set options in nova_conf | 
| Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 470 | neutron_plugin_create_nova_conf $conf | 
| Gary Kotton | 88f8558 | 2016-08-14 06:55:42 -0700 | [diff] [blame] | 471 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 472 | if is_service_enabled q-meta neutron-metadata-agent; then | 
| Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 473 | iniset $conf neutron service_metadata_proxy "True" | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 474 | fi | 
|  | 475 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 476 | iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL" | 
|  | 477 | iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT" | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 478 | } | 
|  | 479 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 480 | # create_neutron_accounts() - Set up common required neutron accounts | 
|  | 481 |  | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 482 | # Tenant               User       Roles | 
|  | 483 | # ------------------------------------------------------------------ | 
|  | 484 | # service              neutron    admin        # if enabled | 
|  | 485 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 486 | # Migrated from keystone_data.sh | 
|  | 487 | function create_neutron_accounts { | 
| Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 488 | local neutron_url | 
| Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 489 | if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 490 | neutron_url=$Q_PROTOCOL://$SERVICE_HOST/ | 
| Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 491 | else | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 492 | neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/ | 
| Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 493 | fi | 
| Slawek Kaplonski | 1a21ccb | 2022-07-08 21:57:45 +0200 | [diff] [blame] | 494 | if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then | 
|  | 495 | neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME | 
|  | 496 | fi | 
| Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 497 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 498 | if is_service_enabled q-svc neutron-api; then | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 499 |  | 
|  | 500 | create_service_user "neutron" | 
|  | 501 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 502 | get_or_create_service "neutron" "network" "Neutron Service" | 
|  | 503 | get_or_create_endpoint \ | 
|  | 504 | "network" \ | 
| Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 505 | "$REGION_NAME" "$neutron_url" | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 506 | fi | 
|  | 507 | } | 
|  | 508 |  | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 509 | # init_neutron() - Initialize databases, etc. | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 510 | function init_neutron { | 
|  | 511 | recreate_database $Q_DB_NAME | 
| Clark Boylan | 633dbc3 | 2017-06-14 12:09:21 -0700 | [diff] [blame] | 512 | time_start "dbsync" | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 513 | # Run Neutron db migrations | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 514 | $NEUTRON_BIN_DIR/neutron-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head | 
| Clark Boylan | 633dbc3 | 2017-06-14 12:09:21 -0700 | [diff] [blame] | 515 | time_stop "dbsync" | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 516 | } | 
|  | 517 |  | 
|  | 518 | # install_neutron() - Collect source and prepare | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 519 | function install_neutron { | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 520 | # Install neutron-lib from git so we make sure we're testing | 
|  | 521 | # the latest code. | 
|  | 522 | if use_library_from_git "neutron-lib"; then | 
|  | 523 | git_clone_by_name "neutron-lib" | 
|  | 524 | setup_dev_lib "neutron-lib" | 
|  | 525 | fi | 
|  | 526 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 527 | git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH | 
|  | 528 | setup_develop $NEUTRON_DIR | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 529 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 530 | if [[ $Q_AGENT == "ovn" ]]; then | 
|  | 531 | install_ovn | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 532 | fi | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 533 | } | 
|  | 534 |  | 
|  | 535 | # install_neutronclient() - Collect source and prepare | 
|  | 536 | function install_neutronclient { | 
|  | 537 | if use_library_from_git "python-neutronclient"; then | 
|  | 538 | git_clone_by_name "python-neutronclient" | 
|  | 539 | setup_dev_lib "python-neutronclient" | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 540 | fi | 
|  | 541 | } | 
|  | 542 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 543 | # install_neutron_agent_packages() - Collect source and prepare | 
|  | 544 | function install_neutron_agent_packages { | 
|  | 545 | # radvd doesn't come with the OS. Install it if the l3 service is enabled. | 
|  | 546 | if is_service_enabled q-l3 neutron-l3; then | 
|  | 547 | install_package radvd | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 548 | fi | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 549 | # install packages that are specific to plugin agent(s) | 
|  | 550 | if is_service_enabled q-agt neutron-agent q-dhcp neutron-dhcp q-l3 neutron-l3; then | 
|  | 551 | neutron_plugin_install_agent_packages | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 552 | fi | 
|  | 553 | } | 
|  | 554 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 555 | # Finish neutron configuration | 
|  | 556 | function configure_neutron_after_post_config { | 
|  | 557 | if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then | 
|  | 558 | iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 559 | fi | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 560 | configure_rbac_policies | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 561 | } | 
|  | 562 |  | 
| Slawek Kaplonski | 24b65ad | 2021-06-22 15:31:46 +0200 | [diff] [blame] | 563 | # configure_rbac_policies() - Configure Neutron to enforce new RBAC | 
|  | 564 | # policies and scopes if NEUTRON_ENFORCE_SCOPE == True | 
|  | 565 | function configure_rbac_policies { | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 566 | if [[ "$NEUTRON_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == True ]]; then | 
| Slawek Kaplonski | 24b65ad | 2021-06-22 15:31:46 +0200 | [diff] [blame] | 567 | iniset $NEUTRON_CONF oslo_policy enforce_new_defaults True | 
|  | 568 | iniset $NEUTRON_CONF oslo_policy enforce_scope True | 
|  | 569 | else | 
|  | 570 | iniset $NEUTRON_CONF oslo_policy enforce_new_defaults False | 
|  | 571 | iniset $NEUTRON_CONF oslo_policy enforce_scope False | 
|  | 572 | fi | 
|  | 573 | } | 
|  | 574 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 575 | # Start running OVN processes | 
|  | 576 | function start_ovn_services { | 
|  | 577 | if [[ $Q_AGENT == "ovn" ]]; then | 
| Lucas Alvares Gomes | a389128 | 2023-07-18 16:31:28 +0100 | [diff] [blame] | 578 | if [ "$VIRT_DRIVER" != 'ironic' ]; then | 
|  | 579 | # NOTE(TheJulia): Ironic's devstack plugin needs to perform | 
|  | 580 | # additional networking configuration to setup a working test | 
|  | 581 | # environment with test virtual machines to emulate baremetal, | 
|  | 582 | # which requires OVN to be up and running earlier to complete | 
|  | 583 | # that base configuration. | 
|  | 584 | init_ovn | 
|  | 585 | start_ovn | 
|  | 586 | fi | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 587 | if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then | 
|  | 588 | if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then | 
|  | 589 | echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored " | 
|  | 590 | echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False" | 
|  | 591 | else | 
|  | 592 | create_public_bridge | 
|  | 593 | fi | 
| Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 594 | fi | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 595 | fi | 
|  | 596 | } | 
|  | 597 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 598 | # Start running processes | 
|  | 599 | function start_neutron_service_and_check { | 
|  | 600 | local service_port=$Q_PORT | 
|  | 601 | local service_protocol=$Q_PROTOCOL | 
|  | 602 | local cfg_file_options | 
|  | 603 | local neutron_url | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 604 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 605 | cfg_file_options="$(determine_config_files neutron-server)" | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 606 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 607 | if is_service_enabled tls-proxy; then | 
|  | 608 | service_port=$Q_PORT_INT | 
|  | 609 | service_protocol="http" | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 610 | fi | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 611 | # Start the Neutron service | 
|  | 612 | if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then | 
|  | 613 | enable_service neutron-api | 
|  | 614 | run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF" | 
|  | 615 | neutron_url=$Q_PROTOCOL://$Q_HOST/ | 
|  | 616 | enable_service neutron-rpc-server | 
|  | 617 | run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options" | 
|  | 618 | else | 
|  | 619 | run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options" | 
|  | 620 | neutron_url=$service_protocol://$Q_HOST:$service_port/ | 
|  | 621 | # Start proxy if enabled | 
|  | 622 | if is_service_enabled tls-proxy; then | 
|  | 623 | start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT | 
|  | 624 | fi | 
|  | 625 | fi | 
|  | 626 | if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then | 
|  | 627 | neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME | 
|  | 628 | fi | 
|  | 629 | echo "Waiting for Neutron to start..." | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 630 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 631 | local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url" | 
|  | 632 | test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT | 
| YAMAMOTO Takashi | eede9dd | 2016-07-15 10:27:53 +0900 | [diff] [blame] | 633 | } | 
|  | 634 |  | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 635 | function start_neutron { | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 636 | start_l2_agent "$@" | 
|  | 637 | start_other_agents "$@" | 
|  | 638 | } | 
|  | 639 |  | 
|  | 640 | # Control of the l2 agent is separated out to make it easier to test partial | 
|  | 641 | # upgrades (everything upgraded except the L2 agent) | 
|  | 642 | function start_l2_agent { | 
|  | 643 | run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE" | 
|  | 644 |  | 
|  | 645 | if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then | 
|  | 646 | sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE | 
|  | 647 | sudo ip link set $OVS_PHYSICAL_BRIDGE up | 
|  | 648 | sudo ip link set br-int up | 
|  | 649 | sudo ip link set $PUBLIC_INTERFACE up | 
|  | 650 | if is_ironic_hardware; then | 
|  | 651 | for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do | 
|  | 652 | sudo ip addr del $IP dev $PUBLIC_INTERFACE | 
|  | 653 | sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE | 
|  | 654 | done | 
|  | 655 | sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE | 
|  | 656 | fi | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 657 | fi | 
|  | 658 | } | 
|  | 659 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 660 | function start_other_agents { | 
|  | 661 | run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE" | 
|  | 662 |  | 
|  | 663 | run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)" | 
|  | 664 |  | 
|  | 665 | run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE" | 
|  | 666 | run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME" | 
|  | 667 | } | 
|  | 668 |  | 
|  | 669 | # Start running processes, including screen | 
|  | 670 | function start_neutron_agents { | 
|  | 671 | # NOTE(slaweq): it's now just a wrapper for start_neutron function | 
|  | 672 | start_neutron "$@" | 
|  | 673 | } | 
|  | 674 |  | 
|  | 675 | function stop_l2_agent { | 
|  | 676 | stop_process q-agt | 
|  | 677 | } | 
|  | 678 |  | 
|  | 679 | # stop_other() - Stop running processes | 
|  | 680 | function stop_other { | 
|  | 681 | if is_service_enabled q-dhcp neutron-dhcp; then | 
|  | 682 | stop_process q-dhcp | 
|  | 683 | pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }') | 
|  | 684 | [ ! -z "$pid" ] && sudo kill -9 $pid | 
|  | 685 | fi | 
|  | 686 |  | 
|  | 687 | if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then | 
|  | 688 | stop_process neutron-rpc-server | 
|  | 689 | stop_process neutron-api | 
|  | 690 | else | 
|  | 691 | stop_process q-svc | 
|  | 692 | fi | 
|  | 693 |  | 
|  | 694 | if is_service_enabled q-l3 neutron-l3; then | 
|  | 695 | sudo pkill -f "radvd -C $DATA_DIR/neutron/ra" | 
|  | 696 | stop_process q-l3 | 
|  | 697 | fi | 
|  | 698 |  | 
|  | 699 | if is_service_enabled q-meta neutron-metadata-agent; then | 
|  | 700 | stop_process q-meta | 
|  | 701 | fi | 
|  | 702 |  | 
|  | 703 | if is_service_enabled q-metering neutron-metering; then | 
|  | 704 | neutron_metering_stop | 
|  | 705 | fi | 
|  | 706 |  | 
|  | 707 | if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then | 
| Bence Romsics | 71c3c40 | 2022-12-21 13:50:54 +0100 | [diff] [blame] | 708 | # pkill takes care not to kill itself, but it may kill its parent | 
|  | 709 | # sudo unless we use the "ps | grep [f]oo" trick | 
|  | 710 | sudo pkill -9 -f "$NEUTRON_ROOTWRAP-[d]aemon" || : | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 711 | fi | 
|  | 712 | } | 
|  | 713 |  | 
|  | 714 | # stop_neutron() - Stop running processes (non-screen) | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 715 | function stop_neutron { | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 716 | stop_other | 
|  | 717 | stop_l2_agent | 
|  | 718 |  | 
|  | 719 | if [[ $Q_AGENT == "ovn" && $SKIP_STOP_OVN != "True" ]]; then | 
|  | 720 | stop_ovn | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 721 | fi | 
|  | 722 | } | 
|  | 723 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 724 | # _move_neutron_addresses_route() - Move the primary IP to the OVS bridge | 
|  | 725 | # on startup, or back to the public interface on cleanup. If no IP is | 
|  | 726 | # configured on the interface, just add it as a port to the OVS bridge. | 
|  | 727 | function _move_neutron_addresses_route { | 
|  | 728 | local from_intf=$1 | 
|  | 729 | local to_intf=$2 | 
|  | 730 | local add_ovs_port=$3 | 
|  | 731 | local del_ovs_port=$4 | 
|  | 732 | local af=$5 | 
|  | 733 |  | 
|  | 734 | if [[ -n "$from_intf" && -n "$to_intf" ]]; then | 
|  | 735 | # Remove the primary IP address from $from_intf and add it to $to_intf, | 
|  | 736 | # along with the default route, if it exists.  Also, when called | 
|  | 737 | # on configure we will also add $from_intf as a port on $to_intf, | 
|  | 738 | # assuming it is an OVS bridge. | 
|  | 739 |  | 
|  | 740 | local IP_REPLACE="" | 
|  | 741 | local IP_DEL="" | 
|  | 742 | local IP_UP="" | 
|  | 743 | local DEFAULT_ROUTE_GW | 
|  | 744 | DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }") | 
|  | 745 | local ADD_OVS_PORT="" | 
|  | 746 | local DEL_OVS_PORT="" | 
|  | 747 | local ARP_CMD="" | 
|  | 748 |  | 
|  | 749 | IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }') | 
|  | 750 |  | 
|  | 751 | if [ "$DEFAULT_ROUTE_GW" != "" ]; then | 
|  | 752 | ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf" | 
|  | 753 | fi | 
|  | 754 |  | 
|  | 755 | if [[ "$add_ovs_port" == "True" ]]; then | 
|  | 756 | ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf" | 
|  | 757 | fi | 
|  | 758 |  | 
|  | 759 | if [[ "$del_ovs_port" == "True" ]]; then | 
|  | 760 | DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf" | 
|  | 761 | fi | 
|  | 762 |  | 
|  | 763 | if [[ "$IP_BRD" != "" ]]; then | 
|  | 764 | IP_DEL="sudo ip addr del $IP_BRD dev $from_intf" | 
|  | 765 | IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf" | 
|  | 766 | IP_UP="sudo ip link set $to_intf up" | 
|  | 767 | if [[ "$af" == "inet" ]]; then | 
|  | 768 | IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1) | 
|  | 769 | ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP " | 
|  | 770 | fi | 
|  | 771 | fi | 
|  | 772 |  | 
|  | 773 | # The add/del OVS port calls have to happen either before or | 
|  | 774 | # after the address is moved in order to not leave it orphaned. | 
|  | 775 | $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD | 
|  | 776 | fi | 
|  | 777 | } | 
|  | 778 |  | 
|  | 779 | # _configure_public_network_connectivity() - Configures connectivity to the | 
|  | 780 | # external network using $PUBLIC_INTERFACE or NAT on the single interface | 
|  | 781 | # machines | 
|  | 782 | function _configure_public_network_connectivity { | 
|  | 783 | # If we've given a PUBLIC_INTERFACE to take over, then we assume | 
|  | 784 | # that we can own the whole thing, and privot it into the OVS | 
|  | 785 | # bridge. If we are not, we're probably on a single interface | 
|  | 786 | # machine, and we just setup NAT so that fixed guests can get out. | 
|  | 787 | if [[ -n "$PUBLIC_INTERFACE" ]]; then | 
|  | 788 | _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet" | 
|  | 789 |  | 
|  | 790 | if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then | 
|  | 791 | _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6" | 
|  | 792 | fi | 
| YAMAMOTO Takashi | c043b6f | 2017-02-23 22:30:08 -0500 | [diff] [blame] | 793 | else | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 794 | for d in $default_v4_route_devs; do | 
|  | 795 | sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE | 
|  | 796 | done | 
|  | 797 | fi | 
|  | 798 | } | 
|  | 799 |  | 
|  | 800 | # cleanup_neutron() - Remove residual data files, anything left over from previous | 
|  | 801 | # runs that a clean run would need to clean up | 
|  | 802 | function cleanup_neutron { | 
|  | 803 | if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then | 
|  | 804 | stop_process neutron-api | 
|  | 805 | stop_process neutron-rpc-server | 
|  | 806 | remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api" | 
|  | 807 | sudo rm -f $(apache_site_config_for neutron-api) | 
|  | 808 | fi | 
|  | 809 |  | 
|  | 810 | if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then | 
|  | 811 | _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet" | 
|  | 812 |  | 
|  | 813 | if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then | 
|  | 814 | # ip(8) wants the prefix length when deleting | 
|  | 815 | local v6_gateway | 
|  | 816 | v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }') | 
|  | 817 | sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE | 
|  | 818 | _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6" | 
|  | 819 | fi | 
|  | 820 |  | 
|  | 821 | if is_provider_network && is_ironic_hardware; then | 
|  | 822 | for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do | 
|  | 823 | sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE | 
|  | 824 | sudo ip addr add $IP dev $PUBLIC_INTERFACE | 
|  | 825 | done | 
|  | 826 | sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE | 
|  | 827 | fi | 
|  | 828 | fi | 
|  | 829 |  | 
|  | 830 | if is_neutron_ovs_base_plugin; then | 
|  | 831 | neutron_ovs_base_cleanup | 
|  | 832 | fi | 
|  | 833 |  | 
|  | 834 | if [[ $Q_AGENT == "linuxbridge" ]]; then | 
|  | 835 | neutron_lb_cleanup | 
|  | 836 | fi | 
|  | 837 |  | 
|  | 838 | # delete all namespaces created by neutron | 
|  | 839 | for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do | 
|  | 840 | sudo ip netns delete ${ns} | 
|  | 841 | done | 
|  | 842 |  | 
|  | 843 | if [[ $Q_AGENT == "ovn" ]]; then | 
|  | 844 | cleanup_ovn | 
|  | 845 | fi | 
|  | 846 | } | 
|  | 847 |  | 
|  | 848 |  | 
|  | 849 | function _create_neutron_conf_dir { | 
|  | 850 | # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find | 
|  | 851 | sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR | 
|  | 852 | } | 
|  | 853 |  | 
|  | 854 | # _configure_neutron_common() | 
|  | 855 | # Set common config for all neutron server and agents. | 
|  | 856 | # This MUST be called before other ``_configure_neutron_*`` functions. | 
|  | 857 | function _configure_neutron_common { | 
|  | 858 | _create_neutron_conf_dir | 
|  | 859 |  | 
|  | 860 | # Uses oslo config generator to generate core sample configuration files | 
|  | 861 | (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh) | 
|  | 862 |  | 
|  | 863 | cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF | 
|  | 864 |  | 
|  | 865 | Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json | 
|  | 866 |  | 
|  | 867 | # allow neutron user to administer neutron to match neutron account | 
|  | 868 | # NOTE(amotoki): This is required for nova works correctly with neutron. | 
|  | 869 | if [ -f $NEUTRON_DIR/etc/policy.json ]; then | 
|  | 870 | cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE | 
|  | 871 | sed -i 's/"context_is_admin":  "role:admin"/"context_is_admin":  "role:admin or user_name:neutron"/g' $Q_POLICY_FILE | 
|  | 872 | else | 
|  | 873 | echo '{"context_is_admin":  "role:admin or user_name:neutron"}' > $Q_POLICY_FILE | 
|  | 874 | fi | 
|  | 875 |  | 
|  | 876 | # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``. | 
|  | 877 | # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``. | 
|  | 878 | neutron_plugin_configure_common | 
|  | 879 |  | 
|  | 880 | if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then | 
|  | 881 | die $LINENO "Neutron plugin not set.. exiting" | 
|  | 882 | fi | 
|  | 883 |  | 
|  | 884 | # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR`` | 
|  | 885 | mkdir -p /$Q_PLUGIN_CONF_PATH | 
|  | 886 | Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME | 
|  | 887 | # NOTE(slaweq): NEUTRON_CORE_PLUGIN_CONF is used e.g. in neutron repository, | 
|  | 888 | # it was previously defined in the lib/neutron module which is now deleted. | 
|  | 889 | NEUTRON_CORE_PLUGIN_CONF=$Q_PLUGIN_CONF_FILE | 
|  | 890 | # NOTE(hichihara): Some neutron vendor plugins were already decomposed and | 
|  | 891 | # there is no config file in Neutron tree. They should prepare the file in each plugin. | 
|  | 892 | if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then | 
|  | 893 | cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE | 
|  | 894 | elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then | 
|  | 895 | cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE | 
|  | 896 | fi | 
|  | 897 |  | 
|  | 898 | iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME` | 
|  | 899 | iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron | 
|  | 900 | iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG | 
|  | 901 | iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS | 
|  | 902 | iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock | 
|  | 903 |  | 
|  | 904 | # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation | 
|  | 905 | iniset $NEUTRON_CONF nova region_name $REGION_NAME | 
|  | 906 |  | 
|  | 907 | if [ "$VIRT_DRIVER" = 'fake' ]; then | 
|  | 908 | # Disable arbitrary limits | 
|  | 909 | iniset $NEUTRON_CONF quotas quota_network -1 | 
|  | 910 | iniset $NEUTRON_CONF quotas quota_subnet -1 | 
|  | 911 | iniset $NEUTRON_CONF quotas quota_port -1 | 
|  | 912 | iniset $NEUTRON_CONF quotas quota_security_group -1 | 
|  | 913 | iniset $NEUTRON_CONF quotas quota_security_group_rule -1 | 
|  | 914 | fi | 
|  | 915 |  | 
|  | 916 | # Format logging | 
|  | 917 | setup_logging $NEUTRON_CONF | 
|  | 918 |  | 
|  | 919 | if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then | 
|  | 920 | # Set the service port for a proxy to take the original | 
|  | 921 | iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT" | 
|  | 922 | iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True | 
|  | 923 | fi | 
|  | 924 |  | 
|  | 925 | _neutron_setup_rootwrap | 
|  | 926 | } | 
|  | 927 |  | 
|  | 928 | function _configure_neutron_dhcp_agent { | 
|  | 929 |  | 
|  | 930 | cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE | 
|  | 931 |  | 
|  | 932 | iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL | 
|  | 933 | # make it so we have working DNS from guests | 
|  | 934 | iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True | 
|  | 935 | configure_root_helper_options $Q_DHCP_CONF_FILE | 
|  | 936 |  | 
|  | 937 | if ! is_service_enabled q-l3 neutron-l3; then | 
|  | 938 | if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then | 
|  | 939 | iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA | 
|  | 940 | iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK | 
|  | 941 | else | 
|  | 942 | if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then | 
|  | 943 | die "$LINENO" "Enable isolated metadata is a must for metadata network" | 
|  | 944 | fi | 
|  | 945 | fi | 
|  | 946 | fi | 
|  | 947 |  | 
|  | 948 | _neutron_setup_interface_driver $Q_DHCP_CONF_FILE | 
|  | 949 |  | 
|  | 950 | neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE | 
|  | 951 | } | 
|  | 952 |  | 
|  | 953 |  | 
|  | 954 | function _configure_neutron_metadata_agent { | 
|  | 955 | cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE | 
|  | 956 |  | 
|  | 957 | iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL | 
|  | 958 | iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP | 
|  | 959 | iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS | 
|  | 960 | configure_root_helper_options $Q_META_CONF_FILE | 
|  | 961 | } | 
|  | 962 |  | 
|  | 963 | function _configure_neutron_ceilometer_notifications { | 
|  | 964 | iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2 | 
|  | 965 | } | 
|  | 966 |  | 
|  | 967 | function _configure_neutron_metering { | 
|  | 968 | neutron_agent_metering_configure_common | 
|  | 969 | neutron_agent_metering_configure_agent | 
|  | 970 | } | 
|  | 971 |  | 
|  | 972 | function _configure_dvr { | 
|  | 973 | iniset $NEUTRON_CONF DEFAULT router_distributed True | 
|  | 974 | iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE | 
|  | 975 | } | 
|  | 976 |  | 
|  | 977 |  | 
|  | 978 | # _configure_neutron_plugin_agent() - Set config files for neutron plugin agent | 
|  | 979 | # It is called when q-agt is enabled. | 
|  | 980 | function _configure_neutron_plugin_agent { | 
|  | 981 | # Specify the default root helper prior to agent configuration to | 
|  | 982 | # ensure that an agent's configuration can override the default | 
|  | 983 | configure_root_helper_options /$Q_PLUGIN_CONF_FILE | 
|  | 984 | iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL | 
|  | 985 |  | 
|  | 986 | # Configure agent for plugin | 
|  | 987 | neutron_plugin_configure_plugin_agent | 
|  | 988 | } | 
|  | 989 |  | 
|  | 990 | function _replace_api_paste_composite { | 
|  | 991 | local sep | 
|  | 992 | sep=$(echo -ne "\x01") | 
|  | 993 | # Replace it | 
|  | 994 | $sudo sed -i -e "s/\/\: neutronversions_composite/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/\: neutronversions_composite/" "$Q_API_PASTE_FILE" | 
|  | 995 | $sudo sed -i -e "s/\/healthcheck\: healthcheck/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/healthcheck\: healthcheck/" "$Q_API_PASTE_FILE" | 
|  | 996 | $sudo sed -i -e "s/\/v2.0\: neutronapi_v2_0/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/v2.0\: neutronapi_v2_0/" "$Q_API_PASTE_FILE" | 
|  | 997 | } | 
|  | 998 |  | 
|  | 999 | # _configure_neutron_service() - Set config files for neutron service | 
|  | 1000 | # It is called when q-svc is enabled. | 
|  | 1001 | function _configure_neutron_service { | 
|  | 1002 | Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini | 
|  | 1003 | cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE | 
|  | 1004 |  | 
|  | 1005 | if [[ -n "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then | 
|  | 1006 | _replace_api_paste_composite | 
|  | 1007 | fi | 
|  | 1008 |  | 
|  | 1009 | # Update either configuration file with plugin | 
|  | 1010 | iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS | 
|  | 1011 |  | 
|  | 1012 | iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL | 
|  | 1013 | iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE | 
|  | 1014 |  | 
|  | 1015 | iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY | 
|  | 1016 | configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME | 
|  | 1017 |  | 
|  | 1018 | # Configuration for neutron notifications to nova. | 
|  | 1019 | iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES | 
|  | 1020 | iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES | 
|  | 1021 |  | 
|  | 1022 | configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova | 
|  | 1023 |  | 
|  | 1024 | # Configuration for placement client | 
|  | 1025 | configure_keystone_authtoken_middleware $NEUTRON_CONF placement placement | 
|  | 1026 |  | 
|  | 1027 | # Configure plugin | 
|  | 1028 | neutron_plugin_configure_service | 
|  | 1029 | } | 
|  | 1030 |  | 
|  | 1031 | # Utility Functions | 
|  | 1032 | #------------------ | 
|  | 1033 |  | 
|  | 1034 | # neutron_service_plugin_class_add() - add service plugin class | 
|  | 1035 | function neutron_service_plugin_class_add { | 
|  | 1036 | local service_plugin_class=$1 | 
|  | 1037 | if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then | 
|  | 1038 | Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class | 
|  | 1039 | elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then | 
|  | 1040 | Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class" | 
|  | 1041 | fi | 
|  | 1042 | } | 
|  | 1043 |  | 
|  | 1044 | # neutron_ml2_extension_driver_add() - add ML2 extension driver | 
|  | 1045 | function neutron_ml2_extension_driver_add { | 
|  | 1046 | local extension=$1 | 
|  | 1047 | if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then | 
|  | 1048 | Q_ML2_PLUGIN_EXT_DRIVERS=$extension | 
|  | 1049 | elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then | 
|  | 1050 | Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension" | 
|  | 1051 | fi | 
|  | 1052 | } | 
|  | 1053 |  | 
|  | 1054 | # neutron_server_config_add() - add server config file | 
|  | 1055 | function neutron_server_config_add { | 
|  | 1056 | _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1) | 
|  | 1057 | } | 
|  | 1058 |  | 
|  | 1059 | # neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root). | 
|  | 1060 | function neutron_deploy_rootwrap_filters { | 
|  | 1061 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then | 
|  | 1062 | return | 
|  | 1063 | fi | 
|  | 1064 | local srcdir=$1 | 
|  | 1065 | sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D | 
|  | 1066 | sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/ | 
|  | 1067 | } | 
|  | 1068 |  | 
|  | 1069 | # _neutron_setup_rootwrap() - configure Neutron's rootwrap | 
|  | 1070 | function _neutron_setup_rootwrap { | 
|  | 1071 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then | 
|  | 1072 | return | 
|  | 1073 | fi | 
|  | 1074 | # Wipe any existing ``rootwrap.d`` files first | 
|  | 1075 | Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d | 
|  | 1076 | if [[ -d $Q_CONF_ROOTWRAP_D ]]; then | 
|  | 1077 | sudo rm -rf $Q_CONF_ROOTWRAP_D | 
|  | 1078 | fi | 
|  | 1079 |  | 
|  | 1080 | neutron_deploy_rootwrap_filters $NEUTRON_DIR | 
|  | 1081 |  | 
|  | 1082 | # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d`` | 
|  | 1083 | # location moved in newer versions, prefer new location | 
|  | 1084 | if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then | 
|  | 1085 | sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE | 
|  | 1086 | else | 
|  | 1087 | sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE | 
|  | 1088 | fi | 
|  | 1089 | sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE | 
| yatinkarel | ffc1b76 | 2023-08-28 10:52:26 +0530 | [diff] [blame] | 1090 | # Rely on $PATH set by devstack to determine what is safe to execute | 
|  | 1091 | # by rootwrap rather than use explicit whitelist of paths in | 
|  | 1092 | # rootwrap.conf | 
|  | 1093 | sudo sed -e 's/^exec_dirs=.*/#&/' -i $Q_RR_CONF_FILE | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 1094 |  | 
|  | 1095 | # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap | 
|  | 1096 | ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *" | 
|  | 1097 | ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE" | 
|  | 1098 |  | 
|  | 1099 | # Set up the rootwrap sudoers for neutron | 
|  | 1100 | TEMPFILE=`mktemp` | 
|  | 1101 | echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE | 
|  | 1102 | echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE | 
|  | 1103 | chmod 0440 $TEMPFILE | 
|  | 1104 | sudo chown root:root $TEMPFILE | 
|  | 1105 | sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap | 
|  | 1106 |  | 
|  | 1107 | # Update the root_helper | 
|  | 1108 | configure_root_helper_options $NEUTRON_CONF | 
|  | 1109 | } | 
|  | 1110 |  | 
|  | 1111 | function configure_root_helper_options { | 
|  | 1112 | local conffile=$1 | 
|  | 1113 | iniset $conffile agent root_helper "$Q_RR_COMMAND" | 
|  | 1114 | if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then | 
|  | 1115 | iniset $conffile agent root_helper_daemon "$Q_RR_DAEMON_COMMAND" | 
|  | 1116 | fi | 
|  | 1117 | } | 
|  | 1118 |  | 
|  | 1119 | function _neutron_setup_interface_driver { | 
|  | 1120 |  | 
|  | 1121 | # ovs_use_veth needs to be set before the plugin configuration | 
|  | 1122 | # occurs to allow plugins to override the setting. | 
|  | 1123 | iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH | 
|  | 1124 |  | 
|  | 1125 | neutron_plugin_setup_interface_driver $1 | 
|  | 1126 | } | 
|  | 1127 | # Functions for Neutron Exercises | 
|  | 1128 | #-------------------------------- | 
|  | 1129 |  | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 1130 | # ssh check | 
|  | 1131 | function _ssh_check_neutron { | 
|  | 1132 | local from_net=$1 | 
|  | 1133 | local key_file=$2 | 
|  | 1134 | local ip=$3 | 
|  | 1135 | local user=$4 | 
|  | 1136 | local timeout_sec=$5 | 
|  | 1137 | local probe_cmd = "" | 
|  | 1138 | probe_cmd=`_get_probe_cmd_prefix $from_net` | 
|  | 1139 | local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success" | 
|  | 1140 | test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec | 
|  | 1141 | } | 
|  | 1142 |  | 
|  | 1143 | function plugin_agent_add_l2_agent_extension { | 
|  | 1144 | local l2_agent_extension=$1 | 
|  | 1145 | if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then | 
|  | 1146 | L2_AGENT_EXTENSIONS=$l2_agent_extension | 
|  | 1147 | elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then | 
|  | 1148 | L2_AGENT_EXTENSIONS+=",$l2_agent_extension" | 
| YAMAMOTO Takashi | c043b6f | 2017-02-23 22:30:08 -0500 | [diff] [blame] | 1149 | fi | 
|  | 1150 | } | 
|  | 1151 |  | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 1152 | # Restore xtrace | 
| Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 1153 | $_XTRACE_NEUTRON | 
|  | 1154 |  | 
|  | 1155 | # Tell emacs to use shell-script-mode | 
|  | 1156 | ## Local variables: | 
|  | 1157 | ## mode: shell-script | 
|  | 1158 | ## End: |