lib/neutron
b05c8769
 # lib/neutron
2394605a
 # functions - functions specific to neutron
d6767d0d
 
60e9c0ab
 # Dependencies:
 # ``functions`` file
 # ``DEST`` must be defined
e578effb
 # ``STACK_USER`` must be defined
60e9c0ab
 
66afb47c
 # ``stack.sh`` calls the entry points in this order:
 #
6a5aa7c6
 # - install_neutron
 # - install_neutronclient
 # - install_neutron_agent_packages
 # - install_neutron_third_party
 # - configure_neutron
 # - init_neutron
 # - configure_neutron_third_party
 # - init_neutron_third_party
 # - start_neutron_third_party
a677b7fe
 # - create_neutron_cache_dir
6a5aa7c6
 # - create_nova_conf_neutron
 # - start_neutron_service_and_check
 # - create_neutron_initial_network
 # - setup_neutron_debug
 # - start_neutron_agents
66afb47c
 #
 # ``unstack.sh`` calls the entry points in this order:
 #
6a5aa7c6
 # - stop_neutron
66afb47c
 
b05c8769
 # Functions in lib/neutron are classified into the following categories:
66afb47c
 #
 # - entry points (called from stack.sh or unstack.sh)
 # - internal functions
b05c8769
 # - neutron exercises
66afb47c
 # - 3rd party programs
 
60e9c0ab
 
b05c8769
 # Neutron Networking
60e9c0ab
 # ------------------
 
b05c8769
 # Make sure that neutron is enabled in ``ENABLED_SERVICES``.  If you want
 # to run Neutron on this host, make sure that q-svc is also in
60e9c0ab
 # ``ENABLED_SERVICES``.
 #
b05c8769
 # If you're planning to use the Neutron openvswitch plugin, set
60e9c0ab
 # ``Q_PLUGIN`` to "openvswitch" and make sure the q-agt service is enabled
b05c8769
 # in ``ENABLED_SERVICES``.  If you're planning to use the Neutron
60e9c0ab
 # linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the
 # q-agt service is enabled in ``ENABLED_SERVICES``.
 #
b05c8769
 # See "Neutron Network Configuration" below for additional variables
60e9c0ab
 # that must be set in localrc for connectivity across hosts with
b05c8769
 # Neutron.
60e9c0ab
 #
b05c8769
 # With Neutron networking the NETWORK_MANAGER variable is ignored.
ebfac64d
 #
 # To enable specific configuration options for either the Open vSwitch or
 # LinuxBridge plugin, please see the top level README file under the
b05c8769
 # Neutron section.
60e9c0ab
 
 
b05c8769
 # Neutron Network Configuration
66afb47c
 # -----------------------------
60e9c0ab
 
9297319f
 # Gateway and subnet defaults, in case they are not customized in localrc
 NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
90234ac4
 PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
9297319f
 PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
 PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
 
60e9c0ab
 # Set up default directories
b05c8769
 NEUTRON_DIR=$DEST/neutron
 NEUTRONCLIENT_DIR=$DEST/python-neutronclient
 NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
 
 # Support entry points installation of console scripts
 if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
     NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
3bdb922c
 else
     NEUTRON_BIN_DIR=$(get_python_exec_prefix)
b05c8769
 fi
5db5bfa2
 
b05c8769
 NEUTRON_CONF_DIR=/etc/neutron
 NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
 export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
60e9c0ab
 
0fc1cc29
 # Default name for Neutron database
 Q_DB_NAME=${Q_DB_NAME:-neutron}
b05c8769
 # Default Neutron Plugin
6d23500a
 Q_PLUGIN=${Q_PLUGIN:-ml2}
b05c8769
 # Default Neutron Port
60e9c0ab
 Q_PORT=${Q_PORT:-9696}
b05c8769
 # Default Neutron Host
f28c9c75
 Q_HOST=${Q_HOST:-$SERVICE_HOST}
60e9c0ab
 # Default admin username
b05c8769
 Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
60e9c0ab
 # Default auth strategy
 Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
 # Use namespace or not
 Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
d7150e9b
 # RHEL's support for namespaces requires using veths with ovs
 Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
60e9c0ab
 Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
 # Meta data IP
f28c9c75
 Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
66afb47c
 # Allow Overlapping IP among subnets
d1742feb
 Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
b05c8769
 # Use neutron-debug command
60e9c0ab
 Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
31c94ab5
 # The name of the default q-l3 router
 Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
4540d00e
 # nova vif driver that all plugins should use
 NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"}
f06c4434
 Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
 Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
cea32b1f
 VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
 VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
4540d00e
 
5ec6f8f1
 ## Provider Network Information
 PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
 
afbc631c
 # The next two variables are configured by plugin
 # e.g.  _configure_neutron_l3_agent or lib/neutron_plugins/*
 #
 # The plugin supports L3.
 Q_L3_ENABLED=${Q_L3_ENABLED:-False}
 # L3 routers exist per tenant
 Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-False}
4540d00e
 
7a8d8527
 # List of config file names in addition to the main plugin config file
