mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 04:11:25 -07:00
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:
parent
8e2dcaf9f6
commit
fbf68b5725
3 changed files with 38 additions and 30 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue