[Fusionforge-commits] r10500 - trunk/tests/openvz

Christian Bayle cbayle at libremir.placard.fr.eu.org
Thu Sep 16 14:55:47 CEST 2010


Author: cbayle
Date: 2010-09-16 14:55:47 +0200 (Thu, 16 Sep 2010)
New Revision: 10500

Modified:
   trunk/tests/openvz/Makefile
Log:
enhancement on vm build for debian and centos


Modified: trunk/tests/openvz/Makefile
===================================================================
--- trunk/tests/openvz/Makefile	2010-09-16 12:55:35 UTC (rev 10499)
+++ trunk/tests/openvz/Makefile	2010-09-16 12:55:47 UTC (rev 10500)
@@ -1,19 +1,33 @@
 
 DEBMIRROR=http://ftp.fr.debian.org/debian
 RINSECONF=/etc/rinse/rinse.conf
+RINSEBPI=
+RINSEPOSTINST=--after-post-install $(CURDIR)/local.rinse.api
 VEID=100
 VEIDDEBTMPL=105
 VEIDCENTOSTMPL=110
 ARCH=amd64
 DIST=squeeze
-EXTRAPACKAGE="--include=ssh,less,htop"
+EXTRADEBPACKAGE=--include=ssh,less,htop,zsh
+EXTRACENTOSPACKAGE=openssh-server,man,zsh,bind-utils
 DEBVERS=5.0
 CENTVERS=5.4
 
+# Local customization can be done using a local.<hostname> file
+# This is convenient if you use local mirror
 -include local.$(shell hostname)
 
-default: createcentos
-	@echo "README !"
+default: 
+	@echo "Run make <target>"
+	@echo "Available target are"
+	@echo "make net : this will setup a /etc/vz/vznet.conf to register new virtual host to vmbr0 bridge"
+	@echo "  See interfaces.sample to know how to setup a bridge"
+	@echo "make builddebiantemplate : build an openvz debian template"
+	@echo "make buildcentostemplate : build an openvz centos template"
+	@echo "make createdeb : build a debian openvz vm with ID=$(VEIDDEBTMPL)"
+	@echo "make createcentos : build a centos openvz vm with ID=$(VEIDCENTOSTMPL)"
+	@echo ""
+	@echo "Read Makefile for other target"
 
 builddebiantemplate: builddebianvm
 	vzctl set $(VEID) --applyconfig basic --save
@@ -57,27 +71,32 @@
 	-rm -f /var/lib/vz/private/$(VEID)/dev/urandom 
 	[ -c /var/lib/vz/private/$(VEID)/dev/urandom ]  || chroot /var/lib/vz/private/$(VEID) /bin/mknod /dev/urandom c 1 9 
 	[ -d /var/lib/vz/private/$(VEID)/var/lock/rpm ] || chroot /var/lib/vz/private/$(VEID) /bin/mkdir /var/lock/rpm	
+	touch /var/lib/vz/private/$(VEID)/etc/fstab
 	grep -q devpts /var/lib/vz/private/$(VEID)/etc/fstab || \
 		echo "none /dev/pts devpts mode=0620 0 0" >> /var/lib/vz/private/$(VEID)/etc/fstab
 	cd /var/lib/vz/private/$(VEID)/ ; tar --numeric-owner -zcf /var/lib/vz/template/cache/centos-$(CENTVERS)-$(ARCH)-minimal.tar.gz .
-		
 
 builddebianvm: /var/lib/vz/private/$(VEID)/etc /etc/vz/conf/$(VEID).conf 
 
 /var/lib/vz/private/$(VEID)/etc: cleanvz /var/lib/vz/private/$(VEID)
-	[ -d /var/lib/vz/private/$(VEID)/etc ] || sudo debootstrap --arch $(ARCH) $(EXTRAPACKAGE) $(DIST) /var/lib/vz/private/$(VEID) $(DEBMIRROR)
+	[ -d /var/lib/vz/private/$(VEID)/etc ] || sudo debootstrap --arch $(ARCH) $(EXTRADEBPACKAGE) $(DIST) /var/lib/vz/private/$(VEID) $(DEBMIRROR)
 
 buildcentosvm: /var/lib/vz/private/$(VEID)/etc/redhat-release 
 
 /var/lib/vz/private/$(VEID)/etc/redhat-release: cleanvz
