Browse code

Make the Neutron l3 plugin use the subnetpools

The plugin creates subnetpools but does not use them when creating the
default subnets. It uses CIDR values that overlap with the
default pools. Change this to use the subnetpools.

Change-Id: I6171c13507e420f146801d323cb1011be36c1e8c
Closes-bug: 1613717

Matt Van Dijk authored on 2016/08/17 00:46:58
Showing 1 changed files
... ...
@@ -149,6 +149,15 @@ function create_neutron_initial_network {
149 149
         neutron_plugin_create_initial_network_profile $PHYSICAL_NETWORK
150 150
     fi
151 151
 
152
+    if is_networking_extension_supported "auto-allocated-topology"; then
153
+        if [[ "$IP_VERSION" =~ 4.* ]]; then
154
+            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)
155
+        fi
156
+        if [[ "$IP_VERSION" =~ .*6 ]]; then
157
+            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)
158
+        fi
159
+    fi
160
+
152 161
     if is_provider_network; then
153 162
         die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
154 163
         die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specify the PROVIDER_NETWORK_TYPE"
... ...
@@ -156,14 +165,20 @@ function create_neutron_initial_network {
156 156
         die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $project_id"
157 157
 
158 158
         if [[ "$IP_VERSION" =~ 4.* ]]; then
159
-            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)
159
+            if [ -z $SUBNETPOOL_V4_ID ]; then
160
+                fixed_range_v4=$FIXED_RANGE
161
+            fi
162
+            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 ${SUBNETPOOL_V4_ID:+--subnetpool $SUBNETPOOL_V4_ID} $NET_ID $fixed_range_v4 | grep ' id ' | get_field 2)
160 163
             die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $PROVIDER_SUBNET_NAME $project_id"
161 164
         fi
162 165
 
163 166
         if [[ "$IP_VERSION" =~ .*6 ]]; then
164 167
             die_if_not_set $LINENO IPV6_PROVIDER_FIXED_RANGE "IPV6_PROVIDER_FIXED_RANGE has not been set, but Q_USE_PROVIDERNET_FOR_PUBLIC is true and IP_VERSION includes 6"
165 168
             die_if_not_set $LINENO IPV6_PROVIDER_NETWORK_GATEWAY "IPV6_PROVIDER_NETWORK_GATEWAY has not been set, but Q_USE_PROVIDERNET_FOR_PUBLIC is true and IP_VERSION includes 6"
166
-            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)
169
+            if [ -z $SUBNETPOOL_V6_ID ]; then
170
+                fixed_range_v6=$IPV6_PROVIDER_FIXED_RANGE
171
+            fi
172
+            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 ${SUBNETPOOL_V6_ID:+--subnetpool $SUBNETPOOL_V6_ID} $NET_ID $fixed_range_v6 | grep 'id' | get_field 2)
167 173
             die_if_not_set $LINENO SUBNET_V6_ID "Failure creating SUBNET_V6_ID for $IPV6_PROVIDER_SUBNET_NAME $project_id"
168 174
         fi
169 175
 
... ...
@@ -200,14 +215,8 @@ function create_neutron_initial_network {
200 200
         fi
201 201
 
202 202
         EXTERNAL_NETWORK_FLAGS="--router:external"
203
-        if is_networking_extension_supported "auto-allocated-topology" && is_networking_extension_supported "subnet_allocation"; then
203
+        if is_networking_extension_supported "auto-allocated-topology"; then
204 204
             EXTERNAL_NETWORK_FLAGS="$EXTERNAL_NETWORK_FLAGS --is-default"
205
-            if [[ "$IP_VERSION" =~ 4.* ]]; then
206
-                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)
207
-            fi
208
-            if [[ "$IP_VERSION" =~ .*6 ]]; then
209
-                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)
210
-            fi
211 205
         fi
212 206
         # Create an external network, and a subnet. Configure the external network as router gw
213 207
         if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
