[Fusionforge-commits] r13772 - branches/Branch_5_1/tests/lxc

Christian Bayle cbayle at fusionforge.org
Wed Jul 13 16:32:21 CEST 2011


Author: cbayle
Date: 2011-07-13 16:32:21 +0200 (Wed, 13 Jul 2011)
New Revision: 13772

Added:
   branches/Branch_5_1/tests/lxc/destroy
   branches/Branch_5_1/tests/lxc/start
   branches/Branch_5_1/tests/lxc/stop
Modified:
   branches/Branch_5_1/tests/lxc/Makefile
   branches/Branch_5_1/tests/lxc/lxc-centos5
   branches/Branch_5_1/tests/lxc/lxc-debian6
Log:
Merge from trunk


Modified: branches/Branch_5_1/tests/lxc/Makefile
===================================================================
--- branches/Branch_5_1/tests/lxc/Makefile	2011-07-13 13:34:32 UTC (rev 13771)
+++ branches/Branch_5_1/tests/lxc/Makefile	2011-07-13 14:32:21 UTC (rev 13772)
@@ -1,70 +1,38 @@
-
-VMROOT=/var/lib/lxc/vmdebian6
-
 -include ../config/default
 -include ../config/$(shell hostname)
 
-#default: vmdebian6-config netstaticdeb installkey
 default: installtemplate
+
+help: 
 	@echo "read the Makefile to see available targets"
 
