Description: set hwaddr in debian template
Author: Serge Hallyn <serge.hallyn@ubuntu.com>
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1080681
Forwarded: no

Index: saucy-lxc/templates/lxc-debian.in
===================================================================
--- saucy-lxc.orig/templates/lxc-debian.in	2013-09-10 18:44:49.608427600 -0400
+++ saucy-lxc/templates/lxc-debian.in	2013-09-10 18:44:49.604427600 -0400
@@ -213,6 +213,13 @@
     rootfs=$2
     hostname=$3
 
+    # if there is exactly one veth network entry, make sure it has an
+    # associated hwaddr.
+    nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
+    if [ $nics -eq 1 ]; then
+        grep -q "^lxc.network.hwaddr" $path/config || sed -i -e "/^lxc\.network\.type[ \t]*=[ \t]*veth/a lxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')" $path/config
+    fi
+
     grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
     cat <<EOF >> $path/config
 lxc.tty = 4
