source openrc demo demo
# create public network and subnet for floating IPs and public router IPs
PUB_NET_ID=`quantum net-create public | grep ' id' | awk '{ print $4}'`
PUB_SUBNET_ID=`quantum subnet-create $PUB_NET_ID 40.0.0.0/24 | grep ' id' | awk '{ print $4}'`
# create two private networks
PRIV_NET1_ID=`quantum net-create priv-net1 | grep ' id' | awk '{ print $4}'`
SUBNET1_ID=`quantum subnet-create $PRIV_NET1_ID 91.0.0.0/24 | grep ' id' | awk '{ print $4}'`
PRIV_NET2_ID=`quantum net-create priv-net2 | grep ' id' | awk '{ print $4}'`
SUBNET2_ID=`quantum subnet-create $PRIV_NET2_ID 92.0.0.0/24 | grep ' id' | awk '{ print $4}'`
# create router
# connect router to the two private subnets
ROUTER_ID=`quantum router-create router1 | grep ' id' | awk '{ print $4}'`
quantum router-interface-add $ROUTER_ID $SUBNET1_ID
quantum router-interface-add $ROUTER_ID $SUBNET2_ID
# connect router to the upstream public network
quantum router-gateway-set $ROUTER_ID $PUB_NET_ID
# boot two VMS
IMG_ID=`nova image-list | grep cirros | grep -v kernel | grep -v ram | awk -F "|" '{print $2}'`
VM1_ID=`nova boot --image $IMG_ID --flavor 1 --nic net-id=$PRIV_NET1_ID test1 | grep ' id' | awk '{ print $4 }'`
VM2_ID=`nova boot --image $IMG_ID --flavor 1 --nic net-id=$PRIV_NET2_ID test2 | grep ' id' | awk '{ print $4 }'`
VM1_PORT_ID=`quantum port-list -c id -c device_id | grep $VM1_ID | awk '{ print $4 }'`
VM2_PORT_ID=`quantum port-list -c id -c device_id | grep $VM2_ID | awk '{ print $4 }'`
# create floating IP for VM1, and associate as a second step
FIP1_ID=`quantum floatingip-create $PUB_NET_ID | grep ' id' | awk '{ print $4 }'`
quantum floatingip-associate $FIP1_ID $VM1_PORT_ID
# create floating IP for VM2, associating it in same step
FIP2_ID=`quantum floatingip-create $PUB_NET_ID --port_id $VM2_PORT_ID | grep ' id' | awk '{ print $4 }'`