-/cgroup: beroot
-	[ ! -d /cgroup ] || mkdir /cgroup
+/cgroup:
+	[ -d /cgroup ] || ( if [ $(shell id -u) != "0" ] then; echo "you should be root to run this" ; else; mkdir /cgroup; fi
 
 checkmount: checkfstab /cgroup
-	grep -q 0 /cgroup/cpuset.cpu || mount /cgroup
+	grep -q 0 /cgroup/cpuset.cpus || mount /cgroup
 
 checkfstab:
-	grep ^cgroup /etc/fstab || (echo "You need to add cgroup entry to fstab \"cgroup        /cgroup        cgroup        defaults    0    0\"" && false)
+	@grep ^cgroup /etc/fstab || (echo "You need to add cgroup entry to fstab 'cgroup /cgroup cgroup defaults 0 0'" && false)
 
-/var/lib/lxc/vmdebian6: beroot /usr/bin/lxc-info bridging
-	mkdir $@
-	LANG=C MIRROR=$(DEBMIRROR) SUITE=$(DIST) ./lxc-debian6 -p $@
+/usr/lib/lxc:
+	@[ -d $@ ] || sudo apt-get install lxc
 
-/usr/bin/lxc-info: beroot
-	apt-get install lxc bridge-utils
+/usr/share/bridge-utils:
+	@[ -d $@ ] || apt-get install bridge-utils
 
-bridging:
-	@grep -q '^iface br0 inet' /etc/network/interfaces || (echo "Please setup network bridging" && false)
+/usr/bin/netmask:
+	@[ -f $@ ] || sudo apt-get install netmask
 
-vmdebian6-config: beroot /var/lib/lxc/vmdebian6
-	@grep -q lxc.utsname /var/lib/lxc/vmdebian6/config || \
-	(sh -c "echo \"lxc.utsname = vmdebian6\" >> $(VMROOT)/config" ; \
-	sh -c "echo \"lxc.network.type = veth\" >> $(VMROOT)/config" ; \
-	sh -c "echo \"lxc.network.flags = up\" >> $(VMROOT)/config" ; \
-	sh -c "echo \"lxc.network.link = br0\" >> $(VMROOT)/config" ; \
-	)
+/usr/bin/rinse:
+	@[ -f $@ ] || sudo apt-get install rinse
 
-vmdebian6-ip: beroot
-	#sh -c "echo \"lxc.network.ipv4 = $(IPDEBBASE).$(VEIDDEB)/24\">> $(VMROOT)/config" ; \
-	#
+/usr/sbin/tunctl:
+	@[ -f $@ ] || sudo apt-get install uml-utilities
 
-cleandeb6: beroot
-	lxc-stop -n vmdebian6 || true
-	lxc-destroy -n vmdebian6 || true
+bridging:
+	@grep -q '^iface br0 inet' /etc/network/interfaces || (echo "Please setup network bridging" && false)
 
-netstaticdeb: beroot
-	@grep -q "iface eth0 inet static" $(VMROOT)/rootfs/etc/network/interfaces || \
-	(sh -c "echo \"auto lo\" > $(VMROOT)/rootfs/etc/network/interfaces" ; \
-	sh -c "echo \"iface lo inet loopback\" >> $(VMROOT)/rootfs/etc/network/interfaces" ; \
-	sh -c "echo \"auto eth0\" >> $(VMROOT)/rootfs/etc/network/interfaces" ; \
-	sh -c "echo \"iface eth0 inet static\" >> $(VMROOT)/rootfs/etc/network/interfaces" ; \
-	sh -c "echo \"	address $(IPDEBBASE).$(VEIDDEB)\" >> $(VMROOT)/rootfs/etc/network/interfaces" ; \
-	sh -c "echo \"	netmask 255.255.255.0\" >> $(VMROOT)/rootfs/etc/network/interfaces" ; \
-	sh -c "echo \"	gateway $(IPDEBBASE).1\" >> $(VMROOT)/rootfs/etc/network/interfaces" ; \
-	)
-
-netstaticdns: beroot
-	#sh -c "echo \"	dns-nameservers $(IPDEBDNS)\" >> $(VMROOT)/rootfs/etc/network/interfaces" ; \
-	#sh -c "echo \"	dns-search $(IPDEBDOMAIN)\" >> $(VMROOT)/rootfs/etc/network/interfaces" ; \
-	#
-
-installkey: beroot ssh
-	[ -d $(VMROOT)/root/.ssh ] || mkdir -p $(VMROOT)/rootfs/root/.ssh
-	cp $(SSHPUBKEY) $(VMROOT)/rootfs/root/.ssh/authorized_keys
-	[ -d $(VMROOT)/etc/ssh ] || mkdir -p $(VMROOT)/rootfs/etc/ssh
-	cp ssh/ssh_host_* $(VMROOT)/rootfs/etc/ssh/
-
 ssh:
 	[ -e ssh ] || (echo "You need a ssh dir containing host keys like /etc/ssh_host_*" && false)
 
@@ -75,44 +43,44 @@
 beroot:
 	@[ $(shell id -u) = "0" ] || (echo "you should be root to run this" ; exit 1)
 
-lxcstart: /cgroup/tasks
-	lxc-start -n vmdebian6 -d
-	sleep 5
-	lxc-info -n vmdebian6
-
 addrights: beroot
 	lxc-setcap
 
 delrights: beroot
 	lxc-setcap -d
 
-installtemplate: beroot
+installtemplate: /usr/lib/lxc/templates/lxc-debian6 /usr/lib/lxc/templates/lxc-centos5
+
+/usr/lib/lxc/templates/lxc-debian6: lxc-debian6 /usr/lib/lxc
 	cat lxc-debian6 | sed 's!http://cdn.debian.net/debian/!$(DEBMIRROR)!' > /usr/lib/lxc/templates/lxc-debian6
 	chmod 755 /usr/lib/lxc/templates/lxc-debian6
+
+/usr/lib/lxc/templates/lxc-centos5: lxc-centos5 /usr/lib/lxc
 	cp lxc-centos5 /usr/lib/lxc/templates/
 
-createdeb: beroot
-	/usr/bin/lxc-create -n debian6.local -f config.debian6 -t debian6
+createdeb:
+	sudo /usr/bin/lxc-create -n dhdebian6.local -f config.debian6 -t debian6
 
-createcos: beroot
-	/usr/bin/lxc-create -n centos5.local -f config.centos5 -t centos5
+createcos: /usr/bin/netmask /usr/bin/rinse
+	sudo /usr/bin/lxc-create -n dhcentos5.local -f config.centos5 -t centos5
 
-startdeb:
-	sudo LANG=C /usr/bin/lxc-start -n debian6.local -d
+startdeb: checkmount
+	sudo LANG=C /usr/bin/lxc-start -n dhdebian6.local -d
 
 stopdeb:
-	sudo LANG=C /usr/bin/lxc-stop -n debian6.local
+	sudo LANG=C /usr/bin/lxc-stop -n dhdebian6.local
 
-startcos:
-	sudo LANG=C /usr/bin/lxc-start -n centos5.local -d
+startcos: checkmount
+	sudo LANG=C /usr/bin/lxc-start -n dhcentos5.local -d
 
 stopcos:
-	sudo LANG=C /usr/bin/lxc-stop -n centos5.local
+	sudo LANG=C /usr/bin/lxc-stop -n dhcentos5.local
 
-destroydeb: beroot
-	sudo LANG=C /usr/bin/lxc-stop -n debian6.local
-	sudo LANG=C /usr/bin/lxc-destroy -n debian6.local
+destroydeb:
+	sudo LANG=C /usr/bin/lxc-stop -n dhdebian6.local
+	sudo LANG=C /usr/bin/lxc-destroy -n dhdebian6.local
 
-destroycos: beroot
-	sudo LANG=C /usr/bin/lxc-stop -n centos5.local
-	sudo LANG=C /usr/bin/lxc-destroy -n centos5.local
+destroycos:
+	sudo LANG=C /usr/bin/lxc-stop -n dhcentos5.local
+	sudo LANG=C /usr/bin/lxc-destroy -n dhcentos5.local
+

Added: branches/Branch_5_1/tests/lxc/destroy
===================================================================
--- branches/Branch_5_1/tests/lxc/destroy	                        (rev 0)
+++ branches/Branch_5_1/tests/lxc/destroy	2011-07-13 14:32:21 UTC (rev 13772)
@@ -0,0 +1,12 @@
+#! /bin/sh -x
+
+lxcdir=`dirname $0`
+
+IFS=: ; VARS=`eval echo \\\$$BASEHOST` ; unset IFS ; set $VARS
+VMENGINE=$1
+TEMPLATE=$2
+CIDR=$3
+IPGW=$4
+
+sudo /usr/bin/lxc-stop -n $HOST
+sudo /usr/bin/lxc-destroy -n $HOST


Property changes on: branches/Branch_5_1/tests/lxc/destroy
___________________________________________________________________
Added: svn:executable
   + *

Modified: branches/Branch_5_1/tests/lxc/lxc-centos5
===================================================================
--- branches/Branch_5_1/tests/lxc/lxc-centos5	2011-07-13 13:34:32 UTC (rev 13771)
+++ branches/Branch_5_1/tests/lxc/lxc-centos5	2011-07-13 14:32:21 UTC (rev 13772)
@@ -36,6 +36,23 @@
     mkdir -p $rootfs/selinux
     echo 0 > $rootfs/selinux/enforce
 
+    # configure localhost
+    if ! grep -q "^127.0.0.1" $rootfs/etc/hosts
+    then
+	cat <<EOF >> $rootfs/etc/hosts
+# Do not remove the following line, or various programs
+# that require network functionality will fail.
+127.0.0.1       localhost.localdomain localhost
+::1             localhost6.localdomain6 localhost6
+EOF
+    fi
+    if ! grep -q "^::1" $rootfs/etc/hosts
+    then
+	cat <<EOF >> $rootfs/etc/hosts
+::1             localhost6.localdomain6 localhost6
+EOF
+    fi
+
     if grep -q ^lxc.network.ipv4 $path/config
     then
         # configure static network
@@ -556,11 +573,11 @@
 fi
 if [ ! -e $hostkeydir ]
 then
-    mkdir $hostkeydir
+    mkdir -p $hostkeydir
 fi
 if [ ! -e $macdir ]
 then
-    mkdir $macdir
+    mkdir -p $macdir
 fi
 
 install_centos $rootfs

Modified: branches/Branch_5_1/tests/lxc/lxc-debian6
===================================================================
--- branches/Branch_5_1/tests/lxc/lxc-debian6	2011-07-13 13:34:32 UTC (rev 13771)
+++ branches/Branch_5_1/tests/lxc/lxc-debian6	2011-07-13 14:32:21 UTC (rev 13772)
@@ -432,11 +432,11 @@
 fi
 if [ ! -e $hostkeydir ]
 then
-    mkdir $hostkeydir
+    mkdir -p $hostkeydir
 fi
 if [ ! -e $macdir ]
 then
-    mkdir $macdir
+    mkdir -p $macdir
 fi
 
 install_debian $rootfs

Added: branches/Branch_5_1/tests/lxc/start
===================================================================
--- branches/Branch_5_1/tests/lxc/start	                        (rev 0)
+++ branches/Branch_5_1/tests/lxc/start	2011-07-13 14:32:21 UTC (rev 13772)
@@ -0,0 +1,40 @@
+#! /bin/sh
+
+lxcdir=`dirname $0`
+
+IFS=: ; VARS=`eval echo \\\$$BASEHOST` ; unset IFS ; set $VARS
+VMENGINE=$1
+TEMPLATE=$2
+CIDR=$3
+IPGW=$4
+
+if [ -z "$VMENGINE" ]
+then
+	echo "ERROR: VMENGINE not set" 
+	exit 1
+fi
+if [ -z "$TEMPLATE" ]
+then
+	echo "ERROR: TEMPLATE not set"
+	exit 2
+fi
+
+if [ ! -e /usr/lib/lxc/templates/lxc-$TEMPLATE ]
+then 
+	echo "/usr/lib/lxc/templates/lxc-$TEMPLATE not found"
+	echo "you need to install template"
+	echo "run: (cd $lxcdir ; sudo make)"
+else
+	tmpconf=`mktemp`
+	cat $lxcdir/config.$TEMPLATE > $tmpconf
+	if [ ! -z "$CIDR" ] 
+	then
+		echo "lxc.network.ipv4 = $CIDR" >> $tmpconf
+	fi
+	# Next is a bit hacky, the only way I found to pass pubkey to the template
+	# LXC don't allow to pass extra args
+	echo "#lxc.pubkey = $SSHPUBKEY" >> $tmpconf
+	sudo /usr/bin/lxc-create -n $HOST -f $tmpconf -t $TEMPLATE
+	rm -f $tmpconf
+	sudo /usr/bin/lxc-start -n $HOST -d
+fi


Property changes on: branches/Branch_5_1/tests/lxc/start
___________________________________________________________________
Added: svn:executable
   + *

Added: branches/Branch_5_1/tests/lxc/stop
===================================================================
--- branches/Branch_5_1/tests/lxc/stop	                        (rev 0)
+++ branches/Branch_5_1/tests/lxc/stop	2011-07-13 14:32:21 UTC (rev 13772)
@@ -0,0 +1,11 @@
+#! /bin/sh -x
+
+lxcdir=`dirname $0`
+
+IFS=: ; VARS=`eval echo \\\$$BASEHOST` ; unset IFS ; set $VARS
+VMENGINE=$1
+TEMPLATE=$2
+CIDR=$3
+IPGW=$4
+
+sudo /usr/bin/lxc-stop -n $HOST


Property changes on: branches/Branch_5_1/tests/lxc/stop
___________________________________________________________________
Added: svn:executable
   + *




More information about the Fusionforge-commits mailing list