... ...
@@ -232,11 +241,15 @@ function create_neutron_initial_network {
232 232
 # Create private IPv4 subnet
233 233
 function _neutron_create_private_subnet_v4 {
234 234
     local project_id=$1
235
+    if [ -z $SUBNETPOOL_V4_ID ]; then
236
+        fixed_range_v4=$FIXED_RANGE
237
+    fi
235 238
     local subnet_params="--tenant-id $project_id "
236 239
     subnet_params+="--ip_version 4 "
237 240
     subnet_params+="--gateway $NETWORK_GATEWAY "
238 241
     subnet_params+="--name $PRIVATE_SUBNET_NAME "
239
-    subnet_params+="$NET_ID $FIXED_RANGE"
242
+    subnet_params+="${SUBNETPOOL_V4_ID:+--subnetpool $SUBNETPOOL_V4_ID} "
243
+    subnet_params+="$NET_ID $fixed_range_v4"
240 244
     local subnet_id
241 245
     subnet_id=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep ' id ' | get_field 2)
242 246
     die_if_not_set $LINENO subnet_id "Failure creating private IPv4 subnet for $project_id"
... ...
@@ -249,11 +262,15 @@ function _neutron_create_private_subnet_v6 {
249 249
     die_if_not_set $LINENO IPV6_RA_MODE "IPV6 RA Mode not set"
250 250
     die_if_not_set $LINENO IPV6_ADDRESS_MODE "IPV6 Address Mode not set"
251 251
     local ipv6_modes="--ipv6-ra-mode $IPV6_RA_MODE --ipv6-address-mode $IPV6_ADDRESS_MODE"
252
+    if [ -z $SUBNETPOOL_V6_ID ]; then
253
+        fixed_range_v6=$FIXED_RANGE_V6
254
+    fi
252 255
     local subnet_params="--tenant-id $project_id "
253 256
     subnet_params+="--ip_version 6 "
254 257
     subnet_params+="--gateway $IPV6_PRIVATE_NETWORK_GATEWAY "
255 258
     subnet_params+="--name $IPV6_PRIVATE_SUBNET_NAME "
256
-    subnet_params+="$NET_ID $FIXED_RANGE_V6 $ipv6_modes"
259
+    subnet_params+="${SUBNETPOOL_V6_ID:+--subnetpool $SUBNETPOOL_V6_ID} "
260
+    subnet_params+="$NET_ID $fixed_range_v6 $ipv6_modes"
257 261
     local ipv6_subnet_id
258 262
     ipv6_subnet_id=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep ' id ' | get_field 2)
259 263
     die_if_not_set $LINENO ipv6_subnet_id "Failure creating private IPv6 subnet for $project_id"
... ...
@@ -321,7 +338,11 @@ function _neutron_configure_router_v4 {
321 321
             fi
322 322
             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' ' ')
323 323
             die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
324
-            sudo ip route replace  $FIXED_RANGE via $ROUTER_GW_IP
324
+            local replace_range=${SUBNETPOOL_PREFIX_V4}
325
+            if [[ -z "${SUBNETPOOL_V4_ID}" ]]; then
326
+                replace_range=${FIXED_RANGE}
327
+            fi
328
+            sudo ip route replace $replace_range via $ROUTER_GW_IP
325 329
         fi
326 330
         _neutron_set_router_id
327 331
     fi
... ...
@@ -360,7 +381,11 @@ function _neutron_configure_router_v6 {
360 360
 
361 361
             # Configure interface for public bridge
362 362
             sudo ip -6 addr replace $ipv6_ext_gw_ip/$ipv6_cidr_len dev $ext_gw_interface
363
-            sudo ip -6 route replace $FIXED_RANGE_V6 via $IPV6_ROUTER_GW_IP dev $ext_gw_interface
363
+            local replace_range=${SUBNETPOOL_PREFIX_V6}
364
+            if [[ -z "${SUBNETPOOL_V6_ID}" ]]; then
365
+                replace_range=${FIXED_RANGE_V6}
366
+            fi
367
+            sudo ip -6 route replace $replace_range via $IPV6_ROUTER_GW_IP dev $ext_gw_interface
364 368
         fi
365 369
         _neutron_set_router_id
366 370
     fi