#!/bin/bash

# PURPOSE: Post DevStack Neutron configuration
#
# DevStack was configured with this local.conf:
# https://kashyapc.fedorapeople.org/virt/openstack/Minimal-DevStack-local.conf

# Traverse into DevStack directory and source 'demo' user credentials
cd ~/src/cloud/devstack
. openrc demo

# Use some environment variables
PRIV_NET=$(neutron net-list | grep private | awk '{print $2;}')
PUB_NET=$(neutron net-list | grep public | awk '{print $2;}')
ROUTER_ID=$(neutron router-list | grep router1 | awk '{print $2;}')

# (1) Associate router to gateway
neutron router-gateway-set $ROUTER_ID $PUB_NET

# (2) Add sercurity group rules for ICMP and SSH
neutron security-group-rule-create --protocol icmp \
     --direction ingress --remote-ip-prefix 0.0.0.0/0 default

neutron security-group-rule-create --protocol tcp  \
     --port-range-min 22 --port-range-max 22 --direction ingress default


# (3) Setup floating IP
# neutron floatingip-create public
# neutron port-list --device-id $NOVA-INSTANCE-UUID
# neutron floatingip-associate $FLOATING-IP-UUID $DEVICE-ID
