Walk the snapshot chain when looking for disk paths
This commit is contained in:
+5
-1
@@ -126,7 +126,11 @@ A disk-scoped **read** ticket also works and returns the same
|
|||||||
|
|
||||||
`diskDeviceKey` is `VirtualDisk.key` from `vm.config.hardware.device`
|
`diskDeviceKey` is `VirtualDisk.key` from `vm.config.hardware.device`
|
||||||
(2000 for Hard disk 1). The replacement resolves it from the datastore
|
(2000 for Hard disk 1). The replacement resolves it from the datastore
|
||||||
path when `open` is given a VMDK rather than a key.
|
path when `open` is given a VMDK rather than a key. That path may be
|
||||||
|
the current leaf or a parent in `backing.parent` (snapshot deltas such
|
||||||
|
as `…-000007.vmdk` after the VM has moved on to `…-000008.vmdk`). The
|
||||||
|
ticket still uses the device key; `OPEN_FILE` then names the snapshot
|
||||||
|
file.
|
||||||
|
|
||||||
### Return value: `vim.HostServiceTicket`
|
### Return value: `vim.HostServiceTicket`
|
||||||
|
|
||||||
|
|||||||
@@ -128,13 +128,22 @@ def connect_vim(
|
|||||||
|
|
||||||
|
|
||||||
def _virtual_disk_key(vm: vim.VirtualMachine, disk_path: str) -> int:
|
def _virtual_disk_key(vm: vim.VirtualMachine, disk_path: str) -> int:
|
||||||
"""Return the VirtualDisk device key whose backing path is ``disk_path``."""
|
"""Return the VirtualDisk device key for ``disk_path``.
|
||||||
|
|
||||||
|
``disk_path`` may be the currently attached leaf or any parent in
|
||||||
|
that disk's snapshot delta chain (``backing.parent``). After a
|
||||||
|
snapshot, the VM's hardware points at the new leaf (for example
|
||||||
|
``…-000008.vmdk``) while VDDK Open still uses the snapshot file
|
||||||
|
(``…-000007.vmdk``). Both share the same ``VirtualDisk.key``.
|
||||||
|
"""
|
||||||
for device in vm.config.hardware.device:
|
for device in vm.config.hardware.device:
|
||||||
if isinstance(device, vim.vm.device.VirtualDisk):
|
if not isinstance(device, vim.vm.device.VirtualDisk):
|
||||||
|
continue
|
||||||
backing = getattr(device, "backing", None)
|
backing = getattr(device, "backing", None)
|
||||||
file_name = getattr(backing, "fileName", None)
|
while backing is not None:
|
||||||
if file_name == disk_path:
|
if getattr(backing, "fileName", None) == disk_path:
|
||||||
return device.key
|
return device.key
|
||||||
|
backing = getattr(backing, "parent", None)
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"VMDK path {disk_path!r} is not attached to {vm._moId}")
|
f"VMDK path {disk_path!r} is not attached to {vm._moId}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user