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.
|
- This is case sensitive parameter.
|
||||||
- Please specify unique folder name as there is no way to detect duplicate names.
|
- 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/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
|
required: False
|
||||||
type: str
|
type: str
|
||||||
folder_type:
|
folder_type:
|
||||||
|
@ -179,23 +180,36 @@ class VmwareFolderManager(PyVmomi):
|
||||||
# Check if the folder already exists
|
# Check if the folder already exists
|
||||||
p_folder_obj = None
|
p_folder_obj = None
|
||||||
if parent_folder:
|
if parent_folder:
|
||||||
p_folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
if "/" in parent_folder:
|
||||||
folder_name=parent_folder,
|
parent_folder_parts = parent_folder.strip('/').split('/')
|
||||||
folder_type=folder_type)
|
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
|
||||||
|
|
||||||
if not p_folder_obj:
|
else:
|
||||||
self.module.fail_json(msg="Parent folder %s does not exist" % parent_folder)
|
p_folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
||||||
|
folder_name=parent_folder,
|
||||||
|
folder_type=folder_type)
|
||||||
|
|
||||||
# Check if folder exists under parent folder
|
if not p_folder_obj:
|
||||||
child_folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
self.module.fail_json(msg="Parent folder %s does not exist" % parent_folder)
|
||||||
folder_name=folder_name,
|
|
||||||
folder_type=folder_type,
|
# Check if folder exists under parent folder
|
||||||
parent_folder=p_folder_obj)
|
child_folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
||||||
if child_folder_obj:
|
folder_name=folder_name,
|
||||||
results['result']['path'] = self.get_folder_path(child_folder_obj)
|
folder_type=folder_type,
|
||||||
results['result']['msg'] = "Folder %s already exists under" \
|
parent_folder=p_folder_obj)
|
||||||
" parent folder %s" % (folder_name, parent_folder)
|
if child_folder_obj:
|
||||||
self.module.exit_json(**results)
|
results['result']['path'] = self.get_folder_path(child_folder_obj)
|
||||||
|
results['result'] = "Folder %s already exists under" \
|
||||||
|
" parent folder %s" % (folder_name, parent_folder)
|
||||||
|
self.module.exit_json(**results)
|
||||||
else:
|
else:
|
||||||
folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
folder_obj = self.get_folder(datacenter_name=datacenter_name,
|
||||||
folder_name=folder_name,
|
folder_name=folder_name,
|
||||||
|
|
|
@ -113,6 +113,20 @@
|
||||||
- datastore
|
- datastore
|
||||||
- network
|
- 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:
|
- debug:
|
||||||
msg: "{{ all_folder_results }}"
|
msg: "{{ all_folder_results }}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue