[lxc-devel] [PATCH] lxc-debian: Add hwaddr handling logic

Stéphane Graber stgraber at ubuntu.com
Wed Oct 23 23:59:49 UTC 2013


Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 templates/lxc-debian.in | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/templates/lxc-debian.in b/templates/lxc-debian.in
index 4dd4910..645fe8d 100644
--- a/templates/lxc-debian.in
+++ b/templates/lxc-debian.in
@@ -207,6 +207,13 @@ copy_configuration()
     hostname=$3
     arch=$4
 
+    # 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
-- 
1.8.3.2





More information about the lxc-devel mailing list