b05c8769
 # See _configure_neutron_common() for details about setting it up
7a8d8527
 declare -a Q_PLUGIN_EXTRA_CONF_FILES
60e9c0ab
 
746dceeb
 # List of (optional) config files for VPN device drivers to use with
 # the neutron-q-vpn agent
 declare -a Q_VPN_EXTRA_CONF_FILES
 
e2907b48
 
 Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
     Q_RR_COMMAND="sudo"
 else
     NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
     Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
66afb47c
 fi
60e9c0ab
 
eea7621d
 
 # Distributed Virtual Router (DVR) configuration
 # Can be:
 #     legacy   - No DVR functionality
 #     dvr_snat - Controller or single node DVR
 #     dvr      - Compute node in multi-node DVR
 Q_DVR_MODE=${Q_DVR_MODE:-legacy}
 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
     Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
 fi
 
e2907b48
 # Provider Network Configurations
 # --------------------------------
 
 # The following variables control the Neutron openvswitch and
 # linuxbridge plugins' allocation of tenant networks and
 # availability of provider networks. If these are not configured
 # in ``localrc``, tenant networks will be local to the host (with no
 # remote connectivity), and no physical resources will be
 # available for the allocation of provider networks.
 
8feaf6c9
 # To disable tunnels (GRE or VXLAN) for tenant networks,
 # set to False in ``local.conf``.
 # GRE tunnels are only supported by the openvswitch.
 ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
e2907b48
 
 # If using GRE tunnels for tenant networks, specify the range of
 # tunnel IDs from which tenant networks are allocated. Can be
 # overriden in ``localrc`` in necesssary.
3827dc03
 TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
e2907b48
 
 # To use VLANs for tenant networks, set to True in localrc. VLANs
 # are supported by the openvswitch and linuxbridge plugins, each
 # requiring additional configuration described below.
 ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
 
 # If using VLANs for tenant networks, set in ``localrc`` to specify
 # the range of VLAN VIDs from which tenant networks are
 # allocated. An external network switch must be configured to
 # trunk these VLANs between hosts for multi-host connectivity.
 #
 # Example: ``TENANT_VLAN_RANGE=1000:1999``
 TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
 
 # If using VLANs for tenant networks, or if using flat or VLAN
 # provider networks, set in ``localrc`` to the name of the physical
 # network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
 # openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
 # agent, as described below.
 #
 # Example: ``PHYSICAL_NETWORK=default``
 PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
 
 # With the openvswitch plugin, if using VLANs for tenant networks,
 # or if using flat or VLAN provider networks, set in ``localrc`` to
 # the name of the OVS bridge to use for the physical network. The
 # bridge will be created if it does not already exist, but a
 # physical interface must be manually added to the bridge as a
 # port for external connectivity.
 #
 # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
 OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
 
 # With the linuxbridge plugin, if using VLANs for tenant networks,
 # or if using flat or VLAN provider networks, set in ``localrc`` to
 # the name of the network interface to use for the physical
 # network.
 #
 # Example: ``LB_PHYSICAL_INTERFACE=eth1``
 LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
 
6f335b9a
 # When Neutron tunnels are enabled it is needed to specify the
 # IP address of the end point in the local server. This IP is set
 # by default to the same IP address that the HOST IP.
 # This variable can be used to specify a different end point IP address
 # Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
 TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
 
e2907b48
 # With the openvswitch plugin, set to True in ``localrc`` to enable
 # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
 #
 # Example: ``OVS_ENABLE_TUNNELING=True``
 OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
 
b05c8769
 # Neutron plugin specific functions
0dd34df4
 # ---------------------------------
1a6d4492
 
b05c8769
 # Please refer to ``lib/neutron_plugins/README.md`` for details.
 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
0dd34df4
 
b7d82842
 # Agent loadbalancer service plugin functions
 # -------------------------------------------
1a6d4492
 
b7d82842
 # Hardcoding for 1 service plugin for now
b05c8769
 source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
b7d82842
 
40546f79
 # Agent metering service plugin functions
 # -------------------------------------------
 
 # Hardcoding for 1 service plugin for now
 source $TOP_DIR/lib/neutron_plugins/services/metering
 
69b3ff63
 # VPN service plugin functions
 # -------------------------------------------
 # Hardcoding for 1 service plugin for now
 source $TOP_DIR/lib/neutron_plugins/services/vpn
 
95c93e2b
 # Firewall Service Plugin functions
cb961597
 # ---------------------------------
95c93e2b
 source $TOP_DIR/lib/neutron_plugins/services/firewall
 
3452f8eb
 # Use security group or not
b05c8769
 if has_neutron_plugin_security_group; then
3452f8eb
     Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
 else
     Q_USE_SECGROUP=False
 fi
 
4237f590
 # Tell Tempest this project is present
 TEMPEST_SERVICES+=,neutron
 
 
e2907b48
 # Save trace setting
 XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
 
cc6b4435
 # Functions
 # ---------
60e9c0ab
 
