pyvmomi-community-samples
pyvmomi-community-samples copied to clipboard
New Sample: Get snapshot's creator name
Is your feature request related to a problem? Please describe.
Hi, It looks like vSphere doesn't inherently store the information about who created a specific snapshot. This information is typically not directly available in the vSphere API.
This code snippet gives attributes and methods of the snapshot:
cluster_name_prefix = "my-cluster"
content = service_instance.RetrieveContent()
vm_list = []
for datacenter in content.rootFolder.childEntity:
for cluster in datacenter.hostFolder.childEntity:
if cluster.name.startswith(cluster_name_prefix):
for host in cluster.host:
for vm in host.vm:
vm_list.append(vm)
for vm in vm_list:
if vm.name == "my-vm":
snapshot = vm.snapshot.rootSnapshotList[0]
print(f"Attributes and Methods of the Snapshot for VM my-vm:")
print(dir(snapshot))
Disconnect(service_instance)
here is the output:
Attributes and Methods of the Snapshot for VM my-vm:
['Array', '_GetPropertyInfo', '_GetPropertyList', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_propInfo', '_propList', '_version', '_wsdlName', 'backupManifest', 'childSnapshotList', 'createTime', 'description', 'dynamicProperty', 'dynamicType', 'id', 'name', 'quiesced', 'replaySupported', 'snapshot', 'state', 'vm']
I can easily get snapshot id, name, state, createtime, description but not creator name.
Does anybody know any way to achieve it?