Merge lp:~guilhem-fr/vmbuilder/oneiric-support into lp:vmbuilder

Proposed by Guilhem Lettron
Status: Needs review
Proposed branch: lp:~guilhem-fr/vmbuilder/oneiric-support
Merge into: lp:vmbuilder
Diff against target: 1849 lines (+729/-243)
26 files modified
VMBuilder/contrib/cli.py (+35/-22)
VMBuilder/disk.py (+90/-39)
VMBuilder/distro.py (+23/-15)
VMBuilder/hypervisor.py (+33/-18)
VMBuilder/plugins/__init__.py (+3/-1)
VMBuilder/plugins/ec2/__init__.py (+11/-11)
VMBuilder/plugins/kvm/__init__.py (+1/-1)
VMBuilder/plugins/kvm/disk.py (+38/-0)
VMBuilder/plugins/kvm/qemu_nbd.py (+117/-0)
VMBuilder/plugins/kvm/vm.py (+4/-0)
VMBuilder/plugins/ubuntu/dapper.py (+138/-34)
VMBuilder/plugins/ubuntu/distro.py (+76/-59)
VMBuilder/plugins/ubuntu/intrepid.py (+1/-0)
VMBuilder/plugins/ubuntu/karmic.py (+1/-0)
VMBuilder/plugins/ubuntu/lucid.py (+29/-1)
VMBuilder/plugins/ubuntu/oneiric.py (+22/-1)
VMBuilder/plugins/ubuntu/precise.py (+22/-0)
VMBuilder/plugins/ubuntu/templates/Copy of devicemap.tmpl (+17/-0)
VMBuilder/plugins/ubuntu/templates/devicemap.tmpl (+9/-3)
VMBuilder/plugins/ubuntu/templates/grubcfg.tmpl (+8/-0)
VMBuilder/plugins/ubuntu/templates/loadcfg.tmpl (+3/-0)
VMBuilder/plugins/ubuntu/templates/sources.list.tmpl (+10/-0)
VMBuilder/tests/disk_tests.py (+7/-7)
VMBuilder/tests/plugin_tests.py (+28/-28)
VMBuilder/util.py (+1/-1)
VMBuilder/vm.py (+2/-2)
To merge this branch: bzr merge lp:~guilhem-fr/vmbuilder/oneiric-support
Reviewer Review Type Date Requested Status
Scott Moser Pending
VMBuilder Pending
Review via email: mp+89858@code.launchpad.net

Description of the change

I change many work for grub2.

I cleanup code in the previous behaviour.
But, to be more "clean", I use another way for KVM hypervisor by using module "nbd" and "qemu-img" (who are dedicated to do this).

Any of my patches must break compatibility, but have a look and don't hesitate to critizise.

FYI, I use it in daily production cloud for my company.

Some parts need some works (especially ended scripts : /etc/fstab and device.map) but nothing blocking for me.

To post a comment you must log in.
Revision history for this message
Guilhem Lettron (guilhem-fr) wrote :

oops for .projects files... they must be ignored (work on eclipse IDE).

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Hi,

Thanks for working on this tree.

I've resolved the conflicts and pushed the result to lp:~serge-hallyn/vmbuilder/merge-guilhem-fr.

I've not yet done any testing of the result.

Could you please elaborate upon:

 Some parts need some works (especially ended scripts : /etc/fstab and device.map) but nothing blocking for me.

Is that extra work just for cleanliness, or will things be broken without it?

Revision history for this message
Guilhem Lettron (guilhem-fr) wrote :

My solution works "out of the box".

To precise what I will do :
* fstab isn't "beautiful". It use /dev/sda[0-1] instead of UUID=****. UUID is usefull when you use virtio (/dev/vda**) as I do.
But VM work fine even if you don't have /dev/vda*

* when you boot for the first time VM, grub show you many fake system (generate from the host). But the first one is the good one, so no problem "out of the box".
I have work many hours to find the problem... but without any succes.
An "update-grub" in the VM clear all the fake.

So for me, my patches solve more problem than they give.

A last things to do for better use, is to prevent user (of KVM) when module "nbd" isn't load.

I don't find any python library to do this... suggestion ?

471. By Guilhem Lettron

big changes :
* add precise
* let parted do a _good_ alignment
* ...

472. By Guilhem Lettron

merge

473. By Guilhem Lettron

no idea what I do #meme

Unmerged revisions

473. By Guilhem Lettron

no idea what I do #meme

472. By Guilhem Lettron

merge

471. By Guilhem Lettron

