Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Subnet IP version |
| 3 | IP_VERSION=${IP_VERSION:-"4+6"} |
| 4 | # Validate IP_VERSION |
| 5 | if [[ $IP_VERSION != "4" ]] && [[ $IP_VERSION != "6" ]] && [[ $IP_VERSION != "4+6" ]]; then |
| 6 | die $LINENO "IP_VERSION must be either 4, 6, or 4+6" |
| 7 | fi |
| 8 | # Specify if the initial private and external networks should be created |
| 9 | NEUTRON_CREATE_INITIAL_NETWORKS=${NEUTRON_CREATE_INITIAL_NETWORKS:-True} |
| 10 | |
| 11 | ## Provider Network Information |
| 12 | PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"} |
| 13 | IPV6_PROVIDER_SUBNET_NAME=${IPV6_PROVIDER_SUBNET_NAME:-"provider_net_v6"} |
| 14 | IPV6_PROVIDER_FIXED_RANGE=${IPV6_PROVIDER_FIXED_RANGE:-} |
| 15 | IPV6_PROVIDER_NETWORK_GATEWAY=${IPV6_PROVIDER_NETWORK_GATEWAY:-} |
| 16 | |
| 17 | PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex} |
| 18 | |
| 19 | # If Q_USE_PUBLIC_VETH=True, create and use a veth pair instead of |
| 20 | # PUBLIC_BRIDGE. This is intended to be used with |
| 21 | # Q_USE_PROVIDERNET_FOR_PUBLIC=True. |
| 22 | Q_USE_PUBLIC_VETH=${Q_USE_PUBLIC_VETH:-False} |
| 23 | Q_PUBLIC_VETH_EX=${Q_PUBLIC_VETH_EX:-veth-pub-ex} |
| 24 | Q_PUBLIC_VETH_INT=${Q_PUBLIC_VETH_INT:-veth-pub-int} |
| 25 | |
| 26 | # The next two variables are configured by plugin |
| 27 | # e.g. _configure_neutron_l3_agent or lib/neutron_plugins/* |
| 28 | # |
| 29 | # The plugin supports L3. |
| 30 | Q_L3_ENABLED=${Q_L3_ENABLED:-True} |
| 31 | # L3 routers exist per tenant |
| 32 | Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-True} |
| 33 | |
| 34 | |
| 35 | # Use flat providernet for public network |
| 36 | # |
| 37 | # If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network |
| 38 | # for external interface of neutron l3-agent. In that case, |
| 39 | # PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value |
| 40 | # used for the network. In case of ofagent, you should add the |
| 41 | # corresponding entry to your OFAGENT_PHYSICAL_INTERFACE_MAPPINGS. |
| 42 | # For openvswitch agent, you should add the corresponding entry to |
| 43 | # your OVS_BRIDGE_MAPPINGS. |
| 44 | # |
| 45 | # eg. (ofagent) |
| 46 | # Q_USE_PROVIDERNET_FOR_PUBLIC=True |
| 47 | # Q_USE_PUBLIC_VETH=True |
| 48 | # PUBLIC_PHYSICAL_NETWORK=public |
| 49 | # OFAGENT_PHYSICAL_INTERFACE_MAPPINGS=public:veth-pub-int |
| 50 | # |
| 51 | # eg. (openvswitch agent) |
| 52 | # Q_USE_PROVIDERNET_FOR_PUBLIC=True |
| 53 | # PUBLIC_PHYSICAL_NETWORK=public |
| 54 | # OVS_BRIDGE_MAPPINGS=public:br-ex |
| 55 | Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-False} |
| 56 | PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public} |
| 57 | |
| 58 | # Generate 40-bit IPv6 Global ID to comply with RFC 4193 |
| 59 | IPV6_GLOBAL_ID=`uuidgen | sed s/-//g | cut -c 23- | sed -e "s/\(..\)\(....\)\(....\)/\1:\2:\3/"` |
| 60 | |
| 61 | # IPv6 gateway and subnet defaults, in case they are not customized in localrc |
| 62 | IPV6_RA_MODE=${IPV6_RA_MODE:-slaac} |
| 63 | IPV6_ADDRESS_MODE=${IPV6_ADDRESS_MODE:-slaac} |
| 64 | IPV6_PUBLIC_SUBNET_NAME=${IPV6_PUBLIC_SUBNET_NAME:-ipv6-public-subnet} |
| 65 | IPV6_PRIVATE_SUBNET_NAME=${IPV6_PRIVATE_SUBNET_NAME:-ipv6-private-subnet} |
| 66 | FIXED_RANGE_V6=${FIXED_RANGE_V6:-fd$IPV6_GLOBAL_ID::/64} |
| 67 | IPV6_PRIVATE_NETWORK_GATEWAY=${IPV6_PRIVATE_NETWORK_GATEWAY:-fd$IPV6_GLOBAL_ID::1} |
| 68 | IPV6_PUBLIC_RANGE=${IPV6_PUBLIC_RANGE:-2001:db8::/64} |
| 69 | IPV6_PUBLIC_NETWORK_GATEWAY=${IPV6_PUBLIC_NETWORK_GATEWAY:-2001:db8::2} |
| 70 | IPV6_ROUTER_GW_IP=${IPV6_ROUTER_GW_IP:-2001:db8::1} |
| 71 | |
| 72 | # Gateway and subnet defaults, in case they are not customized in localrc |
| 73 | NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1} |
| 74 | PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1} |
| 75 | PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"} |
| 76 | PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"} |
| 77 | |
| 78 | # Subnetpool defaults |
| 79 | SUBNETPOOL_NAME=${SUBNETPOOL_NAME:-"shared-default-subnetpool"} |
| 80 | |
| 81 | SUBNETPOOL_PREFIX_V4=${SUBNETPOOL_PREFIX_V4:-10.0.0.0/8} |
| 82 | SUBNETPOOL_PREFIX_V6=${SUBNETPOOL_PREFIX_V6:-2001:db8:8000::/48} |
| 83 | |
| 84 | SUBNETPOOL_SIZE_V4=${SUBNETPOOL_SIZE_V4:-24} |
| 85 | SUBNETPOOL_SIZE_V6=${SUBNETPOOL_SIZE_V6:-64} |
| 86 | |
| 87 | function _determine_config_l3 { |
| 88 | local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE" |
| 89 | echo "$opts" |
| 90 | } |
| 91 | |
| 92 | function _configure_neutron_l3_agent { |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 93 | Q_L3_ENABLED=True |
| 94 | |
| 95 | cp $NEUTRON_DIR/etc/l3_agent.ini.sample $Q_L3_CONF_FILE |
| 96 | |
| 97 | iniset $Q_L3_CONF_FILE DEFAULT verbose True |
| 98 | iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Sean M. Collins | a2ed055 | 2016-05-11 15:35:10 -0400 | [diff] [blame] | 99 | iniset $Q_L3_CONF_FILE AGENT root_helper "$Q_RR_COMMAND" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 100 | if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then |
Sean M. Collins | a2ed055 | 2016-05-11 15:35:10 -0400 | [diff] [blame] | 101 | iniset $Q_L3_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 102 | fi |
| 103 | |
| 104 | _neutron_setup_interface_driver $Q_L3_CONF_FILE |
| 105 | |
| 106 | neutron_plugin_configure_l3_agent |
| 107 | |
Sean M. Collins | a2ed055 | 2016-05-11 15:35:10 -0400 | [diff] [blame] | 108 | _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 109 | |
| 110 | if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then |
Sean M. Collins | a2ed055 | 2016-05-11 15:35:10 -0400 | [diff] [blame] | 111 | _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 112 | fi |
| 113 | } |
| 114 | |
| 115 | # Explicitly set router id in l3 agent configuration |
| 116 | function _neutron_set_router_id { |
| 117 | if [[ "$Q_L3_ROUTER_PER_TENANT" == "False" ]]; then |
| 118 | iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID |
| 119 | fi |
| 120 | } |
| 121 | |
| 122 | # Get ext_gw_interface depending on value of Q_USE_PUBLIC_VETH |
| 123 | function _neutron_get_ext_gw_interface { |
| 124 | if [[ "$Q_USE_PUBLIC_VETH" == "True" ]]; then |
| 125 | echo $Q_PUBLIC_VETH_EX |
| 126 | else |
| 127 | # Disable in-band as we are going to use local port |
| 128 | # to communicate with VMs |
| 129 | sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \ |
| 130 | other_config:disable-in-band=true |
| 131 | echo $PUBLIC_BRIDGE |
| 132 | fi |
| 133 | } |
| 134 | |
| 135 | function create_neutron_initial_network { |
| 136 | local project_id |
| 137 | project_id=$(openstack project list | grep " demo " | get_field 1) |
| 138 | die_if_not_set $LINENO project_id "Failure retrieving project_id for demo" |
| 139 | |
| 140 | # Allow drivers that need to create an initial network to do so here |
| 141 | if type -p neutron_plugin_create_initial_network_profile > /dev/null; then |
| 142 | neutron_plugin_create_initial_network_profile $PHYSICAL_NETWORK |
| 143 | fi |
| 144 | |
| 145 | if is_provider_network; then |
| 146 | die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK" |
| 147 | die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specify the PROVIDER_NETWORK_TYPE" |
| 148 | NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create $PHYSICAL_NETWORK --tenant_id $project_id --provider:network_type $PROVIDER_NETWORK_TYPE --provider:physical_network "$PHYSICAL_NETWORK" ${SEGMENTATION_ID:+--provider:segmentation_id $SEGMENTATION_ID} --shared | grep ' id ' | get_field 2) |
| 149 | die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $project_id" |
| 150 | |
| 151 | if [[ "$IP_VERSION" =~ 4.* ]]; then |
| 152 | SUBNET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create --tenant_id $project_id --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --name $PROVIDER_SUBNET_NAME --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2) |
| 153 | die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $PROVIDER_SUBNET_NAME $project_id" |
| 154 | fi |
| 155 | |
| 156 | if [[ "$IP_VERSION" =~ .*6 ]] && [[ -n "$IPV6_PROVIDER_FIXED_RANGE" ]] && [[ -n "$IPV6_PROVIDER_NETWORK_GATEWAY" ]]; then |
| 157 | SUBNET_V6_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create --tenant_id $project_id --ip_version 6 --ipv6-address-mode $IPV6_ADDRESS_MODE --gateway $IPV6_PROVIDER_NETWORK_GATEWAY --name $IPV6_PROVIDER_SUBNET_NAME $NET_ID $IPV6_PROVIDER_FIXED_RANGE | grep 'id' | get_field 2) |
| 158 | die_if_not_set $LINENO SUBNET_V6_ID "Failure creating SUBNET_V6_ID for $IPV6_PROVIDER_SUBNET_NAME $project_id" |
| 159 | fi |
| 160 | |
| 161 | if [[ $Q_AGENT == "openvswitch" ]]; then |
| 162 | sudo ip link set $OVS_PHYSICAL_BRIDGE up |
| 163 | sudo ip link set br-int up |
| 164 | sudo ip link set $PUBLIC_INTERFACE up |
| 165 | fi |
| 166 | else |
| 167 | NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create --tenant-id $project_id "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2) |
| 168 | die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PRIVATE_NETWORK_NAME $project_id" |
| 169 | |
| 170 | if [[ "$IP_VERSION" =~ 4.* ]]; then |
| 171 | # Create IPv4 private subnet |
| 172 | SUBNET_ID=$(_neutron_create_private_subnet_v4 $project_id) |
| 173 | fi |
| 174 | |
| 175 | if [[ "$IP_VERSION" =~ .*6 ]]; then |
| 176 | # Create IPv6 private subnet |
| 177 | IPV6_SUBNET_ID=$(_neutron_create_private_subnet_v6 $project_id) |
| 178 | fi |
| 179 | fi |
| 180 | |
| 181 | AUTO_ALLOCATE_EXT=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" ext-list | grep 'auto-allocated-topology' | get_field 1) |
| 182 | SUBNETPOOL_EXT=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" ext-list | grep 'subnet_allocation' | get_field 1) |
| 183 | if [[ "$Q_L3_ENABLED" == "True" ]]; then |
| 184 | # Create a router, and add the private subnet as one of its interfaces |
| 185 | if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then |
| 186 | # create a tenant-owned router. |
| 187 | ROUTER_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-create --tenant-id $project_id $Q_ROUTER_NAME | grep ' id ' | get_field 2) |
| 188 | die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $project_id $Q_ROUTER_NAME" |
| 189 | else |
| 190 | # Plugin only supports creating a single router, which should be admin owned. |
| 191 | ROUTER_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2) |
| 192 | die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME" |
| 193 | fi |
| 194 | |
| 195 | # if the extension is available, then mark the external |
| 196 | # network as default, and provision default subnetpools |
| 197 | EXTERNAL_NETWORK_FLAGS="--router:external" |
| 198 | if [[ -n $AUTO_ALLOCATE_EXT && -n $SUBNETPOOL_EXT ]]; then |
| 199 | EXTERNAL_NETWORK_FLAGS="$EXTERNAL_NETWORK_FLAGS --is-default" |
| 200 | if [[ "$IP_VERSION" =~ 4.* ]]; then |
| 201 | SUBNETPOOL_V4_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnetpool-create $SUBNETPOOL_NAME --default-prefixlen $SUBNETPOOL_SIZE_V4 --pool-prefix $SUBNETPOOL_PREFIX_V4 --shared --is-default=True | grep ' id ' | get_field 2) |
| 202 | fi |
| 203 | if [[ "$IP_VERSION" =~ .*6 ]]; then |
| 204 | SUBNETPOOL_V6_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnetpool-create $SUBNETPOOL_NAME --default-prefixlen $SUBNETPOOL_SIZE_V6 --pool-prefix $SUBNETPOOL_PREFIX_V6 --shared --is-default=True | grep ' id ' | get_field 2) |
| 205 | fi |
| 206 | fi |
| 207 | # Create an external network, and a subnet. Configure the external network as router gw |
| 208 | if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then |
| 209 | EXT_NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create "$PUBLIC_NETWORK_NAME" -- $EXTERNAL_NETWORK_FLAGS --provider:network_type=flat --provider:physical_network=${PUBLIC_PHYSICAL_NETWORK} | grep ' id ' | get_field 2) |
| 210 | else |
| 211 | EXT_NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create "$PUBLIC_NETWORK_NAME" -- $EXTERNAL_NETWORK_FLAGS | grep ' id ' | get_field 2) |
| 212 | fi |
| 213 | die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME" |
| 214 | |
| 215 | if [[ "$IP_VERSION" =~ 4.* ]]; then |
| 216 | # Configure router for IPv4 public access |
| 217 | _neutron_configure_router_v4 |
| 218 | fi |
| 219 | |
| 220 | if [[ "$IP_VERSION" =~ .*6 ]]; then |
| 221 | # Configure router for IPv6 public access |
| 222 | _neutron_configure_router_v6 |
| 223 | fi |
| 224 | fi |
| 225 | } |
| 226 | |
| 227 | # Create private IPv4 subnet |
| 228 | function _neutron_create_private_subnet_v4 { |
| 229 | local project_id=$1 |
| 230 | local subnet_params="--tenant-id $project_id " |
| 231 | subnet_params+="--ip_version 4 " |
| 232 | subnet_params+="--gateway $NETWORK_GATEWAY " |
| 233 | subnet_params+="--name $PRIVATE_SUBNET_NAME " |
| 234 | subnet_params+="$NET_ID $FIXED_RANGE" |
| 235 | local subnet_id |
| 236 | subnet_id=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep ' id ' | get_field 2) |
| 237 | die_if_not_set $LINENO subnet_id "Failure creating private IPv4 subnet for $project_id" |
| 238 | echo $subnet_id |
| 239 | } |
| 240 | |
| 241 | # Create private IPv6 subnet |
| 242 | function _neutron_create_private_subnet_v6 { |
| 243 | local project_id=$1 |
| 244 | die_if_not_set $LINENO IPV6_RA_MODE "IPV6 RA Mode not set" |
| 245 | die_if_not_set $LINENO IPV6_ADDRESS_MODE "IPV6 Address Mode not set" |
| 246 | local ipv6_modes="--ipv6-ra-mode $IPV6_RA_MODE --ipv6-address-mode $IPV6_ADDRESS_MODE" |
| 247 | local subnet_params="--tenant-id $project_id " |
| 248 | subnet_params+="--ip_version 6 " |
| 249 | subnet_params+="--gateway $IPV6_PRIVATE_NETWORK_GATEWAY " |
| 250 | subnet_params+="--name $IPV6_PRIVATE_SUBNET_NAME " |
| 251 | subnet_params+="$NET_ID $FIXED_RANGE_V6 $ipv6_modes" |
| 252 | local ipv6_subnet_id |
| 253 | ipv6_subnet_id=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep ' id ' | get_field 2) |
| 254 | die_if_not_set $LINENO ipv6_subnet_id "Failure creating private IPv6 subnet for $project_id" |
| 255 | echo $ipv6_subnet_id |
| 256 | } |
| 257 | |
| 258 | # Create public IPv4 subnet |
| 259 | function _neutron_create_public_subnet_v4 { |
| 260 | local subnet_params+="--ip_version 4 " |
| 261 | subnet_params+="${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} " |
| 262 | subnet_params+="--gateway $PUBLIC_NETWORK_GATEWAY " |
| 263 | subnet_params+="--name $PUBLIC_SUBNET_NAME " |
| 264 | subnet_params+="$EXT_NET_ID $FLOATING_RANGE " |
| 265 | subnet_params+="-- --enable_dhcp=False" |
| 266 | local id_and_ext_gw_ip |
| 267 | id_and_ext_gw_ip=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ') |
| 268 | die_if_not_set $LINENO id_and_ext_gw_ip "Failure creating public IPv4 subnet" |
| 269 | echo $id_and_ext_gw_ip |
| 270 | } |
| 271 | |
| 272 | # Create public IPv6 subnet |
| 273 | function _neutron_create_public_subnet_v6 { |
| 274 | local subnet_params="--ip_version 6 " |
| 275 | subnet_params+="--gateway $IPV6_PUBLIC_NETWORK_GATEWAY " |
| 276 | subnet_params+="--name $IPV6_PUBLIC_SUBNET_NAME " |
| 277 | subnet_params+="$EXT_NET_ID $IPV6_PUBLIC_RANGE " |
| 278 | subnet_params+="-- --enable_dhcp=False" |
| 279 | local ipv6_id_and_ext_gw_ip |
| 280 | ipv6_id_and_ext_gw_ip=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ') |
| 281 | die_if_not_set $LINENO ipv6_id_and_ext_gw_ip "Failure creating an IPv6 public subnet" |
| 282 | echo $ipv6_id_and_ext_gw_ip |
| 283 | } |
| 284 | |
| 285 | # Configure neutron router for IPv4 public access |
| 286 | function _neutron_configure_router_v4 { |
| 287 | neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-interface-add $ROUTER_ID $SUBNET_ID |
| 288 | # Create a public subnet on the external network |
| 289 | local id_and_ext_gw_ip |
| 290 | id_and_ext_gw_ip=$(_neutron_create_public_subnet_v4 $EXT_NET_ID) |
| 291 | local ext_gw_ip |
| 292 | ext_gw_ip=$(echo $id_and_ext_gw_ip | get_field 2) |
| 293 | PUB_SUBNET_ID=$(echo $id_and_ext_gw_ip | get_field 5) |
| 294 | # Configure the external network as the default router gateway |
| 295 | neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-gateway-set $ROUTER_ID $EXT_NET_ID |
| 296 | |
| 297 | # This logic is specific to using the l3-agent for layer 3 |
| 298 | if is_service_enabled q-l3; then |
| 299 | # Configure and enable public bridge |
| 300 | local ext_gw_interface="none" |
| 301 | if is_neutron_ovs_base_plugin; then |
| 302 | ext_gw_interface=$(_neutron_get_ext_gw_interface) |
| 303 | elif [[ "$Q_AGENT" = "linuxbridge" ]]; then |
| 304 | # Search for the brq device the neutron router and network for $FIXED_RANGE |
| 305 | # will be using. |
| 306 | # e.x. brq3592e767-da for NET_ID 3592e767-da66-4bcb-9bec-cdb03cd96102 |
| 307 | ext_gw_interface=brq${EXT_NET_ID:0:11} |
| 308 | fi |
| 309 | if [[ "$ext_gw_interface" != "none" ]]; then |
| 310 | local cidr_len=${FLOATING_RANGE#*/} |
| 311 | local testcmd="ip -o link | grep -q $ext_gw_interface" |
| 312 | test_with_retry "$testcmd" "$ext_gw_interface creation failed" |
| 313 | if [[ $(ip addr show dev $ext_gw_interface | grep -c $ext_gw_ip) == 0 && ( $Q_USE_PROVIDERNET_FOR_PUBLIC == "False" || $Q_USE_PUBLIC_VETH == "True" ) ]]; then |
| 314 | sudo ip addr add $ext_gw_ip/$cidr_len dev $ext_gw_interface |
| 315 | sudo ip link set $ext_gw_interface up |
| 316 | fi |
| 317 | ROUTER_GW_IP=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F'ip_address' '{ print $2 }' | cut -f3 -d\" | tr '\n' ' ') |
| 318 | die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP" |
| 319 | sudo ip route replace $FIXED_RANGE via $ROUTER_GW_IP |
| 320 | fi |
| 321 | _neutron_set_router_id |
| 322 | fi |
| 323 | } |
| 324 | |
| 325 | # Configure neutron router for IPv6 public access |
| 326 | function _neutron_configure_router_v6 { |
| 327 | neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-interface-add $ROUTER_ID $IPV6_SUBNET_ID |
| 328 | # Create a public subnet on the external network |
| 329 | local ipv6_id_and_ext_gw_ip |
| 330 | ipv6_id_and_ext_gw_ip=$(_neutron_create_public_subnet_v6 $EXT_NET_ID) |
| 331 | local ipv6_ext_gw_ip |
| 332 | ipv6_ext_gw_ip=$(echo $ipv6_id_and_ext_gw_ip | get_field 2) |
| 333 | local ipv6_pub_subnet_id |
| 334 | ipv6_pub_subnet_id=$(echo $ipv6_id_and_ext_gw_ip | get_field 5) |
| 335 | |
| 336 | # If the external network has not already been set as the default router |
| 337 | # gateway when configuring an IPv4 public subnet, do so now |
| 338 | if [[ "$IP_VERSION" == "6" ]]; then |
| 339 | neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-gateway-set $ROUTER_ID $EXT_NET_ID |
| 340 | fi |
| 341 | |
| 342 | # This logic is specific to using the l3-agent for layer 3 |
| 343 | if is_service_enabled q-l3; then |
| 344 | # Ensure IPv6 forwarding is enabled on the host |
| 345 | sudo sysctl -w net.ipv6.conf.all.forwarding=1 |
| 346 | # Configure and enable public bridge |
| 347 | # Override global IPV6_ROUTER_GW_IP with the true value from neutron |
| 348 | IPV6_ROUTER_GW_IP=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" port-list -c fixed_ips | grep $ipv6_pub_subnet_id | awk -F'ip_address' '{ print $2 }' | cut -f3 -d\" | tr '\n' ' ') |
| 349 | die_if_not_set $LINENO IPV6_ROUTER_GW_IP "Failure retrieving IPV6_ROUTER_GW_IP" |
| 350 | |
| 351 | if is_neutron_ovs_base_plugin; then |
| 352 | local ext_gw_interface |
| 353 | ext_gw_interface=$(_neutron_get_ext_gw_interface) |
| 354 | local ipv6_cidr_len=${IPV6_PUBLIC_RANGE#*/} |
| 355 | |
| 356 | # Configure interface for public bridge |
| 357 | sudo ip -6 addr add $ipv6_ext_gw_ip/$ipv6_cidr_len dev $ext_gw_interface |
| 358 | sudo ip -6 route replace $FIXED_RANGE_V6 via $IPV6_ROUTER_GW_IP dev $ext_gw_interface |
| 359 | fi |
| 360 | _neutron_set_router_id |
| 361 | fi |
| 362 | } |
watanabe.isao | 4f4d95a | 2016-05-12 20:35:20 +0900 | [diff] [blame^] | 363 | |
| 364 | function is_provider_network { |
| 365 | if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ] && [ "$Q_L3_ENABLED" == "False" ]; then |
| 366 | return 0 |
| 367 | fi |
| 368 | return 1 |
| 369 | } |