Generalize xen network config

Allow dhcp for IP addresses.
dhclient3 bug workaround.
Refactor code to improve network creation logic.

Change-Id: Ia3e2e65bbe8b68cf4832595cb7c283c3dc84db19
diff --git a/stack.sh b/stack.sh
index 08fcafe..e1f3083 100755
--- a/stack.sh
+++ b/stack.sh
@@ -200,14 +200,13 @@
 # cases unless you are working on multi-zone mode.
 SCHEDULER=${SCHEDULER:-nova.scheduler.simple.SimpleScheduler}
 
+HOST_IP_IFACE=${HOST_IP_IFACE:-eth0}
 # Use the eth0 IP unless an explicit is set by ``HOST_IP`` environment variable
-if [ ! -n "$HOST_IP" ]; then
-    HOST_IP=`LC_ALL=C /sbin/ifconfig eth0 | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
+if [ -z "$HOST_IP" -o "$HOST_IP" == "dhcp" ]; then
+    HOST_IP=`LC_ALL=C /sbin/ifconfig ${HOST_IP_IFACE} | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
     if [ "$HOST_IP" = "" ]; then
         echo "Could not determine host ip address."
-        echo "If this is not your first run of stack.sh, it is "
-        echo "possible that nova moved your eth0 ip address to the FLAT_NETWORK_BRIDGE."
-        echo "Please specify your HOST_IP in your localrc."
+        echo "Either localrc specified dhcp on ${HOST_IP_IFACE} or defaulted to eth0"
         exit 1
     fi
 fi