The client.vcenter.vm.guest.Identity.get
just does not have such option (VM's parent folder name).
I have considered a fallback to pyVmomi, but it is pretty slow in general.
The client.vcenter.vm.guest.Identity.get
just does not have such option (VM's parent folder name).
I have considered a fallback to pyVmomi, but it is pretty slow in general.
To retrieve the parent folder of a virtual machine using the vSphere Automation SDK for Python, you can utilize the vSphere REST API. The vSphere Automation SDK for Python is based on the vSphere REST API and provides a convenient way to interact with vSphere using Python. Exp:
from com.vmware.vcenter_client import VM
# Assuming you have already authenticated and created the vcenter_client
# Get the VM object
vm_obj = VM.get(vcenter_client, vm_id)
# Get the VM's parent folder
folder_id = vm_obj.folder
folder_obj = vcenter_client.vcenter.Folder.get(folder_id)
parent_folder_name = folder_obj.name
print("Parent Folder Name:", parent_folder_name)
Make sure you have installed the vsphere-automation-sdk Python package. You can install it using pip:
pip install --upgrade --index-url=https://<vsphere-sdk-repo>/pip/v1/psc-3.0/sdk/ vsphere-automation-sdk-python
Replace with the URL of your vSphere Automation SDK repository.
API documentation for more details: VMware vSphere Automation API - VM Operations.