chef / kitchen-vcenter

A test-kitchen driver for vCenter REST API
https://www.chef.io/implementations/vmware
Apache License 2.0
25 stars 26 forks source link

Allow folder to support nested paths #108

Closed cattywampus closed 4 years ago

cattywampus commented 4 years ago

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 as ParentFolder/ChildFolder. In this case a valid workaround might be to set the value of the folder attribute in the kitchen configuration to be ChildFolder but that only works if this folder object's name is unique in VCenter. An example where this would fail is if folder was set to Kitchen and in VCenter there were two different folder structures that looked like:

In this case the get_folder method would raise the "too many folders" error because filtering on Kitchen 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 add FolderA 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 of group-v12345. This requires an additional API call to get that VCenterFolderSummary 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 the get_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:

Belogix commented 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.

cattywampus commented 4 years ago

Thanks for the feedback @Belogix. I updated the README to include some detail about using the path separator to join nested folders together.