From 82b56ed5b3d1dce157b2a985234313b2436a7239 Mon Sep 17 00:00:00 2001 From: IlyaTsoi <45252974+IlyaTsoi@users.noreply.github.com> Date: Thu, 6 Jul 2023 10:54:12 +0400 Subject: [PATCH] Support for nested resource pools I propose to change the logic of defining the target resource pool. In the current logic, nested resource pools cannot be defined, and the virtual machine is deployed in the first pool found by name, nesting is not considered. Issue #1360 --- plugins/modules/vmware_guest.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/modules/vmware_guest.py b/plugins/modules/vmware_guest.py index 51e4aba1f..f50dd64cd 100644 --- a/plugins/modules/vmware_guest.py +++ b/plugins/modules/vmware_guest.py @@ -2884,12 +2884,19 @@ def get_resource_pool(self, cluster=None, host=None, resource_pool=None): cluster = None # get resource pools limiting search to cluster or datacenter - resource_pool = find_obj(self.content, [vim.ResourcePool], resource_pool_name, folder=cluster or datacenter) - if not resource_pool: - if resource_pool_name: - self.module.fail_json(msg='Unable to find resource_pool "%s"' % resource_pool_name) + resource_pool = find_obj(self.content, [vim.ResourcePool], None, folder=cluster or datacenter) + if not resource_pool: + self.module.fail_json(msg='Unable to find resource pool, need esxi_hostname, resource_pool, or cluster') + resource_pool_path = resource_pool_name.split('/') if resource_pool_name else [] + # filter path from empty items + rp_path_nodes = list(filter(None, resource_pool_path)) + for i in range(len(rp_path_nodes)): + child = list(filter(lambda x: x.name == rp_path_nodes[i], resource_pool.resourcePool)) + if len(child) != 1: + self.module.fail_json(msg='Unable to find node "%s" in resource pool path "%s"' % (rp_path_nodes[i], resource_pool_name)) + break else: - self.module.fail_json(msg='Unable to find resource pool, need esxi_hostname, resource_pool, or cluster') + resource_pool = child[0] return resource_pool def deploy_vm(self):