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