def copy_image_to_volume(self, context, volume, image_service, image_id): """Fetch the image from image_service and create a volume using it.""" # Convert to VHD and file back to VHD vhd_type = self.utils.get_supported_vhd_type() with image_utils.temporary_file(suffix=".vhd") as tmp: volume_path = self.local_path(volume) image_utils.fetch_to_vhd(context, image_service, image_id, tmp, self.configuration.volume_dd_blocksize) # The vhd must be disabled and deleted before being replaced with # the desired image. self.utils.change_disk_status(volume["name"], False) os.unlink(volume_path) self.vhdutils.convert_vhd(tmp, volume_path, vhd_type) self.vhdutils.resize_vhd(volume_path, volume["size"] << 30) self.utils.change_disk_status(volume["name"], True)
def copy_image_to_volume(self, context, volume, image_service, image_id): """Fetch the image from image_service and create a volume using it.""" # Convert to VHD and file back to VHD vhd_type = self.utils.get_supported_vhd_type() with image_utils.temporary_file(suffix='.vhd') as tmp: volume_path = self.local_path(volume) image_utils.fetch_to_vhd(context, image_service, image_id, tmp, self.configuration.volume_dd_blocksize) # The vhd must be disabled and deleted before being replaced with # the desired image. self.utils.change_disk_status(volume['name'], False) os.unlink(volume_path) self.vhdutils.convert_vhd(tmp, volume_path, vhd_type) self.vhdutils.resize_vhd(volume_path, volume['size'] << 30) self.utils.change_disk_status(volume['name'], True)
def test_copy_image_to_volume(self): """resize_image common case usage.""" drv = self._driver volume = db_fakes.get_fake_volume_info() self.stubs.Set(drv, 'local_path', self.fake_local_path) self.mox.StubOutWithMock(image_utils, 'fetch_to_vhd') image_utils.fetch_to_vhd(None, None, None, self.fake_local_path(volume), mox.IgnoreArg()) self.mox.ReplayAll() drv.copy_image_to_volume(None, volume, None, None)
def test_copy_image_to_volume(self): """resize_image common case usage.""" drv = self._driver volume = db_fakes.get_fake_volume_info() fake_get_supported_type = lambda x: constants.VHD_TYPE_FIXED self.stubs.Set(drv, 'local_path', self.fake_local_path) self.stubs.Set(windows_utils.WindowsUtils, 'get_supported_vhd_type', fake_get_supported_type) self.mox.StubOutWithMock(os, 'makedirs') self.mox.StubOutWithMock(os, 'unlink') self.mox.StubOutWithMock(image_utils, 'create_temporary_file') self.mox.StubOutWithMock(image_utils, 'fetch_to_vhd') self.mox.StubOutWithMock(vhdutils.VHDUtils, 'convert_vhd') self.mox.StubOutWithMock(vhdutils.VHDUtils, 'resize_vhd') self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'change_disk_status') fake_temp_path = r'C:\fake\temp\file' if (CONF.image_conversion_dir and not os.path.exists(CONF.image_conversion_dir)): os.makedirs(CONF.image_conversion_dir) image_utils.create_temporary_file(suffix='.vhd').AndReturn( fake_temp_path) fake_volume_path = self.fake_local_path(volume) image_utils.fetch_to_vhd(None, None, None, fake_temp_path, mox.IgnoreArg()) windows_utils.WindowsUtils.change_disk_status(volume['name'], mox.IsA(bool)) os.unlink(mox.IsA(str)) vhdutils.VHDUtils.convert_vhd(fake_temp_path, fake_volume_path, constants.VHD_TYPE_FIXED) vhdutils.VHDUtils.resize_vhd(fake_volume_path, volume['size'] << 30) windows_utils.WindowsUtils.change_disk_status(volume['name'], mox.IsA(bool)) os.unlink(mox.IsA(str)) self.mox.ReplayAll() drv.copy_image_to_volume(None, volume, None, None)
def copy_image_to_volume(self, context, volume, image_service, image_id): """Fetch the image from image_service and create a volume using it.""" # Convert to VHD and file back to VHD if (CONF.image_conversion_dir and not os.path.exists(CONF.image_conversion_dir)): os.makedirs(CONF.image_conversion_dir) with image_utils.temporary_file(suffix='.vhd') as tmp: volume_path = self.local_path(volume) image_utils.fetch_to_vhd(context, image_service, image_id, tmp, self.configuration.volume_dd_blocksize) # The vhd must be disabled and deleted before being replaced with # the desired image. self.utils.change_disk_status(volume['name'], False) os.unlink(volume_path) self.utils.convert_vhd(tmp, volume_path, constants.VHD_TYPE_FIXED) self.utils.resize_vhd(volume_path, volume['size'] << 30) self.utils.change_disk_status(volume['name'], True)
def copy_image_to_volume(self, context, volume, image_service, image_id): """Fetch the image from image_service and write it to the volume.""" # Convert to VHD and file back to VHD image_utils.fetch_to_vhd(context, image_service, image_id, self.local_path(volume), self.configuration.volume_dd_blocksize)
def copy_image_to_volume(self, context, volume, image_service, image_id): """Fetch the image from image_service and write it to the volume.""" # Convert to VHD and file back to VHD image_utils.fetch_to_vhd(context, image_service, image_id, self.local_path(volume))