e4fa7213
 # Test if any Neutron services are enabled
 # is_neutron_enabled
 function is_neutron_enabled {
     [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
     return 1
 }
 
b05c8769
 # configure_neutron()
 # Set common config for all neutron server and agents.
aee18c74
 function configure_neutron {
b05c8769
     _configure_neutron_common
     iniset_rpc_backend neutron $NEUTRON_CONF DEFAULT
66afb47c
 
b7d82842
     # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
     if is_service_enabled q-lbaas; then
b05c8769
         _configure_neutron_lbaas
b7d82842
     fi
40546f79
     if is_service_enabled q-metering; then
         _configure_neutron_metering
     fi
69b3ff63
     if is_service_enabled q-vpn; then
         _configure_neutron_vpn
     fi
95c93e2b
     if is_service_enabled q-fwaas; then
         _configure_neutron_fwaas
     fi
9b38eb23
     if is_service_enabled q-agt q-svc; then
b05c8769
         _configure_neutron_service
66afb47c
     fi
     if is_service_enabled q-agt; then
b05c8769
         _configure_neutron_plugin_agent
66afb47c
     fi
     if is_service_enabled q-dhcp; then
b05c8769
         _configure_neutron_dhcp_agent
66afb47c
     fi
     if is_service_enabled q-l3; then
b05c8769
         _configure_neutron_l3_agent
66afb47c
     fi
     if is_service_enabled q-meta; then
b05c8769
         _configure_neutron_metadata_agent
66afb47c
     fi
 
eea7621d
     if [[ "$Q_DVR_MODE" != "legacy" ]]; then
         _configure_dvr
     fi
58adaa6b
     if is_service_enabled ceilometer; then
         _configure_neutron_ceilometer_notifications
     fi
66afb47c
 
b05c8769
     _configure_neutron_debug_command
66afb47c
 }
 
aee18c74
 function create_nova_conf_neutron {
032e4546
     iniset $NOVA_CONF DEFAULT network_api_class "nova.network.neutronv2.api.API"
13d385e4
     iniset $NOVA_CONF neutron admin_username "$Q_ADMIN_USERNAME"
     iniset $NOVA_CONF neutron admin_password "$SERVICE_PASSWORD"
     iniset $NOVA_CONF neutron admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
     iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
     iniset $NOVA_CONF neutron admin_tenant_name "$SERVICE_TENANT_NAME"
0abde393
     iniset $NOVA_CONF neutron region_name "$REGION_NAME"
13d385e4
     iniset $NOVA_CONF neutron url "http://$Q_HOST:$Q_PORT"
66afb47c
 
3452f8eb
     if [[ "$Q_USE_SECGROUP" == "True" ]]; then
         LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
1143f7e4
         iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
032e4546
         iniset $NOVA_CONF DEFAULT security_group_api neutron
3452f8eb
     fi
 
0dd34df4
     # set NOVA_VIF_DRIVER and optionally set options in nova_conf
b05c8769
     neutron_plugin_create_nova_conf
0dd34df4
 
51c681d6
     iniset $NOVA_CONF libvirt vif_driver "$NOVA_VIF_DRIVER"
9bc47db2
     iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
66afb47c
     if is_service_enabled q-meta; then
032e4546
         iniset $NOVA_CONF DEFAULT service_neutron_metadata_proxy "True"
66afb47c
     fi
cea32b1f
 
     iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
     iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
66afb47c
 }
 
a677b7fe
 # create_neutron_cache_dir() - Part of the _neutron_setup_keystone() process
aee18c74
 function create_neutron_cache_dir {
a677b7fe
     # Create cache dir
     sudo mkdir -p $NEUTRON_AUTH_CACHE_DIR
     sudo chown $STACK_USER $NEUTRON_AUTH_CACHE_DIR
     rm -f $NEUTRON_AUTH_CACHE_DIR/*
 }
 
b05c8769
 # create_neutron_accounts() - Set up common required neutron accounts
66afb47c
 
 # Tenant               User       Roles
 # ------------------------------------------------------------------
b05c8769
 # service              neutron    admin        # if enabled
66afb47c
 
 # Migrated from keystone_data.sh
aee18c74
 function create_neutron_accounts {
66afb47c
 
19685428
     SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
     ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
66afb47c
 
     if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
0abde393
 
         NEUTRON_USER=$(get_or_create_user "neutron" \
6dd8a8be
             "$SERVICE_PASSWORD" $SERVICE_TENANT)
0abde393
         get_or_add_user_role $ADMIN_ROLE $NEUTRON_USER $SERVICE_TENANT
 
66afb47c
         if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
0abde393
 
             NEUTRON_SERVICE=$(get_or_create_service "neutron" \
                 "network" "Neutron Service")
             get_or_create_endpoint $NEUTRON_SERVICE \
                 "$REGION_NAME" \
186119c3
                 "http://$SERVICE_HOST:$Q_PORT/" \
                 "http://$SERVICE_HOST:$Q_PORT/" \
                 "http://$SERVICE_HOST:$Q_PORT/"
66afb47c
         fi
     fi
 }
 
aee18c74
 function create_neutron_initial_network {
19685428
     TENANT_ID=$(openstack project list | grep " demo " | get_field 1)
23178a99
     die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for demo"
66afb47c
 
     # Create a small network
b05c8769
     # Since neutron command is executed in admin context at this point,
25049cd2
     # ``--tenant-id`` needs to be specified.
37a8d157
     if is_baremetal; then
e2c4ee23
         if [[ "$PUBLIC_INTERFACE" == '' || "$OVS_PHYSICAL_BRIDGE" == '' ]]; then
             die $LINENO "Neutron settings for baremetal not set.. exiting"
         fi
37a8d157
         sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
         for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
             sudo ip addr del $IP dev $PUBLIC_INTERFACE
             sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
         done
25049cd2
         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)
23178a99
         die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
25049cd2
         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)
23178a99
         die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
37a8d157
         sudo ifconfig $OVS_PHYSICAL_BRIDGE up
e2c4ee23
         sudo route add default gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
5ec6f8f1
     elif is_provider_network; then
         die_if_not_set $LINENO SEGMENTATION_ID "A SEGMENTATION_ID is required to use provider networking"
         die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specifiy the PROVIDER_NETWORK_TYPE"
21e6c62c
         NET_ID=$(neutron net-create $PHYSICAL_NETWORK --tenant_id $TENANT_ID --provider:network_type $PROVIDER_NETWORK_TYPE --provider:physical_network "$PHYSICAL_NETWORK" --provider:segmentation_id "$SEGMENTATION_ID" --shared | grep ' id ' | get_field 2)
5ec6f8f1
         SUBNET_ID=$(neutron subnet-create --tenant_id $TENANT_ID --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --name $PROVIDER_SUBNET_NAME $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
e13fd600
         SUBNET_V6_ID=$(neutron subnet-create --tenant_id $TENANT_ID --ip_version 6 --ipv6-address-mode slaac --gateway $V6_NETWORK_GATEWAY --name $PROVIDER_SUBNET_NAME_V6 $NET_ID $FIXED_RANGE_V6 | grep 'id' | get_field 2)
5ec6f8f1
         sudo ip link set $OVS_PHYSICAL_BRIDGE up
         sudo ip link set br-int up
         sudo ip link set $PUBLIC_INTERFACE up
37a8d157
     else
25049cd2
         NET_ID=$(neutron net-create --tenant-id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
23178a99
         die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $TENANT_ID"
25049cd2
         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)
23178a99
         die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $TENANT_ID"
37a8d157
     fi
66afb47c
 
555ecd07
     if [[ "$Q_L3_ENABLED" == "True" ]]; then
66afb47c
         # Create a router, and add the private subnet as one of its interfaces
555ecd07
         if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
             # create a tenant-owned router.
25049cd2
             ROUTER_ID=$(neutron router-create --tenant-id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
23178a99
             die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
31c94ab5
         else
555ecd07
             # Plugin only supports creating a single router, which should be admin owned.
b05c8769
             ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
23178a99
             die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
31c94ab5
         fi
b05c8769
         neutron router-interface-add $ROUTER_ID $SUBNET_ID
66afb47c
         # Create an external network, and a subnet. Configure the external network as router gw
b05c8769
         EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
23178a99
         die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
b05c8769
         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)
23178a99
         die_if_not_set $LINENO EXT_GW_IP "Failure creating EXT_GW_IP"
b05c8769
         neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
66afb47c
 
555ecd07
         if is_service_enabled q-l3; then
             # logic is specific to using the l3-agent for l3
b05c8769
             if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
ea3dac9a
                 # Disable in-band as we are going to use local port
                 # to communicate with VMs
                 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE other_config:disable-in-band=true
555ecd07
                 CIDR_LEN=${FLOATING_RANGE#*/}
                 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
                 sudo ip link set $PUBLIC_BRIDGE up
b05c8769
                 ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'`
23178a99
                 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
555ecd07
                 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
             fi
             if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
                 # Explicitly set router id in l3 agent configuration
                 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
             fi
66afb47c
         fi
3bdb922c
     fi
66afb47c
 }
 
