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} |
Ihar Hrachyshka | 7b5c7dc | 2016-07-15 20:17:13 +0200 | [diff] [blame] | 18 | PUBLIC_BRIDGE_MTU=${PUBLIC_BRIDGE_MTU:-1500} |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 19 | |
Kevin Benton | 1554ade | 2016-07-22 09:40:19 -0700 | [diff] [blame] | 20 | # If Q_ASSIGN_GATEWAY_TO_PUBLIC_BRIDGE=True, assign the gateway IP of the public |
| 21 | # subnet to the public bridge interface even if Q_USE_PROVIDERNET_FOR_PUBLIC is |
| 22 | # used. |
| 23 | Q_ASSIGN_GATEWAY_TO_PUBLIC_BRIDGE=${Q_ASSIGN_GATEWAY_TO_PUBLIC_BRIDGE:-True} |
| 24 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 25 | # If Q_USE_PUBLIC_VETH=True, create and use a veth pair instead of |
| 26 | # PUBLIC_BRIDGE. This is intended to be used with |
| 27 | # Q_USE_PROVIDERNET_FOR_PUBLIC=True. |
| 28 | Q_USE_PUBLIC_VETH=${Q_USE_PUBLIC_VETH:-False} |
| 29 | Q_PUBLIC_VETH_EX=${Q_PUBLIC_VETH_EX:-veth-pub-ex} |
| 30 | Q_PUBLIC_VETH_INT=${Q_PUBLIC_VETH_INT:-veth-pub-int} |
| 31 | |
vsaienko | d894221 | 2016-05-13 12:51:30 +0300 | [diff] [blame] | 32 | # The next variable is configured by plugin |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 33 | # e.g. _configure_neutron_l3_agent or lib/neutron_plugins/* |
| 34 | # |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 35 | # L3 routers exist per tenant |
| 36 | Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-True} |
| 37 | |
| 38 | |
| 39 | # Use flat providernet for public network |
| 40 | # |
| 41 | # If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network |
| 42 | # for external interface of neutron l3-agent. In that case, |
| 43 | # PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value |
| 44 | # used for the network. In case of ofagent, you should add the |
| 45 | # corresponding entry to your OFAGENT_PHYSICAL_INTERFACE_MAPPINGS. |
| 46 | # For openvswitch agent, you should add the corresponding entry to |
| 47 | # your OVS_BRIDGE_MAPPINGS. |
| 48 | # |
| 49 | # eg. (ofagent) |
| 50 | # Q_USE_PROVIDERNET_FOR_PUBLIC=True |
| 51 | # Q_USE_PUBLIC_VETH=True |
| 52 | # PUBLIC_PHYSICAL_NETWORK=public |
| 53 | # OFAGENT_PHYSICAL_INTERFACE_MAPPINGS=public:veth-pub-int |
| 54 | # |
| 55 | # eg. (openvswitch agent) |
| 56 | # Q_USE_PROVIDERNET_FOR_PUBLIC=True |
| 57 | # PUBLIC_PHYSICAL_NETWORK=public |
| 58 | # OVS_BRIDGE_MAPPINGS=public:br-ex |
Kevin Benton | 1554ade | 2016-07-22 09:40:19 -0700 | [diff] [blame] | 59 | Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-True} |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 60 | PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public} |
| 61 | |
| 62 | # Generate 40-bit IPv6 Global ID to comply with RFC 4193 |
| 63 | IPV6_GLOBAL_ID=`uuidgen | sed s/-//g | cut -c 23- | sed -e "s/\(..\)\(....\)\(....\)/\1:\2:\3/"` |
| 64 | |
| 65 | # IPv6 gateway and subnet defaults, in case they are not customized in localrc |
| 66 | IPV6_RA_MODE=${IPV6_RA_MODE:-slaac} |
| 67 | IPV6_ADDRESS_MODE=${IPV6_ADDRESS_MODE:-slaac} |
| 68 | IPV6_PUBLIC_SUBNET_NAME=${IPV6_PUBLIC_SUBNET_NAME:-ipv6-public-subnet} |
| 69 | IPV6_PRIVATE_SUBNET_NAME=${IPV6_PRIVATE_SUBNET_NAME:-ipv6-private-subnet} |
| 70 | FIXED_RANGE_V6=${FIXED_RANGE_V6:-fd$IPV6_GLOBAL_ID::/64} |
Brian Haley | 31813e9 | 2016-08-22 15:39:22 -0400 | [diff] [blame] | 71 | IPV6_PRIVATE_NETWORK_GATEWAY=${IPV6_PRIVATE_NETWORK_GATEWAY:-} |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 72 | IPV6_PUBLIC_RANGE=${IPV6_PUBLIC_RANGE:-2001:db8::/64} |
| 73 | IPV6_PUBLIC_NETWORK_GATEWAY=${IPV6_PUBLIC_NETWORK_GATEWAY:-2001:db8::2} |
| 74 | IPV6_ROUTER_GW_IP=${IPV6_ROUTER_GW_IP:-2001:db8::1} |
| 75 | |
| 76 | # Gateway and subnet defaults, in case they are not customized in localrc |
Brian Haley | 31813e9 | 2016-08-22 15:39:22 -0400 | [diff] [blame] | 77 | NETWORK_GATEWAY=${NETWORK_GATEWAY:-} |
| 78 | PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-} |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 79 | PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"} |
| 80 | PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"} |
| 81 | |
| 82 | # Subnetpool defaults |
| 83 | SUBNETPOOL_NAME=${SUBNETPOOL_NAME:-"shared-default-subnetpool"} |
| 84 | |
| 85 | SUBNETPOOL_PREFIX_V4=${SUBNETPOOL_PREFIX_V4:-10.0.0.0/8} |
| 86 | SUBNETPOOL_PREFIX_V6=${SUBNETPOOL_PREFIX_V6:-2001:db8:8000::/48} |
| 87 | |
| 88 | SUBNETPOOL_SIZE_V4=${SUBNETPOOL_SIZE_V4:-24} |
| 89 | SUBNETPOOL_SIZE_V6=${SUBNETPOOL_SIZE_V6:-64} |
| 90 | |
Monty Taylor | c12d1d9 | 2016-08-23 19:07:57 -0500 | [diff] [blame] | 91 | default_route_dev=$(ip route | grep ^default | awk '{print $5}') |
| 92 | die_if_not_set $LINENO default_route_dev "Failure retrieving default route device" |
| 93 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 94 | function _determine_config_l3 { |
Angus Lees | a1c70f2 | 2016-05-31 14:43:14 +1000 | [diff] [blame] | 95 | local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 96 | echo "$opts" |
| 97 | } |
| 98 | |
| 99 | function _configure_neutron_l3_agent { |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 100 | |
| 101 | cp $NEUTRON_DIR/etc/l3_agent.ini.sample $Q_L3_CONF_FILE |
| 102 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 103 | iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Sean M. Collins | a2ed055 | 2016-05-11 15:35:10 -0400 | [diff] [blame] | 104 | iniset $Q_L3_CONF_FILE AGENT root_helper "$Q_RR_COMMAND" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 105 | if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then |
Sean M. Collins | a2ed055 | 2016-05-11 15:35:10 -0400 | [diff] [blame] | 106 | 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] | 107 | fi |
| 108 | |
| 109 | _neutron_setup_interface_driver $Q_L3_CONF_FILE |
| 110 | |
Stephen Finucane | 24e29f2 | 2016-06-15 14:31:51 +0100 | [diff] [blame] | 111 | neutron_plugin_configure_l3_agent $Q_L3_CONF_FILE |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 112 | |
Sean Dague | 6a008fa | 2016-08-03 15:09:01 -0400 | [diff] [blame] | 113 | # If we've given a PUBLIC_INTERFACE to take over, then we assume |
| 114 | # that we can own the whole thing, and privot it into the OVS |
| 115 | # bridge. If we are not, we're probably on a single interface |
| 116 | # machine, and we just setup NAT so that fixed guests can get out. |
| 117 | if [[ -n "$PUBLIC_INTERFACE" ]]; then |
| 118 | _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] | 119 | |
Sean Dague | 6a008fa | 2016-08-03 15:09:01 -0400 | [diff] [blame] | 120 | if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then |
| 121 | _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6" |
| 122 | fi |
| 123 | else |
Monty Taylor | c12d1d9 | 2016-08-23 19:07:57 -0500 | [diff] [blame] | 124 | sudo iptables -t nat -A POSTROUTING -o $default_route_dev -s $FLOATING_RANGE -j MASQUERADE |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 125 | fi |
| 126 | } |
| 127 | |
| 128 | # Explicitly set router id in l3 agent configuration |
| 129 | function _neutron_set_router_id { |
| 130 | if [[ "$Q_L3_ROUTER_PER_TENANT" == "False" ]]; then |
| 131 | iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID |
| 132 | fi |
| 133 | } |
| 134 | |
| 135 | # Get ext_gw_interface depending on value of Q_USE_PUBLIC_VETH |
| 136 | function _neutron_get_ext_gw_interface { |
| 137 | if [[ "$Q_USE_PUBLIC_VETH" == "True" ]]; then |
| 138 | echo $Q_PUBLIC_VETH_EX |
| 139 | else |
| 140 | # Disable in-band as we are going to use local port |
| 141 | # to communicate with VMs |
| 142 | sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \ |
| 143 | other_config:disable-in-band=true |
| 144 | echo $PUBLIC_BRIDGE |
| 145 | fi |
| 146 | } |
| 147 | |
| 148 | function create_neutron_initial_network { |
Gary Kotton | 88f8558 | 2016-08-14 06:55:42 -0700 | [diff] [blame] | 149 | if ! is_service_enabled q-svc && ! is_service_enabled neutron-api; then |
| 150 | echo "Controller services not enabled. No networks configured!" |
| 151 | return |
| 152 | fi |
| 153 | if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" == "False" ]]; then |
| 154 | echo "Network creation disabled!" |
| 155 | return |
| 156 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 157 | local project_id |
| 158 | project_id=$(openstack project list | grep " demo " | get_field 1) |
| 159 | die_if_not_set $LINENO project_id "Failure retrieving project_id for demo" |
| 160 | |
| 161 | # Allow drivers that need to create an initial network to do so here |
| 162 | if type -p neutron_plugin_create_initial_network_profile > /dev/null; then |
| 163 | neutron_plugin_create_initial_network_profile $PHYSICAL_NETWORK |
| 164 | fi |
| 165 | |
| 166 | if is_provider_network; then |
| 167 | die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK" |
| 168 | die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specify the PROVIDER_NETWORK_TYPE" |
| 169 | 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) |
| 170 | die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $project_id" |
| 171 | |
| 172 | if [[ "$IP_VERSION" =~ 4.* ]]; then |
| 173 | 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) |
| 174 | die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $PROVIDER_SUBNET_NAME $project_id" |
| 175 | fi |
| 176 | |
Sean M. Collins | e34ec99 | 2016-06-07 12:36:50 -0400 | [diff] [blame] | 177 | if [[ "$IP_VERSION" =~ .*6 ]]; then |
| 178 | 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" |
| 179 | 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" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 180 | 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) |
| 181 | die_if_not_set $LINENO SUBNET_V6_ID "Failure creating SUBNET_V6_ID for $IPV6_PROVIDER_SUBNET_NAME $project_id" |
| 182 | fi |
| 183 | |
| 184 | if [[ $Q_AGENT == "openvswitch" ]]; then |
| 185 | sudo ip link set $OVS_PHYSICAL_BRIDGE up |
| 186 | sudo ip link set br-int up |
| 187 | sudo ip link set $PUBLIC_INTERFACE up |
| 188 | fi |
| 189 | else |
| 190 | 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) |
| 191 | die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PRIVATE_NETWORK_NAME $project_id" |
| 192 | |
| 193 | if [[ "$IP_VERSION" =~ 4.* ]]; then |
| 194 | # Create IPv4 private subnet |
| 195 | SUBNET_ID=$(_neutron_create_private_subnet_v4 $project_id) |
| 196 | fi |
| 197 | |
| 198 | if [[ "$IP_VERSION" =~ .*6 ]]; then |
| 199 | # Create IPv6 private subnet |
| 200 | IPV6_SUBNET_ID=$(_neutron_create_private_subnet_v6 $project_id) |
| 201 | fi |
| 202 | fi |
| 203 | |
Sean M. Collins | c35110e | 2016-05-18 10:38:51 -0400 | [diff] [blame] | 204 | if is_networking_extension_supported "router" && is_networking_extension_supported "external-net"; then |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 205 | # Create a router, and add the private subnet as one of its interfaces |
| 206 | if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then |
| 207 | # create a tenant-owned router. |
| 208 | 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) |
| 209 | die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $project_id $Q_ROUTER_NAME" |
| 210 | else |
| 211 | # Plugin only supports creating a single router, which should be admin owned. |
| 212 | ROUTER_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2) |
| 213 | die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME" |
| 214 | fi |
| 215 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 216 | EXTERNAL_NETWORK_FLAGS="--router:external" |
Sean M. Collins | c35110e | 2016-05-18 10:38:51 -0400 | [diff] [blame] | 217 | if is_networking_extension_supported "auto-allocated-topology" && is_networking_extension_supported "subnet_allocation"; then |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 218 | EXTERNAL_NETWORK_FLAGS="$EXTERNAL_NETWORK_FLAGS --is-default" |
| 219 | if [[ "$IP_VERSION" =~ 4.* ]]; then |
| 220 | 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) |
| 221 | fi |
| 222 | if [[ "$IP_VERSION" =~ .*6 ]]; then |
| 223 | 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) |
| 224 | fi |
| 225 | fi |
| 226 | # Create an external network, and a subnet. Configure the external network as router gw |
| 227 | if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then |
| 228 | 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) |
| 229 | else |
| 230 | 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) |
| 231 | fi |
| 232 | die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME" |
| 233 | |
| 234 | if [[ "$IP_VERSION" =~ 4.* ]]; then |
| 235 | # Configure router for IPv4 public access |
| 236 | _neutron_configure_router_v4 |
| 237 | fi |
| 238 | |
| 239 | if [[ "$IP_VERSION" =~ .*6 ]]; then |
| 240 | # Configure router for IPv6 public access |
| 241 | _neutron_configure_router_v6 |
| 242 | fi |
| 243 | fi |
| 244 | } |
| 245 | |
| 246 | # Create private IPv4 subnet |
| 247 | function _neutron_create_private_subnet_v4 { |
| 248 | local project_id=$1 |
| 249 | local subnet_params="--tenant-id $project_id " |
| 250 | subnet_params+="--ip_version 4 " |
Brian Haley | 31813e9 | 2016-08-22 15:39:22 -0400 | [diff] [blame] | 251 | if [[ -n "$NETWORK_GATEWAY" ]]; then |
| 252 | subnet_params+="--gateway $NETWORK_GATEWAY " |
| 253 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 254 | subnet_params+="--name $PRIVATE_SUBNET_NAME " |
| 255 | subnet_params+="$NET_ID $FIXED_RANGE" |
| 256 | local subnet_id |
| 257 | subnet_id=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep ' id ' | get_field 2) |
| 258 | die_if_not_set $LINENO subnet_id "Failure creating private IPv4 subnet for $project_id" |
| 259 | echo $subnet_id |
| 260 | } |
| 261 | |
| 262 | # Create private IPv6 subnet |
| 263 | function _neutron_create_private_subnet_v6 { |
| 264 | local project_id=$1 |
| 265 | die_if_not_set $LINENO IPV6_RA_MODE "IPV6 RA Mode not set" |
| 266 | die_if_not_set $LINENO IPV6_ADDRESS_MODE "IPV6 Address Mode not set" |
| 267 | local ipv6_modes="--ipv6-ra-mode $IPV6_RA_MODE --ipv6-address-mode $IPV6_ADDRESS_MODE" |
| 268 | local subnet_params="--tenant-id $project_id " |
| 269 | subnet_params+="--ip_version 6 " |
Brian Haley | 31813e9 | 2016-08-22 15:39:22 -0400 | [diff] [blame] | 270 | if [[ -n "$IPV6_PRIVATE_NETWORK_GATEWAY" ]]; then |
| 271 | subnet_params+="--gateway $IPV6_PRIVATE_NETWORK_GATEWAY " |
| 272 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 273 | subnet_params+="--name $IPV6_PRIVATE_SUBNET_NAME " |
| 274 | subnet_params+="$NET_ID $FIXED_RANGE_V6 $ipv6_modes" |
| 275 | local ipv6_subnet_id |
| 276 | ipv6_subnet_id=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep ' id ' | get_field 2) |
| 277 | die_if_not_set $LINENO ipv6_subnet_id "Failure creating private IPv6 subnet for $project_id" |
| 278 | echo $ipv6_subnet_id |
| 279 | } |
| 280 | |
| 281 | # Create public IPv4 subnet |
| 282 | function _neutron_create_public_subnet_v4 { |
Brian Haley | 31813e9 | 2016-08-22 15:39:22 -0400 | [diff] [blame] | 283 | local subnet_params="--ip_version 4 " |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 284 | subnet_params+="${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} " |
Brian Haley | 31813e9 | 2016-08-22 15:39:22 -0400 | [diff] [blame] | 285 | if [[ -n "$PUBLIC_NETWORK_GATEWAY" ]]; then |
| 286 | subnet_params+="--gateway $PUBLIC_NETWORK_GATEWAY " |
| 287 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 288 | subnet_params+="--name $PUBLIC_SUBNET_NAME " |
| 289 | subnet_params+="$EXT_NET_ID $FLOATING_RANGE " |
| 290 | subnet_params+="-- --enable_dhcp=False" |
| 291 | local id_and_ext_gw_ip |
| 292 | id_and_ext_gw_ip=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ') |
| 293 | die_if_not_set $LINENO id_and_ext_gw_ip "Failure creating public IPv4 subnet" |
| 294 | echo $id_and_ext_gw_ip |
| 295 | } |
| 296 | |
| 297 | # Create public IPv6 subnet |
| 298 | function _neutron_create_public_subnet_v6 { |
| 299 | local subnet_params="--ip_version 6 " |
| 300 | subnet_params+="--gateway $IPV6_PUBLIC_NETWORK_GATEWAY " |
| 301 | subnet_params+="--name $IPV6_PUBLIC_SUBNET_NAME " |
| 302 | subnet_params+="$EXT_NET_ID $IPV6_PUBLIC_RANGE " |
| 303 | subnet_params+="-- --enable_dhcp=False" |
| 304 | local ipv6_id_and_ext_gw_ip |
| 305 | 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 ') |
| 306 | die_if_not_set $LINENO ipv6_id_and_ext_gw_ip "Failure creating an IPv6 public subnet" |
| 307 | echo $ipv6_id_and_ext_gw_ip |
| 308 | } |
| 309 | |
| 310 | # Configure neutron router for IPv4 public access |
| 311 | function _neutron_configure_router_v4 { |
| 312 | neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-interface-add $ROUTER_ID $SUBNET_ID |
| 313 | # Create a public subnet on the external network |
| 314 | local id_and_ext_gw_ip |
| 315 | id_and_ext_gw_ip=$(_neutron_create_public_subnet_v4 $EXT_NET_ID) |
| 316 | local ext_gw_ip |
| 317 | ext_gw_ip=$(echo $id_and_ext_gw_ip | get_field 2) |
| 318 | PUB_SUBNET_ID=$(echo $id_and_ext_gw_ip | get_field 5) |
| 319 | # Configure the external network as the default router gateway |
| 320 | neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-gateway-set $ROUTER_ID $EXT_NET_ID |
| 321 | |
| 322 | # This logic is specific to using the l3-agent for layer 3 |
Sean M. Collins | d00cbb7 | 2016-06-20 13:53:44 -0400 | [diff] [blame] | 323 | if is_service_enabled q-l3 || is_service_enabled neutron-l3; then |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 324 | # Configure and enable public bridge |
| 325 | local ext_gw_interface="none" |
| 326 | if is_neutron_ovs_base_plugin; then |
| 327 | ext_gw_interface=$(_neutron_get_ext_gw_interface) |
| 328 | elif [[ "$Q_AGENT" = "linuxbridge" ]]; then |
Kevin Benton | 6a42a85 | 2016-07-21 11:11:54 -0700 | [diff] [blame] | 329 | # Get the device the neutron router and network for $FIXED_RANGE |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 330 | # will be using. |
Kevin Benton | 6a42a85 | 2016-07-21 11:11:54 -0700 | [diff] [blame] | 331 | if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then |
| 332 | # in provider nets a bridge mapping uses the public bridge directly |
| 333 | ext_gw_interface=$PUBLIC_BRIDGE |
| 334 | else |
| 335 | # e.x. brq3592e767-da for NET_ID 3592e767-da66-4bcb-9bec-cdb03cd96102 |
| 336 | ext_gw_interface=brq${EXT_NET_ID:0:11} |
| 337 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 338 | fi |
| 339 | if [[ "$ext_gw_interface" != "none" ]]; then |
| 340 | local cidr_len=${FLOATING_RANGE#*/} |
| 341 | local testcmd="ip -o link | grep -q $ext_gw_interface" |
| 342 | test_with_retry "$testcmd" "$ext_gw_interface creation failed" |
Kevin Benton | 1554ade | 2016-07-22 09:40:19 -0700 | [diff] [blame] | 343 | 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" || $Q_ASSIGN_GATEWAY_TO_PUBLIC_BRIDGE == "True" ) ]]; then |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 344 | sudo ip addr add $ext_gw_ip/$cidr_len dev $ext_gw_interface |
| 345 | sudo ip link set $ext_gw_interface up |
| 346 | fi |
| 347 | 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' ' ') |
| 348 | die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP" |
| 349 | sudo ip route replace $FIXED_RANGE via $ROUTER_GW_IP |
| 350 | fi |
| 351 | _neutron_set_router_id |
| 352 | fi |
| 353 | } |
| 354 | |
| 355 | # Configure neutron router for IPv6 public access |
| 356 | function _neutron_configure_router_v6 { |
| 357 | neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-interface-add $ROUTER_ID $IPV6_SUBNET_ID |
| 358 | # Create a public subnet on the external network |
| 359 | local ipv6_id_and_ext_gw_ip |
| 360 | ipv6_id_and_ext_gw_ip=$(_neutron_create_public_subnet_v6 $EXT_NET_ID) |
| 361 | local ipv6_ext_gw_ip |
| 362 | ipv6_ext_gw_ip=$(echo $ipv6_id_and_ext_gw_ip | get_field 2) |
| 363 | local ipv6_pub_subnet_id |
| 364 | ipv6_pub_subnet_id=$(echo $ipv6_id_and_ext_gw_ip | get_field 5) |
| 365 | |
| 366 | # If the external network has not already been set as the default router |
| 367 | # gateway when configuring an IPv4 public subnet, do so now |
| 368 | if [[ "$IP_VERSION" == "6" ]]; then |
| 369 | neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-gateway-set $ROUTER_ID $EXT_NET_ID |
| 370 | fi |
| 371 | |
| 372 | # This logic is specific to using the l3-agent for layer 3 |
Sean M. Collins | d00cbb7 | 2016-06-20 13:53:44 -0400 | [diff] [blame] | 373 | if is_service_enabled q-l3 || is_service_enabled neutron-l3; then |
Monty Taylor | c12d1d9 | 2016-08-23 19:07:57 -0500 | [diff] [blame] | 374 | # Ensure IPv6 RAs are accepted on the interface with the default route. |
| 375 | # This is needed for neutron-based devstack clouds to work in |
| 376 | # IPv6-only clouds in the gate. Please do not remove this without |
| 377 | # talking to folks in Infra. |
| 378 | sudo sysctl -w net.ipv6.conf.$default_route_dev.accept_ra=2 |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 379 | # Ensure IPv6 forwarding is enabled on the host |
| 380 | sudo sysctl -w net.ipv6.conf.all.forwarding=1 |
| 381 | # Configure and enable public bridge |
| 382 | # Override global IPV6_ROUTER_GW_IP with the true value from neutron |
| 383 | 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' ' ') |
| 384 | die_if_not_set $LINENO IPV6_ROUTER_GW_IP "Failure retrieving IPV6_ROUTER_GW_IP" |
| 385 | |
| 386 | if is_neutron_ovs_base_plugin; then |
| 387 | local ext_gw_interface |
| 388 | ext_gw_interface=$(_neutron_get_ext_gw_interface) |
| 389 | local ipv6_cidr_len=${IPV6_PUBLIC_RANGE#*/} |
| 390 | |
| 391 | # Configure interface for public bridge |
Yi Zhao | a464ea7 | 2016-05-12 10:32:58 +0800 | [diff] [blame] | 392 | sudo ip -6 addr replace $ipv6_ext_gw_ip/$ipv6_cidr_len dev $ext_gw_interface |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 393 | sudo ip -6 route replace $FIXED_RANGE_V6 via $IPV6_ROUTER_GW_IP dev $ext_gw_interface |
| 394 | fi |
| 395 | _neutron_set_router_id |
| 396 | fi |
| 397 | } |
watanabe.isao | 4f4d95a | 2016-05-12 20:35:20 +0900 | [diff] [blame] | 398 | |
| 399 | function is_provider_network { |
vsaienko | d894221 | 2016-05-13 12:51:30 +0300 | [diff] [blame] | 400 | if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ]; then |
watanabe.isao | 4f4d95a | 2016-05-12 20:35:20 +0900 | [diff] [blame] | 401 | return 0 |
| 402 | fi |
| 403 | return 1 |
| 404 | } |
Sean M. Collins | c35110e | 2016-05-18 10:38:51 -0400 | [diff] [blame] | 405 | |
| 406 | function is_networking_extension_supported { |
| 407 | local extension=$1 |
| 408 | # TODO(sc68cal) cache this instead of calling every time |
| 409 | EXT_LIST=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" ext-list -c alias -f value) |
| 410 | [[ $EXT_LIST =~ $extension ]] && return 0 |
| 411 | } |