Share
Go down
avatar
Admin
Posts : 155
Join date : 2017-11-11
Age : 27
View user profilehttp://net-media.yoo7.com

Pyvmomi - Assign VM to specific folder with non-unique name

on Thu Dec 14, 2017 10:58 am
I'm trying to figure out how to assign a VM to a folder that does not contain a unique name. I'm currently testing with the clone_vm.py template. With the sample, I have the ability to set the folder, but it does not work correctly if there's nested folders with the same name (example below). I would like to make sure the folder assigned is the "Linux/Dev" folder, but I can only pass "Dev" and hope that it picks the right one. The line of code below is how the folder is being set.
Code:
destfolder = get_obj(content, [vim.Folder], vm_folder)
Linux
Code:
 |------Dev

    |------Prod
Windows
Code:
 |------Dev

    |------Prod

Answer

The best way to do that is to use a search_index.FindByInventoryPath and get the folder by the path. It can be a little confusing because of hidden folders but the MOB can help you. I answered a question where I covered how to use that search method see this answer.
Back to top
Permissions in this forum:
You can reply to topics in this forum