b05c8769
 # init_neutron() - Initialize databases, etc.
aee18c74
 function init_neutron {
dd64988f
     recreate_database $Q_DB_NAME utf8
     # Run Neutron db migrations
     $NEUTRON_BIN_DIR/neutron-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head
66afb47c
 }
 
b05c8769
 # install_neutron() - Collect source and prepare
aee18c74
 function install_neutron {
b05c8769
     git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
     setup_develop $NEUTRON_DIR
66afb47c
 }
 
b05c8769
 # install_neutronclient() - Collect source and prepare
aee18c74
 function install_neutronclient {
b05c8769
     git_clone $NEUTRONCLIENT_REPO $NEUTRONCLIENT_DIR $NEUTRONCLIENT_BRANCH
     setup_develop $NEUTRONCLIENT_DIR
fac533e3
     sudo install -D -m 0644 -o $STACK_USER {$NEUTRONCLIENT_DIR/tools/,/etc/bash_completion.d/}neutron.bash_completion
66afb47c
 }
 
b05c8769
 # install_neutron_agent_packages() - Collect source and prepare
aee18c74
 function install_neutron_agent_packages {
72b3e448
     # radvd doesn't come with the OS. Install it if the l3 service is enabled.
     if is_service_enabled q-l3; then
         install_package radvd
     fi
8498487e
     # install packages that are specific to plugin agent(s)
     if is_service_enabled q-agt q-dhcp q-l3; then
b05c8769
         neutron_plugin_install_agent_packages
8498487e
     fi
 
     if is_service_enabled q-lbaas; then
3bdb922c
         neutron_agent_lbaas_install_agent_packages
8498487e
     fi
66afb47c
 }
 
 # Start running processes, including screen
