#!/bin/bash 

echo ""

case "$1" in
  start)
	# On a besoin de mgr
	./vm_start.sh "__mgr.testbed.aaa" || {
		echo "Echec au demarrage de mgr, abandon."
		exit 1
	}

	# On a besoin ensuite de rtmgr
	./vm_start.sh "rt-rtmgr.testbed.aaa" || {
		echo "Echec au demarrage de rtmgr, abandon."
		exit 1
	}
	
	# Maintenant on peut demarrer les autres VM en paralelle
	./vm_start.sh "rt-nas.a.rt.testbed.aaa" &
	sleep 3
	./vm_start.sh "rt-proxy.a.rt.testbed.aaa" &
	sleep 3
	./vm_start.sh "rt-proxy.b.rt.testbed.aaa" &
	sleep 3
	./vm_start.sh "rt-serv.b.rt.testbed.aaa" &
	
	# Done
	wait
	;;
  pause)
	# On arrete toutes ces machines en sauvant leur etat
	./vm_pause.sh "__mgr.testbed.aaa" &
	./vm_pause.sh "rt-rtmgr.testbed.aaa" &
	./vm_pause.sh "rt-nas.a.rt.testbed.aaa" &
	./vm_pause.sh "rt-proxy.a.rt.testbed.aaa" &
	./vm_pause.sh "rt-proxy.b.rt.testbed.aaa" &
	./vm_pause.sh "rt-serv.b.rt.testbed.aaa" &
	wait
	;;
  stop)
	# On arrete toutes ces machines en envoyant un shutdown
	./vm_stop.sh "__mgr.testbed.aaa" &
	./vm_stop.sh "rt-rtmgr.testbed.aaa" &
	./vm_stop.sh "rt-nas.a.rt.testbed.aaa" &
	./vm_stop.sh "rt-proxy.a.rt.testbed.aaa" &
	./vm_stop.sh "rt-proxy.b.rt.testbed.aaa" &
	./vm_stop.sh "rt-serv.b.rt.testbed.aaa" &
	wait
	;;
  *)
	echo "Usage: $0 [start|pause|stop]"
	exit 1
esac

exit 0
