Example #1
0
 def _assert_image_not_larger(self, base, size):
     """
     Asserts that given base image isn't larger than resulting image
     :param base: base image's path
     :param size: target size in bytes, can be None
     """
     # do not perform assertion if size wasn't given
     if not size:
         return
     base_image_size = images.virtual_size(base)
     LOG.debug(_("image_size_bytes=%(base_image_size)d, "
                 "allowed_size_bytes=%(size)d") % locals())
     if base_image_size > size:
         LOG.info(_("Image size %(base_image_size)d exceeded instance_type "
                    "allowed size %(size)d") % locals())
         raise exception.ImageTooLarge()
Example #2
0
    def create_from_raw(self, base, size=None):
        """
            Creating volume from raw image.
        """
        self._assert_image_not_larger(base, size)
        if not size:
            size = images.virtual_size(base)
        target = self.path()

        self.create_clean(size)

        LOG.info(_("disk %s converting to lvm volume %s"), (base, self.lv))
        utils.execute('qemu-img', 'convert', base, '-O',
                      'raw', target, run_as_root=True)
        utils.execute('e2fsck', '-fp', target,
                      run_as_root=True, check_exit_code=False)
        utils.execute('resize2fs', target,
                      run_as_root=True, check_exit_code=False)
Example #3
0
 def resize(self, size):
     if images.virtual_size(self.path())  != size:
         utils.execute('lvresize', '-f','-L', '%db' % size, self.path(), run_as_root=True)
Example #4
0
 def make_snapshot(self, virt_domain, snapshot_name, force_live_snapshot):
     size = images.virtual_size(self._path)
     return LvmSnapshot(virt_domain, self.vg,
                        snapshot_name, size,
                        self.path(), force_live_snapshot)