-	[ -d /var/lib/vz/private/$(VEID)/etc/redhat-release ] || sudo rinse --config $(RINSECONF) --arch $(ARCH) --distribution centos-5 --directory /var/lib/vz/private/$(VEID)
+	[ -d /var/lib/vz/private/$(VEID)/etc/redhat-release ] || sudo extrapackage="$(EXTRACENTOSPACKAGE)" rinse $(RINSEBPI) $(RINSEPOSTINST) --config $(RINSECONF) --arch $(ARCH) --distribution centos-5 --directory /var/lib/vz/private/$(VEID)
 
 cleanvz:
 	-rmdir /var/lib/vz/private/$(VEID)
 	[ ! -d /var/lib/vz/private/$(VEID) ] || vzctl stop $(VEID)
 	[ ! -d /var/lib/vz/private/$(VEID) ] || vzctl destroy $(VEID)
 	-rm -f /etc/vz/conf/$(VEID).conf.destroyed
+
+cleancentos:
+	make cleanvz VEID=$(VEIDCENTOSTMPL)
 	
+cleandeb:
+	make cleanvz VEID=$(VEIDDEBTMPL)
 
 /var/lib/vz/private/$(VEID):
 	sudo mkdir /var/lib/vz/private/$(VEID)
@@ -88,37 +107,44 @@
 
 finalizedeb:
 	# Give it a hostname.
-	echo `hostname`-$(VEID) > /var/lib/vz/private/$(VEID)/etc/hostname
+	echo `hostname`-$(VEIDDEBTMPL) > /var/lib/vz/private/$(VEIDDEBTMPL)/etc/hostname
 	# Disable getty in /etc/inittab as openvz do not have that.
-	sed -i -e '/getty/d' /var/lib/vz/private/$(VEID)/etc/inittab
+	sed -i -e '/getty/d' /var/lib/vz/private/$(VEIDDEBTMPL)/etc/inittab
 	# Link /etc/mtab to /proc/mtab to make mount work as expected.
-	rm -f /var/lib/vz/private/$(VEID)/etc/mtab
-	ln -s /proc/mounts /var/lib/vz/private/$(VEID)/etc/mtab
+	rm -f /var/lib/vz/private/$(VEIDDEBTMPL)/etc/mtab
+	ln -s /proc/mounts /var/lib/vz/private/$(VEIDDEBTMPL)/etc/mtab
 	# If an IP address is needed for the virtual server
-	#vzctl set $(VEID) --ipadd x.x.x.x --save
+	#vzctl set $(VEIDDEBTMPL) --ipadd x.x.x.x --save
 	# In that case you also need to enable IP forwarding
 	#sysctl -w net.ipv4.ip_forward=1
 	# Add eth0 interface
-	vzctl set $(VEID) --netif_add eth0 --save
+	vzctl set $(VEIDDEBTMPL) --netif_add eth0 --save
 	# Setup dhcp
-	grep -q "auto lo" /var/lib/vz/private/$(VEID)/etc/network/interfaces || \
-		echo "auto lo" >> /var/lib/vz/private/$(VEID)/etc/network/interfaces
-	grep -q "iface lo inet loopback" /var/lib/vz/private/$(VEID)/etc/network/interfaces || \
-		echo "iface lo inet loopback" >> /var/lib/vz/private/$(VEID)/etc/network/interfaces
-	grep -q "auto eth0" /var/lib/vz/private/$(VEID)/etc/network/interfaces || \
-		echo "auto eth0" >> /var/lib/vz/private/$(VEID)/etc/network/interfaces
-	grep -q "iface eth0 inet dhcp" /var/lib/vz/private/$(VEID)/etc/network/interfaces || \
-		echo "iface eth0 inet dhcp" >> /var/lib/vz/private/$(VEID)/etc/network/interfaces
+	grep -q "auto lo" /var/lib/vz/private/$(VEIDDEBTMPL)/etc/network/interfaces || \
+		echo "auto lo" >> /var/lib/vz/private/$(VEIDDEBTMPL)/etc/network/interfaces
+	grep -q "iface lo inet loopback" /var/lib/vz/private/$(VEIDDEBTMPL)/etc/network/interfaces || \
+		echo "iface lo inet loopback" >> /var/lib/vz/private/$(VEIDDEBTMPL)/etc/network/interfaces
+	grep -q "auto eth0" /var/lib/vz/private/$(VEIDDEBTMPL)/etc/network/interfaces || \
+		echo "auto eth0" >> /var/lib/vz/private/$(VEIDDEBTMPL)/etc/network/interfaces
+	grep -q "iface eth0 inet dhcp" /var/lib/vz/private/$(VEIDDEBTMPL)/etc/network/interfaces || \
+		echo "iface eth0 inet dhcp" >> /var/lib/vz/private/$(VEIDDEBTMPL)/etc/network/interfaces
 	# Setup dhclient extra
