Open zch-bit opened 8 years ago
In order to get a ChildSnapshot, I suggest you try something like:
def list_snapshot(vm, vm_name):
import collections
try:
snapshots = vm.snapshot.rootSnapshotList
except AttributeError as e:
mylogger.error("No snapshots found for {0}".format(vm_name))
sys.exit(1)
d = collections.deque(snapshots)
all_snapshots = []
while d:
snapshot = d.pop()
all_snapshots.append(snapshot)
d.extend(reversed(snapshot.childSnapshotList))
return all_snapshots
Now you can every child too, for example:
all_snapshots = list_snapshot(vm, args.vm_name)
for snapshot in all_snapshots:
print snapshot.name, snapshot.createTime
Or better, in order to get first child first, last child last, use snapshot.childSnapshotList[::-1]
in the example of create_and_remove_snapshot, the code for removing the snapshot does not work, for the code should go deep into the ChildShnapshotTree to see if the name equals the ChildSnapshot.