62 lines
2.3 KiB
Bash
Executable File
62 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Initialise the neutron server configuration.
|
|
#
|
|
# This creates initial networks for neutron based on heat metadata and local
|
|
# network configuration.
|
|
#
|
|
# It is not idempotent.
|
|
|
|
set -eux
|
|
set -o pipefail
|
|
|
|
PATH=/usr/local/bin:$PATH
|
|
source /root/stackrc
|
|
|
|
PHYSICAL_NETWORK=$(os-config-applier --type raw --key neutron.ovs.physical_network --key-default '')
|
|
ALLOCATION_START=$(os-config-applier --type netaddress --key neutron.ovs.fixed_range.start --key-default '')
|
|
ALLOCATION_END=$(os-config-applier --type netaddress --key neutron.ovs.fixed_range.end --key-default '')
|
|
NETWORK=$(os-config-applier --type netaddress --key neutron.ovs.ovs_range --key-default 'unset')
|
|
|
|
if [ "$NETWORK" == "unset" ] ; then
|
|
# undercloud / seed cloud - lookup the network device
|
|
BRIDGE=$(os-config-applier --type raw --key neutron.ovs.physical_bridge)
|
|
# NB: assumes only one network on the device
|
|
NETWORK=$(ip addr show dev $BRIDGE | grep ' inet ' | awk '{print $2}')
|
|
# Route traffic to this machine
|
|
NETWORK_GATEWAY=`python -c 'import netaddr, sys; print netaddr.IPNetwork(sys.argv[1]).ip' $NETWORK`
|
|
fi
|
|
NETWORK_CIDR=`python -c 'import netaddr, sys; print netaddr.IPNetwork(sys.argv[1]).cidr' $NETWORK`
|
|
|
|
if [ -n "$ALLOCATION_START" -a -n "$ALLOCATION_END" ] ; then
|
|
ALLOCATION_POOL="start=${ALLOCATION_START},end=${ALLOCATION_END}"
|
|
fi
|
|
|
|
# Hackish: ensure the server is running. XXX: Test without this.
|
|
service neutron-server restart
|
|
|
|
TENANT_ID=$(keystone tenant-list | grep ' admin ' | awk '{print $2}')
|
|
|
|
NET_EXTRA="--shared"
|
|
SUBNET_EXTRA=""
|
|
NET_NAME="default-net"
|
|
if [ -n "$PHYSICAL_NETWORK" ] ; then
|
|
NET_NAME=$PHYSICAL_NETWORK
|
|
NET_EXTRA="--tenant_id $TENANT_ID --provider:network_type flat --provider:physical_network $PHYSICAL_NETWORK"
|
|
SUBNET_EXTRA="--tenant_id $TENANT_ID"
|
|
fi
|
|
|
|
# neutron-server might not be fully started yet, so we're going to
|
|
# call `neutron net-create` in a loop until it returns true
|
|
t=0
|
|
while ! NET_ID=$(neutron net-create $NET_NAME $NET_EXTRA | grep ' id ' | awk '{print $4}'); do
|
|
if [ $t -eq 10 ]; then
|
|
echo "Failed to create network $NET_NAME"
|
|
exit 1
|
|
fi
|
|
t=$(($t + 1))
|
|
sleep 1
|
|
done
|
|
|
|
SUBNET_ID=$(neutron subnet-create $SUBNET_EXTRA --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} ${NETWORK_GATEWAY:+--gateway $NETWORK_GATEWAY} $NET_ID $NETWORK_CIDR | grep ' id ' | awk '{print $4}')
|