From 61f97ab06898425d7e26e65d1ae9f73e38763190 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 1 Aug 2013 11:19:20 +0200 Subject: [PATCH] manage use of virtio for disk, add doc --- manifests/one-ide.manifest | 3 +- manifests/one-virtio.manifest | 54 +++++++++++++++++++++++++++++++ providers/raw/REAME.md | 16 +++++++++ providers/raw/tasks/boot.py | 25 ++++++++++++-- providers/raw/tasks/filesystem.py | 14 +++----- 5 files changed, 99 insertions(+), 13 deletions(-) create mode 100644 manifests/one-virtio.manifest create mode 100644 providers/raw/REAME.md diff --git a/manifests/one-ide.manifest b/manifests/one-ide.manifest index 7dc267c..26db2a9 100644 --- a/manifests/one-ide.manifest +++ b/manifests/one-ide.manifest @@ -10,8 +10,7 @@ "bootstrapper": { "mount_dir": "/mnt/target", "image_file": "/tmp/one.img", - "tarball": true, - "device": "/dev/sda" + "tarball": true }, "image": { "name" : "debian-{release}-{architecture}-{virtualization}-{%y}{%m}{%d}", diff --git a/manifests/one-virtio.manifest b/manifests/one-virtio.manifest new file mode 100644 index 0000000..02ce685 --- /dev/null +++ b/manifests/one-virtio.manifest @@ -0,0 +1,54 @@ +{ + "provider" : "raw", + "virtualization": "virtio", + "credentials" : { + "access-key": null, + "secret-key": null, + "root": "test" + }, + + "bootstrapper": { + "mount_dir": "/mnt/target", + "image_file": "/tmp/one.img", + "tarball": true + }, + "image": { + "name" : "debian-{release}-{architecture}-{virtualization}-{%y}{%m}{%d}", + "description": "Debian {release} {architecture} ({virtualization})" + }, + "system": { + "release" : "wheezy", + "architecture": "amd64", + "timezone" : "UTC", + "locale" : "en_US", + "charmap" : "UTF-8", + "mirror" : "ftp://ftp.fr.debian.org/debian/" + }, + "volume": { + "backing" : "raw", + "filesystem": "ext4", + "size" : 1024 + }, + "plugins": { + "admin_user": { + "enabled": false + }, + "build_metadata": { + "enabled": false, + "path" : "/root/build-metadata-{ami_name}" + }, + "prebootstrapped": { + "enabled": false, + "snapshot": "" + }, + "opennebula": { + "enabled": true + }, + "user_packages": { + "enabled": true, + "repo": [ "apache2" ], + "local": [] + } + + } +} diff --git a/providers/raw/REAME.md b/providers/raw/REAME.md new file mode 100644 index 0000000..efbd58b --- /dev/null +++ b/providers/raw/REAME.md @@ -0,0 +1,16 @@ +# RAW provider + +This provider creates a raw image file. It can be combined with opennebula plugin to add OpenNebula contextualization. + +By default, it creates a network interface configured with DHCP. + +# Configuration + +## provider + +*raw* : use this provider + +##virtualization + +* ide: basic disk emulation (/dev/sda) +* virtio: Virtio emulation (for KVM), provides better disk performances (/dev/vda) diff --git a/providers/raw/tasks/boot.py b/providers/raw/tasks/boot.py index 0bf3d28..6ae840c 100644 --- a/providers/raw/tasks/boot.py +++ b/providers/raw/tasks/boot.py @@ -18,22 +18,43 @@ class ConfigureGrub(Task): for cfg in [os.path.join(grubd, f) for f in os.listdir(grubd)]: os.chmod(cfg, os.stat(cfg).st_mode & ~ x_all) + from common.tools import log_check_call from shutil import copy + script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/grub.d/40_custom')) script_dst = os.path.join(info.root, 'etc/grub.d/40_custom') copy(script_src, script_dst) os.chmod(script_dst, rwxr_xr_x) - from common.tools import sed_i + if info.manifest.virtualization == 'virtio': + modules_path = os.path.join(info.root, + 'etc/initramfs-tools/modules') + with open(modules_path, 'a') as modules: + modules.write("\nvirtio_pci\nvirtio_blk\n") + + grub_def = os.path.join(info.root, 'etc/default/grub') - from common.tools import log_check_call log_check_call(['/usr/sbin/chroot', info.root, 'ln', '-s', '/boot/grub/grub.cfg', '/boot/grub/menu.lst']) log_check_call(['/usr/sbin/chroot', info.root, 'update-initramfs', '-u']) log_check_call(['grub-install', '--boot-directory='+info.root+"/boot/", '/dev/loop0']) + + log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-grub']) + log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-grub']) + from common.tools import sed_i + if info.manifest.virtualization == 'virtio': + grub_cfg = os.path.join(info.root, 'boot/grub/grub.cfg') + sed_i(grub_cfg, 'sda', 'vda') + device_map = os.path.join(info.root, + 'boot/grub/device.map') + sed_i(device_map, 'sda', 'vda') + #log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-grub']) + + + class BlackListModules(Task): description = 'Blacklisting kernel modules' phase = phases.system_modification diff --git a/providers/raw/tasks/filesystem.py b/providers/raw/tasks/filesystem.py index 5b255c7..48dc473 100644 --- a/providers/raw/tasks/filesystem.py +++ b/providers/raw/tasks/filesystem.py @@ -138,14 +138,10 @@ class ModifyFstab(Task): mount_opts.append('nobarrier') fstab_path = os.path.join(info.root, 'etc/fstab') with open(fstab_path, 'a') as fstab: - fstab.write(('/dev/sda1 / {filesystem} {mount_opts} 1 1\n' + device = '/dev/sda1' + if info.manifest.virtualization == 'virtio': + device = '/dev/vda1' + + fstab.write((device+' / {filesystem} {mount_opts} 1 1\n' .format(filesystem=info.manifest.volume['filesystem'].lower(), mount_opts=','.join(mount_opts)))) - log_check_call(['/usr/sbin/chroot', info.root, 'cat', '/etc/fstab']) - -class InstallMbr(Task): - description = 'Install MBR' - phase = phases.system_modification - - def run(self, info): - log_check_call(['install-mbr', '-v', info.manifest.bootstrapper['image_file']])