|
|
|
@ -24,6 +24,7 @@ version_added: '2.5'
|
|
|
|
|
author:
|
|
|
|
|
- Abhijeet Kasurde (@Akasurde)
|
|
|
|
|
- Christian Kotte (@ckotte) <christian.kotte@gmx.de>
|
|
|
|
|
- Jan Meerkamp (@meerkampdvv)
|
|
|
|
|
notes:
|
|
|
|
|
- Tested on vSphere 6.5
|
|
|
|
|
requirements:
|
|
|
|
@ -47,7 +48,6 @@ options:
|
|
|
|
|
description:
|
|
|
|
|
- Name of the parent folder under which new folder needs to be created.
|
|
|
|
|
- This is case sensitive parameter.
|
|
|
|
|
- Please specify unique folder name as there is no way to detect duplicate names.
|
|
|
|
|
- "If user wants to create a folder under '/DC0/vm/vm_folder', this value will be 'vm_folder'."
|
|
|
|
|
- "If user wants to create a folder under '/DC0/vm/folder1/folder2', this value will be 'folder1/folder2'."
|
|
|
|
|
required: False
|
|
|
|
@ -191,7 +191,14 @@ class VmwareFolderManager(PyVmomi):
|
|
|
|
|
if not part_folder_obj:
|
|
|
|
|
self.module.fail_json(msg="Could not find folder %s" % part)
|
|
|
|
|
p_folder_obj = part_folder_obj
|
|
|
|
|
|
|
|
|
|
child_folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
|
|
|
|
folder_name=folder_name,
|
|
|
|
|
folder_type=folder_type,
|
|
|
|
|
parent_folder=p_folder_obj)
|
|
|
|
|
if child_folder_obj:
|
|
|
|
|
results['result'] = "Folder %s already exists under" \
|
|
|
|
|
" parent folder %s" % (folder_name, parent_folder)
|
|
|
|
|
self.module.exit_json(**results)
|
|
|
|
|
else:
|
|
|
|
|
p_folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
|
|
|
|
folder_name=parent_folder,
|
|
|
|
@ -259,18 +266,34 @@ class VmwareFolderManager(PyVmomi):
|
|
|
|
|
# Check if the folder already exists
|
|
|
|
|
p_folder_obj = None
|
|
|
|
|
if parent_folder:
|
|
|
|
|
p_folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
|
|
|
|
folder_name=parent_folder,
|
|
|
|
|
folder_type=folder_type)
|
|
|
|
|
if "/" in parent_folder:
|
|
|
|
|
parent_folder_parts = parent_folder.strip('/').split('/')
|
|
|
|
|
p_folder_obj = None
|
|
|
|
|
for part in parent_folder_parts:
|
|
|
|
|
part_folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
|
|
|
|
folder_name=part,
|
|
|
|
|
folder_type=folder_type,
|
|
|
|
|
parent_folder=p_folder_obj)
|
|
|
|
|
if not part_folder_obj:
|
|
|
|
|
self.module.fail_json(msg="Could not find folder %s" % part)
|
|
|
|
|
p_folder_obj = part_folder_obj
|
|
|
|
|
folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
|
|
|
|
folder_name=folder_name,
|
|
|
|
|
folder_type=folder_type,
|
|
|
|
|
parent_folder=p_folder_obj)
|
|
|
|
|
else:
|
|
|
|
|
p_folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
|
|
|
|
folder_name=parent_folder,
|
|
|
|
|
folder_type=folder_type)
|
|
|
|
|
|
|
|
|
|
if not p_folder_obj:
|
|
|
|
|
self.module.fail_json(msg="Parent folder %s does not exist" % parent_folder)
|
|
|
|
|
if not p_folder_obj:
|
|
|
|
|
self.module.fail_json(msg="Parent folder %s does not exist" % parent_folder)
|
|
|
|
|
|
|
|
|
|
# Check if folder exists under parent folder
|
|
|
|
|
folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
|
|
|
|
folder_name=folder_name,
|
|
|
|
|
folder_type=folder_type,
|
|
|
|
|
parent_folder=p_folder_obj)
|
|
|
|
|
# Check if folder exists under parent folder
|
|
|
|
|
folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
|
|
|
|
folder_name=folder_name,
|
|
|
|
|
folder_type=folder_type,
|
|
|
|
|
parent_folder=p_folder_obj)
|
|
|
|
|
else:
|
|
|
|
|
folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
|
|
|
|
folder_name=folder_name,
|
|
|
|
|