mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -07:00
Refactor code for find_host_by_cluster_datacenter (#26859)
Fix adds refactor of code for find_host_by_cluster_datacenter API in vmware_host and vmware_resource_pool. Also, adds strict check for cluster and datacenter object find. Testcase for vmware_resource_pool. Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
62e01aecfb
commit
3e20acbd79
5 changed files with 199 additions and 36 deletions
|
@ -624,3 +624,18 @@ def serialize_spec(clonespec):
|
|||
data[x] = str(xt)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def find_host_by_cluster_datacenter(module, content, datacenter_name, cluster_name, host_name):
|
||||
dc = find_datacenter_by_name(content, datacenter_name)
|
||||
if dc is None:
|
||||
module.fail_json(msg="Unable to find datacenter with name %s" % datacenter_name)
|
||||
cluster = find_cluster_by_name(content, cluster_name, datacenter=dc)
|
||||
if cluster is None:
|
||||
module.fail_json(msg="Unable to find cluster with name %s" % cluster_name)
|
||||
|
||||
for host in cluster.host:
|
||||
if host.name == host_name:
|
||||
return host, cluster
|
||||
|
||||
return None, cluster
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue