lib/neutron_plugins/ml2
e263c82e
 #!/bin/bash
 #
b05c8769
 # Neutron Modular Layer 2 plugin
c9b0f1ab
 # ------------------------------
 
 # Save trace setting
523f4880
 _XTRACE_NEUTRON_ML2=$(set +o | grep xtrace)
c9b0f1ab
 set +o xtrace
 
b772659f
 # Enable this to simply and quickly enable tunneling with ML2.
2307f9de
 # Select either 'gre', 'vxlan', or 'gre,vxlan'
8feaf6c9
 Q_ML2_TENANT_NETWORK_TYPE=${Q_ML2_TENANT_NETWORK_TYPE:-"vxlan"}
b772659f
 # This has to be set here since the agent will set this in the config file
e3cfbf15
 if [[ "$Q_ML2_TENANT_NETWORK_TYPE" == "gre" || "$Q_ML2_TENANT_NETWORK_TYPE" == "vxlan" ]]; then
2307f9de
     Q_TUNNEL_TYPES=$Q_ML2_TENANT_NETWORK_TYPE
bd085505
 elif [[ "$ENABLE_TENANT_TUNNELS" == "True" ]]; then
2307f9de
     Q_TUNNEL_TYPES=gre
b772659f
 fi
 
c9b0f1ab
 # Default openvswitch L2 agent
 Q_AGENT=${Q_AGENT:-openvswitch}
22cf648c
 if [ -f $TOP_DIR/lib/neutron_plugins/${Q_AGENT}_agent ]; then
     source $TOP_DIR/lib/neutron_plugins/${Q_AGENT}_agent
 fi
c9b0f1ab
 
b772659f
 # List of MechanismDrivers to load
bc632477
 Q_ML2_PLUGIN_MECHANISM_DRIVERS=${Q_ML2_PLUGIN_MECHANISM_DRIVERS:-openvswitch,linuxbridge}
b772659f
 # Default GRE TypeDriver options
 Q_ML2_PLUGIN_GRE_TYPE_OPTIONS=${Q_ML2_PLUGIN_GRE_TYPE_OPTIONS:-tunnel_id_ranges=$TENANT_TUNNEL_RANGES}
 # Default VXLAN TypeDriver options
8906b481
 Q_ML2_PLUGIN_VXLAN_TYPE_OPTIONS=${Q_ML2_PLUGIN_VXLAN_TYPE_OPTIONS:-vni_ranges=$TENANT_TUNNEL_RANGES}
b772659f
 # Default VLAN TypeDriver options
 Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS=${Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS:-}
8906b481
 # Default GENEVE TypeDriver options
 Q_ML2_PLUGIN_GENEVE_TYPE_OPTIONS=${Q_ML2_PLUGIN_GENEVE_TYPE_OPTIONS:-vni_ranges=$TENANT_TUNNEL_RANGES}
a48e5dc4
 # List of extension drivers to load, use '-' instead of ':-' to allow people to
 # explicitly override this to blank
c9c9d31d
 if [[ "$NEUTRON_PORT_SECURITY" = "True" ]]; then
     Q_ML2_PLUGIN_EXT_DRIVERS=${Q_ML2_PLUGIN_EXT_DRIVERS-port_security}
 else
     Q_ML2_PLUGIN_EXT_DRIVERS=${Q_ML2_PLUGIN_EXT_DRIVERS:-}
 fi
b772659f
 
14ea1a2b
 # L3 Plugin to load for ML2
1c4c16ce
 # For some flat network environment, they not want to extend L3 plugin.
 # Make sure it is able to set empty to ML2_L3_PLUGIN.
 ML2_L3_PLUGIN=${ML2_L3_PLUGIN-neutron.services.l3_router.l3_router_plugin.L3RouterPlugin}
14ea1a2b
 
aee18c74
 function populate_ml2_config {
130c90ed
     CONF=$1
     SECTION=$2
     OPTS=$3
b772659f
 
130c90ed
     if [ -z "$OPTS" ]; then
         return
     fi
b772659f
     for I in "${OPTS[@]}"; do
         # Replace the first '=' with ' ' for iniset syntax
         iniset $CONF $SECTION ${I/=/ }
     done
 }
 
aee18c74
 function neutron_plugin_configure_common {
b05c8769
     Q_PLUGIN_CONF_PATH=etc/neutron/plugins/ml2
c9b0f1ab
     Q_PLUGIN_CONF_FILENAME=ml2_conf.ini
b05c8769
     Q_PLUGIN_CLASS="neutron.plugins.ml2.plugin.Ml2Plugin"
748fe3d5
     # The ML2 plugin delegates L3 routing/NAT functionality to
     # the L3 service plugin which must therefore be specified.
9e136b4a
     _neutron_service_plugin_class_add $ML2_L3_PLUGIN
c9b0f1ab
 }
 
aee18c74
 function neutron_plugin_configure_service {
8feaf6c9
     if [[ "$Q_ML2_TENANT_NETWORK_TYPE" != "local" ]]; then
061d5250
         Q_SRV_EXTRA_OPTS+=(tenant_network_types=$Q_ML2_TENANT_NETWORK_TYPE)
bd085505
     elif [[ "$ENABLE_TENANT_TUNNELS" == "True" ]]; then
b772659f
         # This assumes you want a simple configuration, and will overwrite
         # Q_SRV_EXTRA_OPTS if set in addition to ENABLE_TENANT_TUNNELS.
061d5250
         Q_SRV_EXTRA_OPTS+=(tenant_network_types=gre)
b772659f
         Q_ML2_PLUGIN_GRE_TYPE_OPTIONS=(tunnel_id_ranges=$TENANT_TUNNEL_RANGES)
bd085505
     elif [[ "$ENABLE_TENANT_VLANS" == "True" ]]; then
061d5250
         Q_SRV_EXTRA_OPTS+=(tenant_network_types=vlan)
c9b0f1ab
     else
         echo "WARNING - The ml2 plugin is using local tenant networks, with no connectivity between hosts."
     fi
 
b772659f
     # Allow for overrding VLAN configuration (for example, to configure provider
     # VLANs) by first checking if Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS is set.
     if [ "$Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS" == "" ]; then
bd085505
         if [[ "$ML2_VLAN_RANGES" == "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]]; then
b772659f
             ML2_VLAN_RANGES=$PHYSICAL_NETWORK
             if [[ "$TENANT_VLAN_RANGE" != "" ]]; then
                 ML2_VLAN_RANGES=$ML2_VLAN_RANGES:$TENANT_VLAN_RANGE
             fi
         fi
         if [[ "$ML2_VLAN_RANGES" != "" ]]; then
             Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS=(network_vlan_ranges=$ML2_VLAN_RANGES)
c9b0f1ab
         fi
     fi
 
73d32161
 
     # Allow for setup the flat type network
6a42a85b
     if [[ -z "$Q_ML2_PLUGIN_FLAT_TYPE_OPTIONS" ]]; then
         if [[ -n "$PHYSICAL_NETWORK" || -n "$PUBLIC_PHYSICAL_NETWORK" ]]; then
             Q_ML2_PLUGIN_FLAT_TYPE_OPTIONS="flat_networks="
             if [[ -n "$PHYSICAL_NETWORK" ]]; then
                 Q_ML2_PLUGIN_FLAT_TYPE_OPTIONS+="${PHYSICAL_NETWORK},"
             fi
             if [[ -n "$PUBLIC_PHYSICAL_NETWORK" ]]; then
                 Q_ML2_PLUGIN_FLAT_TYPE_OPTIONS+="${PUBLIC_PHYSICAL_NETWORK},"
             fi
         fi
73d32161
     fi
c9b0f1ab
     # REVISIT(rkukura): Setting firewall_driver here for
b05c8769
     # neutron.agent.securitygroups_rpc.is_firewall_enabled() which is
c9b0f1ab
     # used in the server, in case no L2 agent is configured on the
     # server's node. If an L2 agent is configured, this will get
     # overridden with the correct driver. The ml2 plugin should
     # instead use its own config variable to indicate whether security
     # groups is enabled, and that will need to be set here instead.
     if [[ "$Q_USE_SECGROUP" == "True" ]]; then
4074e298
         iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.not.a.real.FirewallDriver
c9b0f1ab
     else
4074e298
         iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.firewall.NoopFirewallDriver
c9b0f1ab
     fi
 
130c90ed
     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2 mechanism_drivers=$Q_ML2_PLUGIN_MECHANISM_DRIVERS
3ea28ece
 
8906b481
     if [[ -n "$Q_ML2_PLUGIN_TYPE_DRIVERS" ]]; then
         populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2 type_drivers=$Q_ML2_PLUGIN_TYPE_DRIVERS
     fi
b772659f
 
a48e5dc4
     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2 extension_drivers=$Q_ML2_PLUGIN_EXT_DRIVERS
 
130c90ed
     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2 $Q_SRV_EXTRA_OPTS
b772659f
 
130c90ed
     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_type_gre $Q_ML2_PLUGIN_GRE_TYPE_OPTIONS
b772659f
 
130c90ed
     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_type_vxlan $Q_ML2_PLUGIN_VXLAN_TYPE_OPTIONS
b772659f
 
73d32161
     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_type_flat $Q_ML2_PLUGIN_FLAT_TYPE_OPTIONS
 
130c90ed
     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_type_vlan $Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS
eea7621d
 
8906b481
     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_type_geneve $Q_ML2_PLUGIN_GENEVE_TYPE_OPTIONS
 
eea7621d
     if [[ "$Q_DVR_MODE" != "legacy" ]]; then
         populate_ml2_config /$Q_PLUGIN_CONF_FILE agent l2_population=True
         populate_ml2_config /$Q_PLUGIN_CONF_FILE agent tunnel_types=vxlan
         populate_ml2_config /$Q_PLUGIN_CONF_FILE agent enable_distributed_routing=True
     fi
c9b0f1ab
 }
 
aee18c74
 function has_neutron_plugin_security_group {
c9b0f1ab
     return 0
 }
 
 # Restore xtrace
523f4880
 $_XTRACE_NEUTRON_ML2