From 3a1944edc15de9f13343cb7368fb97fc487a5d77 Mon Sep 17 00:00:00 2001 From: Jay Jahns Date: Sat, 5 Mar 2016 11:50:51 -0800 Subject: [PATCH] add find_vm_by_name function to vmware utils --- lib/ansible/module_utils/vmware.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/ansible/module_utils/vmware.py b/lib/ansible/module_utils/vmware.py index 2f895801466..a0999c05442 100644 --- a/lib/ansible/module_utils/vmware.py +++ b/lib/ansible/module_utils/vmware.py @@ -99,6 +99,15 @@ def find_hostsystem_by_name(content, hostname): return None +def find_vm_by_name(content, vm_name): + + vms = get_all_objs(content, [vim.VirtualMachine]) + for vm in vms: + if vm.name == vm_name: + return vm + return None + + def vmware_argument_spec(): return dict(