Closed cattywampus closed 4 years ago
Interesting, I hit, and solved the issue (in a slightly different way). I like your approach, although I haven't tested yours yet. I think it would be good to update the readme.md
in your PR to show using with /
to make it clear how it works.
Thanks for the feedback @Belogix. I updated the README to include some detail about using the path separator to join nested folders together.
Description
When specifying a folder to store the kitchen created VM, the current
folder
attribute only supports using a single (individual) folder name and fails to find any folder if a user specifies a more common nested notation such asParentFolder/ChildFolder
. In this case a valid workaround might be to set the value of thefolder
attribute in the kitchen configuration to beChildFolder
but that only works if this folder object's name is unique in VCenter. An example where this would fail is iffolder
was set toKitchen
and in VCenter there were two different folder structures that looked like:FolderA/Kitchen
FolderB/Kitchen
In this case the
get_folder
method would raise the "too many folders" error because filtering onKitchen
would return both of these matches.The VSphere Automation
FolderApi#list
method supports additional filter criteria to match folders by their immediate parent. By splitting up the path notation we can addFolderA
to the filter and ensure we get the exact match. The:filter_parent_folders
parameter used for this expects the folder indentifier value which is in the format ofgroup-v12345
. This requires an additional API call to get thatVCenterFolderSummary
object for the parent and retrieve it's folder identifier. Since it's possible for folders to be deeply nested (greater than 2 levels) and for those deep levels to be non-unqiue with other deeply nested paths I'm re-using theget_folder
method recursively to travel up the full path to ensure the match is accurate.I ran into an additional use case where I had duplicate folder hierarchies across datacenters too (within the same VCenter). Thankfully the
FolderApi#list
method provides a:filter_datacenter
property as well. This filter relies on the datacenter specified in the kitchen configuration which means I am making an assumption that the datacenter where the kitchen is created is the same datacenter where the folder exists which I think is a reasonable expectation.I tested this in VCenter 7.0 using different levels of nested folders: 1 folder, 2 folders, and 3 folders
Signed-off-by: Keith Walters kwalters@taphere.com
Related Issue
This should resolve Issue #93
Types of changes
Checklist: