def test_is_resize_required(self): self.assertFalse(vhdutils.is_resize_required( mock.sentinel.disk, 1024, 1024, self._instance)) self.assertTrue(vhdutils.is_resize_required( mock.sentinel.disk, 1024, 2048, self._instance)) self.assertRaises(nova_exception.CannotResizeDisk, vhdutils.is_resize_required, mock.sentinel.disk, 2048, 1024, self._instance)
def test_is_resize_required(self): self.assertFalse( vhdutils.is_resize_required(mock.sentinel.disk, 1024, 1024, self._instance)) self.assertTrue( vhdutils.is_resize_required(mock.sentinel.disk, 1024, 2048, self._instance)) self.assertRaises(nova_exception.CannotResizeDisk, vhdutils.is_resize_required, mock.sentinel.disk, 2048, 1024, self._instance)
def _resize_disk(self, instance, new_size, disk_file): if not new_size: return disk_info = vhdutils.disk_info(disk_file) current_size = disk_info[constants.VHD_CAPACITY] / units.Mi if vhdutils.is_resize_required(disk_file, current_size, new_size, instance): self._vbox_manage.modify_hd( disk_file, constants.FIELD_HD_RESIZE_MB, new_size)
def _resize_disk(self, instance, new_size, disk_file): if not new_size: return disk_info = vhdutils.disk_info(disk_file) current_size = disk_info[constants.VHD_CAPACITY] / units.Mi if vhdutils.is_resize_required(disk_file, current_size, new_size, instance): self._vbox_manage.modify_hd(disk_file, constants.FIELD_HD_RESIZE_MB, new_size)
def create_root_disk(self, context, instance): base_vhd_path = imagecache.get_cached_image(context, instance) base_info = vhdutils.disk_info(base_vhd_path) root_vhd_path = pathutils.root_disk_path( instance, disk_format=base_info[constants.VHD_IMAGE_TYPE]) if CONF.use_cow_images: LOG.debug( "Creating differencing VHD. Parent: %(parent)s, " "Target: %(target)s", { 'parent': base_vhd_path, 'target': root_vhd_path }, instance=instance) self._vbox_manage.create_hd( filename=root_vhd_path, # disk_format=base_info[constants.VHD_IMAGE_TYPE], variant=constants.VARIANT_STANDARD, parent=base_vhd_path) else: LOG.debug( "Cloning VHD image %(base)s to target: %(target)s", { 'base': base_vhd_path, 'target': root_vhd_path }, instance=instance) self._vbox_manage.clone_hd( vhd_path=base_vhd_path, new_vdh_path=root_vhd_path, disk_format=base_info[constants.VHD_IMAGE_TYPE], variant=constants.VARIANT_STANDARD) # Resize image if is necesary disk_format = vhdutils.get_image_type(root_vhd_path) if instance.root_gb and disk_format in (constants.DISK_FORMAT_VDI, constants.DISK_FORMAT_VHD): base_vhd_size = base_info[constants.VHD_CAPACITY] / units.Mi root_vhd_size = instance.root_gb * units.Ki if vhdutils.is_resize_required( disk_path=root_vhd_path, old_size=base_vhd_size, new_size=root_vhd_size, instance=instance): self._vbox_manage.modify_hd( root_vhd_path, constants.FIELD_HD_RESIZE_MB, root_vhd_size) return root_vhd_path
def create_root_disk(self, context, instance): base_vhd_path = imagecache.get_cached_image(context, instance) base_info = vhdutils.disk_info(base_vhd_path) root_vhd_path = pathutils.root_disk_path( instance, disk_format=base_info[constants.VHD_IMAGE_TYPE]) if CONF.use_cow_images: LOG.debug( "Creating differencing VHD. Parent: %(parent)s, " "Target: %(target)s", { 'parent': base_vhd_path, 'target': root_vhd_path }, instance=instance) self._vbox_manage.create_hd( filename=root_vhd_path, # disk_format=base_info[constants.VHD_IMAGE_TYPE], variant=constants.VARIANT_STANDARD, parent=base_vhd_path) else: LOG.debug("Cloning VHD image %(base)s to target: %(target)s", { 'base': base_vhd_path, 'target': root_vhd_path }, instance=instance) self._vbox_manage.clone_hd( vhd_path=base_vhd_path, new_vdh_path=root_vhd_path, disk_format=base_info[constants.VHD_IMAGE_TYPE], variant=constants.VARIANT_STANDARD) # Resize image if is necesary disk_format = vhdutils.get_image_type(root_vhd_path) if instance.root_gb and disk_format in (constants.DISK_FORMAT_VDI, constants.DISK_FORMAT_VHD): base_vhd_size = base_info[constants.VHD_CAPACITY] / units.Mi root_vhd_size = instance.root_gb * units.Ki if vhdutils.is_resize_required(disk_path=root_vhd_path, old_size=base_vhd_size, new_size=root_vhd_size, instance=instance): self._vbox_manage.modify_hd(root_vhd_path, constants.FIELD_HD_RESIZE_MB, root_vhd_size) return root_vhd_path