vmware_guest relative paths for folder (#26927)

* Re-introduce relative paths to vmware_guest folder:

Move compile_folder_path_for_object function from vmware_guest_find to
utilities
Allow full path or relative path to be specified for the folder
parameter.  We will build the full path to the new VM.

* Remove duplicate check

* PEP8 Fixes
This commit is contained in:
Jimmy Conner 2017-07-17 21:18:20 -05:00 committed by jctanner
parent 8e2dcaf9f6
commit fbf68b5725
3 changed files with 38 additions and 30 deletions

View file

@ -213,6 +213,24 @@ def find_host_portgroup_by_name(host, portgroup_name):
return None
def compile_folder_path_for_object(vobj):
""" make a /vm/foo/bar/baz like folder path for an object """
paths = []
if isinstance(vobj, vim.Folder):
paths.append(vobj.name)
thisobj = vobj
while hasattr(thisobj, 'parent'):
thisobj = thisobj.parent
if isinstance(thisobj, vim.Folder):
paths.append(thisobj.name)
paths.reverse()
if paths[0] == 'Datacenters':
paths.remove('Datacenters')
return '/' + '/'.join(paths)
def _get_vm_prop(vm, attributes):
"""Safely get a property or return None"""
result = vm