aee18c74
 function start_neutron_service_and_check {
7a8d8527
     # build config-file options
     local cfg_file
b05c8769
     local CFG_FILE_OPTIONS="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
7a8d8527
     for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
3bdb922c
         CFG_FILE_OPTIONS+=" --config-file /$cfg_file"
7a8d8527
     done
b05c8769
     # Start the Neutron service
     screen_it q-svc "cd $NEUTRON_DIR && python $NEUTRON_BIN_DIR/neutron-server $CFG_FILE_OPTIONS"
     echo "Waiting for Neutron to start..."
0aa8534a
     if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then
3bdb922c
         die $LINENO "Neutron did not start"
66afb47c
     fi
 }
 
 # Start running processes, including screen
aee18c74
 function start_neutron_agents {
b05c8769
     # Start up the neutron agents if enabled
     screen_it q-agt "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
     screen_it q-dhcp "cd $NEUTRON_DIR && python $AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file=$Q_DHCP_CONF_FILE"
584750f9
 
95c93e2b
     L3_CONF_FILES="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
 
5ec6f8f1
     if is_provider_network; then
         sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
         sudo ip link set $OVS_PHYSICAL_BRIDGE up
         sudo ip link set br-int up
         sudo ip link set $PUBLIC_INTERFACE up
     fi
 
95c93e2b
     if is_service_enabled q-fwaas; then
         L3_CONF_FILES="$L3_CONF_FILES --config-file $Q_FWAAS_CONF_FILE"
cf1ef23b
         VPN_CONF_FILES="$VPN_CONF_FILES --config-file $Q_FWAAS_CONF_FILE"
95c93e2b
     fi
584750f9
     if is_service_enabled q-vpn; then
746dceeb
         screen_it q-vpn "cd $NEUTRON_DIR && $AGENT_VPN_BINARY $VPN_CONF_FILES"
584750f9
     else
95c93e2b
         screen_it q-l3 "cd $NEUTRON_DIR && python $AGENT_L3_BINARY $L3_CONF_FILES"
584750f9
     fi
95c93e2b
 
b05c8769
     screen_it q-meta "cd $NEUTRON_DIR && python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
b7d82842
 
f652e0fb
     if [ "$VIRT_DRIVER" = 'xenserver' ]; then
         # For XenServer, start an agent for the domU openvswitch
b05c8769
         screen_it q-domua "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
f652e0fb
     fi
 
b7d82842
     if is_service_enabled q-lbaas; then
b05c8769
         screen_it q-lbaas "cd $NEUTRON_DIR && python $AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
b7d82842
     fi
40546f79
 
     if is_service_enabled q-metering; then
         screen_it q-metering "cd $NEUTRON_DIR && python $AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
     fi
66afb47c
 }
 
b05c8769
 # stop_neutron() - Stop running processes (non-screen)
aee18c74
 function stop_neutron {
66afb47c
     if is_service_enabled q-dhcp; then
         pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
         [ ! -z "$pid" ] && sudo kill -9 $pid
     fi
2ae6acfe
     if is_service_enabled q-meta; then
1f763280
         sudo pkill -9 -f neutron-ns-metadata-proxy || :
2ae6acfe
     fi
edddb1fd
 
     if is_service_enabled q-lbaas; then
         neutron_lbaas_stop
     fi
     if is_service_enabled q-fwaas; then
         neutron_fwaas_stop
     fi
     if is_service_enabled q-vpn; then
         neutron_vpn_stop
     fi
     if is_service_enabled q-metering; then
         neutron_metering_stop
     fi
66afb47c
 }
 
b05c8769
 # cleanup_neutron() - Remove residual data files, anything left over from previous
66afb47c
 # runs that a clean run would need to clean up
aee18c74
 function cleanup_neutron {
b05c8769
     if is_neutron_ovs_base_plugin; then
         neutron_ovs_base_cleanup
614202fc
     fi
 
b05c8769
     # delete all namespaces created by neutron
eea7621d
     for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|qlbaas|fip|snat)-[0-9a-f-]*'); do
614202fc
         sudo ip netns delete ${ns}
     done
