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