diff options
Diffstat (limited to 'nova/virt')
-rw-r--r-- | nova/virt/vmwareapi/ds_util.py | 19 | ||||
-rw-r--r-- | nova/virt/vmwareapi/vmops.py | 17 |
2 files changed, 36 insertions, 0 deletions
diff --git a/nova/virt/vmwareapi/ds_util.py b/nova/virt/vmwareapi/ds_util.py index d447715594..a7011d0c5d 100644 --- a/nova/virt/vmwareapi/ds_util.py +++ b/nova/virt/vmwareapi/ds_util.py @@ -364,6 +364,11 @@ def search_datastore_spec(client_factory, file_name): """Builds the datastore search spec.""" search_spec = client_factory.create('ns0:HostDatastoreBrowserSearchSpec') search_spec.matchPattern = [file_name] + search_spec.details = client_factory.create('ns0:FileQueryFlags') + search_spec.details.fileOwner = False + search_spec.details.fileSize = True + search_spec.details.fileType = False + search_spec.details.modification = False return search_spec @@ -386,6 +391,20 @@ def file_exists(session, ds_browser, ds_path, file_name): return file_exists +def file_size(session, ds_browser, ds_path, file_name): + """Returns the size of the specified file.""" + client_factory = session.vim.client.factory + search_spec = search_datastore_spec(client_factory, file_name) + search_task = session._call_method(session.vim, + "SearchDatastore_Task", + ds_browser, + datastorePath=str(ds_path), + searchSpec=search_spec) + task_info = session._wait_for_task(search_task) + if hasattr(task_info.result, 'file'): + return task_info.result.file[0].fileSize + + def mkdir(session, ds_path, dc_ref): """Creates a directory at the path specified. If it is just "NAME", then a directory with this name is created at the topmost level of the diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index 32de30e77d..e796c3e772 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -419,6 +419,9 @@ class VMwareVMOps(object): self._move_to_cache(vi.dc_info.ref, tmp_image_ds_loc.parent, vi.cache_image_folder) + # The size of the image is different from the size of the virtual + # disk. We want to use the latter. + self._update_image_size(vi) def _cache_flat_image(self, vi, tmp_image_ds_loc): self._move_to_cache(vi.dc_info.ref, @@ -552,6 +555,20 @@ class VMwareVMOps(object): dc_info, size, adapter_type, path) + def _update_image_size(self, vi): + """Updates the file size of the specified image.""" + # The size of the Glance image is different from the deployed VMDK + # size for sparse, streamOptimized and OVA images. We need to retrieve + # the size of the flat VMDK and update the file_size property of the + # image. This ensures that further operations involving size checks + # and disk resizing will work as expected. + ds_browser = self._get_ds_browser(vi.datastore.ref) + flat_file = "%s-flat.vmdk" % vi.ii.image_id + new_size = ds_util.file_size(self._session, ds_browser, + vi.cache_image_folder, flat_file) + if new_size is not None: + vi.ii.file_size = new_size + def spawn(self, context, instance, image_meta, injected_files, admin_password, network_info, block_device_info=None, power_on=True): |