big changes :
* add precise
* let parted do a _good_ alignment
* ...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'VMBuilder/contrib/cli.py'
--- VMBuilder/contrib/cli.py 2012-05-24 13:49:34 +0000
+++ VMBuilder/contrib/cli.py 2012-09-04 13:48:23 +0000
@@ -23,7 +23,7 @@
23import shutil23import shutil
24import sys24import sys
25import tempfile25import tempfile
26import VMBuilder26import VMBuilder.plugins
27import VMBuilder.util as util27import VMBuilder.util as util
28from VMBuilder.disk import parse_size28from VMBuilder.disk import parse_size
29import VMBuilder.hypervisor29import VMBuilder.hypervisor
@@ -194,7 +194,9 @@
194 hypervisor.get_setting_default(option) != val):194 hypervisor.get_setting_default(option) != val):
195 hypervisor.set_setting_fuzzy(option, val)195 hypervisor.set_setting_fuzzy(option, val)
196196
197
197 chroot_dir = None198 chroot_dir = None
199
198 if self.options.existing_chroot:200 if self.options.existing_chroot:
199 distro.set_chroot_dir(self.options.existing_chroot)201 distro.set_chroot_dir(self.options.existing_chroot)
200 distro.call_hooks('preflight_check')202 distro.call_hooks('preflight_check')
@@ -213,18 +215,28 @@
213 else:215 else:
214 chroot_dir = util.tmpdir(tmp_root=self.options.tmp_root)216 chroot_dir = util.tmpdir(tmp_root=self.options.tmp_root)
215 distro.set_chroot_dir(chroot_dir)217 distro.set_chroot_dir(chroot_dir)
216 distro.build_chroot()218 distro.install()
219 distro.prepare_chroot()
220 distro.build()
221 distro.clean_chroot()
217222
218 if self.options.only_chroot:223 if self.options.only_chroot:
219 print 'Chroot can be found in %s' % distro.chroot_dir224 print 'Chroot can be found in %s' % distro.chroot_dir
220 sys.exit(0)225 sys.exit(0)
221226
222 self.set_disk_layout(optparser, hypervisor)227 self.set_disk_layout(hypervisor)
223 hypervisor.install_os()228 hypervisor.create_environement()
224229 hypervisor.migrate()
230 distro.set_chroot_dir(hypervisor.chroot_dir, hypervisor.dev_dir)
231 distro.prepare_chroot()
232 hypervisor.configure_os()
233 distro.clean_chroot()
234 hypervisor.close_environement()
225 os.mkdir(destdir)235 os.mkdir(destdir)
226 self.fix_ownership(destdir)236 self.fix_ownership(destdir)
227 hypervisor.finalise(destdir)237 hypervisor.finalise(destdir)
238
239
228 # If chroot_dir is not None, it means we created it,240 # If chroot_dir is not None, it means we created it,
229 # and if we reach here, it means the user didn't pass241 # and if we reach here, it means the user didn't pass
230 # --only-chroot. Hence, we need to remove it to clean242 # --only-chroot. Hence, we need to remove it to clean
@@ -236,6 +248,7 @@
236 raise248 raise
237 finally:249 finally:
238 if tmpfs_mount_point is not None:250 if tmpfs_mount_point is not None:
251# pass
239 util.clean_up_tmpfs(tmpfs_mount_point)252 util.clean_up_tmpfs(tmpfs_mount_point)
240 util.run_cmd('rmdir', tmpfs_mount_point)253 util.run_cmd('rmdir', tmpfs_mount_point)
241254
@@ -277,7 +290,7 @@
277 optparser.add_option_group(optgroup)290 optparser.add_option_group(optgroup)
278291
279 def versioninfo(self, option, opt, value, parser):292 def versioninfo(self, option, opt, value, parser):
280 print ('%(major)d.%(minor)d.%(micro)s' %293 print ('%(major)d.%(minor)d.%(micro)s.r%(revno)d' %
281 VMBuilder.get_version_info())294 VMBuilder.get_version_info())
282 sys.exit(0)295 sys.exit(0)
283296
@@ -301,18 +314,13 @@
301 elif opt_str == '--quiet':314 elif opt_str == '--quiet':
302 VMBuilder.set_console_loglevel(logging.CRITICAL)315 VMBuilder.set_console_loglevel(logging.CRITICAL)
303316
304 def set_disk_layout(self, optparser, hypervisor):317 def set_disk_layout(self, hypervisor):
305 default_filesystem = hypervisor.distro.preferred_filesystem()318 default_filesystem = hypervisor.distro.preferred_filesystem()
306 if not self.options.part:319 if not self.options.part:
307 rootsize = parse_size(self.options.rootsize)320 rootsize = parse_size(self.options.rootsize)
308 swapsize = parse_size(self.options.swapsize)321 swapsize = parse_size(self.options.swapsize)
309 optsize = parse_size(self.options.optsize)322 optsize = parse_size(self.options.optsize)
310 if hypervisor.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE:323 if hypervisor.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE:
311 tmpfile = util.tmp_filename(tmp_root=self.options.tmp_root)
312 hypervisor.add_filesystem(filename=tmpfile,
313 size='%dM' % rootsize,
314 type='ext3',
315 mntpnt='/')
316 if swapsize > 0:324 if swapsize > 0:
317 tmpfile = util.tmp_filename(tmp_root=self.options.tmp_root)325 tmpfile = util.tmp_filename(tmp_root=self.options.tmp_root)
318 hypervisor.add_filesystem(filename=tmpfile,326 hypervisor.add_filesystem(filename=tmpfile,
@@ -325,6 +333,11 @@
325 size='%dM' % optsize,333 size='%dM' % optsize,
326 type='ext3',334 type='ext3',
327 mntpnt='/opt')335 mntpnt='/opt')
336 tmpfile = util.tmp_filename(tmp_root=self.options.tmp_root)
337 hypervisor.add_filesystem(filename=tmpfile,
338 size='%dM' % rootsize,
339 type='ext3',
340 mntpnt='/')
328 else:341 else:
329 if self.options.raw:342 if self.options.raw:
330 for raw_disk in self.options.raw:343 for raw_disk in self.options.raw:
@@ -335,23 +348,23 @@
335 tmpfile = util.tmp_filename(tmp_root=self.options.tmp_root)348 tmpfile = util.tmp_filename(tmp_root=self.options.tmp_root)
336 disk = hypervisor.add_disk(tmpfile, size='%dM' % size)349 disk = hypervisor.add_disk(tmpfile, size='%dM' % size)
337 offset = 0350 offset = 0
338 disk.add_part(offset, rootsize, default_filesystem, '/')
339 offset += rootsize
340 if swapsize > 0:351 if swapsize > 0:
341 disk.add_part(offset, swapsize, 'swap', 'swap')352 disk.add_part(offset, swapsize, 'swap', 'swap')
342 offset += swapsize353 offset += swapsize
343 if optsize > 0:354 if optsize > 0:
344 disk.add_part(offset, optsize, default_filesystem, '/opt')355 disk.add_part(offset, optsize, default_filesystem, '/opt')
356 offset += optsize
357 disk.add_part(offset, rootsize, default_filesystem, '/')
345 else:358 else:
346 # We need to parse the file specified359 # We need to parse the file specified
347 if hypervisor.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE:360 if hypervisor.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE:
348 try:361 try:
349 for line in file(self.options.part):362 for line in file(self.options.part):
350 elements = line.strip().split(' ')363 elements = line.strip().split(' ')
351 if len(elements) < 4:364 if len(elements) < 4:
352 tmpfile = util.tmp_filename(tmp_root=self.options.tmp_root)365 tmpfile = util.tmp_filename(tmp_root=self.options.tmp_root)
353 else:366 else:
354 tmpfile = elements[3]367 tmpfile = elements[3]
355368
356 if elements[0] == 'root':369 if elements[0] == 'root':
357 hypervisor.add_filesystem(elements[1],370 hypervisor.add_filesystem(elements[1],
@@ -380,8 +393,8 @@
380 filename=tmpfile,393 filename=tmpfile,
381 mntpnt=elements[0])394 mntpnt=elements[0])
382 except IOError, (errno, strerror):395 except IOError, (errno, strerror):
383 optparser.error("%s parsing --part option: %s" %396 self.optparser.error("%s parsing --part option: %s" %
384 (errno, strerror))397 (errno, strerror))
385 else:398 else:
386 try:399 try:
387 curdisk = list()400 curdisk = list()
@@ -403,8 +416,8 @@
403 self.do_disk(hypervisor, curdisk, size, disk_idx)416 self.do_disk(hypervisor, curdisk, size, disk_idx)
404417
405 except IOError, (errno, strerror):418 except IOError, (errno, strerror):
406 optparser.error("%s parsing --part option: %s" %419 hypervisor.optparser.error("%s parsing --part option: %s" %
407 (errno, strerror))420 (errno, strerror))
408421
409 def do_disk(self, hypervisor, curdisk, size, disk_idx):422 def do_disk(self, hypervisor, curdisk, size, disk_idx):
410 default_filesystem = hypervisor.distro.preferred_filesystem()423 default_filesystem = hypervisor.distro.preferred_filesystem()
411424
=== modified file 'VMBuilder/disk.py'
--- VMBuilder/disk.py 2012-01-25 13:48:24 +0000
+++ VMBuilder/disk.py 2012-09-04 13:48:23 +0000
@@ -26,9 +26,13 @@
26import stat26import stat
27import string27import string
28import time28import time
29from VMBuilder.util import run_cmd 29from random import sample as random
30from string import ascii_lowercase
31import string
32from VMBuilder.util import run_cmd, tmpdir
30from VMBuilder.exception import VMBuilderUserError, VMBuilderException33from VMBuilder.exception import VMBuilderUserError, VMBuilderException
31from struct import unpack34from struct import unpack
35#from util import run_cmd
3236
33TYPE_EXT2 = 037TYPE_EXT2 = 0
34TYPE_EXT3 = 138TYPE_EXT3 = 1
@@ -40,8 +44,8 @@
40 """44 """
41 Virtual disk.45 Virtual disk.
4246
43 @type vm: Hypervisor47 @type hypervisor: Hypervisor
44 @param vm: The Hypervisor to which the disk belongs48 @param hypervisor: The Hypervisor to which the disk belongs
45 @type filename: string49 @type filename: string
46 @param filename: filename of the disk image50 @param filename: filename of the disk image
47 @type size: string or number51 @type size: string or number
@@ -51,8 +55,8 @@
51 this size will be created once L{create}() is called.55 this size will be created once L{create}() is called.
52 """56 """
53 57
54 def __init__(self, vm, filename, size=None):58 def __init__(self, hypervisor, filename, size=None):
55 self.vm = vm59 self.hypervisor = hypervisor
56 "The hypervisor to which the disk belongs."60 "The hypervisor to which the disk belongs."
5761
58 self.filename = filename62 self.filename = filename
@@ -66,6 +70,9 @@
6670
67 self.size = 071 self.size = 0
68 "The size of the disk. For preallocated disks, this is detected."72 "The size of the disk. For preallocated disks, this is detected."
73
74 self.dev = None
75 "mount point for this disk. example : /dev/loop1"
6976
70 if not os.path.exists(self.filename):77 if not os.path.exists(self.filename):
71 if not size:78 if not size:
@@ -87,7 +94,7 @@
87 the VM. E.g. the first disk of a VM would return 'a', while the 702nd would return 'zz'94 the VM. E.g. the first disk of a VM would return 'a', while the 702nd would return 'zz'
88 """95 """
8996
90 return index_to_devname(self.vm.disks.index(self))97 return index_to_devname(self.hypervisor.disks.index(self))
9198
92 def create(self):99 def create(self):
93 """100 """
@@ -126,8 +133,25 @@
126 Call this after L{partition}.133 Call this after L{partition}.
127 """134 """
128 logging.info('Creating loop devices corresponding to the created partitions')135 logging.info('Creating loop devices corresponding to the created partitions')
129 self.vm.add_clean_cb(lambda : self.unmap(ignore_fail=True))136 self.hypervisor.add_clean_cb(lambda : self.unmap(ignore_fail=True))
130 kpartx_output = run_cmd('kpartx', '-av', self.filename)137 self.dev_loop = run_cmd('losetup', '-f').split('\n')[0]
138 run_cmd('losetup', self.dev_loop, self.filename )
139 # for another moment : http://pypi.python.org/pypi/losetup/
140 rdevice = "".join(random(ascii_lowercase, 3))
141 self.dev_mapper = rdevice + self.devletters()
142 #TODO cleanup
143 self.dev_kpartx = '/dev/mapper/%s' % self.dev_mapper
144#TODO
145
146 self.dev_mknode = os.path.join(self.hypervisor.dev_dir, self.dev_mapper)
147
148 blockSize = run_cmd('blockdev', '--getsz', self.dev_loop).split('\n')[0]
149 run_cmd('dmsetup', 'create', self.dev_mapper, '--table=0 %s linear %s 0' % (blockSize, self.dev_loop))
150 kpartx_output = run_cmd('kpartx', '-av', self.dev_kpartx)
151 info = os.stat(self.dev_kpartx)
152 os.mknod(self.dev_mknode, stat.S_IFBLK, os.makedev(os.major(info.st_rdev), os.minor(info.st_rdev)))
153 self.dev = os.path.join('/dev', self.dev_mapper)
154# self.dev = self.dev_kpartx
131 parts = []155 parts = []
132 for line in kpartx_output.split('\n'):156 for line in kpartx_output.split('\n'):
133 if line == "" or line.startswith("gpt:") or line.startswith("dos:"):157 if line == "" or line.startswith("gpt:") or line.startswith("dos:"):
@@ -138,9 +162,26 @@
138 logging.error('Skipping unknown line in kpartx output (%s)' % line)162 logging.error('Skipping unknown line in kpartx output (%s)' % line)
139 mapdevs = []163 mapdevs = []
140 for line in parts:164 for line in parts:
141 mapdevs.append(line.split(' ')[2])165 splitted = line.split(' ')
166 mapdevs.append(splitted[2])
142 for (part, mapdev) in zip(self.partitions, mapdevs):167 for (part, mapdev) in zip(self.partitions, mapdevs):
143 part.set_filename('/dev/mapper/%s' % mapdev)168 mapper_filename = '/dev/mapper/%s' % mapdev
169 part_dev = '/dev/%s' % mapdev #device view inside the chroot
170 part_filename = os.path.join(self.hypervisor.dev_dir, mapdev) #device inside the host
171 part.set_filename(part_filename)
172# part.set_filename(mapper_filename)
173 part.set_dev(part_dev)
174# part.set_filename(mapper_filename)
175 info = os.stat(mapper_filename)
176 #print info
177 os.mknod(part.filename, 0600 | stat.S_IFBLK, os.makedev(os.major(info.st_rdev), os.minor(info.st_rdev)))
178#TODO
179# part.set_dev('/dev/mapper/%s' % mapdev)
180 # map /dev/mapper/loop1pX to /dev/loopX to using it
181#TODO freeSlot = run_cmd('losetup', '-f').split('\n')[0]
182# run_cmd('losetup', freeSlot, part.filename )
183# part.set_dev(freeSlot)
184
144185
145 def mkfs(self):186 def mkfs(self):
146 """187 """
@@ -162,7 +203,7 @@
162 @rtype: number203 @rtype: number
163 @return: index of the disk (starting from 0 for the hypervisor's first disk)204 @return: index of the disk (starting from 0 for the hypervisor's first disk)
164 """205 """
165 return self.vm.disks.index(self)206 return self.hypervisor.disks.index(self)
166207
167 def unmap(self, ignore_fail=False):208 def unmap(self, ignore_fail=False):
168 """209 """
@@ -177,7 +218,12 @@
177 max_tries = 3218 max_tries = 3
178 while tries < max_tries:219 while tries < max_tries:
179 try:220 try:
180 run_cmd('kpartx', '-d', self.filename, ignore_fail=False)221 for part in self.partitions:
222 os.remove(part.filename)
223 os.remove(self.dev_mknode)
224 run_cmd('kpartx', '-d', self.dev_kpartx, ignore_fail=False)
225 run_cmd('dmsetup', 'remove', self.dev_kpartx, ignore_fail=False )
226 run_cmd('losetup', '-d', self.dev_loop, ignore_fail=False)
181 break227 break
182 except:228 except:
183 pass229 pass
@@ -187,8 +233,11 @@
187 if tries >= max_tries:233 if tries >= max_tries:
188 # try it one last time234 # try it one last time
189 logging.info("Could not unmap '%s' after '%d' attempts. Final attempt" % (self.filename, tries))235 logging.info("Could not unmap '%s' after '%d' attempts. Final attempt" % (self.filename, tries))
190 run_cmd('kpartx', '-d', self.filename, ignore_fail=ignore_fail)236 #TODO
191237# utils.clean_up_tmpfs()
238# run_cmd('kpartx', '-d', self.filename, ignore_fail=ignore_fail)
239# run_cmd('dmsetup', 'remove', '-f', '/dev/mapper/%s' % self.dev_mapper, ignore_fail=ignore_fail )
240# run_cmd('losetup', '-d', self.dev_loop, ignore_fail=ignore_fail)
192 for part in self.partitions:241 for part in self.partitions:
193 logging.debug("Removing partition %s" % part.filename)242 logging.debug("Removing partition %s" % part.filename)
194 parted_oldmap=part.filename[len("/dev/mapper/"):-1]+"p"+part.filename[-1]243 parted_oldmap=part.filename[len("/dev/mapper/"):-1]+"p"+part.filename[-1]
@@ -276,14 +325,22 @@
276325
277 self.filename = None326 self.filename = None
278 "The filename of this partition (the map device)"327 "The filename of this partition (the map device)"
328
329 self.dev = None
330 "The dev device to use"
279331
280 self.fs = Filesystem(vm=self.disk.vm, type=self.type, mntpnt=self.mntpnt)332 self.fs = Filesystem(hypervisor=self.disk.hypervisor, type=self.type, mntpnt=self.mntpnt)
281 "The enclosed filesystem"333 "The enclosed filesystem"
282334
283 def set_filename(self, filename):335 def set_filename(self, filename):
284 self.filename = filename336 self.filename = filename
285 self.fs.filename = filename337 self.fs.filename = filename
286338
339 def set_dev(self, dev):
340 self.dev = dev
341#TODO change this...
342 self.fs.dev = dev
343
287 def parted_fstype(self):344 def parted_fstype(self):
288 """345 """
289 @rtype: string346 @rtype: string
@@ -294,25 +351,17 @@
294 def create(self, disk):351 def create(self, disk):
295 """Adds partition to the disk image (does not mkfs or anything like that)"""352 """Adds partition to the disk image (does not mkfs or anything like that)"""
296 logging.info('Adding type %d partition to disk image: %s' % (self.type, disk.filename))353 logging.info('Adding type %d partition to disk image: %s' % (self.type, disk.filename))
297 if self.begin == 0:354 run_cmd( 'parted', '--script', '--align=opt', disk.filename, 'mkpart', 'primary', partition_start, self.end)
298 logging.info('Partition at beginning of disk - reserving first cylinder')
299 partition_start = "63s"
300 else:
301 partition_start = self.begin
302 run_cmd('parted', '--script', '--', disk.filename, 'mkpart', 'primary', self.parted_fstype(), partition_start, self.end)
303355
304 def mkfs(self):356 def mkfs(self):
305 """Adds Filesystem object"""357 """Adds Filesystem object"""
306 self.fs.mkfs()358 self.fs.mkfs()
307359
308 def get_grub_id(self):360 # must be refactor in a "linux" class
309 """The name of the partition as known by grub"""
310 return '(hd%d,%d)' % (self.disk.get_index(), self.get_index())
311
312 def get_suffix(self):361 def get_suffix(self):
313 """Returns 'a4' for a device that would be called /dev/sda4 in the guest. 362 """Returns 'a4' for a device that would be called /dev/sda4 in the guest.
314 This allows other parts of VMBuilder to set the prefix to something suitable."""363 This allows other parts of VMBuilder to set the prefix to something suitable."""
315 return '%s%d' % (self.disk.devletters(), self.get_index() + 1)364 return '%s%d' % (self.disk.devletters(), self.get_index()+1)
316365
317 def get_index(self):366 def get_index(self):
318 """Index of the disk (starting from 0)"""367 """Index of the disk (starting from 0)"""
@@ -328,9 +377,10 @@
328 self.type = str_to_type(type)377 self.type = str_to_type(type)
329378
330class Filesystem(object):379class Filesystem(object):
331 def __init__(self, vm=None, size=0, type=None, mntpnt=None, filename=None, devletter='a', device='', dummy=False):380 def __init__(self, hypervisor=None, size=0, type=None, mntpnt=None, filename=None, devletter='a', device='', dummy=False):
332 self.vm = vm381 self.hypervisor = hypervisor
333 self.filename = filename382 self.filename = filename
383 self.dev = None
334 self.size = parse_size(size)384 self.size = parse_size(size)
335 self.devletter = devletter385 self.devletter = devletter
336 self.device = device386 self.device = device
@@ -358,7 +408,7 @@
358 else:408 else:
359 raise VMBuilderException('mntpnt not set')409 raise VMBuilderException('mntpnt not set')
360410
361 self.filename = '%s/%s' % (self.vm.workdir, self.filename)411 self.filename = '%s/%s' % (self.hypervisor.workdir, self.filename)
362 while os.path.exists('%s.img' % self.filename):412 while os.path.exists('%s.img' % self.filename):
363 self.filename += '_'413 self.filename += '_'
364 self.filename += '.img'414 self.filename += '.img'
@@ -382,7 +432,7 @@
382 def mkfs_fstype(self):432 def mkfs_fstype(self):
383 map = { TYPE_EXT2: ['mkfs.ext2', '-F'], TYPE_EXT3: ['mkfs.ext3', '-F'], TYPE_EXT4: ['mkfs.ext4', '-F'], TYPE_XFS: ['mkfs.xfs'], TYPE_SWAP: ['mkswap'] }433 map = { TYPE_EXT2: ['mkfs.ext2', '-F'], TYPE_EXT3: ['mkfs.ext3', '-F'], TYPE_EXT4: ['mkfs.ext4', '-F'], TYPE_XFS: ['mkfs.xfs'], TYPE_SWAP: ['mkswap'] }
384434
385 if not self.vm.distro.has_256_bit_inode_ext3_support():435 if not self.hypervisor.distro.has_256_bit_inode_ext3_support():
386 map[TYPE_EXT3] = ['mkfs.ext3', '-I 128', '-F']436 map[TYPE_EXT3] = ['mkfs.ext3', '-I 128', '-F']
387437
388 return map[self.type]438 return map[self.type]
@@ -400,10 +450,10 @@
400 if not os.path.exists(self.mntpath):450 if not os.path.exists(self.mntpath):
401 os.makedirs(self.mntpath)451 os.makedirs(self.mntpath)
402 run_cmd('mount', '-o', 'loop', self.filename, self.mntpath)452 run_cmd('mount', '-o', 'loop', self.filename, self.mntpath)
403 self.vm.add_clean_cb(self.umount)453 self.hypervisor.add_clean_cb(self.umount)
404454
405 def umount(self):455 def umount(self):
406 self.vm.cancel_cleanup(self.umount)456 self.hypervisor.cancel_cleanup(self.umount)
407 if (self.type != TYPE_SWAP) and not self.dummy:457 if (self.type != TYPE_SWAP) and not self.dummy:
408 logging.debug('Unmounting %s', self.mntpath) 458 logging.debug('Unmounting %s', self.mntpath)
409 run_cmd('umount', self.mntpath)459 run_cmd('umount', self.mntpath)
@@ -414,7 +464,7 @@
414 if self.device:464 if self.device:
415 return self.device465 return self.device
416 else:466 else:
417 return '%s%d' % (self.devletters(), self.get_index() + 1)467 return '%s%d' % (self.devletters(), self.get_index())
418468
419 def devletters(self):469 def devletters(self):
420 """470 """
@@ -425,8 +475,8 @@
425 return self.devletter475 return self.devletter
426 476
427 def get_index(self):477 def get_index(self):
428 """Index of the disk (starting from 0)"""478 """Index of the disk (starting from 1)"""
429 return self.vm.filesystems.index(self)479 return self.hypervisor.filesystems.index(self)+1
430480
431 def set_type(self, type):481 def set_type(self, type):
432 try:482 try:
@@ -518,6 +568,7 @@
518 return 0568 return 0
519 return 26 * devname_to_index_rec(devname[:-1]) + (string.ascii_lowercase.index(devname[-1]) + 1) 569 return 26 * devname_to_index_rec(devname[:-1]) + (string.ascii_lowercase.index(devname[-1]) + 1)
520570
571# must be sort out in a "linux" class
521def index_to_devname(index, suffix=''):572def index_to_devname(index, suffix=''):
522 if index < 0:573 if index < 0:
523 return suffix574 return suffix
@@ -539,15 +590,15 @@
539590
540def qemu_img_path():591def qemu_img_path():
541 exes = ['kvm-img', 'qemu-img']592 exes = ['kvm-img', 'qemu-img']
542 for dir in os.environ['PATH'].split(os.path.pathsep):593 for directory in os.environ['PATH'].split(os.path.pathsep):
543 for exe in exes:594 for exe in exes:
544 path = '%s%s%s' % (dir, os.path.sep, exe)595 path = '%s%s%s' % (directory, os.path.sep, exe)
545 if os.access(path, os.X_OK):596 if os.access(path, os.X_OK):
546 return path597 return path
547598
548def vbox_manager_path():599def vbox_manager_path():
549 exe = 'VBoxManage'600 exe = 'VBoxManage'
550 for dir in os.environ['PATH'].split(os.path.pathsep):601 for directory in os.environ['PATH'].split(os.path.pathsep):
551 path = '%s%s%s' % (dir, os.path.sep, exe)602 path = '%s%s%s' % (directory, os.path.sep, exe)
552 if os.access(path, os.X_OK):603 if os.access(path, os.X_OK):
553 return path604 return path
554605
=== modified file 'VMBuilder/distro.py'
--- VMBuilder/distro.py 2011-05-16 20:00:30 +0000
+++ VMBuilder/distro.py 2012-09-04 13:48:23 +0000
@@ -65,7 +65,10 @@
65 def call_hooks(self, *args, **kwargs):65 def call_hooks(self, *args, **kwargs):
66 try:66 try:
67 call_hooks(self, *args, **kwargs)67 call_hooks(self, *args, **kwargs)
68 except Exception:68 except Exception, e:
69 logging.debug(e)
70 if logging.root.isEnabledFor(logging.DEBUG):
71 raw_input("AN ERROR Occured : press enter to continue...")
69 self.cleanup()72 self.cleanup()
70 raise73 raise
7174
@@ -74,23 +77,28 @@
74 self.plugin_classes = VMBuilder._distro_plugins77 self.plugin_classes = VMBuilder._distro_plugins
75 super(Distro, self).__init__()78 super(Distro, self).__init__()
7679
77 def set_chroot_dir(self, chroot_dir):80 def set_chroot_dir(self, chroot_dir, dev_dir = '/dev'):
78 self.chroot_dir = chroot_dir 81 self.chroot_dir = chroot_dir
7982 self.dev_dir = dev_dir
80 def build_chroot(self):83
84 def prepare_chroot(self):
85 self.call_hooks('prepare_chroot')
86
87 def clean_chroot(self):
88 self.call_hooks('clean_chroot')
89
90 def build(self):
91 self.call_hooks('install_os')
92# self.cleanup()
93
94 def has_xen_support(self):
95 """Install the distro into destdir"""
96 raise NotImplemented('Distro subclasses need to implement the has_xen_support method')
97
98 def install(self):
81 self.call_hooks('preflight_check')99 self.call_hooks('preflight_check')
82 self.call_hooks('set_defaults')100 self.call_hooks('set_defaults')
83 self.call_hooks('bootstrap')101 self.call_hooks('bootstrap')
84 self.call_hooks('configure_os')
85 self.cleanup()
86
87 def has_xen_support(self):
88 """Install the distro into destdir"""
89 raise NotImplemented('Distro subclasses need to implement the has_xen_support method')
90
91 def install(self, destdir):
92 """Install the distro into destdir"""
93 raise NotImplemented('Distro subclasses need to implement the install method')
94102
95 def post_mount(self, fs):103 def post_mount(self, fs):
96 """Called each time a filesystem is mounted to let the distro add things to the filesystem"""104 """Called each time a filesystem is mounted to let the distro add things to the filesystem"""
97105
=== modified file 'VMBuilder/hypervisor.py'
--- VMBuilder/hypervisor.py 2011-05-16 20:00:30 +0000
+++ VMBuilder/hypervisor.py 2012-09-04 13:48:23 +0000
@@ -21,7 +21,7 @@
21import logging21import logging
22import os22import os
23import VMBuilder.distro23import VMBuilder.distro
24import VMBuilder.disk24#import VMBuilder.disk
25from VMBuilder.util import run_cmd, tmpdir25from VMBuilder.util import run_cmd, tmpdir
2626
27STORAGE_DISK_IMAGE = 027STORAGE_DISK_IMAGE = 0
@@ -49,28 +49,36 @@
4949
50 def add_disk(self, *args, **kwargs):50 def add_disk(self, *args, **kwargs):
51 """Adds a disk image to the virtual machine"""51 """Adds a disk image to the virtual machine"""
52 from VMBuilder.disk import Disk52 disk = self._create_disk(*args, **kwargs)
53
54 disk = Disk(self, *args, **kwargs)
55 self.disks.append(disk)53 self.disks.append(disk)
56 return disk54 return disk
5755
58 def install_os(self):56 def _create_disk(self, *args, **kwargs):
57 return VMBuilder.disk.Disk(self, *args, **kwargs)
58
59 def create_environement(self):
60 self.chroot_dir = tmpdir()
61 self.dev_dir = '/dev'
62 self.call_hooks('configure_mounting', self.disks, self.filesystems)
63 self.call_hooks('mount_partitions', self.chroot_dir)
64
65 def close_environement(self):
66 self.call_hooks('unmount_partitions')
67 os.rmdir(self.chroot_dir)
68
69 def migrate(self):
70 self.distro.set_chroot_dir(self.chroot_dir)
71 run_cmd('rsync', '-aHA', '--exclude=/sys', '--exclude=/proc', '--exclude=/dev', '%s/' % self.distro.chroot_dir, self.chroot_dir)
72
73 def configure_os(self):
59 self.nics = [self.NIC()]74 self.nics = [self.NIC()]
60 self.call_hooks('preflight_check')75 self.call_hooks('preflight_check')
61 self.call_hooks('configure_networking', self.nics)76 self.call_hooks('configure_networking', self.nics)
62 self.call_hooks('configure_mounting', self.disks, self.filesystems)77 self.call_hooks('install_kernel')
63
64 self.chroot_dir = tmpdir()
65 self.call_hooks('mount_partitions', self.chroot_dir)
66 run_cmd('rsync', '-aHA', '%s/' % self.distro.chroot_dir, self.chroot_dir)
67 self.distro.set_chroot_dir(self.chroot_dir)
68 if self.needs_bootloader:78 if self.needs_bootloader:
69 self.call_hooks('install_bootloader', self.chroot_dir, self.disks)79 self.call_hooks('install_bootloader', self.disks)
70 self.call_hooks('install_kernel', self.chroot_dir)80 self.call_hooks('install_kernel')
71 self.distro.call_hooks('post_install')81 self.distro.call_hooks('post_install')
72 self.call_hooks('unmount_partitions')
73 os.rmdir(self.chroot_dir)
7482
75 def finalise(self, destdir):83 def finalise(self, destdir):
76 self.call_hooks('convert', 84 self.call_hooks('convert',
@@ -78,7 +86,7 @@
78 destdir)86 destdir)
79 self.call_hooks('deploy', destdir)87 self.call_hooks('deploy', destdir)
8088
81 def mount_partitions(self, mntdir):89 def mount_partitions(self):
82 """Mounts all the vm's partitions and filesystems below .rootmnt"""90 """Mounts all the vm's partitions and filesystems below .rootmnt"""
83 logging.info('Mounting target filesystems')91 logging.info('Mounting target filesystems')
84 for fs in self.filesystems:92 for fs in self.filesystems:
@@ -91,7 +99,7 @@
91 disk.mkfs()99 disk.mkfs()
92 fss = VMBuilder.disk.get_ordered_filesystems(self)100 fss = VMBuilder.disk.get_ordered_filesystems(self)
93 for fs in fss:101 for fs in fss:
94 fs.mount(mntdir)102 fs.mount(self.chroot_dir)
95 self.distro.post_mount(fs)103 self.distro.post_mount(fs)
96104
97 def unmount_partitions(self):105 def unmount_partitions(self):
@@ -108,6 +116,13 @@
108 for disk in disks:116 for disk in disks:
109 disk.convert(destdir, self.filetype)117 disk.convert(destdir, self.filetype)
110118
119 def set_chroot_dir(self, chroot_dir):
120 self.chroot_dir = chroot_dir
121
122 def cleanup(self):
123 self.distro.cleanup()
124 super(Hypervisor, self).cleanup()
125
111 class NIC(object):126 class NIC(object):
112 def __init__(self, type='dhcp', ip=None, network=None, netmask=None,127 def __init__(self, type='dhcp', ip=None, network=None, netmask=None,
113 broadcast=None, dns=None, gateway=None):128 broadcast=None, dns=None, gateway=None):
114129
=== modified file 'VMBuilder/plugins/__init__.py'
--- VMBuilder/plugins/__init__.py 2010-05-07 09:49:56 +0000
+++ VMBuilder/plugins/__init__.py 2012-09-04 13:48:23 +0000
@@ -80,7 +80,9 @@
80 return fullpath80 return fullpath
8181
82 def install_from_template(self, path, tmplname, context=None, mode=None):82 def install_from_template(self, path, tmplname, context=None, mode=None):
83 return self.install_file(path, VMBuilder.util.render_template(self.__module__.split('.')[2], self.context, tmplname, context), mode=mode)83 module = self.__module__.split('.')
84 result = VMBuilder.util.render_template(module[2], self.context, tmplname, context)
85 return self.install_file(path, result, mode=mode)
8486
85 def run_in_target(self, *args, **kwargs):87 def run_in_target(self, *args, **kwargs):
86 return util.run_cmd('chroot', self.chroot_dir, *args, **kwargs)88 return util.run_cmd('chroot', self.chroot_dir, *args, **kwargs)
8789
=== modified file 'VMBuilder/plugins/ec2/__init__.py'
--- VMBuilder/plugins/ec2/__init__.py 2010-02-18 15:54:51 +0000
+++ VMBuilder/plugins/ec2/__init__.py 2012-09-04 13:48:23 +0000
@@ -48,7 +48,7 @@
48 self.context.register_setting_group(group)48 self.context.register_setting_group(group)
4949
50 def preflight_check(self):50 def preflight_check(self):
51 if not getattr(self.vm, 'ec2', False):51 if not getattr(self.hypervisor, 'ec2', False):
52 return True52 return True
5353
54 if not self.context.hypervisor.name == 'Xen':54 if not self.context.hypervisor.name == 'Xen':
@@ -79,11 +79,11 @@
79 raise VMBuilderUserError('When building for EC2 you must provide your EC2 user ID (your AWS account number, not your AWS access key ID)')79 raise VMBuilderUserError('When building for EC2 you must provide your EC2 user ID (your AWS account number, not your AWS access key ID)')
8080
81 if not self.context.ec2_kernel:81 if not self.context.ec2_kernel:
82 self.context.ec2_kernel = self.vm.distro.get_ec2_kernel()82 self.context.ec2_kernel = self.hypervisor.distro.get_ec2_kernel()
83 logging.debug('%s - to be used for AKI.' %(self.context.ec2_kernel))83 logging.debug('%s - to be used for AKI.' %(self.context.ec2_kernel))
8484
85 if not self.context.ec2_ramdisk:85 if not self.context.ec2_ramdisk:
86 self.context.ec2_ramdisk = self.vm.distro.ec2_ramdisk_id()86 self.context.ec2_ramdisk = self.hypervisor.distro.ec2_ramdisk_id()
87 logging.debug('%s - to be use for the ARI.' %(self.context.ec2_ramdisk))87 logging.debug('%s - to be use for the ARI.' %(self.context.ec2_ramdisk))
8888
89 if self.context.ec2_upload:89 if self.context.ec2_upload:
@@ -107,7 +107,7 @@
107 self.context.addpkg += ['landscape-client']107 self.context.addpkg += ['landscape-client']
108108
109 def post_install(self):109 def post_install(self):
110 if not getattr(self.vm, 'ec2', False):110 if not getattr(self.hypervisor, 'ec2', False):
111 return111 return
112112
113 logging.info("Running ec2 postinstall")113 logging.info("Running ec2 postinstall")
@@ -121,29 +121,29 @@
121 self.context.distro.disable_hwclock_access()121 self.context.distro.disable_hwclock_access()
122122
123 def deploy(self):123 def deploy(self):
124 if not getattr(self.vm, 'ec2', False):124 if not getattr(self.hypervisor, 'ec2', False):
125 return False125 return False
126126
127 if self.context.ec2_bundle:127 if self.context.ec2_bundle:
128 logging.info("Building EC2 bundle")128 logging.info("Building EC2 bundle")
129 bundle_cmdline = ['ec2-bundle-image', '--image', self.context.filesystems[0].filename, '--cert', self.vm.ec2_cert, '--privatekey', self.vm.ec2_key, '--user', self.vm.ec2_user, '--prefix', self.vm.ec2_name, '-r', ['i386', 'x86_64'][self.vm.arch == 'amd64'], '-d', self.vm.workdir, '--kernel', self.vm.ec2_kernel, '--ramdisk', self.vm.ec2_ramdisk]129 bundle_cmdline = ['ec2-bundle-image', '--image', self.context.filesystems[0].filename, '--cert', self.hypervisor.ec2_cert, '--privatekey', self.hypervisor.ec2_key, '--user', self.hypervisor.ec2_user, '--prefix', self.hypervisor.ec2_name, '-r', ['i386', 'x86_64'][self.hypervisor.arch == 'amd64'], '-d', self.hypervisor.workdir, '--kernel', self.hypervisor.ec2_kernel, '--ramdisk', self.hypervisor.ec2_ramdisk]
130 run_cmd(*bundle_cmdline)130 run_cmd(*bundle_cmdline)
131131
132 manifest = '%s/%s.manifest.xml' % (self.context.workdir, self.vm.ec2_name)132 manifest = '%s/%s.manifest.xml' % (self.context.workdir, self.hypervisor.ec2_name)
133 if self.context.ec2_upload:133 if self.context.ec2_upload:
134 logging.info("Uploading EC2 bundle")134 logging.info("Uploading EC2 bundle")
135 upload_cmdline = ['ec2-upload-bundle', '--retry', '--manifest', manifest, '--bucket', self.context.ec2_bucket, '--access-key', self.vm.ec2_access_key, '--secret-key', self.vm.ec2_secret_key]135 upload_cmdline = ['ec2-upload-bundle', '--retry', '--manifest', manifest, '--bucket', self.context.ec2_bucket, '--access-key', self.hypervisor.ec2_access_key, '--secret-key', self.hypervisor.ec2_secret_key]
136 run_cmd(*upload_cmdline)136 run_cmd(*upload_cmdline)
137137
138 if self.context.ec2_register:138 if self.context.ec2_register:
139 from boto.ec2.connection import EC2Connection139 from boto.ec2.connection import EC2Connection
140 conn = EC2Connection(self.context.ec2_access_key, self.vm.ec2_secret_key)140 conn = EC2Connection(self.context.ec2_access_key, self.hypervisor.ec2_secret_key)
141 amiid = conn.register_image('%s/%s.manifest.xml' % (self.context.ec2_bucket, self.vm.ec2_name))141 amiid = conn.register_image('%s/%s.manifest.xml' % (self.context.ec2_bucket, self.hypervisor.ec2_name))
142 print 'Image registered as %s' % amiid142 print 'Image registered as %s' % amiid
143 else:143 else:
144 self.context.result_files.append(manifest)144 self.context.result_files.append(manifest)
145 else:145 else:
146 self.context.result_files.append(self.vm.filesystems[0].filename)146 self.context.result_files.append(self.hypervisor.filesystems[0].filename)
147147
148 return True148 return True
149149
150150
=== modified file 'VMBuilder/plugins/kvm/__init__.py'
--- VMBuilder/plugins/kvm/__init__.py 2009-06-10 13:40:41 +0000
+++ VMBuilder/plugins/kvm/__init__.py 2012-09-04 13:48:23 +0000
@@ -16,4 +16,4 @@
16# You should have received a copy of the GNU General Public License16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#18#
19import vm19import vm
20\ No newline at end of file20\ No newline at end of file
2121
=== added file 'VMBuilder/plugins/kvm/disk.py'
--- VMBuilder/plugins/kvm/disk.py 1970-01-01 00:00:00 +0000
+++ VMBuilder/plugins/kvm/disk.py 2012-09-04 13:48:23 +0000
@@ -0,0 +1,38 @@
1#
2# Uncomplicated VM Builder
3# Copyright (C) 2007-2009 Canonical Ltd.
4#
5# See AUTHORS for list of contributors
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 3, as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19import VMBuilder.disk
20from os import path
21import qemu_nbd
22
23class Disk(VMBuilder.disk.Disk):
24 def _init_(self, hypervisor, filename, size=None):
25 super(VMBuilder.disk.Disk, self).__init__(hypervisor, filename, size)
26
27 def map_partitions(self):
28 self.nbd = qemu_nbd.connect(self.filename, read_only=False)
29 self.dev = path.join(self.hypervisor.dev_dir, self.nbd)
30 for (part, mapdev) in zip(self.partitions, qemu_nbd.list_partitions_from_device(self.nbd)):
31 mapdev = path.join(self.hypervisor.dev_dir, mapdev)
32 part.set_dev(mapdev)
33 part.set_filename(mapdev)
34
35 def unmap(self):
36 qemu_nbd.disconnect(self.nbd)
37 for part in self.partitions:
38 part.set_filename(None)
0\ No newline at end of file39\ No newline at end of file
140
=== added file 'VMBuilder/plugins/kvm/qemu_nbd.py'
--- VMBuilder/plugins/kvm/qemu_nbd.py 1970-01-01 00:00:00 +0000
+++ VMBuilder/plugins/kvm/qemu_nbd.py 2012-09-04 13:48:23 +0000
@@ -0,0 +1,117 @@
1#""" qemu-nbd wrapper """
2#http://code.activestate.com/recipes/577593-qemu-nbd-python-wrapper/
3
4import os
5from time import sleep
6from itertools import ifilter
7from VMBuilder.util import run_cmd
8
9def list_devices():
10 return ifilter(
11 lambda dev : len(dev.split('p')) == 1,
12 _list_nbd()
13 )
14
15def list_partitions():
16 return ifilter(
17 lambda part: len(part.split('p')) > 1,
18 _list_nbd()
19 )
20
21def list_partitions_from_device(device):
22 return ifilter(
23 lambda part: part.split('p')[0] == device,
24 list_partitions()
25 )
26
27def _list_nbd():
28 return ifilter(
29 lambda dev: dev.startswith("nbd"),
30 os.listdir("/dev")
31 )
32
33def find_available():
34 devices = []
35 busy = []
36 for x in os.popen("cat /proc/partitions | grep nbd | awk '{print $4}'").readlines():
37 #needed by pipe
38 busy.append(x.strip())
39
40 for d in list_devices():
41 if not d in busy:
42 devices.append(d)
43
44 return devices
45
46def connect(image_file, read_only=True):
47 image_file = os.path.realpath(image_file)
48
49 if not os.path.exists(image_file):
50 return False
51
52 devices = find_available()
53 if len(devices) == 0:
54 return False
55
56 dev = devices[0]
57
58 if read_only:
59 read_only = '-r'
60 else:
61 read_only = None
62
63 run_cmd('qemu-nbd', '-c', '/dev/%s' % dev, read_only, image_file)
64 sleep(2) # partition discovery
65 return dev
66
67def disconnect(dev=None):
68 umount(dev)
69
70 if dev == None:
71 for dev in list_devices():
72 disconnect(dev)
73 else:
74 run_cmd('qemu-nbd', '-d', '/dev/%s' % dev)
75
76def mount(dev, partition=1, path=None):
77 full_dev_path = '/dev/%sp%s' % (dev, partition)
78
79 if path == None:
80 import tempfile
81 path = tempfile.mkdtemp()
82
83 run_cmd('mount', full_dev_path, path)
84
85 return path
86
87def find_mount(dev=None):
88 if dev == None:
89 mounts = []
90 for dev in list_devices():
91 m = find_mount(dev)
92 if m != None and m not in mounts:
93 mounts.append(m)
94
95 return mounts
96
97 else:
98 mount = None
99
100 sys_mount = os.popen('mount | grep %s' % dev).readline().strip().split(' ')
101 if len(sys_mount) > 1:
102 mount = {
103 'dev': sys_mount[0],
104 'mount': sys_mount[2],
105 'type': sys_mount[3]
106 }
107
108 return mount
109
110def umount(dev=None):
111 m = find_mount(dev)
112
113 if dev == None:
114 for x in m:
115 run_cmd('umount', x['mount'])
116 elif m != None:
117 run_cmd('umount', m['mount'])
0\ No newline at end of file118\ No newline at end of file
1119
=== modified file 'VMBuilder/plugins/kvm/vm.py'
--- VMBuilder/plugins/kvm/vm.py 2010-09-24 11:57:05 +0000
+++ VMBuilder/plugins/kvm/vm.py 2012-09-04 13:48:23 +0000
@@ -18,6 +18,7 @@
18#18#
19from VMBuilder import register_hypervisor, Hypervisor19from VMBuilder import register_hypervisor, Hypervisor
20import VMBuilder20import VMBuilder
21import disk
21import os22import os
22import stat23import stat
2324
@@ -59,6 +60,9 @@
5960
60 def libvirt_domain_type_name(self):61 def libvirt_domain_type_name(self):
61 return 'kvm'62 return 'kvm'
63
64 def _create_disk(self, *args, **kwargs):
65 return disk.Disk(self, *args, **kwargs)
6266
63class QEMu(KVM):67class QEMu(KVM):
64 name = 'QEMu'68 name = 'QEMu'
6569
=== modified file 'VMBuilder/plugins/ubuntu/dapper.py'
--- VMBuilder/plugins/ubuntu/dapper.py 2010-12-02 08:15:01 +0000
+++ VMBuilder/plugins/ubuntu/dapper.py 2012-09-04 13:48:23 +0000
@@ -22,6 +22,7 @@
22import suite22import suite
23import shutil23import shutil
24import tempfile24import tempfile
25import time
25import VMBuilder.disk as disk26import VMBuilder.disk as disk
26from VMBuilder.util import run_cmd27from VMBuilder.util import run_cmd
27from VMBuilder.exception import VMBuilderException28from VMBuilder.exception import VMBuilderException
@@ -35,8 +36,20 @@
35 disk_prefix = 'hd'36 disk_prefix = 'hd'
36 xen_kernel_flavour = None37 xen_kernel_flavour = None
37 virtio_net = False38 virtio_net = False
39 virtio_disk = False
38 chpasswd_cmd = [ 'chpasswd', '--md5' ]40 chpasswd_cmd = [ 'chpasswd', '--md5' ]
39 preferred_filesystem = 'ext3'41 preferred_filesystem = 'ext3'
42 grub_version = 1
43 grub_partitions_prefix = ''
44 #prefix to partition. hd0,{prefix}1 (for example)
45
46 grub_part = None
47 # partition with /boot/grub
48
49 grub_disk = None
50 # disk where grub will be installed
51
52 grub_offset = 0
4053
41 def pre_install(self):54 def pre_install(self):
42 pass55 pass
@@ -72,7 +85,7 @@
72 self.call_hook('fix_ownership', manifest)85 self.call_hook('fix_ownership', manifest)
7386
74 def update(self):87 def update(self):
75 self.run_in_target('apt-get', '-y', '--force-yes', 'dist-upgrade',88 self.run_in_target('apt-get', '-y', '--force-yes', '--no-install-recommends', 'dist-upgrade',
76 env={ 'DEBIAN_FRONTEND' : 'noninteractive' })89 env={ 'DEBIAN_FRONTEND' : 'noninteractive' })
7790
78 def install_authorized_keys(self):91 def install_authorized_keys(self):
@@ -92,29 +105,67 @@
92105
93 if ssh_user_key or ssh_key:106 if ssh_user_key or ssh_key:
94 addpkg = self.context.get_setting('addpkg')107 addpkg = self.context.get_setting('addpkg')
95 addpkg += ['openssh-server']108 #use ^ for tasksel
109 addpkg += ['openssh-server^']
96 self.context.set_setting('addpkg', addpkg)110 self.context.set_setting('addpkg', addpkg)
97111
98 def mount_dev_proc(self):112 def mount(self):
99 run_cmd('mount', '--bind', '/dev', '%s/dev' % self.context.chroot_dir)113 run_cmd('mkdir', '-p', '%s/dev' % self.context.chroot_dir)
114 run_cmd('mount', '--bind', '%s' % self.context.dev_dir, '%s/dev' % self.context.chroot_dir)
100 self.context.add_clean_cb(self.unmount_dev)115 self.context.add_clean_cb(self.unmount_dev)
116 logging.debug("add_clean_cb(self.unmount_dev)")
117
118 run_cmd('touch', '%s/dev/urandom' % self.context.chroot_dir)
119 run_cmd('mount', '--bind', '/dev/urandom', '%s/dev/urandom' % self.context.chroot_dir)
120 self.context.add_clean_cb(self.unmount_dev_urandom)
121 logging.debug("add_clean_cb(self.unmount_dev_urandom)")
101122
102 run_cmd('mount', '--bind', '/dev/pts', '%s/dev/pts' % self.context.chroot_dir)123 run_cmd('mkdir', '-p', '%s/dev/pts' % self.context.chroot_dir)
124 run_cmd('mount', '-t', 'devpts', 'devpts-chroot', '%s/dev/pts' % self.context.chroot_dir)
103 self.context.add_clean_cb(self.unmount_dev_pts)125 self.context.add_clean_cb(self.unmount_dev_pts)
126 logging.debug("add_clean_cb(self.unmount_dev_pts)")
104127
105 self.run_in_target('mount', '-t', 'proc', 'proc', '/proc')128 run_cmd('mkdir', '-p', '%s/proc' % self.context.chroot_dir)
129 run_cmd('mount', '-t', 'proc', 'proc-chroot', '%s/proc' % self.context.chroot_dir)
106 self.context.add_clean_cb(self.unmount_proc)130 self.context.add_clean_cb(self.unmount_proc)
131 logging.debug("add_clean_cb(self.unmount_proc)")
132
133 run_cmd('mkdir', '-p', '%s/sys' % self.context.chroot_dir)
134 run_cmd('mount', '--bind', '/sys', '%s/sys' % self.context.chroot_dir)
135 self.context.add_clean_cb(self.unmount_sys)
136 logging.debug("add_clean_cb(self.unmount_sys)")
137
138 def umount(self):
139 self.unmount_dev_urandom()
140 self.unmount_dev_pts()
141 self.unmount_dev()
142 self.unmount_proc()
143 self.unmount_sys()
144 self.unmount_volatile()
145
146 def unmount_sys(self):
147 self.context.cancel_cleanup(self.unmount_sys)
148 time.sleep(1)
149 run_cmd('umount', '%s/sys' % self.context.chroot_dir)
107150
108 def unmount_proc(self):151 def unmount_proc(self):
109 self.context.cancel_cleanup(self.unmount_proc)152 self.context.cancel_cleanup(self.unmount_proc)
153 time.sleep(1)
110 run_cmd('umount', '%s/proc' % self.context.chroot_dir)154 run_cmd('umount', '%s/proc' % self.context.chroot_dir)
111155
112 def unmount_dev_pts(self):156 def unmount_dev_pts(self):
113 self.context.cancel_cleanup(self.unmount_dev_pts)157 self.context.cancel_cleanup(self.unmount_dev_pts)
158 time.sleep(1)
114 run_cmd('umount', '%s/dev/pts' % self.context.chroot_dir)159 run_cmd('umount', '%s/dev/pts' % self.context.chroot_dir)
115160
161 def unmount_dev_urandom(self):
162 self.context.cancel_cleanup(self.unmount_dev_urandom)
163 time.sleep(1)
164 run_cmd('umount', '%s/dev/urandom' % self.context.chroot_dir)
165
116 def unmount_dev(self):166 def unmount_dev(self):
117 self.context.cancel_cleanup(self.unmount_dev)167 self.context.cancel_cleanup(self.unmount_dev)
168 time.sleep(1)
118 run_cmd('umount', '%s/dev' % self.context.chroot_dir)169 run_cmd('umount', '%s/dev' % self.context.chroot_dir)
119170
120 def update_passwords(self):171 def update_passwords(self):
@@ -196,7 +247,7 @@
196 if not addpkg and not removepkg:247 if not addpkg and not removepkg:
197 return248 return
198249
199 cmd = ['apt-get', 'install', '-y', '--force-yes']250 cmd = ['apt-get', 'install', '-y', '--force-yes', '--no-install-recommends']
200 cmd += addpkg or []251 cmd += addpkg or []
201 cmd += ['%s-' % pkg for pkg in removepkg or []]252 cmd += ['%s-' % pkg for pkg in removepkg or []]
202 self.run_in_target(env={ 'DEBIAN_FRONTEND' : 'noninteractive' }, *cmd)253 self.run_in_target(env={ 'DEBIAN_FRONTEND' : 'noninteractive' }, *cmd)
@@ -208,29 +259,29 @@
208259
209 def install_menu_lst(self, disks):260 def install_menu_lst(self, disks):
210 self.run_in_target(self.updategrub, '-y')261 self.run_in_target(self.updategrub, '-y')
211 self.mangle_grub_menu_lst(disks)
212 self.run_in_target(self.updategrub)262 self.run_in_target(self.updategrub)
213 self.run_in_target('grub-set-default', '0')263 self.run_in_target('grub-set-default', '0')
214264 self.run_in_target(self.updategrub)
215 def mangle_grub_menu_lst(self, disks):
216 bootdev = disk.bootpart(disks)
217 run_cmd('sed', '-ie', 's/^# kopt=root=\([^ ]*\)\(.*\)/# kopt=root=\/dev\/hd%s%d\\2/g' % (bootdev.disk.devletters(), bootdev.get_index()+1), '%s/boot/grub/menu.lst' % self.context.chroot_dir)
218 run_cmd('sed', '-ie', 's/^# groot.*/# groot %s/g' % bootdev.get_grub_id(), '%s/boot/grub/menu.lst' % self.context.chroot_dir)
219 run_cmd('sed', '-ie', '/^# kopt_2_6/ d', '%s/boot/grub/menu.lst' % self.context.chroot_dir)
220265
221 def install_sources_list(self, final=False):266 def install_sources_list(self, final=False):
222 if final:267 if final:
223 mirror = updates_mirror = self.context.get_setting('mirror')268 mirror = backport_mirror = proposed_mirror = updates_mirror = self.context.get_setting('mirror')
224 security_mirror = self.context.get_setting('security-mirror')269 security_mirror = self.context.get_setting('security-mirror')
225 else:270 else:
226 mirror, updates_mirror, security_mirror = self.install_mirrors()271 mirror, updates_mirror, security_mirror, proposed_mirror, backport_mirror = self.install_mirrors()
227272
228 components = self.context.get_setting('components')273 components = self.context.get_setting('components')
229 ppa = self.context.get_setting('ppa')274 ppa = self.context.get_setting('ppa')
230 suite = self.context.get_setting('suite')275 suite = self.context.get_setting('suite')
276 proposed = self.context.get_setting('proposed')
277 backport = self.context.get_setting('backport')
231 self.install_from_template('/etc/apt/sources.list', 'sources.list', { 'mirror' : mirror,278 self.install_from_template('/etc/apt/sources.list', 'sources.list', { 'mirror' : mirror,
232 'security_mirror' : security_mirror,279 'security_mirror' : security_mirror,
233 'updates_mirror' : updates_mirror,280 'updates_mirror' : updates_mirror,
281 'proposed' : proposed,
282 'proposed_mirror' : proposed_mirror,
283 'backport' : backport,
284 'backport_mirror' : backport_mirror,
234 'components' : components,285 'components' : components,
235 'ppa' : ppa,286 'ppa' : ppa,
236 'suite' : suite })287 'suite' : suite })
@@ -243,13 +294,36 @@
243 def install_apt_proxy(self):294 def install_apt_proxy(self):
244 proxy = self.context.get_setting('proxy')295 proxy = self.context.get_setting('proxy')
245 if proxy is not None:296 if proxy is not None:
246 self.context.install_file('/etc/apt/apt.conf', '// Proxy added by vmbuilder\nAcquire::http { Proxy "%s"; };' % proxy)297 self.context.install_file('/etc/apt/apt.conf.d/01proxy', '// Proxy added by vmbuilder\nAcquire::http { Proxy "%s"; };\n' % proxy)
247298
248 def install_fstab(self, disks, filesystems):299 def install_fstab(self, disks, filesystems):
249 self.install_from_template('/etc/fstab', 'dapper_fstab', { 'parts' : disk.get_ordered_partitions(disks), 'prefix' : self.disk_prefix })300 self.install_from_template('/etc/fstab', 'dapper_fstab',
250301 { 'parts' : disk.get_ordered_partitions(disks),
251 def install_device_map(self):302 'prefix' : self.disk_prefix })
252 self.install_from_template('/boot/grub/device.map', 'devicemap', { 'prefix' : self.disk_prefix })303 #TODO : use labels or UUID
304
305 def install_device_map(self, disks, final=True):
306 self.install_from_template('/boot/grub/device.map', 'devicemap',
307 { 'disk_prefix' : self.disk_prefix,
308 'grub_partitions_prefix': self.grub_partitions_prefix,
309 'disks': disks,
310 'grub_offset': self.grub_offset,
311 'final': final })
312
313 def install_grub_load_cfg(self):
314 self.install_from_template('/boot/grub/load.cfg', 'loadcfg',
315 { 'UUID': self.grub_part.fs.uuid,
316 'grub_partitions_prefix': self.grub_partitions_prefix,
317 'grub_disk': self.grub_disk,
318 'grub_partition_root_index': self.grub_part.get_index() + self.grub_offset})
319
320 def install_grub_cfg(self, kernel):
321 self.install_from_template('/boot/grub/grub.cfg', 'grubcfg',
322 { 'UUID': self.grub_part.fs.uuid,
323 'grub_disk': self.grub_disk,
324 'grub_partitions_prefix': self.grub_partitions_prefix,
325 'grub_partition_root_index': self.grub_part.get_index() + self.grub_offset,
326 'KERNEL': kernel })
253327
254 def debootstrap(self):328 def debootstrap(self):
255 arch = self.context.get_setting('arch')329 arch = self.context.get_setting('arch')
@@ -289,7 +363,7 @@
289 else:363 else:
290 mirror = self.context.get_setting('mirror')364 mirror = self.context.get_setting('mirror')
291365
292 updates_mirror = mirror366 backport_mirror = proposed_mirror = updates_mirror = mirror
293367
294 install_security_mirror = self.context.get_setting('install-security-mirror')368 install_security_mirror = self.context.get_setting('install-security-mirror')
295 if install_security_mirror:369 if install_security_mirror:
@@ -297,16 +371,46 @@
297 else:371 else:
298 security_mirror = self.context.get_setting('security-mirror')372 security_mirror = self.context.get_setting('security-mirror')
299373
300 return (mirror, updates_mirror, security_mirror)374 return (mirror, updates_mirror, security_mirror, proposed_mirror, backport_mirror)
301375
302 def install_kernel(self, destdir):376 def install_kernel(self):
303 run_cmd('chroot', destdir, 'apt-get', '--force-yes', '-y', 'install', self.kernel_name(), env={ 'DEBIAN_FRONTEND' : 'noninteractive' })377 self.run_in_target('apt-get', '--force-yes', '-y', '--no-install-recommends', 'install', self.kernel_name(), env={ 'DEBIAN_FRONTEND' : 'noninteractive' })
304378
305 def install_grub(self, chroot_dir):379 def prepare_grub(self, disks):
306 self.install_from_template('/etc/kernel-img.conf', 'kernelimg', { 'updategrub' : self.updategrub })380 self.grub_part = disk.bootpart(disks)
381 self.grub_disk = disks[0]
382
383 def install_grub(self):
307 arch = self.context.get_setting('arch')384 arch = self.context.get_setting('arch')
308 self.run_in_target('apt-get', '--force-yes', '-y', 'install', 'grub', env={ 'DEBIAN_FRONTEND' : 'noninteractive' })385 self.run_in_target('apt-get', '--force-yes', '-y', '--no-install-recommends', 'install', 'grub', env={ 'DEBIAN_FRONTEND' : 'noninteractive' })
309 run_cmd('rsync', '-a', '%s%s/%s/' % (chroot_dir, self.grubroot, arch == 'amd64' and 'x86_64-pc' or 'i386-pc'), '%s/boot/grub/' % chroot_dir) 386
387 def configure_grub(self, disks):
388
389 # Install device_map
390 self.install_device_map(disks,False)
391 self.install_grub_load_cfg()
392
393 def install_grub_ondisk(self):
394 self.run_in_target('grub-install',
395 self.grub_disk.dev)
396
397 def install_menu_lst(self, disks):
398 self.run_in_target('grub-set-default', '0')
399 self.run_in_target('cp', '/proc/mounts', '/etc/mtab')
400 self.run_in_target(self.updategrub)
401 self.mangle_grub_menu_lst(disks)
402 #Test generate file to stdout
403 self.run_in_target('grub-mkconfig')
404
405 def mangle_grub_menu_lst(self, disks):
406 bootdev = disk.bootpart(disks)
407 run_cmd('sed', '-ie', 's/^# kopt=root=\([^ ]*\)\(.*\)/# kopt=root=\/dev\/hd%s%d\\2/g' % (bootdev.disk.devletters(), bootdev.get_index()+1), '%s/boot/grub/menu.lst' % self.context.chroot_dir)
408 run_cmd('sed', '-ie', 's/^# groot.*/# groot %s/g' % bootdev.get_grub_id(), '%s/boot/grub/menu.lst' % self.context.chroot_dir)
409 run_cmd('sed', '-ie', '/^# kopt_2_6/ d', '%s/boot/grub/menu.lst' % self.context.chroot_dir)
410
411 def finalise_grub(self, disks):
412 self.install_menu_lst(disks)
413
310414
311 def create_devices(self):415 def create_devices(self):
312 pass416 pass
@@ -328,9 +432,9 @@
328432
329 def copy_to_target(self, infile, destpath):433 def copy_to_target(self, infile, destpath):
330 logging.debug("Copying %s on host to %s in guest" % (infile, destpath))434 logging.debug("Copying %s on host to %s in guest" % (infile, destpath))
331 dir = '%s/%s' % (self.destdir, os.path.dirname(destpath))435 directory = '%s/%s' % (self.destdir, os.path.dirname(destpath))
332 if not os.path.isdir(dir):436 if not os.path.isdir(directory):
333 os.makedirs(dir)437 os.makedirs(directory)
334 if os.path.isdir(infile):438 if os.path.isdir(infile):
335 shutil.copytree(infile, '%s/%s' % (self.destdir, destpath))439 shutil.copytree(infile, '%s/%s' % (self.destdir, destpath))
336 else:440 else:
337441
=== modified file 'VMBuilder/plugins/ubuntu/distro.py'
--- VMBuilder/plugins/ubuntu/distro.py 2012-08-06 19:37:24 +0000
+++ VMBuilder/plugins/ubuntu/distro.py 2012-09-04 13:48:23 +0000
@@ -21,10 +21,12 @@
21import shutil21import shutil
22import stat22import stat
23import VMBuilder23import VMBuilder
24import VMBuilder.disk as vmdisk
24from VMBuilder import register_distro, Distro25from VMBuilder import register_distro, Distro
25from VMBuilder.util import run_cmd26from VMBuilder.util import run_cmd
26from VMBuilder.exception import VMBuilderUserError, VMBuilderException27from VMBuilder.exception import VMBuilderUserError, VMBuilderException
2728
29
28class Ubuntu(Distro):30class Ubuntu(Distro):
29 name = 'Ubuntu'31 name = 'Ubuntu'
30 arg = 'ubuntu'32 arg = 'ubuntu'
@@ -33,12 +35,13 @@
33 'precise', 'quantal' ]35 'precise', 'quantal' ]
3436
35 # Maps host arch to valid guest archs37 # Maps host arch to valid guest archs
36 valid_archs = { 'amd64' : ['amd64', 'i386', 'lpia' ],38 valid_archs = {'amd64': ['amd64', 'i386', 'lpia'],
37 'i386' : [ 'i386', 'lpia' ],39 'i386': ['i386', 'lpia'],
38 'lpia' : [ 'i386', 'lpia' ] }40 'lpia': ['i386', 'lpia']}
3941
40 xen_kernel = ''42 xen_kernel = ''
4143
44
42 def register_options(self):45 def register_options(self):
43 group = self.setting_group('Package options')46 group = self.setting_group('Package options')
44 group.add_setting('addpkg', type='list', metavar='PKG', help='Install PKG into the guest (can be specified multiple times).')47 group.add_setting('addpkg', type='list', metavar='PKG', help='Install PKG into the guest (can be specified multiple times).')
@@ -54,16 +57,22 @@
54 group.add_setting('suite', default='lucid', help='Suite to install. Valid options: %s [default: %%default]' % ' '.join(self.suites))57 group.add_setting('suite', default='lucid', help='Suite to install. Valid options: %s [default: %%default]' % ' '.join(self.suites))
55 group.add_setting('flavour', extra_args=['--kernel-flavour'], help='Kernel flavour to use. Default and valid options depend on architecture and suite')58 group.add_setting('flavour', extra_args=['--kernel-flavour'], help='Kernel flavour to use. Default and valid options depend on architecture and suite')
56 group.add_setting('variant', metavar='VARIANT', help='Passed to debootstrap --variant flag; use minbase, buildd, or fakechroot.')59 group.add_setting('variant', metavar='VARIANT', help='Passed to debootstrap --variant flag; use minbase, buildd, or fakechroot.')
57 group.add_setting('iso', metavar='PATH', help='Use an iso image as the source for installation of file. Full path to the iso must be provided. If --mirror is also provided, it will be used in the final sources.list of the vm. This requires suite and kernel parameter to match what is available on the iso, obviously.')60 group.add_setting('iso', metavar='PATH', help='Use an iso image as the source for installation of file. Full path to the iso must be provided. If --mirror is also provided, it will be used in the final sources.list of the hypervisor. This requires suite and kernel parameter to match what is available on the iso, obviously.')
58 group.add_setting('mirror', metavar='URL', help='Use Ubuntu mirror at URL instead of the default, which is http://archive.ubuntu.com/ubuntu for official arches and http://ports.ubuntu.com/ubuntu-ports otherwise')61 group.add_setting('mirror', metavar='URL', help='Use Ubuntu mirror at URL instead of the default, which is http://archive.ubuntu.com/ubuntu for official arches and http://ports.ubuntu.com/ubuntu-ports otherwise')
59 group.add_setting('proxy', metavar='URL', help='Use proxy at URL for cached packages')62 group.add_setting('proxy', metavar='URL', help='Use proxy at URL for cached packages')
60 group.add_setting('install-mirror', metavar='URL', help='Use Ubuntu mirror at URL for the installation only. Apt\'s sources.list will still use default or URL set by --mirror')63 group.add_setting('install-mirror', metavar='URL', help='Use Ubuntu mirror at URL for the installation only. Apt\'s sources.list will still use default or URL set by --mirror')
61 group.add_setting('security-mirror', metavar='URL', help='Use Ubuntu security mirror at URL instead of the default, which is http://security.ubuntu.com/ubuntu for official arches and http://ports.ubuntu.com/ubuntu-ports otherwise.')64 group.add_setting('security-mirror', metavar='URL', help='Use Ubuntu security mirror at URL instead of the default, which is http://security.ubuntu.com/ubuntu for official arches and http://ports.ubuntu.com/ubuntu-ports otherwise.')
62 group.add_setting('install-security-mirror', metavar='URL', help='Use the security mirror at URL for installation only. Apt\'s sources.list will still use default or URL set by --security-mirror')65 group.add_setting('install-security-mirror', metavar='URL', help='Use the security mirror at URL for installation only. Apt\'s sources.list will still use default or URL set by --security-mirror')
63 group.add_setting('components', type='list', metavar='COMPS', help='A comma seperated list of distro components to include (e.g. main,universe).')66 group.add_setting('components', type='list', metavar='COMPS', help='A comma seperated list of distro components to include (e.g. main,universe).')
67 group.add_setting('backport', type='bool', default=False, help='add backport to sources.list')
68 group.add_setting('proposed', type='bool', default=False, help='add proposed to sources.list')
69<<<<<<< TREE
64 group.add_setting('ppa', metavar='PPA', type='list', help='Add ppa belonging to PPA to the vm\'s sources.list.')70 group.add_setting('ppa', metavar='PPA', type='list', help='Add ppa belonging to PPA to the vm\'s sources.list.')
71=======
72 group.add_setting('ppa', metavar='PPA', type='list', help='Add ppa belonging to PPA to the hypervisor\'s sources.list.')
73>>>>>>> MERGE-SOURCE
65 group.add_setting('lang', metavar='LANG', default=get_locale(), help='Set the locale to LANG [default: %default]')74 group.add_setting('lang', metavar='LANG', default=get_locale(), help='Set the locale to LANG [default: %default]')
66 group.add_setting('timezone', metavar='TZ', default='UTC', help='Set the timezone to TZ in the vm. [default: %default]')75 group.add_setting('timezone', metavar='TZ', default='UTC', help='Set the timezone to TZ in the hypervisor. [default: %default]')
6776
68 group = self.setting_group('Settings for the initial user')77 group = self.setting_group('Settings for the initial user')
69 group.add_setting('user', default='ubuntu', help='Username of initial user [default: %default]')78 group.add_setting('user', default='ubuntu', help='Username of initial user [default: %default]')
@@ -89,22 +98,22 @@
89 self.set_setting_default('mirror', 'http://archive.ubuntu.com/ubuntu')98 self.set_setting_default('mirror', 'http://archive.ubuntu.com/ubuntu')
90 self.set_setting_default('security-mirror', 'http://security.ubuntu.com/ubuntu')99 self.set_setting_default('security-mirror', 'http://security.ubuntu.com/ubuntu')
91100
92 self.set_setting_default('components', ['main', 'restricted', 'universe'])101 self.set_setting_default('components', ['main', 'restricted', 'universe'])
93102
94 def preflight_check(self):103 def preflight_check(self):
95 """While not all of these are strictly checks, their failure would inevitably104 """While not all of these are strictly checks, their failure would inevitably
96 lead to failure, and since we can check them before we start setting up disk105 lead to failure, and since we can check them before we start setting up disk
97 and whatnot, we might as well go ahead an do this now."""106 and whatnot, we might as well go ahead an do this now."""
98107
99 suite = self.get_setting('suite') 108 suite = self.get_setting('suite')
100 if not suite in self.suites:109 if not suite in self.suites:
101 raise VMBuilderUserError('Invalid suite: "%s". Valid suites are: %s' % (suite, ' '.join(self.suites)))110 raise VMBuilderUserError('Invalid suite: "%s". Valid suites are: %s' % (suite, ' '.join(self.suites)))
102 111
103 modname = 'VMBuilder.plugins.ubuntu.%s' % (suite, )112 modname = 'VMBuilder.plugins.ubuntu.%s' % (suite, )
104 mod = __import__(modname, fromlist=[suite])113 mod = __import__(modname, fromlist=[suite])
105 self.suite = getattr(mod, suite.capitalize())(self)114 self.suite = getattr(mod, suite.capitalize())(self)
106115
107 arch = self.get_setting('arch') 116 arch = self.get_setting('arch')
108 if arch not in self.valid_archs[self.host_arch] or \117 if arch not in self.valid_archs[self.host_arch] or \
109 not self.suite.check_arch_validity(arch):118 not self.suite.check_arch_validity(arch):
110 raise VMBuilderUserError('%s is not a valid architecture. Valid architectures are: %s' % (arch,119 raise VMBuilderUserError('%s is not a valid architecture. Valid architectures are: %s' % (arch,
@@ -115,7 +124,7 @@
115 self.set_config_value_list = ['main', 'restricted', 'universe']124 self.set_config_value_list = ['main', 'restricted', 'universe']
116 else:125 else:
117 if type(components) is str:126 if type(components) is str:
118 self.vm.components = self.vm.components.split(',')127 self.hypervisor.components = self.hypervisor.components.split(',')
119128
120 self.context.virtio_net = self.use_virtio_net()129 self.context.virtio_net = self.use_virtio_net()
121130
@@ -127,7 +136,7 @@
127 lang = self.get_setting('lang')136 lang = self.get_setting('lang')
128137
129# FIXME138# FIXME
130# if getattr(self.vm, 'ec2', False):139# if getattr(self.hypervisor, 'ec2', False):
131# self.get_ec2_kernel()140# self.get_ec2_kernel()
132# self.get_ec2_ramdisk()141# self.get_ec2_ramdisk()
133# self.apply_ec2_settings()142# self.apply_ec2_settings()
@@ -136,12 +145,40 @@
136 self.suite.debootstrap()145 self.suite.debootstrap()
137 self.suite.pre_install()146 self.suite.pre_install()
138147
148<<<<<<< TREE
149<<<<<<< TREE
150=======
151>>>>>>> MERGE-SOURCE
152 def prepare_chroot(self):
153 self.suite.create_devices()
154 self.suite.mount()
155<<<<<<< TREE
156=======
157 self.run_in_target('cp', '/proc/mounts', '/etc/mtab')
158>>>>>>> MERGE-SOURCE
159
160 def clean_chroot(self):
161 self.suite.umount()
162
163 def install_os(self):
164<<<<<<< TREE
165=======
139 def configure_os(self):166 def configure_os(self):
140 self.suite.install_apt_proxy()167 self.suite.install_apt_proxy()
168>>>>>>> MERGE-SOURCE
169=======
170>>>>>>> MERGE-SOURCE
141 self.suite.install_sources_list()171 self.suite.install_sources_list()
172<<<<<<< TREE
173 self.suite.install_apt_proxy()
174<<<<<<< TREE
175=======
142 self.suite.create_devices()176 self.suite.create_devices()
177>>>>>>> MERGE-SOURCE
178=======
179>>>>>>> MERGE-SOURCE
143 self.suite.prevent_daemons_starting()180 self.suite.prevent_daemons_starting()
144 self.suite.mount_dev_proc()181# self.suite.install_grub()
145 self.suite.install_extras()182 self.suite.install_extras()
146 self.suite.create_initial_user()183 self.suite.create_initial_user()
147 self.suite.install_authorized_keys()184 self.suite.install_authorized_keys()
@@ -149,11 +186,7 @@
149 self.suite.set_locale()186 self.suite.set_locale()
150 self.suite.update()187 self.suite.update()
151 self.suite.install_sources_list(final=True)188 self.suite.install_sources_list(final=True)
152 self.suite.run_in_target('apt-get', 'clean');189 self.suite.run_in_target("apt-get", "clean")
153 self.suite.unmount_volatile()
154 self.suite.unmount_proc()
155 self.suite.unmount_dev_pts()
156 self.suite.unmount_dev()
157 self.suite.unprevent_daemons_starting()190 self.suite.unprevent_daemons_starting()
158 self.suite.create_manifest()191 self.suite.create_manifest()
159192
@@ -164,9 +197,9 @@
164 def configure_mounting(self, disks, filesystems):197 def configure_mounting(self, disks, filesystems):
165 self.suite.install_fstab(disks, filesystems)198 self.suite.install_fstab(disks, filesystems)
166199
167 def install(self, destdir):200# def install(self, destdir):
168 self.destdir = destdir201# self.destdir = destdir
169 self.suite.install(destdir)202# self.suite.install(destdir)
170203
171 def install_vmbuilder_log(self, logfile, rootdir):204 def install_vmbuilder_log(self, logfile, rootdir):
172 self.suite.install_vmbuilder_log(logfile, rootdir)205 self.suite.install_vmbuilder_log(logfile, rootdir)
@@ -177,44 +210,27 @@
177 def use_virtio_net(self):210 def use_virtio_net(self):
178 return self.suite.virtio_net211 return self.suite.virtio_net
179212
180 def install_bootloader_cleanup(self, chroot_dir):213 def install_kernel(self):
181 self.context.cancel_cleanup(self.install_bootloader_cleanup)214 self.suite.install_kernel()
182 tmpdir = '%s/tmp/vmbuilder-grub' % chroot_dir215
183 for disk in os.listdir(tmpdir):216 def install_bootloader(self, disks):
184 if disk != 'device.map':217<<<<<<< TREE
185 run_cmd('umount', os.path.join(tmpdir, disk))218=======
186 shutil.rmtree(tmpdir)219 self.suite.prepare_grub(disks)
187220>>>>>>> MERGE-SOURCE
188 def install_kernel(self, destdir):221 self.suite.install_grub()
189 self.suite.install_kernel(destdir)222<<<<<<< TREE
190223 dev_device = VMBuilder.disk.bootpart(disks).devletters()
191 def install_bootloader(self, chroot_dir, disks):224 self.run_in_target('grub-install', '--force --no-floppy /dev/sd%s' % dev_device)
192 root_dev = VMBuilder.disk.bootpart(disks).get_grub_id()
193
194 tmpdir = '/tmp/vmbuilder-grub'
195 os.makedirs('%s%s' % (chroot_dir, tmpdir))
196 self.context.add_clean_cb(self.install_bootloader_cleanup)
197 devmapfile = os.path.join(tmpdir, 'device.map')
198 devmap = open('%s%s' % (chroot_dir, devmapfile), 'w')
199 for (disk, id) in zip(disks, range(len(disks))):
200 new_filename = os.path.join(tmpdir, os.path.basename(disk.filename))
201 open('%s%s' % (chroot_dir, new_filename), 'w').close()
202 run_cmd('mount', '--bind', disk.filename, '%s%s' % (chroot_dir, new_filename))
203 st = os.stat(disk.filename)
204 if stat.S_ISBLK(st.st_mode):
205 for (part, part_id) in zip(disk.partitions, range(len(disk.partitions))):
206 part_mountpnt = '%s%s%d' % (chroot_dir, new_filename, part_id+1)
207 open(part_mountpnt, 'w').close()
208 run_cmd('mount', '--bind', part.filename, part_mountpnt)
209 devmap.write("(hd%d) %s\n" % (id, new_filename))
210 devmap.close()
211 run_cmd('cat', '%s%s' % (chroot_dir, devmapfile))
212 self.suite.install_grub(chroot_dir)
213 self.run_in_target('grub', '--device-map=%s' % devmapfile, '--batch', stdin='''root %s
214setup (hd0)
215EOT''' % root_dev)
216 self.suite.install_menu_lst(disks)225 self.suite.install_menu_lst(disks)
217 self.install_bootloader_cleanup(chroot_dir)226=======
227 self.suite.configure_grub(disks)
228 self.suite.install_grub_ondisk()
229 #kernel = '3.0.0-12-virtual'
230 #self.suite.install_grub_cfg(kernel)
231 # Maybe useless. Removing device.map can be a better solution
232 self.suite.finalise_grub(disks)
233>>>>>>> MERGE-SOURCE
218234
219 def xen_kernel_version(self):235 def xen_kernel_version(self):
220 if self.suite.xen_kernel_flavour:236 if self.suite.xen_kernel_flavour:
@@ -227,7 +243,7 @@
227 return self.xen_kernel243 return self.xen_kernel
228 if not self.xen_kernel:244 if not self.xen_kernel:
229 rmad = run_cmd('rmadison', 'linux-image-%s' % self.suite.xen_kernel_flavour)245 rmad = run_cmd('rmadison', 'linux-image-%s' % self.suite.xen_kernel_flavour)
230 version = ['0', '0','0', '0']246 version = ['0', '0', '0', '0']
231247
232 for line in rmad.splitlines():248 for line in rmad.splitlines():
233 sline = line.split('|')249 sline = line.split('|')
@@ -242,7 +258,7 @@
242 if version[0] == '0':258 if version[0] == '0':
243 raise VMBuilderException('Something is wrong, no valid xen kernel for the suite %s found by rmadison' % self.context.suite)259 raise VMBuilderException('Something is wrong, no valid xen kernel for the suite %s found by rmadison' % self.context.suite)
244260
245 self.xen_kernel = '%s.%s.%s-%s' % (version[0],version[1],version[2],version[3])261 self.xen_kernel = '%s.%s.%s-%s' % (version[0], version[1], version[2], version[3])
246 return self.xen_kernel262 return self.xen_kernel
247 else:263 else:
248 raise VMBuilderUserError('There is no valid xen kernel for the suite selected.')264 raise VMBuilderUserError('There is no valid xen kernel for the suite selected.')
@@ -281,6 +297,7 @@
281 def preferred_filesystem(self):297 def preferred_filesystem(self):
282 return self.suite.preferred_filesystem298 return self.suite.preferred_filesystem
283299
300
284def get_locale():301def get_locale():
285 lang = os.getenv('LANG')302 lang = os.getenv('LANG')
286 if lang is None:303 if lang is None:
287304
=== modified file 'VMBuilder/plugins/ubuntu/intrepid.py'
--- VMBuilder/plugins/ubuntu/intrepid.py 2010-06-15 20:56:43 +0000
+++ VMBuilder/plugins/ubuntu/intrepid.py 2012-09-04 13:48:23 +0000
@@ -28,6 +28,7 @@
28 xen_kernel_flavour = 'virtual'28 xen_kernel_flavour = 'virtual'
29 ec2_kernel_info = { 'i386' : 'aki-714daa18', 'amd64' : 'aki-4f4daa26' }29 ec2_kernel_info = { 'i386' : 'aki-714daa18', 'amd64' : 'aki-4f4daa26' }
30 ec2_ramdisk_info = { 'i386': 'ari-7e4daa17', 'amd64' : 'ari-4c4daa25' }30 ec2_ramdisk_info = { 'i386': 'ari-7e4daa17', 'amd64' : 'ari-4c4daa25' }
31 Virtio_disk = True
3132
32 def install_ec2(self):33 def install_ec2(self):
33# workaround for policy bug on ubuntu-server. (see bug #275432)34# workaround for policy bug on ubuntu-server. (see bug #275432)
3435
=== modified file 'VMBuilder/plugins/ubuntu/karmic.py'
--- VMBuilder/plugins/ubuntu/karmic.py 2010-02-24 15:49:04 +0000
+++ VMBuilder/plugins/ubuntu/karmic.py 2012-09-04 13:48:23 +0000
@@ -25,6 +25,7 @@
2525
26 preferred_filesystem = 'ext4'26 preferred_filesystem = 'ext4'
2727
28
28 def apply_ec2_settings(self):29 def apply_ec2_settings(self):
29 self.context.addpkg += ['standard^',30 self.context.addpkg += ['standard^',
30 'uec^']31 'uec^']
3132
=== modified file 'VMBuilder/plugins/ubuntu/lucid.py'
--- VMBuilder/plugins/ubuntu/lucid.py 2012-07-24 04:09:25 +0000
+++ VMBuilder/plugins/ubuntu/lucid.py 2012-09-04 13:48:23 +0000
@@ -19,14 +19,42 @@
19import os19import os
20from VMBuilder.util import run_cmd20from VMBuilder.util import run_cmd
21from VMBuilder.plugins.ubuntu.karmic import Karmic21from VMBuilder.plugins.ubuntu.karmic import Karmic
22from VMBuilder.util import run_cmd
2223
23class Lucid(Karmic):24class Lucid(Karmic):
24 valid_flavours = { 'i386' : ['386', 'generic', 'generic-pae', 'virtual'],25 valid_flavours = { 'i386' : ['386', 'generic', 'generic-pae', 'virtual'],
25 'amd64' : ['generic', 'preempt', 'server', 'virtual'] }26 'amd64' : ['generic', 'preempt', 'server', 'virtual'] }
26
27 def divert_file(self, path, add):27 def divert_file(self, path, add):
28 if add: action = "--add"28 if add: action = "--add"
29 else: action = "--remove"29 else: action = "--remove"
30 if not add:30 if not add:
31 os.remove('%s/%s' % (self.context.chroot_dir, path))31 os.remove('%s/%s' % (self.context.chroot_dir, path))
32 run_cmd('chroot', self.context.chroot_dir, 'dpkg-divert', '--local', '--rename', action, path)32 run_cmd('chroot', self.context.chroot_dir, 'dpkg-divert', '--local', '--rename', action, path)
33
34 grub_version = 2
35 grub_offset = 1
36
37 def install_grub(self):
38 self.run_in_target('apt-get', '--force-yes', '-y', 'install', 'grub-pc', env={ 'DEBIAN_FRONTEND' : 'noninteractive' })
39
40 def install_grub_ondisk(self):
41# self.run_in_target('grub-probe', '--device-map=/boot/grub/device.map', '-d', '(hd0)')
42 self.run_in_target('grub-install',
43 '--no-floppy',
44# '--grub-mkdevicemap=/boot/grub/device.map',
45 '--modules=ext2.mod',
46 '--modules=part_msdos.mod',
47 self.grub_disk.dev)
48 self.run_in_target('update-grub2')
49
50 def mangle_grub_menu_lst(self, disks):
51 run_cmd('sed', '-ie', '/insmod gzio/ a\ insmod part_msdos', '%s/boot/grub/grub.cfg' % self.context.chroot_dir)
52 dev_final = '(' + self.grub_disk.get_grub_id() + ',' + self.grub_partitions_prefix + str(self.grub_part.get_index() + self.grub_offset) + ')'
53 run_cmd('sed', '-ie', 's-/dev/loop[0-9]-%s-g' % dev_final, '%s/boot/grub/grub.cfg' % self.context.chroot_dir)
54 run_cmd('sed', '-ie', '/loopback/d', '%s/boot/grub/grub.cfg' % self.context.chroot_dir)
55 run_cmd('sed', '-ie', '/set root=(loop/d', '%s/boot/grub/grub.cfg' % self.context.chroot_dir)
56
57
58 def finalise_grub(self, disks):
59 self.install_menu_lst(disks)
60 self.install_device_map(disks,True)
3361
=== modified file 'VMBuilder/plugins/ubuntu/oneiric.py'
--- VMBuilder/plugins/ubuntu/oneiric.py 2012-07-24 04:09:25 +0000
+++ VMBuilder/plugins/ubuntu/oneiric.py 2012-09-04 13:48:23 +0000
@@ -16,7 +16,28 @@
16# You should have received a copy of the GNU General Public License16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#18#
19
19from VMBuilder.plugins.ubuntu.natty import Natty20from VMBuilder.plugins.ubuntu.natty import Natty
2021
21class Oneiric(Natty):22class Oneiric(Natty):
22 pass23 grub_partitions_prefix = 'msdos'
24
25 def install_grub_ondisk(self):
26# self.run_in_target('grub-probe', '--device-map=/boot/grub/device.map', '-d', '(hd0)')
27 self.run_in_target('grub-install',
28 '--no-floppy',
29# '--grub-mkdevicemap=/boot/grub/device.map',
30 '--modules=ext2.mod',
31 '--modules=part_msdos.mod',
32 self.grub_disk.dev)
33 self.run_in_target('update-grub2')
34
35 def unmount_dev(self):
36 # no idea why, but something keep /dev busy briefly during the
37 # bootstrap
38 time.sleep(1)
39 super(Oneiric, self).unmount_dev()
40
41 def install_grub(self):
42 arch = self.context.get_setting('arch')
43 self.run_in_target('apt-get', '--force-yes', '-y', 'install', 'grub-pc', env={ 'DEBIAN_FRONTEND' : 'noninteractive' })
2344
=== added file 'VMBuilder/plugins/ubuntu/precise.py'
--- VMBuilder/plugins/ubuntu/precise.py 1970-01-01 00:00:00 +0000
+++ VMBuilder/plugins/ubuntu/precise.py 2012-09-04 13:48:23 +0000
@@ -0,0 +1,22 @@
1#
2# Uncomplicated VM Builder
3# Copyright (C) 2010 Canonical Ltd.
4#
5# See AUTHORS for list of contributors
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 3, as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19from VMBuilder.plugins.ubuntu.oneiric import Oneiric
20
21class Precise(Oneiric):
22 pass
0\ No newline at end of file23\ No newline at end of file
124
=== renamed file 'VMBuilder/plugins/ubuntu/precise.py' => 'VMBuilder/plugins/ubuntu/precise.py.moved'
=== added file 'VMBuilder/plugins/ubuntu/templates/Copy of devicemap.tmpl'
--- VMBuilder/plugins/ubuntu/templates/Copy of devicemap.tmpl 1970-01-01 00:00:00 +0000
+++ VMBuilder/plugins/ubuntu/templates/Copy of devicemap.tmpl 2012-09-04 13:48:23 +0000
@@ -0,0 +1,17 @@
1#if $final
2#for $disk in $disks
3(hd$disk.get_index()) /dev/$disk_prefix$disk.devletters()
4#for $part in $disk.partitions
5#set $grub_part_index = $part.get_index() + $grub_offset
6(hd$disk.get_index(),$grub_partitions_prefix$grub_part_index) /dev/$disk_prefix$part.get_suffix()
7#end for
8#end for
9#else
10#for $disk in $disks
11(hd$disk.get_index()) $disk.dev
12#for $part in $disk.partitions
13#set $grub_part_index = $part.get_index() + $grub_offset
14(hd$disk.get_index(),$grub_partitions_prefix$grub_part_index) $part.dev
15#end for
16#end for
17#end if
018
=== modified file 'VMBuilder/plugins/ubuntu/templates/devicemap.tmpl'
--- VMBuilder/plugins/ubuntu/templates/devicemap.tmpl 2008-10-17 17:41:05 +0000
+++ VMBuilder/plugins/ubuntu/templates/devicemap.tmpl 2012-09-04 13:48:23 +0000
@@ -1,3 +1,9 @@
1#for $disk in $disks1#if $final
2$disk.get_grub_id() /dev/$prefix$disk.devletters()2#for $disk in $disks
3#end for3(hd$disk.get_index()) /dev/$disk_prefix$disk.devletters()
4#end for
5#else
6#for $disk in $disks
7(hd$disk.get_index()) $disk.dev
8#end for
9#end if
410
=== added file 'VMBuilder/plugins/ubuntu/templates/grubcfg.tmpl'
--- VMBuilder/plugins/ubuntu/templates/grubcfg.tmpl 1970-01-01 00:00:00 +0000
+++ VMBuilder/plugins/ubuntu/templates/grubcfg.tmpl 2012-09-04 13:48:23 +0000
@@ -0,0 +1,8 @@
1insmod gzio
2insmod part_msdos
3insmod ext2
4set root='(hd$grub_disk.get_index(),$grub_partitions_prefix$grub_partition_root_index)'
5search --no-floppy --fs-uuid --set=root $UUID
6linux /boot/vmlinuz-$KERNEL root=UUID=$UUID ro quiet splash
7initrd /boot/initrd.img-$KERNEL
8boot
0\ No newline at end of file9\ No newline at end of file
110
=== added file 'VMBuilder/plugins/ubuntu/templates/loadcfg.tmpl'
--- VMBuilder/plugins/ubuntu/templates/loadcfg.tmpl 1970-01-01 00:00:00 +0000
+++ VMBuilder/plugins/ubuntu/templates/loadcfg.tmpl 2012-09-04 13:48:23 +0000
@@ -0,0 +1,3 @@
1search.fs_uuid $UUID root
2set prefix=(\$root)/boot/grub
3set root=(hd$grub_disk.get_index(),$grub_partitions_prefix$grub_partition_root_index)
0\ No newline at end of file4\ No newline at end of file
15
=== modified file 'VMBuilder/plugins/ubuntu/templates/sources.list.tmpl'
--- VMBuilder/plugins/ubuntu/templates/sources.list.tmpl 2011-04-19 08:29:59 +0000
+++ VMBuilder/plugins/ubuntu/templates/sources.list.tmpl 2012-09-04 13:48:23 +0000
@@ -7,6 +7,16 @@
7deb $security_mirror $suite-security #slurp7deb $security_mirror $suite-security #slurp
8#echo ' '.join($components)8#echo ' '.join($components)
99
10#if $backport
11deb $backport_mirror $suite-backport
12#echo ' '.join($components)
13#end if
14
15#if $proposed
16deb $proposed_mirror $suite-proposed
17#echo ' '.join($components)
18#end if
19
10#if $ppa20#if $ppa
11#for $p in $ppa21#for $p in $ppa
12deb http://ppa.launchpad.net/$p/ubuntu $suite main22deb http://ppa.launchpad.net/$p/ubuntu $suite main
1323
=== modified file 'VMBuilder/tests/disk_tests.py'
--- VMBuilder/tests/disk_tests.py 2010-03-29 22:10:16 +0000
+++ VMBuilder/tests/disk_tests.py 2012-09-04 13:48:23 +0000
@@ -199,8 +199,8 @@
199 self.tmpfile = get_temp_filename()199 self.tmpfile = get_temp_filename()
200 os.unlink(self.tmpfile)200 os.unlink(self.tmpfile)
201201
202 self.vm = MockHypervisor()202 self.hypervisor = MockHypervisor()
203 self.disk = self.vm.add_disk(self.tmpfile, size='1G')203 self.disk = self.hypervisor.add_disk(self.tmpfile, size='1G')
204 self.disk.create()204 self.disk.create()
205205
206 def tearDown(self):206 def tearDown(self):
@@ -215,7 +215,7 @@
215 self.assertRaises(VMBuilderUserError, self.disk.add_part, 512, 514, 'ext3', '/')215 self.assertRaises(VMBuilderUserError, self.disk.add_part, 512, 514, 'ext3', '/')
216216
217 def test_partition_table_empty(self):217 def test_partition_table_empty(self):
218 from VMBuilder.util import run_cmd218# from VMBuilder.util import run_cmd
219219
220 file_output = run_cmd('file', self.tmpfile)220 file_output = run_cmd('file', self.tmpfile)
221 self.assertEqual('%s: data' % self.tmpfile, file_output.strip())221 self.assertEqual('%s: data' % self.tmpfile, file_output.strip())
@@ -232,7 +232,7 @@
232Number Start End Size Type File system Flags''' % self.tmpfile, file_output.strip())232Number Start End Size Type File system Flags''' % self.tmpfile, file_output.strip())
233233
234 def test_partition_table_nonempty(self):234 def test_partition_table_nonempty(self):
235 from VMBuilder.util import run_cmd235# from VMBuilder.util import run_cmd
236236
237 self.disk.add_part(1, 1023, 'ext3', '/')237 self.disk.add_part(1, 1023, 'ext3', '/')
238 self.disk.partition()238 self.disk.partition()
@@ -251,7 +251,7 @@
251 self.disk.partition()251 self.disk.partition()
252 self.disk.map_partitions()252 self.disk.map_partitions()
253 try:253 try:
254 from VMBuilder.disk import detect_size254# from VMBuilder.disk import detect_size
255 self.assertEqual(detect_size(self.disk.partitions[0].filename), 1023000576)255 self.assertEqual(detect_size(self.disk.partitions[0].filename), 1023000576)
256 except:256 except:
257 raise257 raise
@@ -275,7 +275,7 @@
275275
276 tmpfile2 = get_temp_filename()276 tmpfile2 = get_temp_filename()
277 os.unlink(tmpfile2)277 os.unlink(tmpfile2)
278 disk2 = self.vm.add_disk(tmpfile2, '1G')278 disk2 = self.hypervisor.add_disk(tmpfile2, '1G')
279 self.assertEqual(self.disk.get_grub_id(), '(hd0)')279 self.assertEqual(self.disk.get_grub_id(), '(hd0)')
280 self.assertEqual(disk2.get_grub_id(), '(hd1)')280 self.assertEqual(disk2.get_grub_id(), '(hd1)')
281281
@@ -284,6 +284,6 @@
284284
285 tmpfile2 = get_temp_filename()285 tmpfile2 = get_temp_filename()
286 os.unlink(tmpfile2)286 os.unlink(tmpfile2)
287 disk2 = self.vm.add_disk(tmpfile2, '1G')287 disk2 = self.hypervisor.add_disk(tmpfile2, '1G')
288 self.assertEqual(self.disk.get_index(), 0)288 self.assertEqual(self.disk.get_index(), 0)
289 self.assertEqual(disk2.get_index(), 1)289 self.assertEqual(disk2.get_index(), 1)
290290
=== modified file 'VMBuilder/tests/plugin_tests.py'
--- VMBuilder/tests/plugin_tests.py 2010-02-25 23:41:18 +0000
+++ VMBuilder/tests/plugin_tests.py 2012-09-04 13:48:23 +0000
@@ -13,8 +13,8 @@
13 pass13 pass
1414
15 def setUp(self):15 def setUp(self):
16 self.vm = self.VM()16 self.hypervisor = self.VM()
17 self.plugin = self.TestPlugin(self.vm)17 self.plugin = self.TestPlugin(self.hypervisor)
18 self.i = 018 self.i = 0
1919
20 def test_add_setting_group_and_setting(self):20 def test_add_setting_group_and_setting(self):
@@ -22,17 +22,17 @@
22 self.assertTrue(setting_group in self.plugin._setting_groups, "Setting not added correctly to plugin's registry of setting groups.")22 self.assertTrue(setting_group in self.plugin._setting_groups, "Setting not added correctly to plugin's registry of setting groups.")
2323
24 setting_group.add_setting('testsetting')24 setting_group.add_setting('testsetting')
25 self.assertEqual(self.vm.get_setting('testsetting'), None, "Setting's default value is not None.")25 self.assertEqual(self.hypervisor.get_setting('testsetting'), None, "Setting's default value is not None.")
2626
27 self.vm.set_setting_default('testsetting', 'newdefault')27 self.hypervisor.set_setting_default('testsetting', 'newdefault')
28 self.assertEqual(self.vm.get_setting('testsetting'), 'newdefault', "Setting does not return custom default value when no value is set.")28 self.assertEqual(self.hypervisor.get_setting('testsetting'), 'newdefault', "Setting does not return custom default value when no value is set.")
29 self.assertEqual(self.vm.get_setting_default('testsetting'), 'newdefault', "Setting does not return custom default value through get_setting_default().")29 self.assertEqual(self.hypervisor.get_setting_default('testsetting'), 'newdefault', "Setting does not return custom default value through get_setting_default().")
3030
31 self.vm.set_setting('testsetting', 'foo')31 self.hypervisor.set_setting('testsetting', 'foo')
32 self.assertEqual(self.vm.get_setting('testsetting'), 'foo', "Setting does not return set value.")32 self.assertEqual(self.hypervisor.get_setting('testsetting'), 'foo', "Setting does not return set value.")
3333
34 self.vm.set_setting_default('testsetting', 'newerdefault')34 self.hypervisor.set_setting_default('testsetting', 'newerdefault')
35 self.assertEqual(self.vm.get_setting('testsetting'), 'foo', "Setting does not return set value after setting new default value.")35 self.assertEqual(self.hypervisor.get_setting('testsetting'), 'foo', "Setting does not return set value after setting new default value.")
3636
37 def test_invalid_type_raises_exception(self):37 def test_invalid_type_raises_exception(self):
38 setting_group = self.plugin.setting_group('Test Setting Group')38 setting_group = self.plugin.setting_group('Test Setting Group')
@@ -42,13 +42,13 @@
42 setting_group = self.plugin.setting_group('Test Setting Group')42 setting_group = self.plugin.setting_group('Test Setting Group')
4343
44 setting_group.add_setting('strsetting')44 setting_group.add_setting('strsetting')
45 self.assertRaises(VMBuilderException, self.vm.set_setting_valid_options, 'strsetting', '')45 self.assertRaises(VMBuilderException, self.hypervisor.set_setting_valid_options, 'strsetting', '')
46 self.vm.set_setting_valid_options('strsetting', ['foo', 'bar'])46 self.hypervisor.set_setting_valid_options('strsetting', ['foo', 'bar'])
47 self.assertEqual(self.vm.get_setting_valid_options('strsetting'), ['foo', 'bar'])47 self.assertEqual(self.hypervisor.get_setting_valid_options('strsetting'), ['foo', 'bar'])
48 self.vm.set_setting('strsetting', 'foo')48 self.hypervisor.set_setting('strsetting', 'foo')
49 self.assertRaises(VMBuilderException, self.vm.set_setting, 'strsetting', 'baz')49 self.assertRaises(VMBuilderException, self.hypervisor.set_setting, 'strsetting', 'baz')
50 self.vm.set_setting_valid_options('strsetting', None)50 self.hypervisor.set_setting_valid_options('strsetting', None)
51 self.vm.set_setting('strsetting', 'baz')51 self.hypervisor.set_setting('strsetting', 'baz')
5252
53 def test_invalid_type_setting_raises_exception(self):53 def test_invalid_type_setting_raises_exception(self):
54 setting_group = self.plugin.setting_group('Test Setting Group')54 setting_group = self.plugin.setting_group('Test Setting Group')
@@ -102,18 +102,18 @@
102102
103 for setting_type in test_table:103 for setting_type in test_table:
104 for good in setting_type['good']:104 for good in setting_type['good']:
105 try_good_setting(setting_type['type'], good, self.vm.get_setting, self.vm.set_setting)105 try_good_setting(setting_type['type'], good, self.hypervisor.get_setting, self.hypervisor.set_setting)
106 try_good_setting(setting_type['type'], good, self.vm.get_setting, self.vm.set_setting_default)106 try_good_setting(setting_type['type'], good, self.hypervisor.get_setting, self.hypervisor.set_setting_default)
107 try_good_setting(setting_type['type'], good, self.vm.get_setting_default, self.vm.set_setting_default)107 try_good_setting(setting_type['type'], good, self.hypervisor.get_setting_default, self.hypervisor.set_setting_default)
108 try_good_setting(setting_type['type'], good, self.vm.get_setting, self.vm.set_setting_fuzzy)108 try_good_setting(setting_type['type'], good, self.hypervisor.get_setting, self.hypervisor.set_setting_fuzzy)
109 for fuzzy in setting_type['fuzzy']:109 for fuzzy in setting_type['fuzzy']:
110 try_good_setting(setting_type['type'], fuzzy, self.vm.get_setting, self.vm.set_setting_fuzzy)110 try_good_setting(setting_type['type'], fuzzy, self.hypervisor.get_setting, self.hypervisor.set_setting_fuzzy)
111 for bad in setting_type['bad']:111 for bad in setting_type['bad']:
112 try_bad_setting(setting_type['type'], bad, self.vm.set_setting)112 try_bad_setting(setting_type['type'], bad, self.hypervisor.set_setting)
113 try_bad_setting(setting_type['type'], bad, self.vm.set_setting_default)113 try_bad_setting(setting_type['type'], bad, self.hypervisor.set_setting_default)
114114
115 def test_set_setting_raises_exception_on_invalid_setting(self):115 def test_set_setting_raises_exception_on_invalid_setting(self):
116 self.assertRaises(VMBuilderException, self.vm.set_setting_default, 'testsetting', 'newdefault')116 self.assertRaises(VMBuilderException, self.hypervisor.set_setting_default, 'testsetting', 'newdefault')
117117
118 def test_add_setting(self):118 def test_add_setting(self):
119 setting_group = self.plugin.setting_group('Test Setting Group')119 setting_group = self.plugin.setting_group('Test Setting Group')
120120
=== modified file 'VMBuilder/util.py'
--- VMBuilder/util.py 2010-06-10 17:20:58 +0000
+++ VMBuilder/util.py 2012-09-04 13:48:23 +0000
@@ -81,7 +81,7 @@
81 env = kwargs.get('env', {})81 env = kwargs.get('env', {})
82 stdin = kwargs.get('stdin', None)82 stdin = kwargs.get('stdin', None)
83 ignore_fail = kwargs.get('ignore_fail', False)83 ignore_fail = kwargs.get('ignore_fail', False)
84 args = [str(arg) for arg in argv]84 args = [str(arg) for arg in argv if not arg is None]
85 logging.debug(args.__repr__())85 logging.debug(args.__repr__())
86 if stdin:86 if stdin:
87 logging.debug('stdin was set and it was a string: %s' % (stdin,))87 logging.debug('stdin was set and it was a string: %s' % (stdin,))
8888
=== modified file 'VMBuilder/vm.py'
--- VMBuilder/vm.py 2010-05-11 10:14:14 +0000
+++ VMBuilder/vm.py 2012-09-04 13:48:23 +0000
@@ -49,7 +49,7 @@
4949
50 """50 """
51 def __init__(self, conf=None):51 def __init__(self, conf=None):
52 self.hypervisor = None #: hypervisor object, representing the hypervisor the vm is destined for52 self.hypervisor = None #: hypervisor object, representing the hypervisor the hypervisor is destined for
53 self.distro = None53 self.distro = None
5454
55 self.disks = []55 self.disks = []
@@ -70,7 +70,7 @@
7070
71 self.fsmounted = False71 self.fsmounted = False
7272
73 self.optparser = _MyOptParser(epilog="ubuntu-vm-builder is Copyright (C) 2007-2009 Canonical Ltd. and written by Soren Hansen <soren@linux2go.dk>.", usage='%prog hypervisor distro [options]')73 self.optparser = _MyOptParser(epilog="ubuntu-hypervisor-builder is Copyright (C) 2007-2009 Canonical Ltd. and written by Soren Hansen <soren@linux2go.dk>.", usage='%prog hypervisor distro [options]')
74 self.optparser.arg_help = (('hypervisor', self.hypervisor_help), ('distro', self.distro_help))74 self.optparser.arg_help = (('hypervisor', self.hypervisor_help), ('distro', self.distro_help))
7575
76 self.confparser = ConfigParser.SafeConfigParser()76 self.confparser = ConfigParser.SafeConfigParser()

Subscribers

People subscribed via source and target branches