Skip to content

Commit eb59751

Browse files
authored
list_disk_snapshots.py: look for template snapshots in the chain (#14)
When a VM is created from template with Thin Storage Allocation, the parent of one of the snapshots will be the template image, thus not returned in the result set for the list disksnapshots request. In this case, when requesting snapshots of a disk created this way - this script returns an error. This patch takes advantage of the disks/xxx/disksnapshots API with 'include_active' and 'include_template' flags to fetch all the snapshots required for the chain reconstruction Bug-Url: https://bugzilla.redhat.com/1900597
1 parent 72edb70 commit eb59751

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

examples/list_disk_snapshots.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,13 @@ def parse_args():
4545
# Find the disk.
4646
disks_service = connection.system_service().disks_service()
4747
disk_service = disks_service.disk_service(args.disk_id)
48-
49-
try:
50-
disk = disk_service.get()
51-
except sdk.NotFoundError:
52-
raise RuntimeError("No such disk: {}".format(args.disk_id)) from None
53-
54-
# Find the storage domain service.
55-
sd_id = disk.storage_domains[0].id
56-
sds_service = connection.system_service().storage_domains_service()
57-
sd_service = sds_service.storage_domain_service(sd_id)
58-
59-
# Find the disk snapshots using the disk snapshots service.
60-
# TODO: Use disk's snapshots service to get filter the snapshot on the
61-
# server side.
62-
disk_snapshots_service = sd_service.disk_snapshots_service()
48+
disk_snapshots_service = disk_service.disk_snapshots_service()
6349

6450
# Create mapping from snapshot parent to snapshot, used to reconstruct the
6551
# snapshot chain.
6652
snapshots = {}
67-
for s in disk_snapshots_service.list(include_active=True):
68-
if s.disk.id != disk.id:
69-
continue
53+
54+
for s in disk_snapshots_service.list(include_active=True, include_template=True):
7055
parent = s.parent.id if s.parent else None
7156
child = {
7257
"actual_size": s.actual_size,

0 commit comments

Comments
 (0)