Struggling with grasping OOP and pyvmomi in general. Have a question about calling a specific folder by name - it seems that the object names can be folder or VM, and calling hasattr is the best way to differentiate the two?
Also, when I want to call the contents of a specific folder, I've been setting a variable with the name of the folder and looping through each object checking for a match, isn't there a better way, like calling specific object and folder name? I can't see to get it work. Here is what I have right now:
vmfolder = datacenter.vmFolder
vmfolderList = vmfolder.childEntity
folder = "FooFolder"
for i in vmfolderList:
try:
folderName = i.name
if folderName == folder:
vmfolder = i
print(f"Working in folder: {folderName}")
except:
pass
What I have right now doesn't feel very pythonic. I used to write code years ago but it was entirely procedureal and the whole object/attribute thing is a struggle - if anyone recommends a good tutorial or resource as well, it would be appreciated. I feel that once I get over that hurdle I should be able to pick up any SDK and run with it.