66afb47c
 }
 
b05c8769
 # _configure_neutron_common()
 # Set common config for all neutron server and agents.
 # This MUST be called before other ``_configure_neutron_*`` functions.
aee18c74
 function _configure_neutron_common {
b05c8769
     # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
     if [[ ! -d $NEUTRON_CONF_DIR ]]; then
         sudo mkdir -p $NEUTRON_CONF_DIR
66afb47c
     fi
b05c8769
     sudo chown $STACK_USER $NEUTRON_CONF_DIR
66afb47c
 
b05c8769
     cp $NEUTRON_DIR/etc/neutron.conf $NEUTRON_CONF
66afb47c
 
1a6d4492
     # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
     # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
     # For addition plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH``,
     # ``Q_PLUGIN_EXTRA_CONF_FILES``.  For example:
cb961597
     #
1a6d4492
     #    ``Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)``
b05c8769
     neutron_plugin_configure_common
66afb47c
 
e2c4ee23
     if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
b05c8769
         die $LINENO "Neutron plugin not set.. exiting"
66afb47c
     fi
 
b05c8769
     # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
66afb47c
     mkdir -p /$Q_PLUGIN_CONF_PATH
     Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
b05c8769
     cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
66afb47c
 
b816e5d2
     iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
b05c8769
     iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
66afb47c
 
7a8d8527
     # If addition config files are set, make sure their path name is set as well
     if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
b05c8769
         die $LINENO "Neutron additional plugin config not set.. exiting"
7a8d8527
     fi
 
b05c8769
     # If additional config files exist, copy them over to neutron configuration
7a8d8527
     # directory
     if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
         local f
         for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
             Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
         done
     fi
 
bee5c507
     if [ "$VIRT_DRIVER" = 'fake' ]; then
         # Disable arbitrary limits
         iniset $NEUTRON_CONF quotas quota_network -1
         iniset $NEUTRON_CONF quotas quota_subnet -1
         iniset $NEUTRON_CONF quotas quota_port -1
         iniset $NEUTRON_CONF quotas quota_security_group -1
         iniset $NEUTRON_CONF quotas quota_security_group_rule -1
     fi
 
05ae833b
     # Format logging
     if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
bc7f643b
         setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
05ae833b
     fi
 
b05c8769
     _neutron_setup_rootwrap
66afb47c
 }
 
aee18c74
 function _configure_neutron_debug_command {
66afb47c
     if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
         return
     fi
 
b05c8769
     cp $NEUTRON_DIR/etc/l3_agent.ini $NEUTRON_TEST_CONFIG_FILE
66afb47c
 
b05c8769
     iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT verbose False
     iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
     iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
     iniset $NEUTRON_TEST_CONFIG_FILE agent root_helper "$Q_RR_COMMAND"
66afb47c
 
b05c8769
     _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
66afb47c
 
b05c8769
     neutron_plugin_configure_debug_command
66afb47c
 }
 
aee18c74
 function _configure_neutron_dhcp_agent {
b05c8769
     AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
     Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
66afb47c
 
b05c8769
     cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
66afb47c
 
     iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
03997942
     iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
66afb47c
     iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
     iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
 
b05c8769
     _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
66afb47c
 
b05c8769
     neutron_plugin_configure_dhcp_agent
66afb47c
 }
 
aee18c74
 function _configure_neutron_l3_agent {
746dceeb
     local cfg_file
555ecd07
     Q_L3_ENABLED=True
     # for l3-agent, only use per tenant router if we have namespaces
     Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
69b3ff63
 
     AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
b05c8769
     Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
66afb47c
 
95c93e2b
     if is_service_enabled q-fwaas; then
         Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
     fi
 
746dceeb
     if is_service_enabled q-vpn; then
         Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
         cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
         VPN_CONF_FILES="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
         for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
             VPN_CONF_FILES+=" --config-file $cfg_file"
         done
     fi
 
b05c8769
     cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
66afb47c
 
     iniset $Q_L3_CONF_FILE DEFAULT verbose True
03997942
     iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
66afb47c
     iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
     iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
 
b05c8769
     _neutron_setup_interface_driver $Q_L3_CONF_FILE
66afb47c
 
b05c8769
     neutron_plugin_configure_l3_agent
66afb47c
 }
 
aee18c74
 function _configure_neutron_metadata_agent {
b05c8769
     AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
     Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
66afb47c
 
b05c8769
     cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
66afb47c
 
     iniset $Q_META_CONF_FILE DEFAULT verbose True
03997942
     iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
66afb47c
     iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
     iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
 
3561d7f9
     _neutron_setup_keystone $Q_META_CONF_FILE DEFAULT True True
bf10ac55
 
66afb47c
 }
 
58adaa6b
 function _configure_neutron_ceilometer_notifications {
     iniset $NEUTRON_CONF DEFAULT notification_driver neutron.openstack.common.notifier.rpc_notifier
 }
 
