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 | |
| 72 | # Set up default directories |
| 73 | NEUTRON_DIR=$DEST/neutron |
| 74 | NEUTRONCLIENT_DIR=$DEST/python-neutronclient |
| 75 | NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron} |
| 76 | |
| 77 | # Support entry points installation of console scripts |
| 78 | if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then |
| 79 | NEUTRON_BIN_DIR=$NEUTRON_DIR/bin |
Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 80 | else |
| 81 | NEUTRON_BIN_DIR=$(get_python_exec_prefix) |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 82 | fi |
| 83 | |
| 84 | NEUTRON_CONF_DIR=/etc/neutron |
| 85 | NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf |
| 86 | export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"} |
| 87 | |
| 88 | # Default Neutron Plugin |
Kyle Mestery | 6d23500 | 2013-09-18 20:27:08 +0000 | [diff] [blame] | 89 | Q_PLUGIN=${Q_PLUGIN:-ml2} |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 90 | # Default Neutron Port |
| 91 | Q_PORT=${Q_PORT:-9696} |
| 92 | # Default Neutron Host |
| 93 | Q_HOST=${Q_HOST:-$SERVICE_HOST} |
| 94 | # Default admin username |
| 95 | Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron} |
| 96 | # Default auth strategy |
| 97 | Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone} |
| 98 | # Use namespace or not |
| 99 | Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True} |
| 100 | # RHEL's support for namespaces requires using veths with ovs |
| 101 | Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False} |
| 102 | Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True} |
| 103 | # Meta data IP |
| 104 | Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST} |
| 105 | # Allow Overlapping IP among subnets |
| 106 | Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True} |
| 107 | # Use neutron-debug command |
| 108 | Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False} |
| 109 | # The name of the default q-l3 router |
| 110 | Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1} |
Aaron Rosen | 4540d00 | 2013-10-24 13:59:33 -0700 | [diff] [blame] | 111 | # nova vif driver that all plugins should use |
| 112 | NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"} |
Aaron Rosen | cea32b1 | 2014-03-04 16:20:14 -0800 | [diff] [blame^] | 113 | Q_NOTIFY_NOVA_PORT_STATUS_CHANGE=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGE:-True} |
| 114 | Q_NOTIFY_NOVA_ON_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_CHANGE:-True} |
| 115 | VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True} |
| 116 | VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300} |
Aaron Rosen | 4540d00 | 2013-10-24 13:59:33 -0700 | [diff] [blame] | 117 | |
Tomoe Sugihara | afbc631 | 2013-11-14 20:02:47 +0000 | [diff] [blame] | 118 | # The next two variables are configured by plugin |
| 119 | # e.g. _configure_neutron_l3_agent or lib/neutron_plugins/* |
| 120 | # |
| 121 | # The plugin supports L3. |
| 122 | Q_L3_ENABLED=${Q_L3_ENABLED:-False} |
| 123 | # L3 routers exist per tenant |
| 124 | Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False} |
Aaron Rosen | 4540d00 | 2013-10-24 13:59:33 -0700 | [diff] [blame] | 125 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 126 | # List of config file names in addition to the main plugin config file |
| 127 | # See _configure_neutron_common() for details about setting it up |
| 128 | declare -a Q_PLUGIN_EXTRA_CONF_FILES |
| 129 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 130 | |
Dean Troyer | e2907b4 | 2014-02-26 17:35:37 -0600 | [diff] [blame] | 131 | Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf |
| 132 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then |
| 133 | Q_RR_COMMAND="sudo" |
| 134 | else |
| 135 | NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron) |
| 136 | Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE" |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 137 | fi |
| 138 | |
Dean Troyer | e2907b4 | 2014-02-26 17:35:37 -0600 | [diff] [blame] | 139 | # Provider Network Configurations |
| 140 | # -------------------------------- |
| 141 | |
| 142 | # The following variables control the Neutron openvswitch and |
| 143 | # linuxbridge plugins' allocation of tenant networks and |
| 144 | # availability of provider networks. If these are not configured |
| 145 | # in ``localrc``, tenant networks will be local to the host (with no |
| 146 | # remote connectivity), and no physical resources will be |
| 147 | # available for the allocation of provider networks. |
| 148 | |
| 149 | # To use GRE tunnels for tenant networks, set to True in |
| 150 | # ``localrc``. GRE tunnels are only supported by the openvswitch |
| 151 | # plugin, and currently only on Ubuntu. |
| 152 | ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False} |
| 153 | |
| 154 | # If using GRE tunnels for tenant networks, specify the range of |
| 155 | # tunnel IDs from which tenant networks are allocated. Can be |
| 156 | # overriden in ``localrc`` in necesssary. |
| 157 | TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGE:-1:1000} |
| 158 | |
| 159 | # To use VLANs for tenant networks, set to True in localrc. VLANs |
| 160 | # are supported by the openvswitch and linuxbridge plugins, each |
| 161 | # requiring additional configuration described below. |
| 162 | ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False} |
| 163 | |
| 164 | # If using VLANs for tenant networks, set in ``localrc`` to specify |
| 165 | # the range of VLAN VIDs from which tenant networks are |
| 166 | # allocated. An external network switch must be configured to |
| 167 | # trunk these VLANs between hosts for multi-host connectivity. |
| 168 | # |
| 169 | # Example: ``TENANT_VLAN_RANGE=1000:1999`` |
| 170 | TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-} |
| 171 | |
| 172 | # If using VLANs for tenant networks, or if using flat or VLAN |
| 173 | # provider networks, set in ``localrc`` to the name of the physical |
| 174 | # network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the |
| 175 | # openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge |
| 176 | # agent, as described below. |
| 177 | # |
| 178 | # Example: ``PHYSICAL_NETWORK=default`` |
| 179 | PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-} |
| 180 | |
| 181 | # With the openvswitch plugin, if using VLANs for tenant networks, |
| 182 | # or if using flat or VLAN provider networks, set in ``localrc`` to |
| 183 | # the name of the OVS bridge to use for the physical network. The |
| 184 | # bridge will be created if it does not already exist, but a |
| 185 | # physical interface must be manually added to the bridge as a |
| 186 | # port for external connectivity. |
| 187 | # |
| 188 | # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1`` |
| 189 | OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-} |
| 190 | |
| 191 | # With the linuxbridge plugin, if using VLANs for tenant networks, |
| 192 | # or if using flat or VLAN provider networks, set in ``localrc`` to |
| 193 | # the name of the network interface to use for the physical |
| 194 | # network. |
| 195 | # |
| 196 | # Example: ``LB_PHYSICAL_INTERFACE=eth1`` |
| 197 | LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-} |
| 198 | |
| 199 | # With the openvswitch plugin, set to True in ``localrc`` to enable |
| 200 | # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False. |
| 201 | # |
| 202 | # Example: ``OVS_ENABLE_TUNNELING=True`` |
| 203 | OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS} |
| 204 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 205 | # Neutron plugin specific functions |
| 206 | # --------------------------------- |
| 207 | |
| 208 | # Please refer to ``lib/neutron_plugins/README.md`` for details. |
| 209 | source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN |
| 210 | |
| 211 | # Agent loadbalancer service plugin functions |
| 212 | # ------------------------------------------- |
| 213 | |
| 214 | # Hardcoding for 1 service plugin for now |
| 215 | source $TOP_DIR/lib/neutron_plugins/services/loadbalancer |
| 216 | |
Emilien Macchi | 40546f7 | 2013-09-24 15:10:25 +0200 | [diff] [blame] | 217 | # Agent metering service plugin functions |
| 218 | # ------------------------------------------- |
| 219 | |
| 220 | # Hardcoding for 1 service plugin for now |
| 221 | source $TOP_DIR/lib/neutron_plugins/services/metering |
| 222 | |
Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 223 | # VPN service plugin functions |
| 224 | # ------------------------------------------- |
| 225 | # Hardcoding for 1 service plugin for now |
| 226 | source $TOP_DIR/lib/neutron_plugins/services/vpn |
| 227 | |
Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 228 | # Firewall Service Plugin functions |
Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 229 | # --------------------------------- |
Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 230 | source $TOP_DIR/lib/neutron_plugins/services/firewall |
| 231 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 232 | # Use security group or not |
| 233 | if has_neutron_plugin_security_group; then |
| 234 | Q_USE_SECGROUP=${Q_USE_SECGROUP:-True} |
| 235 | else |
| 236 | Q_USE_SECGROUP=False |
| 237 | fi |
| 238 | |
Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 239 | # Tell Tempest this project is present |
| 240 | TEMPEST_SERVICES+=,neutron |
| 241 | |
| 242 | |
Dean Troyer | e2907b4 | 2014-02-26 17:35:37 -0600 | [diff] [blame] | 243 | # Save trace setting |
| 244 | XTRACE=$(set +o | grep xtrace) |
| 245 | set +o xtrace |
| 246 | |
| 247 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 248 | # Functions |
| 249 | # --------- |
| 250 | |
Dean Troyer | e4fa721 | 2014-01-15 15:04:49 -0600 | [diff] [blame] | 251 | # Test if any Neutron services are enabled |
| 252 | # is_neutron_enabled |
| 253 | function is_neutron_enabled { |
| 254 | [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0 |
| 255 | return 1 |
| 256 | } |
| 257 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 258 | # configure_neutron() |
| 259 | # Set common config for all neutron server and agents. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 260 | function configure_neutron { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 261 | _configure_neutron_common |
| 262 | iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT |
| 263 | |
| 264 | # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES |
| 265 | if is_service_enabled q-lbaas; then |
| 266 | _configure_neutron_lbaas |
| 267 | fi |
Emilien Macchi | 40546f7 | 2013-09-24 15:10:25 +0200 | [diff] [blame] | 268 | if is_service_enabled q-metering; then |
| 269 | _configure_neutron_metering |
| 270 | fi |
Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 271 | if is_service_enabled q-vpn; then |
| 272 | _configure_neutron_vpn |
| 273 | fi |
Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 274 | if is_service_enabled q-fwaas; then |
| 275 | _configure_neutron_fwaas |
| 276 | fi |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 277 | if is_service_enabled q-svc; then |
| 278 | _configure_neutron_service |
| 279 | fi |
| 280 | if is_service_enabled q-agt; then |
| 281 | _configure_neutron_plugin_agent |
| 282 | fi |
| 283 | if is_service_enabled q-dhcp; then |
| 284 | _configure_neutron_dhcp_agent |
| 285 | fi |
| 286 | if is_service_enabled q-l3; then |
| 287 | _configure_neutron_l3_agent |
| 288 | fi |
| 289 | if is_service_enabled q-meta; then |
| 290 | _configure_neutron_metadata_agent |
| 291 | fi |
| 292 | |
| 293 | _configure_neutron_debug_command |
| 294 | } |
| 295 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 296 | function create_nova_conf_neutron { |
Yong Sheng Gong | 032e454 | 2013-08-25 10:21:10 +0800 | [diff] [blame] | 297 | iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API" |
| 298 | iniset $NOVA_CONF DEFAULT neutron_admin_username "$Q_ADMIN_USERNAME" |
| 299 | iniset $NOVA_CONF DEFAULT neutron_admin_password "$SERVICE_PASSWORD" |
| 300 | iniset $NOVA_CONF DEFAULT neutron_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0" |
| 301 | iniset $NOVA_CONF DEFAULT neutron_auth_strategy "$Q_AUTH_STRATEGY" |
| 302 | iniset $NOVA_CONF DEFAULT neutron_admin_tenant_name "$SERVICE_TENANT_NAME" |
| 303 | iniset $NOVA_CONF DEFAULT neutron_region_name "RegionOne" |
| 304 | iniset $NOVA_CONF DEFAULT neutron_url "http://$Q_HOST:$Q_PORT" |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 305 | |
| 306 | if [[ "$Q_USE_SECGROUP" == "True" ]]; then |
| 307 | LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver |
Jeff Peeler | 1143f7e | 2013-10-31 16:21:52 -0400 | [diff] [blame] | 308 | iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER |
Yong Sheng Gong | 032e454 | 2013-08-25 10:21:10 +0800 | [diff] [blame] | 309 | iniset $NOVA_CONF DEFAULT security_group_api neutron |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 310 | fi |
| 311 | |
| 312 | # set NOVA_VIF_DRIVER and optionally set options in nova_conf |
| 313 | neutron_plugin_create_nova_conf |
| 314 | |
| 315 | iniset $NOVA_CONF DEFAULT libvirt_vif_driver "$NOVA_VIF_DRIVER" |
| 316 | iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER" |
| 317 | if is_service_enabled q-meta; then |
Yong Sheng Gong | 032e454 | 2013-08-25 10:21:10 +0800 | [diff] [blame] | 318 | iniset $NOVA_CONF DEFAULT service_neutron_metadata_proxy "True" |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 319 | fi |
Aaron Rosen | cea32b1 | 2014-03-04 16:20:14 -0800 | [diff] [blame^] | 320 | |
| 321 | iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL" |
| 322 | iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT" |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 323 | } |
| 324 | |
Emilien Macchi | a677b7f | 2013-11-25 23:40:20 +0100 | [diff] [blame] | 325 | # create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 326 | function create_neutron_cache_dir { |
Emilien Macchi | a677b7f | 2013-11-25 23:40:20 +0100 | [diff] [blame] | 327 | # Create cache dir |
| 328 | sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR |
| 329 | sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR |
| 330 | rm -f $NEUTRON_AUTH_CACHE_DIR/* |
| 331 | } |
| 332 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 333 | # create_neutron_accounts() - Set up common required neutron accounts |
| 334 | |
| 335 | # Tenant User Roles |
| 336 | # ------------------------------------------------------------------ |
| 337 | # service neutron admin # if enabled |
| 338 | |
| 339 | # Migrated from keystone_data.sh |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 340 | function create_neutron_accounts { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 341 | |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 342 | SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 343 | ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }") |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 344 | |
| 345 | if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 346 | NEUTRON_USER=$(openstack user create \ |
| 347 | neutron \ |
| 348 | --password "$SERVICE_PASSWORD" \ |
| 349 | --project $SERVICE_TENANT \ |
| 350 | --email neutron@example.com \ |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 351 | | grep " id " | get_field 2) |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 352 | openstack role add \ |
| 353 | $ADMIN_ROLE \ |
| 354 | --project $SERVICE_TENANT \ |
| 355 | --user $NEUTRON_USER |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 356 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 357 | NEUTRON_SERVICE=$(openstack service create \ |
| 358 | neutron \ |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 359 | --type=network \ |
| 360 | --description="Neutron Service" \ |
| 361 | | grep " id " | get_field 2) |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 362 | openstack endpoint create \ |
| 363 | $NEUTRON_SERVICE \ |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 364 | --region RegionOne \ |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 365 | --publicurl "http://$SERVICE_HOST:9696/" \ |
| 366 | --adminurl "http://$SERVICE_HOST:9696/" \ |
| 367 | --internalurl "http://$SERVICE_HOST:9696/" |
| 368 | fi |
| 369 | fi |
| 370 | } |
| 371 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 372 | function create_neutron_initial_network { |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 373 | TENANT_ID=$(openstack project list | grep " demo " | get_field 1) |
DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 374 | 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] | 375 | |
| 376 | # Create a small network |
| 377 | # Since neutron command is executed in admin context at this point, |
Dirk Mueller | 25049cd | 2014-01-09 13:53:52 +0100 | [diff] [blame] | 378 | # ``--tenant-id`` needs to be specified. |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 379 | if is_baremetal; then |
sbauza | e2c4ee2 | 2013-08-29 17:29:46 +0200 | [diff] [blame] | 380 | if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then |
| 381 | die $LINENO "Neutron settings for baremetal not set.. exiting" |
| 382 | fi |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 383 | sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE |
| 384 | for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do |
| 385 | sudo ip addr del $IP dev $PUBLIC_INTERFACE |
| 386 | sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE |
| 387 | done |
Dirk Mueller | 25049cd | 2014-01-09 13:53:52 +0100 | [diff] [blame] | 388 | 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] | 389 | 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] | 390 | 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] | 391 | 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] | 392 | sudo ifconfig $OVS_PHYSICAL_BRIDGE up |
sbauza | e2c4ee2 | 2013-08-29 17:29:46 +0200 | [diff] [blame] | 393 | sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 394 | else |
Dirk Mueller | 25049cd | 2014-01-09 13:53:52 +0100 | [diff] [blame] | 395 | 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] | 396 | 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] | 397 | 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] | 398 | 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] | 399 | fi |
| 400 | |
| 401 | if [[ "$Q_L3_ENABLED" == "True" ]]; then |
| 402 | # Create a router, and add the private subnet as one of its interfaces |
| 403 | if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then |
| 404 | # create a tenant-owned router. |
Dirk Mueller | 25049cd | 2014-01-09 13:53:52 +0100 | [diff] [blame] | 405 | 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] | 406 | 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] | 407 | else |
| 408 | # Plugin only supports creating a single router, which should be admin owned. |
| 409 | ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2) |
DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 410 | 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] | 411 | fi |
| 412 | neutron router-interface-add $ROUTER_ID $SUBNET_ID |
| 413 | # Create an external network, and a subnet. Configure the external network as router gw |
| 414 | EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2) |
DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 415 | 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] | 416 | 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] | 417 | 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] | 418 | neutron router-gateway-set $ROUTER_ID $EXT_NET_ID |
| 419 | |
| 420 | if is_service_enabled q-l3; then |
| 421 | # logic is specific to using the l3-agent for l3 |
| 422 | if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then |
| 423 | CIDR_LEN=${FLOATING_RANGE#*/} |
| 424 | sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE |
| 425 | sudo ip link set $PUBLIC_BRIDGE up |
| 426 | 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] | 427 | 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] | 428 | sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP |
| 429 | fi |
| 430 | if [[ "$Q_USE_NAMESPACE" == "False" ]]; then |
| 431 | # Explicitly set router id in l3 agent configuration |
| 432 | iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID |
| 433 | fi |
| 434 | fi |
Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 435 | fi |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | # init_neutron() - Initialize databases, etc. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 439 | function init_neutron { |
Salvatore Orlando | dd64988 | 2013-08-05 08:56:17 -0700 | [diff] [blame] | 440 | recreate_database $Q_DB_NAME utf8 |
| 441 | # Run Neutron db migrations |
| 442 | $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] | 443 | } |
| 444 | |
| 445 | # install_neutron() - Collect source and prepare |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 446 | function install_neutron { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 447 | git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH |
| 448 | setup_develop $NEUTRON_DIR |
| 449 | } |
| 450 | |
| 451 | # install_neutronclient() - Collect source and prepare |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 452 | function install_neutronclient { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 453 | git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH |
| 454 | setup_develop $NEUTRONCLIENT_DIR |
Attila Fazekas | fac533e | 2013-08-14 16:04:01 +0200 | [diff] [blame] | 455 | 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] | 456 | } |
| 457 | |
| 458 | # install_neutron_agent_packages() - Collect source and prepare |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 459 | function install_neutron_agent_packages { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 460 | # install packages that are specific to plugin agent(s) |
| 461 | if is_service_enabled q-agt q-dhcp q-l3; then |
| 462 | neutron_plugin_install_agent_packages |
| 463 | fi |
| 464 | |
| 465 | if is_service_enabled q-lbaas; then |
Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 466 | neutron_agent_lbaas_install_agent_packages |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 467 | fi |
| 468 | } |
| 469 | |
| 470 | # Start running processes, including screen |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 471 | function start_neutron_service_and_check { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 472 | # build config-file options |
| 473 | local cfg_file |
| 474 | local CFG_FILE_OPTIONS="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE" |
| 475 | for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do |
Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 476 | CFG_FILE_OPTIONS+=" --config-file /$cfg_file" |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 477 | done |
| 478 | # Start the Neutron service |
| 479 | screen_it q-svc "cd $NEUTRON_DIR && python $NEUTRON_BIN_DIR/neutron-server $CFG_FILE_OPTIONS" |
| 480 | echo "Waiting for Neutron to start..." |
JUN JIE NAN | 0aa8534 | 2013-09-13 15:47:09 +0800 | [diff] [blame] | 481 | if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then |
Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 482 | die $LINENO "Neutron did not start" |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 483 | fi |
| 484 | } |
| 485 | |
| 486 | # Start running processes, including screen |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 487 | function start_neutron_agents { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 488 | # Start up the neutron agents if enabled |
| 489 | screen_it q-agt "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE" |
| 490 | screen_it q-dhcp "cd $NEUTRON_DIR && 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] | 491 | |
Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 492 | L3_CONF_FILES="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE" |
| 493 | |
| 494 | if is_service_enabled q-fwaas; then |
| 495 | L3_CONF_FILES="$L3_CONF_FILES --config-file $Q_FWAAS_CONF_FILE" |
Nachi Ueno | 584750f | 2013-07-15 18:22:21 -0700 | [diff] [blame] | 496 | fi |
Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 497 | if is_service_enabled q-vpn; then |
| 498 | screen_it q-vpn "cd $NEUTRON_DIR && $AGENT_VPN_BINARY $L3_CONF_FILES" |
| 499 | else |
| 500 | screen_it q-l3 "cd $NEUTRON_DIR && python $AGENT_L3_BINARY $L3_CONF_FILES" |
| 501 | fi |
| 502 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 503 | screen_it q-meta "cd $NEUTRON_DIR && python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE" |
| 504 | |
| 505 | if [ "$VIRT_DRIVER" = 'xenserver' ]; then |
| 506 | # For XenServer, start an agent for the domU openvswitch |
| 507 | screen_it q-domua "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU" |
| 508 | fi |
| 509 | |
| 510 | if is_service_enabled q-lbaas; then |
| 511 | screen_it q-lbaas "cd $NEUTRON_DIR && python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME" |
| 512 | fi |
Emilien Macchi | 40546f7 | 2013-09-24 15:10:25 +0200 | [diff] [blame] | 513 | |
| 514 | if is_service_enabled q-metering; then |
| 515 | screen_it q-metering "cd $NEUTRON_DIR && python $AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME" |
| 516 | fi |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | # stop_neutron() - Stop running processes (non-screen) |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 520 | function stop_neutron { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 521 | if is_service_enabled q-dhcp; then |
| 522 | pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }') |
| 523 | [ ! -z "$pid" ] && sudo kill -9 $pid |
| 524 | fi |
| 525 | if is_service_enabled q-meta; then |
Jakub Libosvar | 1f76328 | 2014-01-28 23:01:38 +0100 | [diff] [blame] | 526 | sudo pkill -9 -f neutron-ns-metadata-proxy || : |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 527 | fi |
Akihiro Motoki | edddb1f | 2013-12-09 20:21:06 +0900 | [diff] [blame] | 528 | |
| 529 | if is_service_enabled q-lbaas; then |
| 530 | neutron_lbaas_stop |
| 531 | fi |
| 532 | if is_service_enabled q-fwaas; then |
| 533 | neutron_fwaas_stop |
| 534 | fi |
| 535 | if is_service_enabled q-vpn; then |
| 536 | neutron_vpn_stop |
| 537 | fi |
| 538 | if is_service_enabled q-metering; then |
| 539 | neutron_metering_stop |
| 540 | fi |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | # cleanup_neutron() - Remove residual data files, anything left over from previous |
| 544 | # runs that a clean run would need to clean up |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 545 | function cleanup_neutron { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 546 | if is_neutron_ovs_base_plugin; then |
| 547 | neutron_ovs_base_cleanup |
| 548 | fi |
| 549 | |
| 550 | # delete all namespaces created by neutron |
Akihiro Motoki | edddb1f | 2013-12-09 20:21:06 +0900 | [diff] [blame] | 551 | for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|qlbaas)-[0-9a-f-]*'); do |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 552 | sudo ip netns delete ${ns} |
| 553 | done |
| 554 | } |
| 555 | |
| 556 | # _configure_neutron_common() |
| 557 | # Set common config for all neutron server and agents. |
| 558 | # This MUST be called before other ``_configure_neutron_*`` functions. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 559 | function _configure_neutron_common { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 560 | # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find |
| 561 | if [[ ! -d $NEUTRON_CONF_DIR ]]; then |
| 562 | sudo mkdir -p $NEUTRON_CONF_DIR |
| 563 | fi |
| 564 | sudo chown $STACK_USER $NEUTRON_CONF_DIR |
| 565 | |
| 566 | cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF |
| 567 | |
| 568 | # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``. |
| 569 | # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``. |
| 570 | # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``, |
| 571 | # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example: |
Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 572 | # |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 573 | # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)`` |
| 574 | neutron_plugin_configure_common |
| 575 | |
sbauza | e2c4ee2 | 2013-08-29 17:29:46 +0200 | [diff] [blame] | 576 | 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] | 577 | die $LINENO "Neutron plugin not set.. exiting" |
| 578 | fi |
| 579 | |
| 580 | # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR`` |
| 581 | mkdir -p /$Q_PLUGIN_CONF_PATH |
| 582 | Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME |
| 583 | cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE |
| 584 | |
| 585 | iniset /$Q_PLUGIN_CONF_FILE database connection `database_connection_url $Q_DB_NAME` |
| 586 | iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron |
| 587 | |
| 588 | # If addition config files are set, make sure their path name is set as well |
| 589 | if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then |
| 590 | die $LINENO "Neutron additional plugin config not set.. exiting" |
| 591 | fi |
| 592 | |
| 593 | # If additional config files exist, copy them over to neutron configuration |
| 594 | # directory |
| 595 | if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 596 | local f |
| 597 | for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do |
| 598 | 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] | 599 | done |
| 600 | fi |
| 601 | |
Joe Gordon | bee5c50 | 2013-08-30 13:48:08 -0400 | [diff] [blame] | 602 | if [ "$VIRT_DRIVER" = 'fake' ]; then |
| 603 | # Disable arbitrary limits |
| 604 | iniset $NEUTRON_CONF quotas quota_network -1 |
| 605 | iniset $NEUTRON_CONF quotas quota_subnet -1 |
| 606 | iniset $NEUTRON_CONF quotas quota_port -1 |
| 607 | iniset $NEUTRON_CONF quotas quota_security_group -1 |
| 608 | iniset $NEUTRON_CONF quotas quota_security_group_rule -1 |
| 609 | fi |
| 610 | |
Salvatore Orlando | 05ae833 | 2013-08-20 14:51:08 -0700 | [diff] [blame] | 611 | # Format logging |
| 612 | if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then |
Salvatore Orlando | bc7f643 | 2013-11-25 10:11:14 -0800 | [diff] [blame] | 613 | setup_colorized_logging $NEUTRON_CONF DEFAULT project_id |
Salvatore Orlando | 05ae833 | 2013-08-20 14:51:08 -0700 | [diff] [blame] | 614 | fi |
| 615 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 616 | _neutron_setup_rootwrap |
| 617 | } |
| 618 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 619 | function _configure_neutron_debug_command { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 620 | if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then |
| 621 | return |
| 622 | fi |
| 623 | |
| 624 | cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE |
| 625 | |
| 626 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False |
| 627 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False |
| 628 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 629 | iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND" |
| 630 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 631 | _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE |
| 632 | |
| 633 | neutron_plugin_configure_debug_command |
| 634 | } |
| 635 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 636 | function _configure_neutron_dhcp_agent { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 637 | AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent" |
| 638 | Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini |
| 639 | |
| 640 | cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE |
| 641 | |
| 642 | iniset $Q_DHCP_CONF_FILE DEFAULT verbose True |
Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 643 | iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 644 | iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE |
| 645 | iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" |
| 646 | |
Kyle Mestery | 73b2191 | 2013-08-22 11:25:21 +0000 | [diff] [blame] | 647 | # Define extra "DEFAULT" configuration options when q-dhcp is configured by |
| 648 | # defining the array ``Q_DHCP_EXTRA_DEFAULT_OPTS``. |
| 649 | # For Example: ``Q_DHCP_EXTRA_DEFAULT_OPTS=(foo=true bar=2)`` |
| 650 | for I in "${Q_DHCP_EXTRA_DEFAULT_OPTS[@]}"; do |
| 651 | # Replace the first '=' with ' ' for iniset syntax |
| 652 | iniset $Q_DHCP_CONF_FILE DEFAULT ${I/=/ } |
| 653 | done |
| 654 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 655 | _neutron_setup_interface_driver $Q_DHCP_CONF_FILE |
| 656 | |
| 657 | neutron_plugin_configure_dhcp_agent |
| 658 | } |
| 659 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 660 | function _configure_neutron_l3_agent { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 661 | Q_L3_ENABLED=True |
| 662 | # for l3-agent, only use per tenant router if we have namespaces |
| 663 | Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE |
Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 664 | |
| 665 | AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"} |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 666 | Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini |
| 667 | |
Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 668 | if is_service_enabled q-fwaas; then |
| 669 | Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini |
| 670 | fi |
| 671 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 672 | cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE |
| 673 | |
| 674 | iniset $Q_L3_CONF_FILE DEFAULT verbose True |
Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 675 | iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 676 | iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE |
| 677 | iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" |
| 678 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 679 | _neutron_setup_interface_driver $Q_L3_CONF_FILE |
| 680 | |
| 681 | neutron_plugin_configure_l3_agent |
| 682 | } |
| 683 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 684 | function _configure_neutron_metadata_agent { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 685 | AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent" |
| 686 | Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini |
| 687 | |
| 688 | cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE |
| 689 | |
| 690 | iniset $Q_META_CONF_FILE DEFAULT verbose True |
Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 691 | iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 692 | iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP |
| 693 | iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" |
| 694 | |
Yong Sheng Gong | 8535d8b | 2013-08-25 11:21:13 +0800 | [diff] [blame] | 695 | _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT True True True |
Maru Newby | bf10ac5 | 2013-08-10 21:27:54 +0000 | [diff] [blame] | 696 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 697 | } |
| 698 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 699 | function _configure_neutron_lbaas { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 700 | neutron_agent_lbaas_configure_common |
| 701 | neutron_agent_lbaas_configure_agent |
| 702 | } |
| 703 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 704 | function _configure_neutron_metering { |
Emilien Macchi | 40546f7 | 2013-09-24 15:10:25 +0200 | [diff] [blame] | 705 | neutron_agent_metering_configure_common |
| 706 | neutron_agent_metering_configure_agent |
| 707 | } |
| 708 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 709 | function _configure_neutron_fwaas { |
Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 710 | neutron_fwaas_configure_common |
| 711 | neutron_fwaas_configure_driver |
| 712 | } |
| 713 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 714 | function _configure_neutron_vpn { |
Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 715 | neutron_vpn_install_agent_packages |
| 716 | neutron_vpn_configure_common |
Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 719 | # _configure_neutron_plugin_agent() - Set config files for neutron plugin agent |
| 720 | # It is called when q-agt is enabled. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 721 | function _configure_neutron_plugin_agent { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 722 | # Specify the default root helper prior to agent configuration to |
| 723 | # ensure that an agent's configuration can override the default |
| 724 | iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND" |
| 725 | iniset $NEUTRON_CONF DEFAULT verbose True |
Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 726 | iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 727 | |
| 728 | # Configure agent for plugin |
| 729 | neutron_plugin_configure_plugin_agent |
| 730 | } |
| 731 | |
| 732 | # _configure_neutron_service() - Set config files for neutron service |
| 733 | # It is called when q-svc is enabled. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 734 | function _configure_neutron_service { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 735 | Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini |
| 736 | Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json |
| 737 | |
| 738 | cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE |
| 739 | cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE |
| 740 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 741 | # Update either configuration file with plugin |
| 742 | iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS |
| 743 | |
| 744 | if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then |
| 745 | iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES |
| 746 | fi |
| 747 | |
| 748 | iniset $NEUTRON_CONF DEFAULT verbose True |
Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 749 | iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 750 | iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE |
| 751 | iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP |
| 752 | |
| 753 | iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY |
| 754 | _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken |
| 755 | |
Simon Pasquier | ca96b0a | 2013-07-09 16:59:12 +0200 | [diff] [blame] | 756 | # Define extra "DEFAULT" configuration options when q-svc is configured by |
| 757 | # defining the array ``Q_SRV_EXTRA_DEFAULT_OPTS``. |
| 758 | # For Example: ``Q_SRV_EXTRA_DEFAULT_OPTS=(foo=true bar=2)`` |
| 759 | for I in "${Q_SRV_EXTRA_DEFAULT_OPTS[@]}"; do |
| 760 | # Replace the first '=' with ' ' for iniset syntax |
| 761 | iniset $NEUTRON_CONF DEFAULT ${I/=/ } |
| 762 | done |
| 763 | |
Aaron Rosen | cea32b1 | 2014-03-04 16:20:14 -0800 | [diff] [blame^] | 764 | # Configuration for neutron notifations to nova. |
| 765 | iniset $NEUTRON_CONF DEFAULT notify_nova_port_status_change $Q_NOTIFY_NOVA_PORT_STATUS_CHANGE |
| 766 | iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_ON_PORT_DATA_CHANGES |
| 767 | iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2" |
| 768 | iniset $NEUTRON_CONF DEFAULT nova_admin_username nova $NOVA_USER |
| 769 | iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD |
| 770 | ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }") |
| 771 | iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID |
| 772 | iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0" |
| 773 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 774 | # Configure plugin |
| 775 | neutron_plugin_configure_service |
| 776 | } |
| 777 | |
| 778 | # Utility Functions |
| 779 | #------------------ |
| 780 | |
Isaku Yamahata | 9e136b4 | 2013-12-16 15:52:03 +0900 | [diff] [blame] | 781 | # _neutron_service_plugin_class_add() - add service plugin class |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 782 | function _neutron_service_plugin_class_add { |
Isaku Yamahata | 9e136b4 | 2013-12-16 15:52:03 +0900 | [diff] [blame] | 783 | local service_plugin_class=$1 |
| 784 | if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then |
| 785 | Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class |
| 786 | elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then |
| 787 | Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class" |
| 788 | fi |
| 789 | } |
| 790 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 791 | # _neutron_setup_rootwrap() - configure Neutron's rootwrap |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 792 | function _neutron_setup_rootwrap { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 793 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then |
| 794 | return |
| 795 | fi |
| 796 | # Deploy new rootwrap filters files (owned by root). |
| 797 | # Wipe any existing ``rootwrap.d`` files first |
| 798 | Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d |
| 799 | if [[ -d $Q_CONF_ROOTWRAP_D ]]; then |
| 800 | sudo rm -rf $Q_CONF_ROOTWRAP_D |
| 801 | fi |
| 802 | # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d`` |
| 803 | mkdir -p -m 755 $Q_CONF_ROOTWRAP_D |
| 804 | cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/ |
| 805 | sudo chown -R root:root $Q_CONF_ROOTWRAP_D |
| 806 | sudo chmod 644 $Q_CONF_ROOTWRAP_D/* |
| 807 | # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d`` |
| 808 | # location moved in newer versions, prefer new location |
| 809 | if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then |
Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 810 | 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] | 811 | else |
Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 812 | sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 813 | fi |
| 814 | sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE |
| 815 | sudo chown root:root $Q_RR_CONF_FILE |
| 816 | sudo chmod 0644 $Q_RR_CONF_FILE |
| 817 | # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap |
| 818 | ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *" |
| 819 | |
| 820 | # Set up the rootwrap sudoers for neutron |
| 821 | TEMPFILE=`mktemp` |
Stephan Renatus | e578eff | 2013-11-19 13:31:04 +0100 | [diff] [blame] | 822 | echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 823 | chmod 0440 $TEMPFILE |
| 824 | sudo chown root:root $TEMPFILE |
| 825 | sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap |
| 826 | |
| 827 | # Update the root_helper |
| 828 | iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND" |
| 829 | } |
| 830 | |
| 831 | # Configures keystone integration for neutron service and agents |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 832 | function _neutron_setup_keystone { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 833 | local conf_file=$1 |
| 834 | local section=$2 |
| 835 | local use_auth_url=$3 |
Maru Newby | bf10ac5 | 2013-08-10 21:27:54 +0000 | [diff] [blame] | 836 | local skip_auth_cache=$4 |
Yong Sheng Gong | 8535d8b | 2013-08-25 11:21:13 +0800 | [diff] [blame] | 837 | local use_service_port=$5 |
| 838 | local keystone_port=$KEYSTONE_AUTH_PORT |
| 839 | if [[ -n $use_service_port ]]; then |
| 840 | keystone_port=$KEYSTONE_SERVICE_PORT |
| 841 | fi |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 842 | if [[ -n $use_auth_url ]]; then |
Yong Sheng Gong | 8535d8b | 2013-08-25 11:21:13 +0800 | [diff] [blame] | 843 | iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$keystone_port/v2.0" |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 844 | else |
| 845 | iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST |
Yong Sheng Gong | 8535d8b | 2013-08-25 11:21:13 +0800 | [diff] [blame] | 846 | iniset $conf_file $section auth_port $keystone_port |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 847 | iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL |
| 848 | fi |
| 849 | iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME |
| 850 | iniset $conf_file $section admin_user $Q_ADMIN_USERNAME |
| 851 | iniset $conf_file $section admin_password $SERVICE_PASSWORD |
Maru Newby | bf10ac5 | 2013-08-10 21:27:54 +0000 | [diff] [blame] | 852 | if [[ -z $skip_auth_cache ]]; then |
| 853 | iniset $conf_file $section signing_dir $NEUTRON_AUTH_CACHE_DIR |
| 854 | # Create cache dir |
Emilien Macchi | a677b7f | 2013-11-25 23:40:20 +0100 | [diff] [blame] | 855 | create_neutron_cache_dir |
Maru Newby | bf10ac5 | 2013-08-10 21:27:54 +0000 | [diff] [blame] | 856 | fi |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 857 | } |
| 858 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 859 | function _neutron_setup_interface_driver { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 860 | |
| 861 | # ovs_use_veth needs to be set before the plugin configuration |
| 862 | # occurs to allow plugins to override the setting. |
| 863 | iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH |
| 864 | |
| 865 | neutron_plugin_setup_interface_driver $1 |
| 866 | } |
| 867 | |
| 868 | # Functions for Neutron Exercises |
| 869 | #-------------------------------- |
| 870 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 871 | function delete_probe { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 872 | local from_net="$1" |
| 873 | net_id=`_get_net_id $from_net` |
| 874 | 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}'` |
| 875 | neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id |
| 876 | } |
| 877 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 878 | function setup_neutron_debug { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 879 | if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then |
| 880 | public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME` |
| 881 | neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id |
| 882 | private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME` |
| 883 | neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id |
| 884 | fi |
| 885 | } |
| 886 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 887 | function teardown_neutron_debug { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 888 | delete_probe $PUBLIC_NETWORK_NAME |
| 889 | delete_probe $PRIVATE_NETWORK_NAME |
| 890 | } |
| 891 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 892 | function _get_net_id { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 893 | neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}' |
| 894 | } |
| 895 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 896 | function _get_probe_cmd_prefix { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 897 | local from_net="$1" |
| 898 | net_id=`_get_net_id $from_net` |
| 899 | 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` |
| 900 | echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id" |
| 901 | } |
| 902 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 903 | function _ping_check_neutron { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 904 | local from_net=$1 |
| 905 | local ip=$2 |
| 906 | local timeout_sec=$3 |
| 907 | local expected=${4:-"True"} |
| 908 | local check_command="" |
| 909 | probe_cmd=`_get_probe_cmd_prefix $from_net` |
| 910 | if [[ "$expected" = "True" ]]; then |
| 911 | check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done" |
| 912 | else |
| 913 | check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done" |
| 914 | fi |
| 915 | if ! timeout $timeout_sec sh -c "$check_command"; then |
| 916 | if [[ "$expected" = "True" ]]; then |
| 917 | die $LINENO "[Fail] Couldn't ping server" |
| 918 | else |
| 919 | die $LINENO "[Fail] Could ping server" |
| 920 | fi |
| 921 | fi |
| 922 | } |
| 923 | |
| 924 | # ssh check |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 925 | function _ssh_check_neutron { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 926 | local from_net=$1 |
| 927 | local key_file=$2 |
| 928 | local ip=$3 |
| 929 | local user=$4 |
| 930 | local timeout_sec=$5 |
| 931 | local probe_cmd = "" |
| 932 | probe_cmd=`_get_probe_cmd_prefix $from_net` |
| 933 | 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 |
| 934 | die $LINENO "server didn't become ssh-able!" |
| 935 | fi |
| 936 | } |
| 937 | |
| 938 | # Neutron 3rd party programs |
| 939 | #--------------------------- |
| 940 | |
| 941 | # please refer to ``lib/neutron_thirdparty/README.md`` for details |
| 942 | NEUTRON_THIRD_PARTIES="" |
| 943 | for f in $TOP_DIR/lib/neutron_thirdparty/*; do |
Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 944 | third_party=$(basename $f) |
| 945 | if is_service_enabled $third_party; then |
| 946 | source $TOP_DIR/lib/neutron_thirdparty/$third_party |
| 947 | NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party" |
| 948 | fi |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 949 | done |
| 950 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 951 | function _neutron_third_party_do { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 952 | for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do |
| 953 | ${1}_${third_party} |
| 954 | done |
| 955 | } |
| 956 | |
| 957 | # configure_neutron_third_party() - Set config files, create data dirs, etc |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 958 | function configure_neutron_third_party { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 959 | _neutron_third_party_do configure |
| 960 | } |
| 961 | |
| 962 | # init_neutron_third_party() - Initialize databases, etc. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 963 | function init_neutron_third_party { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 964 | _neutron_third_party_do init |
| 965 | } |
| 966 | |
| 967 | # install_neutron_third_party() - Collect source and prepare |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 968 | function install_neutron_third_party { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 969 | _neutron_third_party_do install |
| 970 | } |
| 971 | |
| 972 | # start_neutron_third_party() - Start running processes, including screen |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 973 | function start_neutron_third_party { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 974 | _neutron_third_party_do start |
| 975 | } |
| 976 | |
| 977 | # stop_neutron_third_party - Stop running processes (non-screen) |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 978 | function stop_neutron_third_party { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 979 | _neutron_third_party_do stop |
| 980 | } |
| 981 | |
armando-migliaccio | ef1e080 | 2014-01-02 16:33:53 -0800 | [diff] [blame] | 982 | # check_neutron_third_party_integration() - Check that third party integration is sane |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 983 | function check_neutron_third_party_integration { |
armando-migliaccio | ef1e080 | 2014-01-02 16:33:53 -0800 | [diff] [blame] | 984 | _neutron_third_party_do check |
| 985 | } |
| 986 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 987 | |
| 988 | # Restore xtrace |
| 989 | $XTRACE |
| 990 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 991 | # Tell emacs to use shell-script-mode |
| 992 | ## Local variables: |
| 993 | ## mode: shell-script |
| 994 | ## End: |