]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Gentoo template - Add a hwaddr if there is only one veth
authorVicente Olivert Riera <Vincent.Riera@imgtec.com>
Fri, 23 Jan 2015 16:03:13 +0000 (16:03 +0000)
committerStéphane Graber <stgraber@ubuntu.com>
Sat, 24 Jan 2015 21:47:24 +0000 (16:47 -0500)
Reuse the code from the Debian template to associate a hwaddr if there
is only one veth interface in the container's config file.

Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
templates/lxc-gentoo.in

index d0df8999fc7e60ed6833b8ac7c3b924199eb5253..92edcd4c42e61d93b708f81311b47a4ac01d1d5e 100644 (file)
@@ -681,6 +681,13 @@ container_conf()
     #at this point if there
     conf_file="${path}/config"
 
+    # if there is exactly one veth network entry, make sure it has an
+    # associated hwaddr.
+    nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' ${conf_file} | wc -l`
+    if [ $nics -eq 1 ]; then
+        grep -q "^lxc.network.hwaddr" ${conf_file} || 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/.$//')" ${conf_file}
+    fi
+
     if grep -q "^lxc.rootfs" "${conf_file}" ; then
         #lxc-create already provided one
         conf_rootfs_line=""