Revision dbf466eb image_creator/disk.py

b/image_creator/disk.py
168 168
        self.bootable = bootable
169 169
        self.progress_bar = None
170 170
        self.guestfs_device = None
171
        self.size = 0
171 172
        self.meta = {}
172 173

  
173 174
        self.g = guestfs.GuestFS()
......
213 214
                             "We only support images with one OS.")
214 215
        self.root = roots[0]
215 216
        self.guestfs_device = self.g.part_to_dev(self.root)
216
        self.meta['SIZE'] = self.g.blockdev_getsize64(self.guestfs_device)
217
        self.size = self.g.blockdev_getsize64(self.guestfs_device)
217 218
        self.meta['PARTITION_TABLE'] = \
218 219
            self.g.part_get_parttype(self.guestfs_device)
219 220

  
......
343 344
            # Most disk manipulation programs leave 2048 sectors after the last
344 345
            # partition
345 346
            new_size = last_part['part_end'] + 1 + 2048 * sector_size
346
            self.meta['SIZE'] = min(self.meta['SIZE'], new_size)
347
            self.size = min(self.size, new_size)
347 348
            break
348 349

  
349 350
        if not re.match("ext[234]", fstype):
350 351
            self.out.warn("Don't know how to resize %s partitions." % fstype)
351
            return self.meta['SIZE']
352
            return self.size
352 353

  
353 354
        part_dev = "%s%d" % (self.guestfs_device, last_part['part_num'])
354 355
        self.g.e2fsck_f(part_dev)
......
405 406

  
406 407
        new_size = (end + 1) * sector_size
407 408

  
408
        assert (new_size <= self.meta['SIZE'])
409
        assert (new_size <= self.size)
409 410

  
410 411
        if self.meta['PARTITION_TABLE'] == 'gpt':
411 412
            ptable = GPTPartitionTable(self.real_device)
412
            self.meta['SIZE'] = ptable.shrink(new_size, self.meta['SIZE'])
413
            self.size = ptable.shrink(new_size, self.size)
413 414
        else:
414
            self.meta['SIZE'] = min(new_size + 2048 * sector_size,
415
                                    self.meta['SIZE'])
415
            self.size = min(new_size + 2048 * sector_size, self.size)
416 416

  
417
        self.out.success("new size is %dMB" %
418
                         ((self.meta['SIZE'] + MB - 1) // MB))
417
        self.out.success("new size is %dMB" % ((self.size + MB - 1) // MB))
419 418

  
420
        return self.meta['SIZE']
419
        return self.size
421 420

  
422 421
    def dump(self, outfile):
423 422
        """Dumps the content of device into a file.
......
427 426
        """
428 427
        MB = 2 ** 20
429 428
        blocksize = 4 * MB  # 4MB
430
        size = self.meta['SIZE']
429
        size = self.size
431 430
        progr_size = (size + MB - 1) // MB  # in MB
432 431
        progressbar = self.out.Progress(progr_size, "Dumping image file", 'mb')
433 432

  

Also available in: Unified diff