VMware: vcenter_folder checks nested parent folder path (#62741)
added possibility to create Subfolder by defining full path below datacenter Closes: #64442
This commit is contained in:
parent
d05d5cfc39
commit
315cc2f3ea
2 changed files with 43 additions and 15 deletions
|
@ -49,6 +49,7 @@ options:
|
|||
- 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
|
||||
type: str
|
||||
folder_type:
|
||||
|
@ -179,6 +180,19 @@ class VmwareFolderManager(PyVmomi):
|
|||
# Check if the folder already exists
|
||||
p_folder_obj = None
|
||||
if parent_folder:
|
||||
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
|
||||
|
||||
else:
|
||||
p_folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
||||
folder_name=parent_folder,
|
||||
folder_type=folder_type)
|
||||
|
@ -193,7 +207,7 @@ class VmwareFolderManager(PyVmomi):
|
|||
parent_folder=p_folder_obj)
|
||||
if child_folder_obj:
|
||||
results['result']['path'] = self.get_folder_path(child_folder_obj)
|
||||
results['result']['msg'] = "Folder %s already exists under" \
|
||||
results['result'] = "Folder %s already exists under" \
|
||||
" parent folder %s" % (folder_name, parent_folder)
|
||||
self.module.exit_json(**results)
|
||||
else:
|
||||
|
|
|
@ -113,6 +113,20 @@
|
|||
- datastore
|
||||
- network
|
||||
|
||||
- name: Create a 3rd level of directory
|
||||
vcenter_folder:
|
||||
hostname: "{{ vcenter_hostname }}"
|
||||
username: "{{ vcenter_username }}"
|
||||
password: "{{ vcenter_password }}"
|
||||
validate_certs: no
|
||||
datacenter: "{{ dc1 }}"
|
||||
folder_name: yet_another_level
|
||||
parent_folder: vm_folder/sub_vm_folder
|
||||
state: present
|
||||
register: yet_another_level
|
||||
- debug: var=yet_another_level
|
||||
|
||||
|
||||
- debug:
|
||||
msg: "{{ all_folder_results }}"
|
||||
|
||||
|
|
Loading…
Reference in a new issue