| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1 | # lib/neutron | 
| Joe Gordon | 2394605 | 2014-01-15 21:42:32 +0000 | [diff] [blame] | 2 | # functions - functions specific to neutron | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 3 |  | 
|  | 4 | # Dependencies: | 
|  | 5 | # ``functions`` file | 
|  | 6 | # ``DEST`` must be defined | 
| Stephan Renatus | e578eff | 2013-11-19 13:31:04 +0100 | [diff] [blame] | 7 | # ``STACK_USER`` must be defined | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 8 |  | 
|  | 9 | # ``stack.sh`` calls the entry points in this order: | 
|  | 10 | # | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 11 | # - install_neutron | 
|  | 12 | # - install_neutronclient | 
|  | 13 | # - install_neutron_agent_packages | 
|  | 14 | # - install_neutron_third_party | 
|  | 15 | # - configure_neutron | 
|  | 16 | # - init_neutron | 
|  | 17 | # - configure_neutron_third_party | 
|  | 18 | # - init_neutron_third_party | 
|  | 19 | # - start_neutron_third_party | 
| Emilien Macchi | a677b7f | 2013-11-25 23:40:20 +0100 | [diff] [blame] | 20 | # - create_neutron_cache_dir | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 21 | # - create_nova_conf_neutron | 
|  | 22 | # - start_neutron_service_and_check | 
|  | 23 | # - create_neutron_initial_network | 
|  | 24 | # - setup_neutron_debug | 
|  | 25 | # - start_neutron_agents | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 26 | # | 
|  | 27 | # ``unstack.sh`` calls the entry points in this order: | 
|  | 28 | # | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 29 | # - stop_neutron | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 30 |  | 
|  | 31 | # Functions in lib/neutron are classified into the following categories: | 
|  | 32 | # | 
|  | 33 | # - entry points (called from stack.sh or unstack.sh) | 
|  | 34 | # - internal functions | 
|  | 35 | # - neutron exercises | 
|  | 36 | # - 3rd party programs | 
|  | 37 |  | 
|  | 38 |  | 
|  | 39 | # Neutron Networking | 
|  | 40 | # ------------------ | 
|  | 41 |  | 
|  | 42 | # Make sure that neutron is enabled in ``ENABLED_SERVICES``.  If you want | 
|  | 43 | # to run Neutron on this host, make sure that q-svc is also in | 
|  | 44 | # ``ENABLED_SERVICES``. | 
|  | 45 | # | 
|  | 46 | # If you're planning to use the Neutron openvswitch plugin, set | 
|  | 47 | # ``Q_PLUGIN`` to "openvswitch" and make sure the q-agt service is enabled | 
|  | 48 | # in ``ENABLED_SERVICES``.  If you're planning to use the Neutron | 
|  | 49 | # linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the | 
|  | 50 | # q-agt service is enabled in ``ENABLED_SERVICES``. | 
|  | 51 | # | 
|  | 52 | # See "Neutron Network Configuration" below for additional variables | 
|  | 53 | # that must be set in localrc for connectivity across hosts with | 
|  | 54 | # Neutron. | 
|  | 55 | # | 
|  | 56 | # With Neutron networking the NETWORK_MANAGER variable is ignored. | 
|  | 57 | # | 
|  | 58 | # To enable specific configuration options for either the Open vSwitch or | 
|  | 59 | # LinuxBridge plugin, please see the top level README file under the | 
|  | 60 | # Neutron section. | 
|  | 61 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 62 |  | 
|  | 63 | # Neutron Network Configuration | 
|  | 64 | # ----------------------------- | 
|  | 65 |  | 
|  | 66 | # Gateway and subnet defaults, in case they are not customized in localrc | 
|  | 67 | NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1} | 
| Salvatore Orlando | 90234ac | 2013-11-25 05:44:10 -0800 | [diff] [blame] | 68 | PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1} | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 69 | PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"} | 
|  | 70 | PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"} | 
|  | 71 |  | 
| Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 72 | if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then | 
|  | 73 | Q_PROTOCOL="https" | 
|  | 74 | fi | 
|  | 75 |  | 
|  | 76 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 77 | # Set up default directories | 
|  | 78 | NEUTRON_DIR=$DEST/neutron | 
|  | 79 | NEUTRONCLIENT_DIR=$DEST/python-neutronclient | 
|  | 80 | NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron} | 
|  | 81 |  | 
|  | 82 | # Support entry points installation of console scripts | 
|  | 83 | if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then | 
|  | 84 | NEUTRON_BIN_DIR=$NEUTRON_DIR/bin | 
| Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 85 | else | 
|  | 86 | NEUTRON_BIN_DIR=$(get_python_exec_prefix) | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 87 | fi | 
|  | 88 |  | 
|  | 89 | NEUTRON_CONF_DIR=/etc/neutron | 
|  | 90 | NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf | 
|  | 91 | export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"} | 
|  | 92 |  | 
| Adam Gandelman | 7614d21 | 2014-08-11 14:27:50 -0700 | [diff] [blame] | 93 | # Agent binaries.  Note, binary paths for other agents are set in per-service | 
|  | 94 | # scripts in lib/neutron_plugins/services/ | 
|  | 95 | AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent" | 
|  | 96 | AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"} | 
|  | 97 | AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent" | 
|  | 98 |  | 
|  | 99 | # Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and | 
|  | 100 | # loaded from per-plugin  scripts in lib/neutron_plugins/ | 
|  | 101 | Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini | 
|  | 102 | Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini | 
|  | 103 | Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini | 
|  | 104 | Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini | 
|  | 105 | Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini | 
|  | 106 |  | 
| Henry Gessau | 0fc1cc2 | 2014-07-06 22:54:34 -0400 | [diff] [blame] | 107 | # Default name for Neutron database | 
|  | 108 | Q_DB_NAME=${Q_DB_NAME:-neutron} | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 109 | # Default Neutron Plugin | 
| Kyle Mestery | 6d23500 | 2013-09-18 20:27:08 +0000 | [diff] [blame] | 110 | Q_PLUGIN=${Q_PLUGIN:-ml2} | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 111 | # Default Neutron Port | 
|  | 112 | Q_PORT=${Q_PORT:-9696} | 
| Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 113 | # Default Neutron Internal Port when using TLS proxy | 
|  | 114 | Q_PORT_INT=${Q_PORT_INT:-19696} | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 115 | # Default Neutron Host | 
|  | 116 | Q_HOST=${Q_HOST:-$SERVICE_HOST} | 
| Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 117 | # Default protocol | 
|  | 118 | Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL} | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 119 | # Default admin username | 
|  | 120 | Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron} | 
|  | 121 | # Default auth strategy | 
|  | 122 | Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone} | 
|  | 123 | # Use namespace or not | 
|  | 124 | Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True} | 
|  | 125 | # RHEL's support for namespaces requires using veths with ovs | 
|  | 126 | Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False} | 
|  | 127 | Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True} | 
|  | 128 | # Meta data IP | 
|  | 129 | Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST} | 
|  | 130 | # Allow Overlapping IP among subnets | 
|  | 131 | Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True} | 
|  | 132 | # Use neutron-debug command | 
|  | 133 | Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False} | 
|  | 134 | # The name of the default q-l3 router | 
|  | 135 | Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1} | 
| Aaron Rosen | 4540d00 | 2013-10-24 13:59:33 -0700 | [diff] [blame] | 136 | # nova vif driver that all plugins should use | 
|  | 137 | NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"} | 
| Terry Wilson | f06c443 | 2014-05-20 10:54:51 -0500 | [diff] [blame] | 138 | Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True} | 
|  | 139 | Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True} | 
| Aaron Rosen | cea32b1 | 2014-03-04 16:20:14 -0800 | [diff] [blame] | 140 | VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True} | 
|  | 141 | VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300} | 
| Aaron Rosen | 4540d00 | 2013-10-24 13:59:33 -0700 | [diff] [blame] | 142 |  | 
| Sean M. Collins | 5ec6f8f | 2014-05-14 17:01:03 -0400 | [diff] [blame] | 143 | ## Provider Network Information | 
|  | 144 | PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"} | 
|  | 145 |  | 
| YAMAMOTO Takashi | 6a633fd | 2014-07-23 12:02:18 +0900 | [diff] [blame] | 146 | # Use flat providernet for public network | 
|  | 147 | # | 
|  | 148 | # If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network | 
|  | 149 | # for external interface of neutron l3-agent.  In that case, | 
|  | 150 | # PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value | 
|  | 151 | # used for the network.  In case of openvswitch agent, you should | 
|  | 152 | # add the corresponding entry to your OVS_BRIDGE_MAPPINGS. | 
|  | 153 | # | 
|  | 154 | # eg. | 
|  | 155 | #    Q_USE_PROVIDERNET_FOR_PUBLIC=True | 
|  | 156 | #    PUBLIC_PHYSICAL_NETWORK=public | 
|  | 157 | #    OVS_BRIDGE_MAPPINGS=public:br-ex | 
|  | 158 | Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-False} | 
|  | 159 | PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public} | 
|  | 160 |  | 
| Tomoe Sugihara | afbc631 | 2013-11-14 20:02:47 +0000 | [diff] [blame] | 161 | # The next two variables are configured by plugin | 
|  | 162 | # e.g.  _configure_neutron_l3_agent or lib/neutron_plugins/* | 
|  | 163 | # | 
|  | 164 | # The plugin supports L3. | 
|  | 165 | Q_L3_ENABLED=${Q_L3_ENABLED:-False} | 
|  | 166 | # L3 routers exist per tenant | 
|  | 167 | Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False} | 
| Aaron Rosen | 4540d00 | 2013-10-24 13:59:33 -0700 | [diff] [blame] | 168 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 169 | # List of config file names in addition to the main plugin config file | 
|  | 170 | # See _configure_neutron_common() for details about setting it up | 
|  | 171 | declare -a Q_PLUGIN_EXTRA_CONF_FILES | 
|  | 172 |  | 
| Paul Michali | 746dcee | 2014-04-02 19:12:22 +0000 | [diff] [blame] | 173 | # List of (optional) config files for VPN device drivers to use with | 
|  | 174 | # the neutron-q-vpn agent | 
|  | 175 | declare -a Q_VPN_EXTRA_CONF_FILES | 
|  | 176 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 177 |  | 
| Dean Troyer | e2907b4 | 2014-02-26 17:35:37 -0600 | [diff] [blame] | 178 | Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf | 
|  | 179 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then | 
|  | 180 | Q_RR_COMMAND="sudo" | 
|  | 181 | else | 
|  | 182 | NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron) | 
|  | 183 | Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 184 | fi | 
|  | 185 |  | 
| Brian Haley | eea7621 | 2014-06-27 11:45:50 -0400 | [diff] [blame] | 186 |  | 
|  | 187 | # Distributed Virtual Router (DVR) configuration | 
|  | 188 | # Can be: | 
| Dean Troyer | 3324f19 | 2014-09-18 09:26:39 -0500 | [diff] [blame] | 189 | # - ``legacy``   - No DVR functionality | 
|  | 190 | # - ``dvr_snat`` - Controller or single node DVR | 
|  | 191 | # - ``dvr``      - Compute node in multi-node DVR | 
|  | 192 | # | 
| Brian Haley | eea7621 | 2014-06-27 11:45:50 -0400 | [diff] [blame] | 193 | Q_DVR_MODE=${Q_DVR_MODE:-legacy} | 
|  | 194 | if [[ "$Q_DVR_MODE" != "legacy" ]]; then | 
|  | 195 | Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population | 
|  | 196 | fi | 
|  | 197 |  | 
| Dean Troyer | e2907b4 | 2014-02-26 17:35:37 -0600 | [diff] [blame] | 198 | # Provider Network Configurations | 
|  | 199 | # -------------------------------- | 
|  | 200 |  | 
|  | 201 | # The following variables control the Neutron openvswitch and | 
|  | 202 | # linuxbridge plugins' allocation of tenant networks and | 
|  | 203 | # availability of provider networks. If these are not configured | 
|  | 204 | # in ``localrc``, tenant networks will be local to the host (with no | 
|  | 205 | # remote connectivity), and no physical resources will be | 
|  | 206 | # available for the allocation of provider networks. | 
|  | 207 |  | 
| Attila Fazekas | 8feaf6c | 2014-07-27 20:47:04 +0200 | [diff] [blame] | 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} | 
| Dean Troyer | e2907b4 | 2014-02-26 17:35:37 -0600 | [diff] [blame] | 212 |  | 
|  | 213 | # If using GRE tunnels for tenant networks, specify the range of | 
|  | 214 | # tunnel IDs from which tenant networks are allocated. Can be | 
|  | 215 | # overriden in ``localrc`` in necesssary. | 
| Anant Patil | 3827dc0 | 2014-07-03 21:38:16 +0530 | [diff] [blame] | 216 | TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000} | 
| Dean Troyer | e2907b4 | 2014-02-26 17:35:37 -0600 | [diff] [blame] | 217 |  | 
|  | 218 | # To use VLANs for tenant networks, set to True in localrc. VLANs | 
|  | 219 | # are supported by the openvswitch and linuxbridge plugins, each | 
|  | 220 | # requiring additional configuration 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:-} | 
|  | 239 |  | 
|  | 240 | # With the openvswitch plugin, 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:-} | 
|  | 249 |  | 
|  | 250 | # With the linuxbridge plugin, 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 | LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-} | 
|  | 257 |  | 
| Edgar Magana | 6f335b9 | 2014-07-10 15:42:44 -0700 | [diff] [blame] | 258 | # When Neutron tunnels are enabled it is needed to specify the | 
|  | 259 | # IP address of the end point in the local server. This IP is set | 
|  | 260 | # by default to the same IP address that the HOST IP. | 
|  | 261 | # This variable can be used to specify a different end point IP address | 
|  | 262 | # Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1`` | 
|  | 263 | TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP} | 
|  | 264 |  | 
| Dean Troyer | e2907b4 | 2014-02-26 17:35:37 -0600 | [diff] [blame] | 265 | # With the openvswitch plugin, set to True in ``localrc`` to enable | 
|  | 266 | # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False. | 
|  | 267 | # | 
|  | 268 | # Example: ``OVS_ENABLE_TUNNELING=True`` | 
|  | 269 | OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS} | 
|  | 270 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 271 | # Neutron plugin specific functions | 
|  | 272 | # --------------------------------- | 
|  | 273 |  | 
|  | 274 | # Please refer to ``lib/neutron_plugins/README.md`` for details. | 
|  | 275 | source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN | 
|  | 276 |  | 
|  | 277 | # Agent loadbalancer service plugin functions | 
|  | 278 | # ------------------------------------------- | 
|  | 279 |  | 
|  | 280 | # Hardcoding for 1 service plugin for now | 
|  | 281 | source $TOP_DIR/lib/neutron_plugins/services/loadbalancer | 
|  | 282 |  | 
| Emilien Macchi | 40546f7 | 2013-09-24 15:10:25 +0200 | [diff] [blame] | 283 | # Agent metering service plugin functions | 
|  | 284 | # ------------------------------------------- | 
|  | 285 |  | 
|  | 286 | # Hardcoding for 1 service plugin for now | 
|  | 287 | source $TOP_DIR/lib/neutron_plugins/services/metering | 
|  | 288 |  | 
| Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 289 | # VPN service plugin functions | 
|  | 290 | # ------------------------------------------- | 
|  | 291 | # Hardcoding for 1 service plugin for now | 
|  | 292 | source $TOP_DIR/lib/neutron_plugins/services/vpn | 
|  | 293 |  | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 294 | # Firewall Service Plugin functions | 
| Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 295 | # --------------------------------- | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 296 | source $TOP_DIR/lib/neutron_plugins/services/firewall | 
|  | 297 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 298 | # Use security group or not | 
|  | 299 | if has_neutron_plugin_security_group; then | 
|  | 300 | Q_USE_SECGROUP=${Q_USE_SECGROUP:-True} | 
|  | 301 | else | 
|  | 302 | Q_USE_SECGROUP=False | 
|  | 303 | fi | 
|  | 304 |  | 
| Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 305 | # Tell Tempest this project is present | 
|  | 306 | TEMPEST_SERVICES+=,neutron | 
|  | 307 |  | 
|  | 308 |  | 
| Dean Troyer | e2907b4 | 2014-02-26 17:35:37 -0600 | [diff] [blame] | 309 | # Save trace setting | 
|  | 310 | XTRACE=$(set +o | grep xtrace) | 
|  | 311 | set +o xtrace | 
|  | 312 |  | 
|  | 313 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 314 | # Functions | 
|  | 315 | # --------- | 
|  | 316 |  | 
| Adam Gandelman | 7614d21 | 2014-08-11 14:27:50 -0700 | [diff] [blame] | 317 | function _determine_config_server { | 
|  | 318 | local cfg_file | 
|  | 319 | local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE" | 
|  | 320 | for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do | 
|  | 321 | opts+=" --config-file /$cfg_file" | 
|  | 322 | done | 
|  | 323 | echo "$opts" | 
|  | 324 | } | 
|  | 325 |  | 
|  | 326 | function _determine_config_vpn { | 
|  | 327 | local cfg_file | 
|  | 328 | local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE" | 
|  | 329 | if is_service_enabled q-fwaas; then | 
|  | 330 | opts+=" --config-file $Q_FWAAS_CONF_FILE" | 
|  | 331 | fi | 
|  | 332 | for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do | 
|  | 333 | opts+=" --config-file $cfg_file" | 
|  | 334 | done | 
|  | 335 | echo "$opts" | 
|  | 336 |  | 
|  | 337 | } | 
|  | 338 |  | 
|  | 339 | function _determine_config_l3 { | 
|  | 340 | local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE" | 
|  | 341 | if is_service_enabled q-fwaas; then | 
|  | 342 | opts+=" --config-file $Q_FWAAS_CONF_FILE" | 
|  | 343 | fi | 
|  | 344 | echo "$opts" | 
|  | 345 | } | 
|  | 346 |  | 
|  | 347 | # For services and agents that require it, dynamically construct a list of | 
|  | 348 | # --config-file arguments that are passed to the binary. | 
|  | 349 | function determine_config_files { | 
|  | 350 | local opts="" | 
|  | 351 | case "$1" in | 
|  | 352 | "neutron-server") opts="$(_determine_config_server)" ;; | 
|  | 353 | "neutron-vpn-agent") opts="$(_determine_config_vpn)" ;; | 
|  | 354 | "neutron-l3-agent") opts="$(_determine_config_l3)" ;; | 
|  | 355 | esac | 
|  | 356 | if [ -z "$opts" ] ; then | 
|  | 357 | die $LINENO "Could not determine config files for $1." | 
|  | 358 | fi | 
|  | 359 | echo "$opts" | 
|  | 360 | } | 
|  | 361 |  | 
| Dean Troyer | e4fa721 | 2014-01-15 15:04:49 -0600 | [diff] [blame] | 362 | # Test if any Neutron services are enabled | 
|  | 363 | # is_neutron_enabled | 
|  | 364 | function is_neutron_enabled { | 
|  | 365 | [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0 | 
|  | 366 | return 1 | 
|  | 367 | } | 
|  | 368 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 369 | # configure_neutron() | 
|  | 370 | # Set common config for all neutron server and agents. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 371 | function configure_neutron { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 372 | _configure_neutron_common | 
|  | 373 | iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT | 
|  | 374 |  | 
|  | 375 | # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES | 
|  | 376 | if is_service_enabled q-lbaas; then | 
|  | 377 | _configure_neutron_lbaas | 
|  | 378 | fi | 
| Emilien Macchi | 40546f7 | 2013-09-24 15:10:25 +0200 | [diff] [blame] | 379 | if is_service_enabled q-metering; then | 
|  | 380 | _configure_neutron_metering | 
|  | 381 | fi | 
| Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 382 | if is_service_enabled q-vpn; then | 
|  | 383 | _configure_neutron_vpn | 
|  | 384 | fi | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 385 | if is_service_enabled q-fwaas; then | 
|  | 386 | _configure_neutron_fwaas | 
|  | 387 | fi | 
| Stephen Ma | 9b38eb2 | 2014-04-02 02:13:09 +0000 | [diff] [blame] | 388 | if is_service_enabled q-agt q-svc; then | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 389 | _configure_neutron_service | 
|  | 390 | fi | 
|  | 391 | if is_service_enabled q-agt; then | 
|  | 392 | _configure_neutron_plugin_agent | 
|  | 393 | fi | 
|  | 394 | if is_service_enabled q-dhcp; then | 
|  | 395 | _configure_neutron_dhcp_agent | 
|  | 396 | fi | 
|  | 397 | if is_service_enabled q-l3; then | 
|  | 398 | _configure_neutron_l3_agent | 
|  | 399 | fi | 
|  | 400 | if is_service_enabled q-meta; then | 
|  | 401 | _configure_neutron_metadata_agent | 
|  | 402 | fi | 
|  | 403 |  | 
| Brian Haley | eea7621 | 2014-06-27 11:45:50 -0400 | [diff] [blame] | 404 | if [[ "$Q_DVR_MODE" != "legacy" ]]; then | 
|  | 405 | _configure_dvr | 
|  | 406 | fi | 
| Dina Belova | 58adaa6 | 2014-07-11 18:18:12 +0400 | [diff] [blame] | 407 | if is_service_enabled ceilometer; then | 
|  | 408 | _configure_neutron_ceilometer_notifications | 
|  | 409 | fi | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 410 |  | 
|  | 411 | _configure_neutron_debug_command | 
|  | 412 | } | 
|  | 413 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 414 | function create_nova_conf_neutron { | 
| Yong Sheng Gong | 032e454 | 2013-08-25 10:21:10 +0800 | [diff] [blame] | 415 | iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API" | 
| Gary Kotton | 13d385e | 2014-06-17 23:24:53 -0700 | [diff] [blame] | 416 | iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME" | 
|  | 417 | iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD" | 
|  | 418 | iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0" | 
|  | 419 | iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY" | 
|  | 420 | iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME" | 
| Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 421 | iniset $NOVA_CONF neutron region_name "$REGION_NAME" | 
| Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 422 | iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 423 |  | 
|  | 424 | if [[ "$Q_USE_SECGROUP" == "True" ]]; then | 
|  | 425 | LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver | 
| Jeff Peeler | 1143f7e | 2013-10-31 16:21:52 -0400 | [diff] [blame] | 426 | iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER | 
| Yong Sheng Gong | 032e454 | 2013-08-25 10:21:10 +0800 | [diff] [blame] | 427 | iniset $NOVA_CONF DEFAULT security_group_api neutron | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 428 | fi | 
|  | 429 |  | 
|  | 430 | # set NOVA_VIF_DRIVER and optionally set options in nova_conf | 
|  | 431 | neutron_plugin_create_nova_conf | 
|  | 432 |  | 
| Gary Kotton | 51c681d | 2014-04-22 01:40:56 -0700 | [diff] [blame] | 433 | iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 434 | iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER" | 
|  | 435 | if is_service_enabled q-meta; then | 
| Gary Kotton | dd74550 | 2014-08-11 23:38:47 -0700 | [diff] [blame] | 436 | iniset $NOVA_CONF neutron service_metadata_proxy "True" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 437 | fi | 
| Aaron Rosen | cea32b1 | 2014-03-04 16:20:14 -0800 | [diff] [blame] | 438 |  | 
|  | 439 | iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL" | 
|  | 440 | iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 441 | } | 
|  | 442 |  | 
| Emilien Macchi | a677b7f | 2013-11-25 23:40:20 +0100 | [diff] [blame] | 443 | # create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 444 | function create_neutron_cache_dir { | 
| Emilien Macchi | a677b7f | 2013-11-25 23:40:20 +0100 | [diff] [blame] | 445 | # Create cache dir | 
|  | 446 | sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR | 
|  | 447 | sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR | 
|  | 448 | rm -f $NEUTRON_AUTH_CACHE_DIR/* | 
|  | 449 | } | 
|  | 450 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 451 | # create_neutron_accounts() - Set up common required neutron accounts | 
|  | 452 |  | 
|  | 453 | # Tenant               User       Roles | 
|  | 454 | # ------------------------------------------------------------------ | 
|  | 455 | # service              neutron    admin        # if enabled | 
|  | 456 |  | 
|  | 457 | # Migrated from keystone_data.sh | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 458 | function create_neutron_accounts { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 459 |  | 
| Dean Troyer | 188493d | 2014-07-25 15:54:11 -0500 | [diff] [blame] | 460 | local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") | 
| Kevin Benton | 08a5fcc | 2014-07-18 16:06:12 -0700 | [diff] [blame] | 461 | local service_role=$(openstack role list | awk "/ service / { print \$2 }") | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 462 |  | 
|  | 463 | if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then | 
| Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 464 |  | 
| Dean Troyer | 188493d | 2014-07-25 15:54:11 -0500 | [diff] [blame] | 465 | local neutron_user=$(get_or_create_user "neutron" \ | 
|  | 466 | "$SERVICE_PASSWORD" $service_tenant) | 
| Kevin Benton | 08a5fcc | 2014-07-18 16:06:12 -0700 | [diff] [blame] | 467 | get_or_add_user_role $service_role $neutron_user $service_tenant | 
| Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 468 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 469 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then | 
| Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 470 |  | 
| Dean Troyer | 188493d | 2014-07-25 15:54:11 -0500 | [diff] [blame] | 471 | local neutron_service=$(get_or_create_service "neutron" \ | 
| Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 472 | "network" "Neutron Service") | 
| Dean Troyer | 188493d | 2014-07-25 15:54:11 -0500 | [diff] [blame] | 473 | get_or_create_endpoint $neutron_service \ | 
| Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 474 | "$REGION_NAME" \ | 
| Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 475 | "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \ | 
|  | 476 | "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \ | 
|  | 477 | "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 478 | fi | 
|  | 479 | fi | 
|  | 480 | } | 
|  | 481 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 482 | function create_neutron_initial_network { | 
| Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 483 | TENANT_ID=$(openstack project list | grep " demo " | get_field 1) | 
| DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 484 | die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 485 |  | 
|  | 486 | # Create a small network | 
|  | 487 | # Since neutron command is executed in admin context at this point, | 
| Dirk Mueller | 25049cd | 2014-01-09 13:53:52 +0100 | [diff] [blame] | 488 | # ``--tenant-id`` needs to be specified. | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 489 | if is_baremetal; then | 
| sbauza | e2c4ee2 | 2013-08-29 17:29:46 +0200 | [diff] [blame] | 490 | if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then | 
|  | 491 | die $LINENO "Neutron settings for baremetal not set.. exiting" | 
|  | 492 | fi | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 493 | sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE | 
|  | 494 | for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do | 
|  | 495 | sudo ip addr del $IP dev $PUBLIC_INTERFACE | 
|  | 496 | sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE | 
|  | 497 | done | 
| Dirk Mueller | 25049cd | 2014-01-09 13:53:52 +0100 | [diff] [blame] | 498 | NET_ID=$(neutron net-create $PHYSICAL_NETWORK --tenant-id $TENANT_ID --provider:network_type flat --provider:physical_network "$PHYSICAL_NETWORK" | grep ' id ' | get_field 2) | 
| DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 499 | die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID" | 
| Dirk Mueller | 25049cd | 2014-01-09 13:53:52 +0100 | [diff] [blame] | 500 | SUBNET_ID=$(neutron subnet-create --tenant-id $TENANT_ID --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --gateway $NETWORK_GATEWAY --name $PRIVATE_SUBNET_NAME $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2) | 
| DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 501 | die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 502 | sudo ifconfig $OVS_PHYSICAL_BRIDGE up | 
| sbauza | e2c4ee2 | 2013-08-29 17:29:46 +0200 | [diff] [blame] | 503 | sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE | 
| Sean M. Collins | 5ec6f8f | 2014-05-14 17:01:03 -0400 | [diff] [blame] | 504 | elif is_provider_network; then | 
| Satoru Moriya | af9b251 | 2014-09-01 20:43:08 +0900 | [diff] [blame] | 505 | die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK" | 
| Sean M. Collins | 5ec6f8f | 2014-05-14 17:01:03 -0400 | [diff] [blame] | 506 | die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE" | 
| Satoru Moriya | af9b251 | 2014-09-01 20:43:08 +0900 | [diff] [blame] | 507 | NET_ID=$(neutron net-create $PHYSICAL_NETWORK --tenant_id $TENANT_ID --provider:network_type $PROVIDER_NETWORK_TYPE --provider:physical_network "$PHYSICAL_NETWORK" ${SEGMENTATION_ID:+--provider:segmentation_id $SEGMENTATION_ID} --shared | grep ' id ' | get_field 2) | 
| Sean M. Collins | 5ec6f8f | 2014-05-14 17:01:03 -0400 | [diff] [blame] | 508 | SUBNET_ID=$(neutron subnet-create --tenant_id $TENANT_ID --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --name $PROVIDER_SUBNET_NAME $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2) | 
| Sean M. Collins | e13fd60 | 2014-05-14 17:01:53 -0400 | [diff] [blame] | 509 | SUBNET_V6_ID=$(neutron subnet-create --tenant_id $TENANT_ID --ip_version 6 --ipv6-address-mode slaac --gateway $V6_NETWORK_GATEWAY --name $PROVIDER_SUBNET_NAME_V6 $NET_ID $FIXED_RANGE_V6 | grep 'id' | get_field 2) | 
| Sean M. Collins | 5ec6f8f | 2014-05-14 17:01:03 -0400 | [diff] [blame] | 510 | sudo ip link set $OVS_PHYSICAL_BRIDGE up | 
|  | 511 | sudo ip link set br-int up | 
|  | 512 | sudo ip link set $PUBLIC_INTERFACE up | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 513 | else | 
| Dirk Mueller | 25049cd | 2014-01-09 13:53:52 +0100 | [diff] [blame] | 514 | NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2) | 
| DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 515 | die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID" | 
| Dirk Mueller | 25049cd | 2014-01-09 13:53:52 +0100 | [diff] [blame] | 516 | SUBNET_ID=$(neutron subnet-create --tenant-id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY --name $PRIVATE_SUBNET_NAME $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2) | 
| DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 517 | die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 518 | fi | 
|  | 519 |  | 
|  | 520 | if [[ "$Q_L3_ENABLED" == "True" ]]; then | 
|  | 521 | # Create a router, and add the private subnet as one of its interfaces | 
|  | 522 | if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then | 
|  | 523 | # create a tenant-owned router. | 
| Dirk Mueller | 25049cd | 2014-01-09 13:53:52 +0100 | [diff] [blame] | 524 | ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2) | 
| DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 525 | die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 526 | else | 
|  | 527 | # Plugin only supports creating a single router, which should be admin owned. | 
|  | 528 | ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2) | 
| DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 529 | die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 530 | fi | 
|  | 531 | neutron router-interface-add $ROUTER_ID $SUBNET_ID | 
|  | 532 | # Create an external network, and a subnet. Configure the external network as router gw | 
| YAMAMOTO Takashi | 6a633fd | 2014-07-23 12:02:18 +0900 | [diff] [blame] | 533 | if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then | 
|  | 534 | EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True --provider:network_type=flat --provider:physical_network=${PUBLIC_PHYSICAL_NETWORK} | grep ' id ' | get_field 2) | 
|  | 535 | else | 
|  | 536 | EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2) | 
|  | 537 | fi | 
| DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 538 | die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 539 | EXT_GW_IP=$(neutron subnet-create --ip_version 4 ${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} --gateway $PUBLIC_NETWORK_GATEWAY --name $PUBLIC_SUBNET_NAME $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2) | 
| DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 540 | die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 541 | neutron router-gateway-set $ROUTER_ID $EXT_NET_ID | 
|  | 542 |  | 
|  | 543 | if is_service_enabled q-l3; then | 
|  | 544 | # logic is specific to using the l3-agent for l3 | 
|  | 545 | if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then | 
| YAMAMOTO Takashi | ea3dac9 | 2014-07-23 16:07:21 +0900 | [diff] [blame] | 546 | # Disable in-band as we are going to use local port | 
|  | 547 | # to communicate with VMs | 
|  | 548 | sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE other_config:disable-in-band=true | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 549 | CIDR_LEN=${FLOATING_RANGE#*/} | 
|  | 550 | sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE | 
|  | 551 | sudo ip link set $PUBLIC_BRIDGE up | 
|  | 552 | ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'` | 
| DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 553 | die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 554 | sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP | 
|  | 555 | fi | 
|  | 556 | if [[ "$Q_USE_NAMESPACE" == "False" ]]; then | 
|  | 557 | # Explicitly set router id in l3 agent configuration | 
|  | 558 | iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID | 
|  | 559 | fi | 
|  | 560 | fi | 
| Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 561 | fi | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 562 | } | 
|  | 563 |  | 
|  | 564 | # init_neutron() - Initialize databases, etc. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 565 | function init_neutron { | 
| Salvatore Orlando | dd64988 | 2013-08-05 08:56:17 -0700 | [diff] [blame] | 566 | recreate_database $Q_DB_NAME utf8 | 
|  | 567 | # Run Neutron db migrations | 
|  | 568 | $NEUTRON_BIN_DIR/neutron-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 569 | } | 
|  | 570 |  | 
|  | 571 | # install_neutron() - Collect source and prepare | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 572 | function install_neutron { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 573 | git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH | 
|  | 574 | setup_develop $NEUTRON_DIR | 
|  | 575 | } | 
|  | 576 |  | 
|  | 577 | # install_neutronclient() - Collect source and prepare | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 578 | function install_neutronclient { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 579 | git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH | 
|  | 580 | setup_develop $NEUTRONCLIENT_DIR | 
| Attila Fazekas | fac533e | 2013-08-14 16:04:01 +0200 | [diff] [blame] | 581 | sudo install -D -m 0644 -o $STACK_USER {$NEUTRONCLIENT_DIR/tools/,/etc/bash_completion.d/}neutron.bash_completion | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 582 | } | 
|  | 583 |  | 
|  | 584 | # install_neutron_agent_packages() - Collect source and prepare | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 585 | function install_neutron_agent_packages { | 
| Robert Li | 72b3e44 | 2014-07-17 15:04:52 -0400 | [diff] [blame] | 586 | # radvd doesn't come with the OS. Install it if the l3 service is enabled. | 
|  | 587 | if is_service_enabled q-l3; then | 
|  | 588 | install_package radvd | 
|  | 589 | fi | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 590 | # install packages that are specific to plugin agent(s) | 
|  | 591 | if is_service_enabled q-agt q-dhcp q-l3; then | 
|  | 592 | neutron_plugin_install_agent_packages | 
|  | 593 | fi | 
|  | 594 |  | 
|  | 595 | if is_service_enabled q-lbaas; then | 
| Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 596 | neutron_agent_lbaas_install_agent_packages | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 597 | fi | 
|  | 598 | } | 
|  | 599 |  | 
|  | 600 | # Start running processes, including screen | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 601 | function start_neutron_service_and_check { | 
| Adam Gandelman | 7614d21 | 2014-08-11 14:27:50 -0700 | [diff] [blame] | 602 | local cfg_file_options="$(determine_config_files neutron-server)" | 
| Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 603 | local service_port=$Q_PORT | 
|  | 604 | local service_protocol=$Q_PROTOCOL | 
|  | 605 | if is_service_enabled tls-proxy; then | 
|  | 606 | service_port=$Q_PORT_INT | 
|  | 607 | service_protocol="http" | 
|  | 608 | fi | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 609 | # Start the Neutron service | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 610 | run_process q-svc "python $NEUTRON_BIN_DIR/neutron-server $cfg_file_options" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 611 | echo "Waiting for Neutron to start..." | 
| Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 612 | if is_ssl_enabled_service "neutron"; then | 
|  | 613 | ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}" | 
|  | 614 | fi | 
|  | 615 | if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget ${ssl_ca} --no-proxy -q -O- $service_protocol://$Q_HOST:$service_port; do sleep 1; done"; then | 
| Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 616 | die $LINENO "Neutron did not start" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 617 | fi | 
| Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 618 | # Start proxy if enabled | 
|  | 619 | if is_service_enabled tls-proxy; then | 
|  | 620 | start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT & | 
|  | 621 | fi | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 622 | } | 
|  | 623 |  | 
|  | 624 | # Start running processes, including screen | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 625 | function start_neutron_agents { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 626 | # Start up the neutron agents if enabled | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 627 | run_process q-agt "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE" | 
|  | 628 | run_process q-dhcp "python $AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file=$Q_DHCP_CONF_FILE" | 
| Nachi Ueno | 584750f | 2013-07-15 18:22:21 -0700 | [diff] [blame] | 629 |  | 
| Sean M. Collins | 5ec6f8f | 2014-05-14 17:01:03 -0400 | [diff] [blame] | 630 | if is_provider_network; then | 
|  | 631 | sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE | 
|  | 632 | sudo ip link set $OVS_PHYSICAL_BRIDGE up | 
|  | 633 | sudo ip link set br-int up | 
|  | 634 | sudo ip link set $PUBLIC_INTERFACE up | 
|  | 635 | fi | 
|  | 636 |  | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 637 | if is_service_enabled q-vpn; then | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 638 | run_process q-vpn "$AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)" | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 639 | else | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 640 | run_process q-l3 "python $AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)" | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 641 | fi | 
|  | 642 |  | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 643 | run_process q-meta "python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 644 |  | 
|  | 645 | if [ "$VIRT_DRIVER" = 'xenserver' ]; then | 
|  | 646 | # For XenServer, start an agent for the domU openvswitch | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 647 | run_process q-domua "python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 648 | fi | 
|  | 649 |  | 
|  | 650 | if is_service_enabled q-lbaas; then | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 651 | run_process q-lbaas "python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME" | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 652 | fi | 
| Emilien Macchi | 40546f7 | 2013-09-24 15:10:25 +0200 | [diff] [blame] | 653 |  | 
|  | 654 | if is_service_enabled q-metering; then | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 655 | run_process q-metering "python $AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME" | 
| Emilien Macchi | 40546f7 | 2013-09-24 15:10:25 +0200 | [diff] [blame] | 656 | fi | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 657 | } | 
|  | 658 |  | 
|  | 659 | # stop_neutron() - Stop running processes (non-screen) | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 660 | function stop_neutron { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 661 | if is_service_enabled q-dhcp; then | 
|  | 662 | pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }') | 
|  | 663 | [ ! -z "$pid" ] && sudo kill -9 $pid | 
|  | 664 | fi | 
|  | 665 | if is_service_enabled q-meta; then | 
| Jakub Libosvar | 1f76328 | 2014-01-28 23:01:38 +0100 | [diff] [blame] | 666 | sudo pkill -9 -f neutron-ns-metadata-proxy || : | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 667 | fi | 
| Akihiro Motoki | edddb1f | 2013-12-09 20:21:06 +0900 | [diff] [blame] | 668 |  | 
|  | 669 | if is_service_enabled q-lbaas; then | 
|  | 670 | neutron_lbaas_stop | 
|  | 671 | fi | 
|  | 672 | if is_service_enabled q-fwaas; then | 
|  | 673 | neutron_fwaas_stop | 
|  | 674 | fi | 
|  | 675 | if is_service_enabled q-vpn; then | 
|  | 676 | neutron_vpn_stop | 
|  | 677 | fi | 
|  | 678 | if is_service_enabled q-metering; then | 
|  | 679 | neutron_metering_stop | 
|  | 680 | fi | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 681 | } | 
|  | 682 |  | 
|  | 683 | # cleanup_neutron() - Remove residual data files, anything left over from previous | 
|  | 684 | # runs that a clean run would need to clean up | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 685 | function cleanup_neutron { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 686 | if is_neutron_ovs_base_plugin; then | 
|  | 687 | neutron_ovs_base_cleanup | 
|  | 688 | fi | 
|  | 689 |  | 
|  | 690 | # delete all namespaces created by neutron | 
| Brian Haley | eea7621 | 2014-06-27 11:45:50 -0400 | [diff] [blame] | 691 | for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|qlbaas|fip|snat)-[0-9a-f-]*'); do | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 692 | sudo ip netns delete ${ns} | 
|  | 693 | done | 
|  | 694 | } | 
|  | 695 |  | 
|  | 696 | # _configure_neutron_common() | 
|  | 697 | # Set common config for all neutron server and agents. | 
|  | 698 | # This MUST be called before other ``_configure_neutron_*`` functions. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 699 | function _configure_neutron_common { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 700 | # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find | 
|  | 701 | if [[ ! -d $NEUTRON_CONF_DIR ]]; then | 
|  | 702 | sudo mkdir -p $NEUTRON_CONF_DIR | 
|  | 703 | fi | 
|  | 704 | sudo chown $STACK_USER $NEUTRON_CONF_DIR | 
|  | 705 |  | 
|  | 706 | cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF | 
|  | 707 |  | 
|  | 708 | # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``. | 
|  | 709 | # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``. | 
|  | 710 | # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``, | 
|  | 711 | # ``Q_PLUGIN_EXTRA_CONF_FILES``.  For example: | 
| Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 712 | # | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 713 | #    ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)`` | 
|  | 714 | neutron_plugin_configure_common | 
|  | 715 |  | 
| sbauza | e2c4ee2 | 2013-08-29 17:29:46 +0200 | [diff] [blame] | 716 | if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 717 | die $LINENO "Neutron plugin not set.. exiting" | 
|  | 718 | fi | 
|  | 719 |  | 
|  | 720 | # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR`` | 
|  | 721 | mkdir -p /$Q_PLUGIN_CONF_PATH | 
|  | 722 | Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME | 
|  | 723 | cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE | 
|  | 724 |  | 
| Ihar Hrachyshka | b816e5d | 2014-07-21 13:53:50 +0200 | [diff] [blame] | 725 | iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME` | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 726 | iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron | 
|  | 727 |  | 
|  | 728 | # If addition config files are set, make sure their path name is set as well | 
|  | 729 | if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then | 
|  | 730 | die $LINENO "Neutron additional plugin config not set.. exiting" | 
|  | 731 | fi | 
|  | 732 |  | 
|  | 733 | # If additional config files exist, copy them over to neutron configuration | 
|  | 734 | # directory | 
|  | 735 | if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 736 | local f | 
|  | 737 | for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do | 
|  | 738 | Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]} | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 739 | done | 
|  | 740 | fi | 
|  | 741 |  | 
| Joe Gordon | bee5c50 | 2013-08-30 13:48:08 -0400 | [diff] [blame] | 742 | if [ "$VIRT_DRIVER" = 'fake' ]; then | 
|  | 743 | # Disable arbitrary limits | 
|  | 744 | iniset $NEUTRON_CONF quotas quota_network -1 | 
|  | 745 | iniset $NEUTRON_CONF quotas quota_subnet -1 | 
|  | 746 | iniset $NEUTRON_CONF quotas quota_port -1 | 
|  | 747 | iniset $NEUTRON_CONF quotas quota_security_group -1 | 
|  | 748 | iniset $NEUTRON_CONF quotas quota_security_group_rule -1 | 
|  | 749 | fi | 
|  | 750 |  | 
| Salvatore Orlando | 05ae833 | 2013-08-20 14:51:08 -0700 | [diff] [blame] | 751 | # Format logging | 
|  | 752 | if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then | 
| Salvatore Orlando | bc7f643 | 2013-11-25 10:11:14 -0800 | [diff] [blame] | 753 | setup_colorized_logging $NEUTRON_CONF DEFAULT project_id | 
| Salvatore Orlando | 05ae833 | 2013-08-20 14:51:08 -0700 | [diff] [blame] | 754 | fi | 
|  | 755 |  | 
| Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 756 | if is_service_enabled tls-proxy; then | 
|  | 757 | # Set the service port for a proxy to take the original | 
|  | 758 | iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT" | 
|  | 759 | fi | 
|  | 760 |  | 
|  | 761 | if is_ssl_enabled_service "nova"; then | 
|  | 762 | iniset $NEUTRON_CONF DEFAULT nova_ca_certificates_file "$SSL_BUNDLE_FILE" | 
|  | 763 | fi | 
|  | 764 |  | 
|  | 765 | if is_ssl_enabled_service "neutron"; then | 
|  | 766 | ensure_certificates NEUTRON | 
|  | 767 |  | 
|  | 768 | iniset $NEUTRON_CONF DEFAULT use_ssl True | 
|  | 769 | iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT" | 
|  | 770 | iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY" | 
|  | 771 | fi | 
|  | 772 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 773 | _neutron_setup_rootwrap | 
|  | 774 | } | 
|  | 775 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 776 | function _configure_neutron_debug_command { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 777 | if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then | 
|  | 778 | return | 
|  | 779 | fi | 
|  | 780 |  | 
|  | 781 | cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE | 
|  | 782 |  | 
|  | 783 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False | 
|  | 784 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False | 
|  | 785 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 786 | iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND" | 
|  | 787 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 788 | _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE | 
|  | 789 |  | 
|  | 790 | neutron_plugin_configure_debug_command | 
|  | 791 | } | 
|  | 792 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 793 | function _configure_neutron_dhcp_agent { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 794 |  | 
|  | 795 | cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE | 
|  | 796 |  | 
|  | 797 | iniset $Q_DHCP_CONF_FILE DEFAULT verbose True | 
| Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 798 | iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 799 | iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE | 
|  | 800 | iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" | 
|  | 801 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 802 | _neutron_setup_interface_driver $Q_DHCP_CONF_FILE | 
|  | 803 |  | 
|  | 804 | neutron_plugin_configure_dhcp_agent | 
|  | 805 | } | 
|  | 806 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 807 | function _configure_neutron_l3_agent { | 
| Paul Michali | 746dcee | 2014-04-02 19:12:22 +0000 | [diff] [blame] | 808 | local cfg_file | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 809 | Q_L3_ENABLED=True | 
|  | 810 | # for l3-agent, only use per tenant router if we have namespaces | 
|  | 811 | Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE | 
| Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 812 |  | 
| Paul Michali | 746dcee | 2014-04-02 19:12:22 +0000 | [diff] [blame] | 813 | if is_service_enabled q-vpn; then | 
| Paul Michali | 746dcee | 2014-04-02 19:12:22 +0000 | [diff] [blame] | 814 | cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE | 
| Paul Michali | 746dcee | 2014-04-02 19:12:22 +0000 | [diff] [blame] | 815 | fi | 
|  | 816 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 817 | cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE | 
|  | 818 |  | 
|  | 819 | iniset $Q_L3_CONF_FILE DEFAULT verbose True | 
| Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 820 | iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 821 | iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE | 
|  | 822 | iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" | 
|  | 823 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 824 | _neutron_setup_interface_driver $Q_L3_CONF_FILE | 
|  | 825 |  | 
|  | 826 | neutron_plugin_configure_l3_agent | 
|  | 827 | } | 
|  | 828 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 829 | function _configure_neutron_metadata_agent { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 830 | cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE | 
|  | 831 |  | 
|  | 832 | iniset $Q_META_CONF_FILE DEFAULT verbose True | 
| Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 833 | iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 834 | iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP | 
|  | 835 | iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" | 
|  | 836 |  | 
| Brant Knudson | 0595237 | 2014-09-19 17:22:22 -0500 | [diff] [blame] | 837 | _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT | 
| Maru Newby | bf10ac5 | 2013-08-10 21:27:54 +0000 | [diff] [blame] | 838 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 839 | } | 
|  | 840 |  | 
| Dina Belova | 58adaa6 | 2014-07-11 18:18:12 +0400 | [diff] [blame] | 841 | function _configure_neutron_ceilometer_notifications { | 
| JordanP | d4d4a34 | 2014-09-15 09:26:53 +0000 | [diff] [blame] | 842 | iniset $NEUTRON_CONF DEFAULT notification_driver messaging | 
| Dina Belova | 58adaa6 | 2014-07-11 18:18:12 +0400 | [diff] [blame] | 843 | } | 
|  | 844 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 845 | function _configure_neutron_lbaas { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 846 | neutron_agent_lbaas_configure_common | 
|  | 847 | neutron_agent_lbaas_configure_agent | 
|  | 848 | } | 
|  | 849 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 850 | function _configure_neutron_metering { | 
| Emilien Macchi | 40546f7 | 2013-09-24 15:10:25 +0200 | [diff] [blame] | 851 | neutron_agent_metering_configure_common | 
|  | 852 | neutron_agent_metering_configure_agent | 
|  | 853 | } | 
|  | 854 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 855 | function _configure_neutron_fwaas { | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 856 | neutron_fwaas_configure_common | 
|  | 857 | neutron_fwaas_configure_driver | 
|  | 858 | } | 
|  | 859 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 860 | function _configure_neutron_vpn { | 
| Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 861 | neutron_vpn_install_agent_packages | 
|  | 862 | neutron_vpn_configure_common | 
| Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 863 | } | 
|  | 864 |  | 
| Brian Haley | eea7621 | 2014-06-27 11:45:50 -0400 | [diff] [blame] | 865 | function _configure_dvr { | 
|  | 866 | iniset $NEUTRON_CONF DEFAULT router_distributed True | 
|  | 867 | iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE | 
|  | 868 | } | 
|  | 869 |  | 
|  | 870 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 871 | # _configure_neutron_plugin_agent() - Set config files for neutron plugin agent | 
|  | 872 | # It is called when q-agt is enabled. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 873 | function _configure_neutron_plugin_agent { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 874 | # Specify the default root helper prior to agent configuration to | 
|  | 875 | # ensure that an agent's configuration can override the default | 
|  | 876 | iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND" | 
|  | 877 | iniset $NEUTRON_CONF DEFAULT verbose True | 
| Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 878 | iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 879 |  | 
|  | 880 | # Configure agent for plugin | 
|  | 881 | neutron_plugin_configure_plugin_agent | 
|  | 882 | } | 
|  | 883 |  | 
|  | 884 | # _configure_neutron_service() - Set config files for neutron service | 
|  | 885 | # It is called when q-svc is enabled. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 886 | function _configure_neutron_service { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 887 | Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini | 
|  | 888 | Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json | 
|  | 889 |  | 
|  | 890 | cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE | 
|  | 891 | cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE | 
|  | 892 |  | 
| Kevin Benton | 08a5fcc | 2014-07-18 16:06:12 -0700 | [diff] [blame] | 893 | # allow neutron user to administer neutron to match neutron account | 
|  | 894 | sed -i 's/"context_is_admin":  "role:admin"/"context_is_admin":  "role:admin or user_name:neutron"/g' $Q_POLICY_FILE | 
|  | 895 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 896 | # Update either configuration file with plugin | 
|  | 897 | iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS | 
|  | 898 |  | 
|  | 899 | if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then | 
|  | 900 | iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES | 
|  | 901 | fi | 
|  | 902 |  | 
|  | 903 | iniset $NEUTRON_CONF DEFAULT verbose True | 
| Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 904 | iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 905 | iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE | 
|  | 906 | iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP | 
|  | 907 |  | 
|  | 908 | iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY | 
|  | 909 | _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken | 
|  | 910 |  | 
| Aaron Rosen | cea32b1 | 2014-03-04 16:20:14 -0800 | [diff] [blame] | 911 | # Configuration for neutron notifations to nova. | 
| Terry Wilson | f06c443 | 2014-05-20 10:54:51 -0500 | [diff] [blame] | 912 | iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES | 
|  | 913 | iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES | 
| Aaron Rosen | cea32b1 | 2014-03-04 16:20:14 -0800 | [diff] [blame] | 914 | iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2" | 
| Dirk Mueller | 5ca261a | 2014-04-04 22:48:02 +0200 | [diff] [blame] | 915 | iniset $NEUTRON_CONF DEFAULT nova_admin_username nova | 
| Aaron Rosen | cea32b1 | 2014-03-04 16:20:14 -0800 | [diff] [blame] | 916 | iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD | 
|  | 917 | ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }") | 
|  | 918 | iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID | 
|  | 919 | iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url  "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0" | 
|  | 920 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 921 | # Configure plugin | 
|  | 922 | neutron_plugin_configure_service | 
|  | 923 | } | 
|  | 924 |  | 
|  | 925 | # Utility Functions | 
|  | 926 | #------------------ | 
|  | 927 |  | 
| Isaku Yamahata | 9e136b4 | 2013-12-16 15:52:03 +0900 | [diff] [blame] | 928 | # _neutron_service_plugin_class_add() - add service plugin class | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 929 | function _neutron_service_plugin_class_add { | 
| Isaku Yamahata | 9e136b4 | 2013-12-16 15:52:03 +0900 | [diff] [blame] | 930 | local service_plugin_class=$1 | 
|  | 931 | if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then | 
|  | 932 | Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class | 
|  | 933 | elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then | 
|  | 934 | Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class" | 
|  | 935 | fi | 
|  | 936 | } | 
|  | 937 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 938 | # _neutron_setup_rootwrap() - configure Neutron's rootwrap | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 939 | function _neutron_setup_rootwrap { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 940 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then | 
|  | 941 | return | 
|  | 942 | fi | 
|  | 943 | # Deploy new rootwrap filters files (owned by root). | 
|  | 944 | # Wipe any existing ``rootwrap.d`` files first | 
|  | 945 | Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d | 
|  | 946 | if [[ -d $Q_CONF_ROOTWRAP_D ]]; then | 
|  | 947 | sudo rm -rf $Q_CONF_ROOTWRAP_D | 
|  | 948 | fi | 
|  | 949 | # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d`` | 
|  | 950 | mkdir -p -m 755 $Q_CONF_ROOTWRAP_D | 
|  | 951 | cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/ | 
|  | 952 | sudo chown -R root:root $Q_CONF_ROOTWRAP_D | 
|  | 953 | sudo chmod 644 $Q_CONF_ROOTWRAP_D/* | 
|  | 954 | # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d`` | 
|  | 955 | # location moved in newer versions, prefer new location | 
|  | 956 | if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then | 
| Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 957 | sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 958 | else | 
| Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 959 | sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 960 | fi | 
|  | 961 | sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE | 
|  | 962 | sudo chown root:root $Q_RR_CONF_FILE | 
|  | 963 | sudo chmod 0644 $Q_RR_CONF_FILE | 
|  | 964 | # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap | 
|  | 965 | ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *" | 
|  | 966 |  | 
|  | 967 | # Set up the rootwrap sudoers for neutron | 
|  | 968 | TEMPFILE=`mktemp` | 
| Stephan Renatus | e578eff | 2013-11-19 13:31:04 +0100 | [diff] [blame] | 969 | echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 970 | chmod 0440 $TEMPFILE | 
|  | 971 | sudo chown root:root $TEMPFILE | 
|  | 972 | sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap | 
|  | 973 |  | 
|  | 974 | # Update the root_helper | 
|  | 975 | iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND" | 
|  | 976 | } | 
|  | 977 |  | 
|  | 978 | # Configures keystone integration for neutron service and agents | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 979 | function _neutron_setup_keystone { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 980 | local conf_file=$1 | 
|  | 981 | local section=$2 | 
| Jamie Lennox | 3561d7f | 2014-05-21 17:18:43 +1000 | [diff] [blame] | 982 |  | 
| Brant Knudson | 0595237 | 2014-09-19 17:22:22 -0500 | [diff] [blame] | 983 | create_neutron_cache_dir | 
|  | 984 | configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 985 | } | 
|  | 986 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 987 | function _neutron_setup_interface_driver { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 988 |  | 
|  | 989 | # ovs_use_veth needs to be set before the plugin configuration | 
|  | 990 | # occurs to allow plugins to override the setting. | 
|  | 991 | iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH | 
|  | 992 |  | 
|  | 993 | neutron_plugin_setup_interface_driver $1 | 
|  | 994 | } | 
|  | 995 |  | 
|  | 996 | # Functions for Neutron Exercises | 
|  | 997 | #-------------------------------- | 
|  | 998 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 999 | function delete_probe { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1000 | local from_net="$1" | 
|  | 1001 | net_id=`_get_net_id $from_net` | 
|  | 1002 | probe_id=`neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-list -c id -c network_id | grep $net_id | awk '{print $2}'` | 
|  | 1003 | neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id | 
|  | 1004 | } | 
|  | 1005 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1006 | function setup_neutron_debug { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1007 | if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then | 
|  | 1008 | public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME` | 
|  | 1009 | neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id | 
|  | 1010 | private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME` | 
|  | 1011 | neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id | 
|  | 1012 | fi | 
|  | 1013 | } | 
|  | 1014 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1015 | function teardown_neutron_debug { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1016 | delete_probe $PUBLIC_NETWORK_NAME | 
|  | 1017 | delete_probe $PRIVATE_NETWORK_NAME | 
|  | 1018 | } | 
|  | 1019 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1020 | function _get_net_id { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1021 | neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}' | 
|  | 1022 | } | 
|  | 1023 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1024 | function _get_probe_cmd_prefix { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1025 | local from_net="$1" | 
|  | 1026 | net_id=`_get_net_id $from_net` | 
|  | 1027 | probe_id=`neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-list -c id -c network_id | grep $net_id | awk '{print $2}' | head -n 1` | 
|  | 1028 | echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id" | 
|  | 1029 | } | 
|  | 1030 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1031 | function _ping_check_neutron { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1032 | local from_net=$1 | 
|  | 1033 | local ip=$2 | 
|  | 1034 | local timeout_sec=$3 | 
|  | 1035 | local expected=${4:-"True"} | 
|  | 1036 | local check_command="" | 
|  | 1037 | probe_cmd=`_get_probe_cmd_prefix $from_net` | 
|  | 1038 | if [[ "$expected" = "True" ]]; then | 
|  | 1039 | check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done" | 
|  | 1040 | else | 
|  | 1041 | check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done" | 
|  | 1042 | fi | 
|  | 1043 | if ! timeout $timeout_sec sh -c "$check_command"; then | 
|  | 1044 | if [[ "$expected" = "True" ]]; then | 
|  | 1045 | die $LINENO "[Fail] Couldn't ping server" | 
|  | 1046 | else | 
|  | 1047 | die $LINENO "[Fail] Could ping server" | 
|  | 1048 | fi | 
|  | 1049 | fi | 
|  | 1050 | } | 
|  | 1051 |  | 
|  | 1052 | # ssh check | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1053 | function _ssh_check_neutron { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1054 | local from_net=$1 | 
|  | 1055 | local key_file=$2 | 
|  | 1056 | local ip=$3 | 
|  | 1057 | local user=$4 | 
|  | 1058 | local timeout_sec=$5 | 
|  | 1059 | local probe_cmd = "" | 
|  | 1060 | probe_cmd=`_get_probe_cmd_prefix $from_net` | 
|  | 1061 | if ! timeout $timeout_sec sh -c "while ! $probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success; do sleep 1; done"; then | 
|  | 1062 | die $LINENO "server didn't become ssh-able!" | 
|  | 1063 | fi | 
|  | 1064 | } | 
|  | 1065 |  | 
|  | 1066 | # Neutron 3rd party programs | 
|  | 1067 | #--------------------------- | 
|  | 1068 |  | 
|  | 1069 | # please refer to ``lib/neutron_thirdparty/README.md`` for details | 
|  | 1070 | NEUTRON_THIRD_PARTIES="" | 
|  | 1071 | for f in $TOP_DIR/lib/neutron_thirdparty/*; do | 
| Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 1072 | third_party=$(basename $f) | 
|  | 1073 | if is_service_enabled $third_party; then | 
|  | 1074 | source $TOP_DIR/lib/neutron_thirdparty/$third_party | 
|  | 1075 | NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party" | 
|  | 1076 | fi | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1077 | done | 
|  | 1078 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1079 | function _neutron_third_party_do { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1080 | for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do | 
|  | 1081 | ${1}_${third_party} | 
|  | 1082 | done | 
|  | 1083 | } | 
|  | 1084 |  | 
|  | 1085 | # configure_neutron_third_party() - Set config files, create data dirs, etc | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1086 | function configure_neutron_third_party { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1087 | _neutron_third_party_do configure | 
|  | 1088 | } | 
|  | 1089 |  | 
|  | 1090 | # init_neutron_third_party() - Initialize databases, etc. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1091 | function init_neutron_third_party { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1092 | _neutron_third_party_do init | 
|  | 1093 | } | 
|  | 1094 |  | 
|  | 1095 | # install_neutron_third_party() - Collect source and prepare | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1096 | function install_neutron_third_party { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1097 | _neutron_third_party_do install | 
|  | 1098 | } | 
|  | 1099 |  | 
|  | 1100 | # start_neutron_third_party() - Start running processes, including screen | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1101 | function start_neutron_third_party { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1102 | _neutron_third_party_do start | 
|  | 1103 | } | 
|  | 1104 |  | 
|  | 1105 | # stop_neutron_third_party - Stop running processes (non-screen) | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1106 | function stop_neutron_third_party { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1107 | _neutron_third_party_do stop | 
|  | 1108 | } | 
|  | 1109 |  | 
| armando-migliaccio | ef1e080 | 2014-01-02 16:33:53 -0800 | [diff] [blame] | 1110 | # check_neutron_third_party_integration() - Check that third party integration is sane | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 1111 | function check_neutron_third_party_integration { | 
| armando-migliaccio | ef1e080 | 2014-01-02 16:33:53 -0800 | [diff] [blame] | 1112 | _neutron_third_party_do check | 
|  | 1113 | } | 
|  | 1114 |  | 
| Sean M. Collins | 5ec6f8f | 2014-05-14 17:01:03 -0400 | [diff] [blame] | 1115 | function is_provider_network { | 
|  | 1116 | if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then | 
|  | 1117 | return 0 | 
|  | 1118 | fi | 
|  | 1119 | return 1 | 
|  | 1120 | } | 
|  | 1121 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1122 |  | 
|  | 1123 | # Restore xtrace | 
|  | 1124 | $XTRACE | 
|  | 1125 |  | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 1126 | # Tell emacs to use shell-script-mode | 
|  | 1127 | ## Local variables: | 
|  | 1128 | ## mode: shell-script | 
|  | 1129 | ## End: |