aee18c74
 function _configure_neutron_lbaas {
b05c8769
     neutron_agent_lbaas_configure_common
     neutron_agent_lbaas_configure_agent
b7d82842
 }
 
aee18c74
 function _configure_neutron_metering {
40546f79
     neutron_agent_metering_configure_common
     neutron_agent_metering_configure_agent
 }
 
aee18c74
 function _configure_neutron_fwaas {
95c93e2b
     neutron_fwaas_configure_common
     neutron_fwaas_configure_driver
 }
 
aee18c74
 function _configure_neutron_vpn {
69b3ff63
     neutron_vpn_install_agent_packages
     neutron_vpn_configure_common
 }
 
eea7621d
 function _configure_dvr {
     iniset $NEUTRON_CONF DEFAULT router_distributed True
     iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
 }
 
 
b05c8769
 # _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
66afb47c
 # It is called when q-agt is enabled.
aee18c74
 function _configure_neutron_plugin_agent {
2298ca4f
     # Specify the default root helper prior to agent configuration to
98e18e99
     # ensure that an agent's configuration can override the default
d42634ff
     iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
b05c8769
     iniset $NEUTRON_CONF DEFAULT verbose True
03997942
     iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
2298ca4f
 
66afb47c
     # Configure agent for plugin
b05c8769
     neutron_plugin_configure_plugin_agent
66afb47c
 }
 
b05c8769
 # _configure_neutron_service() - Set config files for neutron service
66afb47c
 # It is called when q-svc is enabled.
aee18c74
 function _configure_neutron_service {
b05c8769
     Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
     Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
66afb47c
 
b05c8769
     cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
     cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
66afb47c
 
     # Update either configuration file with plugin
b05c8769
     iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
66afb47c
 
b7d82842
     if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
b05c8769
         iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
b7d82842
     fi
 
b05c8769
     iniset $NEUTRON_CONF DEFAULT verbose True
03997942
     iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
b05c8769
     iniset $NEUTRON_CONF DEFAULT policy_file $Q_POLICY_FILE
     iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
66afb47c
 
b05c8769
     iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
     _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
66afb47c
 
cea32b1f
     # Configuration for neutron notifations to nova.
f06c4434
     iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
     iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
cea32b1f
     iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
5ca261aa
     iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
cea32b1f
     iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
     ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
     iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
     iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url  "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
 
66afb47c
     # Configure plugin
b05c8769
     neutron_plugin_configure_service
66afb47c
 }
 
 # Utility Functions
 #------------------
 
9e136b4a
 # _neutron_service_plugin_class_add() - add service plugin class
aee18c74
 function _neutron_service_plugin_class_add {
9e136b4a
     local service_plugin_class=$1
     if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
         Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
     elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
         Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
     fi
 }
 
b05c8769
 # _neutron_setup_rootwrap() - configure Neutron's rootwrap
aee18c74
 function _neutron_setup_rootwrap {
eb1aa3d5
     if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
         return
     fi
     # Deploy new rootwrap filters files (owned by root).
1a6d4492
     # Wipe any existing ``rootwrap.d`` files first
b05c8769
     Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
eb1aa3d5
     if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
         sudo rm -rf $Q_CONF_ROOTWRAP_D
     fi
b05c8769
     # Deploy filters to ``$NEUTRON_CONF_DIR/rootwrap.d``
eb1aa3d5
     mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
b05c8769
     cp -pr $NEUTRON_DIR/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
eb1aa3d5
     sudo chown -R root:root $Q_CONF_ROOTWRAP_D
     sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
b05c8769
     # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
13aab25d
     # location moved in newer versions, prefer new location
b05c8769
     if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
3bdb922c
         sudo cp -p $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
13aab25d
     else
3bdb922c
         sudo cp -p $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
13aab25d
     fi
eb1aa3d5
     sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
     sudo chown root:root $Q_RR_CONF_FILE
     sudo chmod 0644 $Q_RR_CONF_FILE
b05c8769
     # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
     ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
eb1aa3d5
 
b05c8769
     # Set up the rootwrap sudoers for neutron
eb1aa3d5
     TEMPFILE=`mktemp`
e578effb
     echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
eb1aa3d5
     chmod 0440 $TEMPFILE
     sudo chown root:root $TEMPFILE
b05c8769
     sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
98e18e99
 
     # Update the root_helper
b05c8769
     iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
eb1aa3d5
 }
 
b05c8769
 # Configures keystone integration for neutron service and agents
aee18c74
 function _neutron_setup_keystone {
d6767d0d
     local conf_file=$1
     local section=$2
     local use_auth_url=$3
bf10ac55
     local skip_auth_cache=$4
3561d7f9
 
     iniset $conf_file $section auth_uri $KEYSTONE_SERVICE_URI
     iniset $conf_file $section identity_uri $KEYSTONE_AUTH_URI
d6767d0d
     iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
     iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
     iniset $conf_file $section admin_password $SERVICE_PASSWORD
bf10ac55
     if [[ -z $skip_auth_cache ]]; then
         iniset $conf_file $section signing_dir $NEUTRON_AUTH_CACHE_DIR
         # Create cache dir
a677b7fe
         create_neutron_cache_dir
bf10ac55
     fi
d6767d0d
 }
 
