MYFLATLANIF:=$(shell netstat -i |grep "flat"|awk '{print $$1}' )
MYFLATLANIP:=$(shell ifconfig $(MYFLATLANIF) | grep "inet addr" | awk -F: '{print $$2}' | awk '{print $$1}' )
SETUPDIR:=../setup

all: prereqs admin-openrc flat_name nodes_yaml public_key private_key ceilometer_url node_key

prereqs:
	make -f Makefile.prereqs
	mkdir -p $(SETUPDIR)

admin-openrc:
	sudo cat /root/setup/admin-openrc.sh > $(SETUPDIR)/admin-openrc.sh
	sudo cat /root/setup/settings > $(SETUPDIR)/controller_settings
	echo 'CONTROLLER_FLAT_LAN_IP=$(MYFLATLANIP)' >> $(SETUPDIR)/controller_settings

flat_name:
	sudo bash -c "source /root/setup/admin-openrc.sh ; neutron net-list" |grep flat|awk '{printf "%s",$$4}' > $(SETUPDIR)/flat_net_name
	[ -s $(SETUPDIR)/flat_net_name ] # throw error if flat_net_name is empty

nodes_yaml:
	bash ./make-nodes-yaml.sh > $(SETUPDIR)/nodes.yaml

ceilometer_url:
	echo http://`hostname -i`/xosmetering/ > $(SETUPDIR)/ceilometer_url

public_key: ~/.ssh/id_rsa.pub
	cp ~/.ssh/id_rsa.pub $(SETUPDIR)

private_key: ~/.ssh/id_rsa
	cp ~/.ssh/id_rsa $(SETUPDIR)

~/.ssh/id_rsa.pub:
	cat /dev/zero | ssh-keygen -q -N ""

node_key:
	sudo cat /root/setup/id_rsa > $(SETUPDIR)/node_key
	sudo cat /root/setup/id_rsa.pub > $(SETUPDIR)/node_key.pub

images:
	source 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
