Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1 | # lib/neutron |
| 2 | # functions - funstions specific to neutron |
| 3 | |
| 4 | # Dependencies: |
| 5 | # ``functions`` file |
| 6 | # ``DEST`` must be defined |
| 7 | |
| 8 | # ``stack.sh`` calls the entry points in this order: |
| 9 | # |
| 10 | # install_neutron |
| 11 | # install_neutronclient |
| 12 | # install_neutron_agent_packages |
| 13 | # install_neutron_third_party |
| 14 | # configure_neutron |
| 15 | # init_neutron |
| 16 | # configure_neutron_third_party |
| 17 | # init_neutron_third_party |
| 18 | # start_neutron_third_party |
| 19 | # create_nova_conf_neutron |
| 20 | # start_neutron_service_and_check |
| 21 | # create_neutron_initial_network |
| 22 | # setup_neutron_debug |
| 23 | # start_neutron_agents |
| 24 | # |
| 25 | # ``unstack.sh`` calls the entry points in this order: |
| 26 | # |
| 27 | # stop_neutron |
| 28 | |
| 29 | # Functions in lib/neutron are classified into the following categories: |
| 30 | # |
| 31 | # - entry points (called from stack.sh or unstack.sh) |
| 32 | # - internal functions |
| 33 | # - neutron exercises |
| 34 | # - 3rd party programs |
| 35 | |
| 36 | |
| 37 | # Neutron Networking |
| 38 | # ------------------ |
| 39 | |
| 40 | # Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want |
| 41 | # to run Neutron on this host, make sure that q-svc is also in |
| 42 | # ``ENABLED_SERVICES``. |
| 43 | # |
| 44 | # If you're planning to use the Neutron openvswitch plugin, set |
| 45 | # ``Q_PLUGIN`` to "openvswitch" and make sure the q-agt service is enabled |
| 46 | # in ``ENABLED_SERVICES``. If you're planning to use the Neutron |
| 47 | # linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the |
| 48 | # q-agt service is enabled in ``ENABLED_SERVICES``. |
| 49 | # |
| 50 | # See "Neutron Network Configuration" below for additional variables |
| 51 | # that must be set in localrc for connectivity across hosts with |
| 52 | # Neutron. |
| 53 | # |
| 54 | # With Neutron networking the NETWORK_MANAGER variable is ignored. |
| 55 | # |
| 56 | # To enable specific configuration options for either the Open vSwitch or |
| 57 | # LinuxBridge plugin, please see the top level README file under the |
| 58 | # Neutron section. |
| 59 | |
| 60 | # Save trace setting |
| 61 | XTRACE=$(set +o | grep xtrace) |
| 62 | set +o xtrace |
| 63 | |
| 64 | |
| 65 | # Neutron Network Configuration |
| 66 | # ----------------------------- |
| 67 | |
| 68 | # Gateway and subnet defaults, in case they are not customized in localrc |
| 69 | NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1} |
| 70 | PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.225} |
| 71 | PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"} |
| 72 | PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"} |
| 73 | |
| 74 | # Set up default directories |
| 75 | NEUTRON_DIR=$DEST/neutron |
| 76 | NEUTRONCLIENT_DIR=$DEST/python-neutronclient |
| 77 | NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron} |
| 78 | |
| 79 | # Support entry points installation of console scripts |
| 80 | if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then |
| 81 | NEUTRON_BIN_DIR=$NEUTRON_DIR/bin |
| 82 | else |
| 83 | NEUTRON_BIN_DIR=$(get_python_exec_prefix) |
| 84 | fi |
| 85 | |
| 86 | NEUTRON_CONF_DIR=/etc/neutron |
| 87 | NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf |
| 88 | export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"} |
| 89 | |
| 90 | # Default Neutron Plugin |
| 91 | Q_PLUGIN=${Q_PLUGIN:-openvswitch} |
| 92 | # Default Neutron Port |
| 93 | Q_PORT=${Q_PORT:-9696} |
| 94 | # Default Neutron Host |
| 95 | Q_HOST=${Q_HOST:-$SERVICE_HOST} |
| 96 | # Default admin username |
| 97 | Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron} |
| 98 | # Default auth strategy |
| 99 | Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone} |
| 100 | # Use namespace or not |
| 101 | Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True} |
| 102 | # RHEL's support for namespaces requires using veths with ovs |
| 103 | Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False} |
| 104 | Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True} |
| 105 | # Meta data IP |
| 106 | Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST} |
| 107 | # Allow Overlapping IP among subnets |
| 108 | Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True} |
| 109 | # Use neutron-debug command |
| 110 | Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False} |
| 111 | # The name of the default q-l3 router |
| 112 | Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1} |
| 113 | # List of config file names in addition to the main plugin config file |
| 114 | # See _configure_neutron_common() for details about setting it up |
| 115 | declare -a Q_PLUGIN_EXTRA_CONF_FILES |
| 116 | |
| 117 | if is_service_enabled neutron; then |
| 118 | Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf |
| 119 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then |
| 120 | Q_RR_COMMAND="sudo" |
| 121 | else |
| 122 | NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron) |
| 123 | Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE" |
| 124 | fi |
| 125 | |
| 126 | # Provider Network Configurations |
| 127 | # -------------------------------- |
| 128 | |
| 129 | # The following variables control the Neutron openvswitch and |
| 130 | # linuxbridge plugins' allocation of tenant networks and |
| 131 | # availability of provider networks. If these are not configured |
| 132 | # in ``localrc``, tenant networks will be local to the host (with no |
| 133 | # remote connectivity), and no physical resources will be |
| 134 | # available for the allocation of provider networks. |
| 135 | |
| 136 | # To use GRE tunnels for tenant networks, set to True in |
| 137 | # ``localrc``. GRE tunnels are only supported by the openvswitch |
| 138 | # plugin, and currently only on Ubuntu. |
| 139 | ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False} |
| 140 | |
| 141 | # If using GRE tunnels for tenant networks, specify the range of |
| 142 | # tunnel IDs from which tenant networks are allocated. Can be |
| 143 | # overriden in ``localrc`` in necesssary. |
| 144 | TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGE:-1:1000} |
| 145 | |
| 146 | # To use VLANs for tenant networks, set to True in localrc. VLANs |
| 147 | # are supported by the openvswitch and linuxbridge plugins, each |
| 148 | # requiring additional configuration described below. |
| 149 | ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False} |
| 150 | |
| 151 | # If using VLANs for tenant networks, set in ``localrc`` to specify |
| 152 | # the range of VLAN VIDs from which tenant networks are |
| 153 | # allocated. An external network switch must be configured to |
| 154 | # trunk these VLANs between hosts for multi-host connectivity. |
| 155 | # |
| 156 | # Example: ``TENANT_VLAN_RANGE=1000:1999`` |
| 157 | TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-} |
| 158 | |
| 159 | # If using VLANs for tenant networks, or if using flat or VLAN |
| 160 | # provider networks, set in ``localrc`` to the name of the physical |
| 161 | # network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the |
| 162 | # openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge |
| 163 | # agent, as described below. |
| 164 | # |
| 165 | # Example: ``PHYSICAL_NETWORK=default`` |
| 166 | PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-} |
| 167 | |
| 168 | # With the openvswitch plugin, if using VLANs for tenant networks, |
| 169 | # or if using flat or VLAN provider networks, set in ``localrc`` to |
| 170 | # the name of the OVS bridge to use for the physical network. The |
| 171 | # bridge will be created if it does not already exist, but a |
| 172 | # physical interface must be manually added to the bridge as a |
| 173 | # port for external connectivity. |
| 174 | # |
| 175 | # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1`` |
| 176 | OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-} |
| 177 | |
| 178 | # With the linuxbridge plugin, if using VLANs for tenant networks, |
| 179 | # or if using flat or VLAN provider networks, set in ``localrc`` to |
| 180 | # the name of the network interface to use for the physical |
| 181 | # network. |
| 182 | # |
| 183 | # Example: ``LB_PHYSICAL_INTERFACE=eth1`` |
| 184 | LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-} |
| 185 | |
| 186 | # With the openvswitch plugin, set to True in ``localrc`` to enable |
| 187 | # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False. |
| 188 | # |
| 189 | # Example: ``OVS_ENABLE_TUNNELING=True`` |
| 190 | OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS} |
| 191 | fi |
| 192 | |
| 193 | # Neutron plugin specific functions |
| 194 | # --------------------------------- |
| 195 | |
| 196 | # Please refer to ``lib/neutron_plugins/README.md`` for details. |
| 197 | source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN |
| 198 | |
| 199 | # Agent loadbalancer service plugin functions |
| 200 | # ------------------------------------------- |
| 201 | |
| 202 | # Hardcoding for 1 service plugin for now |
| 203 | source $TOP_DIR/lib/neutron_plugins/services/loadbalancer |
| 204 | |
Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 205 | # VPN service plugin functions |
| 206 | # ------------------------------------------- |
| 207 | # Hardcoding for 1 service plugin for now |
| 208 | source $TOP_DIR/lib/neutron_plugins/services/vpn |
| 209 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 210 | # Use security group or not |
| 211 | if has_neutron_plugin_security_group; then |
| 212 | Q_USE_SECGROUP=${Q_USE_SECGROUP:-True} |
| 213 | else |
| 214 | Q_USE_SECGROUP=False |
| 215 | fi |
| 216 | |
| 217 | # Functions |
| 218 | # --------- |
| 219 | |
| 220 | # configure_neutron() |
| 221 | # Set common config for all neutron server and agents. |
| 222 | function configure_neutron() { |
| 223 | _configure_neutron_common |
| 224 | iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT |
| 225 | |
| 226 | # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES |
| 227 | if is_service_enabled q-lbaas; then |
| 228 | _configure_neutron_lbaas |
| 229 | fi |
Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 230 | if is_service_enabled q-vpn; then |
| 231 | _configure_neutron_vpn |
| 232 | fi |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 233 | if is_service_enabled q-svc; then |
| 234 | _configure_neutron_service |
| 235 | fi |
| 236 | if is_service_enabled q-agt; then |
| 237 | _configure_neutron_plugin_agent |
| 238 | fi |
| 239 | if is_service_enabled q-dhcp; then |
| 240 | _configure_neutron_dhcp_agent |
| 241 | fi |
| 242 | if is_service_enabled q-l3; then |
| 243 | _configure_neutron_l3_agent |
| 244 | fi |
| 245 | if is_service_enabled q-meta; then |
| 246 | _configure_neutron_metadata_agent |
| 247 | fi |
| 248 | |
| 249 | _configure_neutron_debug_command |
| 250 | } |
| 251 | |
| 252 | function create_nova_conf_neutron() { |
| 253 | iniset $NOVA_CONF DEFAULT network_api_class "nova.network.quantumv2.api.API" |
| 254 | iniset $NOVA_CONF DEFAULT quantum_admin_username "$Q_ADMIN_USERNAME" |
| 255 | iniset $NOVA_CONF DEFAULT quantum_admin_password "$SERVICE_PASSWORD" |
| 256 | iniset $NOVA_CONF DEFAULT quantum_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0" |
| 257 | iniset $NOVA_CONF DEFAULT quantum_auth_strategy "$Q_AUTH_STRATEGY" |
| 258 | iniset $NOVA_CONF DEFAULT quantum_admin_tenant_name "$SERVICE_TENANT_NAME" |
Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 259 | iniset $NOVA_CONF DEFAULT quantum_region_name "RegionOne" |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 260 | iniset $NOVA_CONF DEFAULT quantum_url "http://$Q_HOST:$Q_PORT" |
| 261 | |
| 262 | if [[ "$Q_USE_SECGROUP" == "True" ]]; then |
| 263 | LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver |
| 264 | iniset $NOVA_CONF DEFAULT security_group_api quantum |
| 265 | fi |
| 266 | |
| 267 | # set NOVA_VIF_DRIVER and optionally set options in nova_conf |
| 268 | neutron_plugin_create_nova_conf |
| 269 | |
| 270 | iniset $NOVA_CONF DEFAULT libvirt_vif_driver "$NOVA_VIF_DRIVER" |
| 271 | iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER" |
| 272 | if is_service_enabled q-meta; then |
| 273 | iniset $NOVA_CONF DEFAULT service_quantum_metadata_proxy "True" |
| 274 | fi |
| 275 | } |
| 276 | |
| 277 | # create_neutron_accounts() - Set up common required neutron accounts |
| 278 | |
| 279 | # Tenant User Roles |
| 280 | # ------------------------------------------------------------------ |
| 281 | # service neutron admin # if enabled |
| 282 | |
| 283 | # Migrated from keystone_data.sh |
| 284 | function create_neutron_accounts() { |
| 285 | |
| 286 | SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 287 | ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }") |
| 288 | |
| 289 | if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then |
| 290 | NEUTRON_USER=$(keystone user-create \ |
| 291 | --name=neutron \ |
| 292 | --pass="$SERVICE_PASSWORD" \ |
| 293 | --tenant_id $SERVICE_TENANT \ |
| 294 | --email=neutron@example.com \ |
| 295 | | grep " id " | get_field 2) |
| 296 | keystone user-role-add \ |
| 297 | --tenant_id $SERVICE_TENANT \ |
| 298 | --user_id $NEUTRON_USER \ |
| 299 | --role_id $ADMIN_ROLE |
| 300 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 301 | NEUTRON_SERVICE=$(keystone service-create \ |
| 302 | --name=neutron \ |
| 303 | --type=network \ |
| 304 | --description="Neutron Service" \ |
| 305 | | grep " id " | get_field 2) |
| 306 | keystone endpoint-create \ |
| 307 | --region RegionOne \ |
| 308 | --service_id $NEUTRON_SERVICE \ |
| 309 | --publicurl "http://$SERVICE_HOST:9696/" \ |
| 310 | --adminurl "http://$SERVICE_HOST:9696/" \ |
| 311 | --internalurl "http://$SERVICE_HOST:9696/" |
| 312 | fi |
| 313 | fi |
| 314 | } |
| 315 | |
| 316 | function create_neutron_initial_network() { |
| 317 | TENANT_ID=$(keystone tenant-list | grep " demo " | get_field 1) |
| 318 | |
| 319 | # Create a small network |
| 320 | # Since neutron command is executed in admin context at this point, |
| 321 | # ``--tenant_id`` needs to be specified. |
| 322 | if is_baremetal; then |
| 323 | sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE |
| 324 | for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do |
| 325 | sudo ip addr del $IP dev $PUBLIC_INTERFACE |
| 326 | sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE |
| 327 | done |
| 328 | 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) |
| 329 | 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) |
| 330 | sudo ifconfig $OVS_PHYSICAL_BRIDGE up |
| 331 | else |
| 332 | NET_ID=$(neutron net-create --tenant_id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2) |
| 333 | 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) |
| 334 | fi |
| 335 | |
| 336 | if [[ "$Q_L3_ENABLED" == "True" ]]; then |
| 337 | # Create a router, and add the private subnet as one of its interfaces |
| 338 | if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then |
| 339 | # create a tenant-owned router. |
| 340 | ROUTER_ID=$(neutron router-create --tenant_id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2) |
| 341 | else |
| 342 | # Plugin only supports creating a single router, which should be admin owned. |
| 343 | ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2) |
| 344 | fi |
| 345 | neutron router-interface-add $ROUTER_ID $SUBNET_ID |
| 346 | # Create an external network, and a subnet. Configure the external network as router gw |
| 347 | EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2) |
| 348 | 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) |
| 349 | neutron router-gateway-set $ROUTER_ID $EXT_NET_ID |
| 350 | |
| 351 | if is_service_enabled q-l3; then |
| 352 | # logic is specific to using the l3-agent for l3 |
| 353 | if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then |
| 354 | CIDR_LEN=${FLOATING_RANGE#*/} |
| 355 | sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE |
| 356 | sudo ip link set $PUBLIC_BRIDGE up |
| 357 | ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'` |
| 358 | sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP |
| 359 | fi |
| 360 | if [[ "$Q_USE_NAMESPACE" == "False" ]]; then |
| 361 | # Explicitly set router id in l3 agent configuration |
| 362 | iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID |
| 363 | fi |
| 364 | fi |
| 365 | fi |
| 366 | } |
| 367 | |
| 368 | # init_neutron() - Initialize databases, etc. |
| 369 | function init_neutron() { |
Salvatore Orlando | dd64988 | 2013-08-05 08:56:17 -0700 | [diff] [blame] | 370 | recreate_database $Q_DB_NAME utf8 |
| 371 | # Run Neutron db migrations |
| 372 | $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] | 373 | } |
| 374 | |
| 375 | # install_neutron() - Collect source and prepare |
| 376 | function install_neutron() { |
| 377 | git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH |
| 378 | setup_develop $NEUTRON_DIR |
| 379 | } |
| 380 | |
| 381 | # install_neutronclient() - Collect source and prepare |
| 382 | function install_neutronclient() { |
| 383 | git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH |
| 384 | setup_develop $NEUTRONCLIENT_DIR |
| 385 | } |
| 386 | |
| 387 | # install_neutron_agent_packages() - Collect source and prepare |
| 388 | function install_neutron_agent_packages() { |
| 389 | # install packages that are specific to plugin agent(s) |
| 390 | if is_service_enabled q-agt q-dhcp q-l3; then |
| 391 | neutron_plugin_install_agent_packages |
| 392 | fi |
| 393 | |
| 394 | if is_service_enabled q-lbaas; then |
| 395 | neutron_agent_lbaas_install_agent_packages |
| 396 | fi |
| 397 | } |
| 398 | |
| 399 | # Start running processes, including screen |
| 400 | function start_neutron_service_and_check() { |
| 401 | # build config-file options |
| 402 | local cfg_file |
| 403 | local CFG_FILE_OPTIONS="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE" |
| 404 | for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do |
| 405 | CFG_FILE_OPTIONS+=" --config-file /$cfg_file" |
| 406 | done |
| 407 | # Start the Neutron service |
| 408 | screen_it q-svc "cd $NEUTRON_DIR && python $NEUTRON_BIN_DIR/neutron-server $CFG_FILE_OPTIONS" |
| 409 | echo "Waiting for Neutron to start..." |
| 410 | if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then |
| 411 | die $LINENO "Neutron did not start" |
| 412 | fi |
| 413 | } |
| 414 | |
| 415 | # Start running processes, including screen |
| 416 | function start_neutron_agents() { |
| 417 | # Start up the neutron agents if enabled |
| 418 | screen_it q-agt "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE" |
| 419 | 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] | 420 | |
| 421 | if is_service_enabled q-vpn; then |
| 422 | screen_it q-vpn "cd $NEUTRON_DIR && $AGENT_VPN_BINARY --config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE" |
| 423 | else |
| 424 | screen_it q-l3 "cd $NEUTRON_DIR && python $AGENT_L3_BINARY --config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE" |
| 425 | fi |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 426 | screen_it q-meta "cd $NEUTRON_DIR && python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE" |
| 427 | |
| 428 | if [ "$VIRT_DRIVER" = 'xenserver' ]; then |
| 429 | # For XenServer, start an agent for the domU openvswitch |
| 430 | screen_it q-domua "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU" |
| 431 | fi |
| 432 | |
| 433 | if is_service_enabled q-lbaas; then |
| 434 | screen_it q-lbaas "cd $NEUTRON_DIR && python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME" |
| 435 | fi |
| 436 | } |
| 437 | |
| 438 | # stop_neutron() - Stop running processes (non-screen) |
| 439 | function stop_neutron() { |
| 440 | if is_service_enabled q-dhcp; then |
| 441 | pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }') |
| 442 | [ ! -z "$pid" ] && sudo kill -9 $pid |
| 443 | fi |
| 444 | if is_service_enabled q-meta; then |
| 445 | pid=$(ps aux | awk '/neutron-ns-metadata-proxy/ { print $2 }') |
| 446 | [ ! -z "$pid" ] && sudo kill -9 $pid |
| 447 | fi |
| 448 | } |
| 449 | |
| 450 | # cleanup_neutron() - Remove residual data files, anything left over from previous |
| 451 | # runs that a clean run would need to clean up |
| 452 | function cleanup_neutron() { |
| 453 | if is_neutron_ovs_base_plugin; then |
| 454 | neutron_ovs_base_cleanup |
| 455 | fi |
| 456 | |
| 457 | # delete all namespaces created by neutron |
| 458 | for ns in $(sudo ip netns list | grep -o -e qdhcp-[0-9a-f\-]* -e qrouter-[0-9a-f\-]*); do |
| 459 | sudo ip netns delete ${ns} |
| 460 | done |
| 461 | } |
| 462 | |
| 463 | # _configure_neutron_common() |
| 464 | # Set common config for all neutron server and agents. |
| 465 | # This MUST be called before other ``_configure_neutron_*`` functions. |
| 466 | function _configure_neutron_common() { |
| 467 | # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find |
| 468 | if [[ ! -d $NEUTRON_CONF_DIR ]]; then |
| 469 | sudo mkdir -p $NEUTRON_CONF_DIR |
| 470 | fi |
| 471 | sudo chown $STACK_USER $NEUTRON_CONF_DIR |
| 472 | |
| 473 | cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF |
| 474 | |
| 475 | # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``. |
| 476 | # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``. |
| 477 | # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``, |
| 478 | # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example: |
| 479 | # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)`` |
| 480 | neutron_plugin_configure_common |
| 481 | |
| 482 | if [[ $Q_PLUGIN_CONF_PATH == '' || $Q_PLUGIN_CONF_FILENAME == '' || $Q_PLUGIN_CLASS == '' ]]; then |
| 483 | die $LINENO "Neutron plugin not set.. exiting" |
| 484 | fi |
| 485 | |
| 486 | # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR`` |
| 487 | mkdir -p /$Q_PLUGIN_CONF_PATH |
| 488 | Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME |
| 489 | cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE |
| 490 | |
| 491 | iniset /$Q_PLUGIN_CONF_FILE database connection `database_connection_url $Q_DB_NAME` |
| 492 | iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron |
| 493 | |
| 494 | # If addition config files are set, make sure their path name is set as well |
| 495 | if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then |
| 496 | die $LINENO "Neutron additional plugin config not set.. exiting" |
| 497 | fi |
| 498 | |
| 499 | # If additional config files exist, copy them over to neutron configuration |
| 500 | # directory |
| 501 | if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then |
| 502 | mkdir -p /$Q_PLUGIN_EXTRA_CONF_PATH |
| 503 | local f |
| 504 | for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do |
| 505 | Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]} |
| 506 | cp $NEUTRON_DIR/${Q_PLUGIN_EXTRA_CONF_FILES[$f]} /${Q_PLUGIN_EXTRA_CONF_FILES[$f]} |
| 507 | done |
| 508 | fi |
| 509 | |
Joe Gordon | bee5c50 | 2013-08-30 13:48:08 -0400 | [diff] [blame^] | 510 | if [ "$VIRT_DRIVER" = 'fake' ]; then |
| 511 | # Disable arbitrary limits |
| 512 | iniset $NEUTRON_CONF quotas quota_network -1 |
| 513 | iniset $NEUTRON_CONF quotas quota_subnet -1 |
| 514 | iniset $NEUTRON_CONF quotas quota_port -1 |
| 515 | iniset $NEUTRON_CONF quotas quota_security_group -1 |
| 516 | iniset $NEUTRON_CONF quotas quota_security_group_rule -1 |
| 517 | fi |
| 518 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 519 | _neutron_setup_rootwrap |
| 520 | } |
| 521 | |
| 522 | function _configure_neutron_debug_command() { |
| 523 | if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then |
| 524 | return |
| 525 | fi |
| 526 | |
| 527 | cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE |
| 528 | |
| 529 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False |
| 530 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False |
| 531 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE |
| 532 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT root_helper "$Q_RR_COMMAND" |
| 533 | # Intermediate fix until Neutron patch lands and then line above will |
| 534 | # be cleaned. |
| 535 | iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND" |
| 536 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 537 | _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE |
| 538 | |
| 539 | neutron_plugin_configure_debug_command |
| 540 | } |
| 541 | |
| 542 | function _configure_neutron_dhcp_agent() { |
| 543 | AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent" |
| 544 | Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini |
| 545 | |
| 546 | cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE |
| 547 | |
| 548 | iniset $Q_DHCP_CONF_FILE DEFAULT verbose True |
Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 549 | iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 550 | iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE |
| 551 | iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" |
| 552 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 553 | _neutron_setup_interface_driver $Q_DHCP_CONF_FILE |
| 554 | |
| 555 | neutron_plugin_configure_dhcp_agent |
| 556 | } |
| 557 | |
| 558 | function _configure_neutron_l3_agent() { |
| 559 | Q_L3_ENABLED=True |
| 560 | # for l3-agent, only use per tenant router if we have namespaces |
| 561 | Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE |
Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 562 | |
| 563 | AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"} |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 564 | Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini |
| 565 | |
| 566 | cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE |
| 567 | |
| 568 | iniset $Q_L3_CONF_FILE DEFAULT verbose True |
Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 569 | iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 570 | iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE |
| 571 | iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" |
| 572 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 573 | _neutron_setup_interface_driver $Q_L3_CONF_FILE |
| 574 | |
| 575 | neutron_plugin_configure_l3_agent |
| 576 | } |
| 577 | |
| 578 | function _configure_neutron_metadata_agent() { |
| 579 | AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent" |
| 580 | Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini |
| 581 | |
| 582 | cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE |
| 583 | |
| 584 | iniset $Q_META_CONF_FILE DEFAULT verbose True |
Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 585 | iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 586 | iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP |
| 587 | iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" |
| 588 | |
Maru Newby | bf10ac5 | 2013-08-10 21:27:54 +0000 | [diff] [blame] | 589 | _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT True True |
| 590 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | function _configure_neutron_lbaas() { |
| 594 | neutron_agent_lbaas_configure_common |
| 595 | neutron_agent_lbaas_configure_agent |
| 596 | } |
| 597 | |
Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 598 | function _configure_neutron_vpn() |
| 599 | { |
| 600 | neutron_vpn_install_agent_packages |
| 601 | neutron_vpn_configure_common |
Nachi Ueno | 69b3ff6 | 2013-06-07 10:28:33 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 604 | # _configure_neutron_plugin_agent() - Set config files for neutron plugin agent |
| 605 | # It is called when q-agt is enabled. |
| 606 | function _configure_neutron_plugin_agent() { |
| 607 | # Specify the default root helper prior to agent configuration to |
| 608 | # ensure that an agent's configuration can override the default |
| 609 | iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND" |
| 610 | iniset $NEUTRON_CONF DEFAULT verbose True |
Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 611 | iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 612 | |
| 613 | # Configure agent for plugin |
| 614 | neutron_plugin_configure_plugin_agent |
| 615 | } |
| 616 | |
| 617 | # _configure_neutron_service() - Set config files for neutron service |
| 618 | # It is called when q-svc is enabled. |
| 619 | function _configure_neutron_service() { |
| 620 | Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini |
| 621 | Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json |
| 622 | |
| 623 | cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE |
| 624 | cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE |
| 625 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 626 | # Update either configuration file with plugin |
| 627 | iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS |
| 628 | |
| 629 | if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then |
| 630 | iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES |
| 631 | fi |
| 632 | |
| 633 | iniset $NEUTRON_CONF DEFAULT verbose True |
Ben Nemec | 0399794 | 2013-08-10 09:56:16 -0500 | [diff] [blame] | 634 | iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 635 | iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE |
| 636 | iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP |
| 637 | |
| 638 | iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY |
| 639 | _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken |
| 640 | |
Simon Pasquier | ca96b0a | 2013-07-09 16:59:12 +0200 | [diff] [blame] | 641 | # Define extra "DEFAULT" configuration options when q-svc is configured by |
| 642 | # defining the array ``Q_SRV_EXTRA_DEFAULT_OPTS``. |
| 643 | # For Example: ``Q_SRV_EXTRA_DEFAULT_OPTS=(foo=true bar=2)`` |
| 644 | for I in "${Q_SRV_EXTRA_DEFAULT_OPTS[@]}"; do |
| 645 | # Replace the first '=' with ' ' for iniset syntax |
| 646 | iniset $NEUTRON_CONF DEFAULT ${I/=/ } |
| 647 | done |
| 648 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 649 | # Configure plugin |
| 650 | neutron_plugin_configure_service |
| 651 | } |
| 652 | |
| 653 | # Utility Functions |
| 654 | #------------------ |
| 655 | |
| 656 | # _neutron_setup_rootwrap() - configure Neutron's rootwrap |
| 657 | function _neutron_setup_rootwrap() { |
| 658 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then |
| 659 | return |
| 660 | fi |
| 661 | # Deploy new rootwrap filters files (owned by root). |
| 662 | # Wipe any existing ``rootwrap.d`` files first |
| 663 | Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d |
| 664 | if [[ -d $Q_CONF_ROOTWRAP_D ]]; then |
| 665 | sudo rm -rf $Q_CONF_ROOTWRAP_D |
| 666 | fi |
| 667 | # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d`` |
| 668 | mkdir -p -m 755 $Q_CONF_ROOTWRAP_D |
| 669 | cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/ |
| 670 | sudo chown -R root:root $Q_CONF_ROOTWRAP_D |
| 671 | sudo chmod 644 $Q_CONF_ROOTWRAP_D/* |
| 672 | # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d`` |
| 673 | # location moved in newer versions, prefer new location |
| 674 | if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then |
| 675 | sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE |
| 676 | else |
| 677 | sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE |
| 678 | fi |
| 679 | sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE |
| 680 | sudo chown root:root $Q_RR_CONF_FILE |
| 681 | sudo chmod 0644 $Q_RR_CONF_FILE |
| 682 | # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap |
| 683 | ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *" |
| 684 | |
| 685 | # Set up the rootwrap sudoers for neutron |
| 686 | TEMPFILE=`mktemp` |
| 687 | echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE |
| 688 | chmod 0440 $TEMPFILE |
| 689 | sudo chown root:root $TEMPFILE |
| 690 | sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap |
| 691 | |
| 692 | # Update the root_helper |
| 693 | iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND" |
| 694 | } |
| 695 | |
| 696 | # Configures keystone integration for neutron service and agents |
| 697 | function _neutron_setup_keystone() { |
| 698 | local conf_file=$1 |
| 699 | local section=$2 |
| 700 | local use_auth_url=$3 |
Maru Newby | bf10ac5 | 2013-08-10 21:27:54 +0000 | [diff] [blame] | 701 | local skip_auth_cache=$4 |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 702 | if [[ -n $use_auth_url ]]; then |
| 703 | iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0" |
| 704 | else |
| 705 | iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST |
| 706 | iniset $conf_file $section auth_port $KEYSTONE_AUTH_PORT |
| 707 | iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL |
| 708 | fi |
| 709 | iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME |
| 710 | iniset $conf_file $section admin_user $Q_ADMIN_USERNAME |
| 711 | iniset $conf_file $section admin_password $SERVICE_PASSWORD |
Maru Newby | bf10ac5 | 2013-08-10 21:27:54 +0000 | [diff] [blame] | 712 | if [[ -z $skip_auth_cache ]]; then |
| 713 | iniset $conf_file $section signing_dir $NEUTRON_AUTH_CACHE_DIR |
| 714 | # Create cache dir |
| 715 | sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR |
| 716 | sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR |
| 717 | rm -f $NEUTRON_AUTH_CACHE_DIR/* |
| 718 | fi |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | function _neutron_setup_interface_driver() { |
| 722 | |
| 723 | # ovs_use_veth needs to be set before the plugin configuration |
| 724 | # occurs to allow plugins to override the setting. |
| 725 | iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH |
| 726 | |
| 727 | neutron_plugin_setup_interface_driver $1 |
| 728 | } |
| 729 | |
| 730 | # Functions for Neutron Exercises |
| 731 | #-------------------------------- |
| 732 | |
| 733 | function delete_probe() { |
| 734 | local from_net="$1" |
| 735 | net_id=`_get_net_id $from_net` |
| 736 | 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}'` |
| 737 | neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id |
| 738 | } |
| 739 | |
| 740 | function setup_neutron_debug() { |
| 741 | if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then |
| 742 | public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME` |
| 743 | neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id |
| 744 | private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME` |
| 745 | neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id |
| 746 | fi |
| 747 | } |
| 748 | |
| 749 | function teardown_neutron_debug() { |
| 750 | delete_probe $PUBLIC_NETWORK_NAME |
| 751 | delete_probe $PRIVATE_NETWORK_NAME |
| 752 | } |
| 753 | |
| 754 | function _get_net_id() { |
| 755 | neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}' |
| 756 | } |
| 757 | |
| 758 | function _get_probe_cmd_prefix() { |
| 759 | local from_net="$1" |
| 760 | net_id=`_get_net_id $from_net` |
| 761 | 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` |
| 762 | echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id" |
| 763 | } |
| 764 | |
| 765 | function _ping_check_neutron() { |
| 766 | local from_net=$1 |
| 767 | local ip=$2 |
| 768 | local timeout_sec=$3 |
| 769 | local expected=${4:-"True"} |
| 770 | local check_command="" |
| 771 | probe_cmd=`_get_probe_cmd_prefix $from_net` |
| 772 | if [[ "$expected" = "True" ]]; then |
| 773 | check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done" |
| 774 | else |
| 775 | check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done" |
| 776 | fi |
| 777 | if ! timeout $timeout_sec sh -c "$check_command"; then |
| 778 | if [[ "$expected" = "True" ]]; then |
| 779 | die $LINENO "[Fail] Couldn't ping server" |
| 780 | else |
| 781 | die $LINENO "[Fail] Could ping server" |
| 782 | fi |
| 783 | fi |
| 784 | } |
| 785 | |
| 786 | # ssh check |
| 787 | function _ssh_check_neutron() { |
| 788 | local from_net=$1 |
| 789 | local key_file=$2 |
| 790 | local ip=$3 |
| 791 | local user=$4 |
| 792 | local timeout_sec=$5 |
| 793 | local probe_cmd = "" |
| 794 | probe_cmd=`_get_probe_cmd_prefix $from_net` |
| 795 | 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 |
| 796 | die $LINENO "server didn't become ssh-able!" |
| 797 | fi |
| 798 | } |
| 799 | |
| 800 | # Neutron 3rd party programs |
| 801 | #--------------------------- |
| 802 | |
| 803 | # please refer to ``lib/neutron_thirdparty/README.md`` for details |
| 804 | NEUTRON_THIRD_PARTIES="" |
| 805 | for f in $TOP_DIR/lib/neutron_thirdparty/*; do |
| 806 | third_party=$(basename $f) |
| 807 | if is_service_enabled $third_party; then |
| 808 | source $TOP_DIR/lib/neutron_thirdparty/$third_party |
| 809 | NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party" |
| 810 | fi |
| 811 | done |
| 812 | |
| 813 | function _neutron_third_party_do() { |
| 814 | for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do |
| 815 | ${1}_${third_party} |
| 816 | done |
| 817 | } |
| 818 | |
| 819 | # configure_neutron_third_party() - Set config files, create data dirs, etc |
| 820 | function configure_neutron_third_party() { |
| 821 | _neutron_third_party_do configure |
| 822 | } |
| 823 | |
| 824 | # init_neutron_third_party() - Initialize databases, etc. |
| 825 | function init_neutron_third_party() { |
| 826 | _neutron_third_party_do init |
| 827 | } |
| 828 | |
| 829 | # install_neutron_third_party() - Collect source and prepare |
| 830 | function install_neutron_third_party() { |
| 831 | _neutron_third_party_do install |
| 832 | } |
| 833 | |
| 834 | # start_neutron_third_party() - Start running processes, including screen |
| 835 | function start_neutron_third_party() { |
| 836 | _neutron_third_party_do start |
| 837 | } |
| 838 | |
| 839 | # stop_neutron_third_party - Stop running processes (non-screen) |
| 840 | function stop_neutron_third_party() { |
| 841 | _neutron_third_party_do stop |
| 842 | } |
| 843 | |
| 844 | |
| 845 | # Restore xtrace |
| 846 | $XTRACE |
| 847 | |
| 848 | # Local variables: |
| 849 | # mode: shell-script |
| 850 | # End: |