aee18c74
 function _neutron_setup_interface_driver {
d7150e9b
 
     # ovs_use_veth needs to be set before the plugin configuration
     # occurs to allow plugins to override the setting.
     iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
 
b05c8769
     neutron_plugin_setup_interface_driver $1
602cf9bd
 }
 
b05c8769
 # Functions for Neutron Exercises
66afb47c
 #--------------------------------
 
aee18c74
 function delete_probe {
66afb47c
     local from_net="$1"
     net_id=`_get_net_id $from_net`
b05c8769
     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}'`
     neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
66afb47c
 }
 
aee18c74
 function setup_neutron_debug {
66afb47c
     if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
         public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
b05c8769
         neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
66afb47c
         private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
b05c8769
         neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
602cf9bd
     fi
66afb47c
 }
 
aee18c74
 function teardown_neutron_debug {
66afb47c
     delete_probe $PUBLIC_NETWORK_NAME
     delete_probe $PRIVATE_NETWORK_NAME
602cf9bd
 }
 
aee18c74
 function _get_net_id {
b05c8769
     neutron --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
5db5bfa2
 }
 
aee18c74
 function _get_probe_cmd_prefix {
5db5bfa2
     local from_net="$1"
     net_id=`_get_net_id $from_net`
b05c8769
     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`
8bc21f64
     echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
5db5bfa2
 }
 
aee18c74
 function _ping_check_neutron {
5db5bfa2
     local from_net=$1
     local ip=$2
     local timeout_sec=$3
     local expected=${4:-"True"}
     local check_command=""
     probe_cmd=`_get_probe_cmd_prefix $from_net`
     if [[ "$expected" = "True" ]]; then
8bc21f64
         check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
5db5bfa2
     else
8bc21f64
         check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
5db5bfa2
     fi
     if ! timeout $timeout_sec sh -c "$check_command"; then
         if [[ "$expected" = "True" ]]; then
07115eb5
             die $LINENO "[Fail] Couldn't ping server"
5db5bfa2
         else
07115eb5
             die $LINENO "[Fail] Could ping server"
5db5bfa2
         fi
     fi
 }
 
 # ssh check
aee18c74
 function _ssh_check_neutron {
5db5bfa2
     local from_net=$1
     local key_file=$2
     local ip=$3
     local user=$4
     local timeout_sec=$5
     local probe_cmd = ""
     probe_cmd=`_get_probe_cmd_prefix $from_net`
cc6b4435
     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
07115eb5
         die $LINENO "server didn't become ssh-able!"
5db5bfa2
     fi
 }
 
b05c8769
 # Neutron 3rd party programs
66afb47c
 #---------------------------
1a6d4492
 
b05c8769
 # please refer to ``lib/neutron_thirdparty/README.md`` for details
 NEUTRON_THIRD_PARTIES=""
 for f in $TOP_DIR/lib/neutron_thirdparty/*; do
3bdb922c
     third_party=$(basename $f)
     if is_service_enabled $third_party; then
         source $TOP_DIR/lib/neutron_thirdparty/$third_party
         NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
     fi
66afb47c
 done
 
aee18c74
 function _neutron_third_party_do {
b05c8769
     for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
0dd34df4
         ${1}_${third_party}
66afb47c
     done
5db5bfa2
 }
 
b05c8769
 # configure_neutron_third_party() - Set config files, create data dirs, etc
aee18c74
 function configure_neutron_third_party {
b05c8769
     _neutron_third_party_do configure
0dd34df4
 }
 
b05c8769
 # init_neutron_third_party() - Initialize databases, etc.
aee18c74
 function init_neutron_third_party {
b05c8769
     _neutron_third_party_do init
66afb47c
 }
 
b05c8769
 # install_neutron_third_party() - Collect source and prepare
aee18c74
 function install_neutron_third_party {
b05c8769
     _neutron_third_party_do install
66afb47c
 }
 
b05c8769
 # start_neutron_third_party() - Start running processes, including screen
aee18c74
 function start_neutron_third_party {
b05c8769
     _neutron_third_party_do start
5db5bfa2
 }
 
b05c8769
 # stop_neutron_third_party - Stop running processes (non-screen)
aee18c74
 function stop_neutron_third_party {
b05c8769
     _neutron_third_party_do stop
66afb47c
 }
 
ef1e0802
 # check_neutron_third_party_integration() - Check that third party integration is sane
aee18c74
 function check_neutron_third_party_integration {
ef1e0802
     _neutron_third_party_do check
 }
 
5ec6f8f1
 function is_provider_network {
     if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then
         return 0
     fi
     return 1
 }
 
66afb47c
 
d6767d0d
 # Restore xtrace
 $XTRACE
584d90ec
 
6a5aa7c6
 # Tell emacs to use shell-script-mode
 ## Local variables:
 ## mode: shell-script
 ## End: