MYIP:=$(shell hostname -i)
RUNNING_CONTAINER:=$(shell sudo docker ps|grep "xos"|awk '{print $$NF}')
LAST_CONTAINER=$(shell sudo docker ps -l -q)

# For installing XOS on a node that is not the OpenStack head node
MGMT_SUBNET="192.168.122.0/24"
HEAD_NODE_IP="130.127.133.61"

test: common_cloudlab images
	echo "# Autogenerated -- do not edit" > Dockerfile
	cat ../common/Dockerfile.common Dockerfile.kilo-install >> Dockerfile
	cd ../../..; sudo docker build -t xos -f xos/configurations/kilo-install/Dockerfile .
	sudo docker run -d -p 9999:8000 -v /usr/local/share/ca-certificates:/usr/local/share/ca-certificates:ro  xos
	bash ../common/wait_for_xos.sh

common_cloudlab:
	make -C ../common -f Makefile.cloudlab

stop:
	sudo docker stop $(RUNNING_CONTAINER)

showlogs:
	sudo docker logs $(LAST_CONTAINER)

enter:
	sudo docker exec -t -i $(RUNNING_CONTAINER) bash

images:
	sudo bash -c "source /root/setup/admin-openrc.sh; \
		glance image-show trusty-server-multi-nic || \
		glance image-create --name trusty-server-multi-nic \
			--disk-format qcow2 \
			--file /proj/xos-PG0/acb/images/trusty-server-multi-nic.img \
			--container-format bare"

remote_head_node:
	sudo iptables -t nat -A OUTPUT -p tcp -d $MGMT_SUBNET -j DNAT --to-destination $HEAD_NODE_IP
	sudo iptables -t nat -A PREROUTING -p tcp -d $MGMT_SUBNET -j DNAT --to-destination $HEAD_NODE_IP