-	grep -q "^send host-name" /var/lib/vz/private/$(VEID)/etc/dhcp/dhclient.conf || \
-		echo "send host-name \"`hostname`-$(VEID)\";" >> /var/lib/vz/private/$(VEID)/etc/dhcp/dhclient.conf
+	grep -q "^send host-name" /var/lib/vz/private/$(VEIDDEBTMPL)/etc/dhcp/dhclient.conf || \
+		echo "send host-name \"`hostname`-$(VEIDDEBTMPL)\";" >> /var/lib/vz/private/$(VEIDDEBTMPL)/etc/dhcp/dhclient.conf
 
 finalizecentos:
 	# Give it a hostname.
-	echo `hostname`-$(VEID) > /var/lib/vz/private/$(VEID)/etc/hostname
+	echo `hostname`-$(VEIDCENTOSTMPL) > /var/lib/vz/private/$(VEIDCENTOSTMPL)/etc/hostname
+	grep -q "^HOSTNAME=" /var/lib/vz/private/$(VEIDCENTOSTMPL)/etc/sysconfig/network || \
+		echo "HOSTNAME=`hostname`-$(VEIDCENTOSTMPL)" >> /var/lib/vz/private/$(VEIDCENTOSTMPL)/etc/sysconfig/network
 	# Add eth0 interface
-	vzctl set $(VEID) --netif_add eth0 --save
+	vzctl set $(VEIDCENTOSTMPL) --netif_add eth0 --save
 	# Setup dhcp
+	echo "DEVICE=eth0" > /var/lib/vz/private/$(VEIDCENTOSTMPL)/etc/sysconfig/network-scripts/ifcfg-eth0
+	echo "BOOTPROTO=dhcp" >> /var/lib/vz/private/$(VEIDCENTOSTMPL)/etc/sysconfig/network-scripts/ifcfg-eth0
+	echo "ONBOOT=yes" >> /var/lib/vz/private/$(VEIDCENTOSTMPL)/etc/sysconfig/network-scripts/ifcfg-eth0
+	# Setup dhclient extra
+	[ -f /var/lib/vz/private/$(VEIDCENTOSTMPL)/etc/dhclient.conf ] || echo "send host-name \"`hostname`-$(VEIDCENTOSTMPL)\";" > /var/lib/vz/private/$(VEIDCENTOSTMPL)/etc/dhclient.conf
 	
 
 net: /etc/vz/vznet.conf
@@ -133,13 +159,13 @@
 	#sudo ifconfig vmbr0 0
 	#sudo brctl addif vmbr0 eth0
 
-createdeb:
+createdeb: cleandeb
 	vzctl create $(VEIDDEBTMPL) --ostemplate debian-$(DEBVERS)-$(ARCH)-minimal
-	make finalizedeb VEID=$(VEIDDEBTMPL)
+	make finalizedeb
 	
-createcentos:
-	#vzctl create $(VEIDCENTOSTMPL) --ostemplate centos-$(CENTVERS)-$(ARCH)-minimal
-	make finalizecentos VEID=$(VEIDCENTOSTMPL)
+createcentos: cleancentos
+	vzctl create $(VEIDCENTOSTMPL) --ostemplate centos-$(CENTVERS)-$(ARCH)-minimal
+	make finalizecentos
 	
 start:
 	sudo vzctl start $(VEID)




More information about the Fusionforge-commits mailing list