Commit 4eff1b4a authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis

deploy/ci: Make vcluster use debootstrap

Introduce a new helper script, mkimage.sh that creates a debian base
raw image with debootstrap so that it can be used in a virtual
cluster.

Install network-manager and a hook to update hostname with info
provided by DHCP responce.

Add new conf setting for the size of the image.

Create another empty image as well so that the VM can use it for
LVM.

Remove unused settings.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
parent 0a3ef83c
[DEFAULT]
# url to get the base image. This is a debian base image with preconfigured
# root password and installed rsa/dsa keys. Plus a NetworkManager hook that
# changes the VM's name based on info provided by dhcp response.
# To create it run: snf-deploy image
image_url = https://pithos.okeanos.grnet.gr/public/832xv
# in order ganeti nodes to support lvm storage (plain disk template) it will
# be needed an extra disk to eventually be able to create a VG. Ganeti requires
# this VG to be at least of 30GB. To this end in order the virtual nodes to have
# this extra disk an image should be created locally. There are three options:
# 1. not create an extra disk (only file storage template will be supported)
# 2. create an image of 30G in image dir (default /var/lib/snf-deploy/images)
# using dd if=/dev/zero of=squeeze.disk1
# 3. create this image in a local VG using lvgreate -L30G squeeze.disk1 lvg
# and create a symbolic link in /var/lib/snf-deploy/images
# Whether to create an extra disk or not
create_extra_disk = False
# lvg is the name of the local VG if any
lvg =
disk_size = 10G
# the bridge to use for the virtual cluster
# on this bridge we will launch a dnsnmasq and provide
......
[DEFAULT]
# url to get the base image. This is a debian base image with preconfigured
# root password and installed rsa/dsa keys. Plus a NetworkManager hook that
# changes the VM's name based on info provided by dhcp response.
# To create it run: snf-deploy image
image_url = https://pithos.okeanos.grnet.gr/public/832xv
# in order ganeti nodes to support lvm storage (plain disk template) it will
# be needed an extra disk to eventually be able to create a VG. Ganeti requires
# this VG to be at least of 30GB. To this end in order the virtual nodes to have
# this extra disk an image should be created locally. There are three options:
# 1. not create an extra disk (only file storage template will be supported)
# 2. create an image of 30G in image dir (default /var/lib/snf-deploy/images)
# using dd if=/dev/zero of=squeeze.disk1
# 3. create this image in a local VG using lvgreate -L30G squeeze.disk1 lvg
# and create a symbolic link in /var/lib/snf-deploy/images
# Whether to create an extra disk or not
create_extra_disk = False
# lvg is the name of the local VG if any
lvg =
disk_size = 10G
# the bridge to use for the virtual cluster
# on this bridge we will launch a dnsnmasq and provide
......
#!/bin/sh
# Filename: /etc/dhcp3/dhclient-exit-hooks.d/hostname
# Purpose: Used by dhclient-script to set the hostname of the system
# to match the DNS information for the host as provided by
# DHCP.
# Depends: dhcp3-client (should be in the base install)
# hostname (for hostname, again, should be in the base)
# bind9-host (for host)
# coreutils (for cut and echo)
#
if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] \
&& [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
then
return
fi
echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
hostname=$(host $new_ip_address | sed 's/.$//' | cut -d ' ' -f 5)
echo $hostname > /etc/hostname
hostname $hostname
echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname
# And that _should_ just about do it...
#!/bin/bash -x
DISTRO=wheezy
MIRROR=http://ftp.gr.debian.org/debian
EXTRA_PACKAGES=acpi-support-base,console-tools,udev,linux-image-amd64,network-manager
: ${DISK0:=/var/lib/snf-deploy/vcluster/disk0}
: ${DISK1:=/var/lib/snf-deploy/vcluster/disk1}
: ${HOSTNAME:=vc}
: ${SIZE:=2G}
: ${DISTRO:=wheezy}
: ${MIRROR:=http://ftp.gr.debian.org/debian}
: ${EXTRA_PACKAGES:=acpi-support-base,console-tools,udev,linux-image-amd64,network-manager}
: ${NMHOOK:=etc/NetworkManager/dispatcher.d/02hostname}
set -e
truncate -s $SIZE $DISK0
truncate -s $SIZE $DISK1
# sfdisk -H 255 -S 63 -u S --quiet --Linux $DISK0 <<EOF
# 2048,,L,*
# EOF
/sbin/parted -s $DISK0 mklabel msdos
/sbin/parted -s $DISK0 mkpart primary ext3 2048s 100%
/sbin/parted -s $DISK0 set 1 boot on
BLOCKDEV=$(losetup -f --show $DISK0)
PARTITION=$(kpartx -l $BLOCKDEV | awk '{print $1}')
kpartx -a $BLOCKDEV
FSDEV=/dev/mapper/$PARTITION
mkfs.ext3 $FSDEV
TEMP=$(mktemp -d)
mount $FSDEV $TEMP
debootstrap --include $EXTRA_PACKAGES $DISTRO $TEMP $MIRROR
BLKID=$(blkid -o value -s UUID $FSDEV)
cat >> $TEMP/etc/fstab <<EOF
proc /proc proc defaults 0 0
UUID=$BLKID / ext3 defaults 0 1
EOF
echo $HOSTNAME > $TEMP/etc/hostname
echo "T0:23:respawn:/sbin/getty ttyS0 38400" >> $TEMP/etc/inittab
mkdir -p $TEMP/$(dirname $NMHOOK)
cat >> $TEMP/$NMHOOK <<EOF
#!/bin/bash
if [ -n "\$DHCP4_HOST_NAME" ]; then
echo \$DHCP4_HOST_NAME > /etc/hostname
hostname \$DHCP4_HOST_NAME
fi
EOF
chmod +x $TEMP/$NMHOOK
chroot $TEMP passwd -d root
umount $TEMP
kpartx -d $BLOCKDEV
losetup -d $BLOCKDEV
#!/bin/bash
if [ -n "$DHCP4_HOST_NAME" ]; then
echo $DHCP4_HOST_NAME > /etc/hostname
hostname $DHCP4_HOST_NAME
fi
......@@ -153,7 +153,6 @@ def init(args):
config.testing_vm = getbool(config.testing_vm)
config.use_local_packages = getbool(config.use_local_packages)
config.create_extra_disk = getbool(config.create_extra_disk)
config.net = ipaddr.IPNetwork(config.subnet)
config.all_nodes = config.nodes.sections()
......
......@@ -18,6 +18,7 @@ import os
import sys
import re
import random
import subprocess
from snfdeploy import config
from snfdeploy import context
from snfdeploy.lib import check_pidfile, create_dir, get_default_route, \
......@@ -149,32 +150,20 @@ def network():
def image():
# FIXME: Create a wheezy image with debootstrap and use it for vcluster
url = config.image_url
disk0 = "{0}/vcluster.disk0".format(config.vcluster_dir)
disk1 = "{0}/vcluster.disk1".format(config.vcluster_dir)
disk0 = os.path.join(config.vcluster_dir, "disk0")
disk1 = os.path.join(config.vcluster_dir, "disk1")
create_dir(config.vcluster_dir, False)
if url and not os.path.exists(disk0):
cmd = "wget {0} -O {1}".format(url, disk0)
os.system(cmd)
if config.create_extra_disk and not os.path.exists(disk1):
disk1_base = os.path.basename(disk1)
if config.lvg:
cmd = """
lvcreate -L30G -n{0} {1}
""".format(disk1_base, config.lvg)
os.system(cmd)
cmd = """
ln -s /dev/{0}/{1} {2}
""".format(config.lvg, disk1_base, disk1)
os.system(cmd)
else:
cmd = "truncate -s 30G {0}".format(disk1)
os.system(cmd)
env = os.environ.copy()
env.update({
"SIZE": config.disk_size,
"DISK0": disk0,
"DISK1": disk1,
})
cmd = os.path.join(config.lib_dir, "mkimage.sh")
subprocess.Popen([cmd], env=env)
def cluster(ctx):
......@@ -190,6 +179,9 @@ def cluster(ctx):
def _launch_vm(name, mac):
check_pidfile("%s/%s.pid" % (config.run_dir, name))
disk0 = os.path.join(config.vcluster_dir, "disk0")
disk1 = os.path.join(config.vcluster_dir, "disk1")
print("Launching cluster node {0}..".format(name))
os.environ["BRIDGE"] = config.bridge
if config.vnc:
......@@ -198,17 +190,13 @@ def _launch_vm(name, mac):
graphics = "-nographic"
disks = """ \
-drive file={0}/vcluster.disk0,format=raw,if=none,id=drive0,snapshot=on \
-drive file={0},format=raw,if=none,id=drive0,snapshot=on \
-device virtio-blk-pci,drive=drive0,id=virtio-blk-pci.0 \
""".format(config.vcluster_dir)
if config.create_extra_disk:
disks += """ \
-drive file={0}/vcluster.disk1,format=raw,if=none,id=drive1,snapshot=on \
-drive file={1},format=raw,if=none,id=drive1,snapshot=on \
-device virtio-blk-pci,drive=drive1,id=virtio-blk-pci.1 \
""".format(config.vcluster_dir)
""".format(disk0, disk1)
ifup = config.lib_dir + "/ifup"
ifup = os.path.join(config.lib_dir, "ifup")
nics = """ \
-netdev tap,id=netdev0,script={0},downscript=no \
-device virtio-net-pci,mac={1},netdev=netdev0,id=virtio-net-pci.0 \
......@@ -218,13 +206,20 @@ def _launch_vm(name, mac):
-device virtio-net-pci,mac={3},netdev=netdev2,id=virtio-net-pci.2 \
""".format(ifup, mac, random_mac(), random_mac())
kernel = """ \
--kernel /boot/vmlinuz-3.2.0-4-amd64 \
--initrd /boot/initrd.img-3.2.0-4-amd64 \
--append "root=/dev/vda1 ro console=ttyS0,38400" \
"""
cmd = """
/usr/bin/kvm -name {0} -pidfile {1}/{0}.pid -balloon virtio -daemonize \
-monitor unix:{1}/{0}.monitor,server,nowait -usbdevice tablet -boot c \
{2} \
{3} \
-m {4} -smp {5} {6} \
""".format(name, config.run_dir, disks, nics, config.mem, config.smp, graphics)
-m {4} -smp {5} {6} {7} \
""".format(name, config.run_dir, disks, nics,
config.mem, config.smp, graphics, kernel)
print cmd
os.system(cmd)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment