Skip to content

Commit

Permalink
Add support for Python3 in vmware_guest_find
Browse files Browse the repository at this point in the history
* Remove redundant get_obj method
* Fix testcase
* Correct logic for compile_folder_path_for_object

Fixes: ansible#25984

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde authored and abadger committed Sep 1, 2017
1 parent c51a4bc commit 8027aad
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lib/ansible/module_utils/vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ def compile_folder_path_for_object(vobj):
thisobj = vobj
while hasattr(thisobj, 'parent'):
thisobj = thisobj.parent
if thisobj.name == 'Datacenters':
break
if isinstance(thisobj, vim.Folder):
paths.append(thisobj.name)
paths.reverse()
if paths[0] == 'Datacenters':
paths.remove('Datacenters')
return '/' + '/'.join(paths)


Expand Down
23 changes: 2 additions & 21 deletions lib/ansible/modules/cloud/vmware/vmware_guest_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
- This is required if name is not supplied.
datacenter:
description:
- Destination datacenter for the deploy operation.
- Destination datacenter for the find operation.
required: True
extends_documentation_fragment: vmware.documentation
'''
Expand Down Expand Up @@ -78,14 +78,13 @@
find_datacenter_by_name
)

HAS_PYVMOMI = False
try:
import pyVmomi
from pyVmomi import vim

HAS_PYVMOMI = True
except ImportError:
pass
HAS_PYVMOMI = False


class PyVmomiHelper(object):
Expand Down Expand Up @@ -199,24 +198,6 @@ def getfolders(self):
self.folders = self._build_folder_tree(self.datacenter.vmFolder)
self._build_folder_map(self.folders)

@staticmethod
def compile_folder_path_for_object(vobj):
""" make a /vm/foo/bar/baz like folder path for an object """

paths = []
if isinstance(vobj, vim.Folder):
paths.append(vobj.name)

thisobj = vobj
while hasattr(thisobj, 'parent'):
thisobj = thisobj.parent
if isinstance(thisobj, vim.Folder):
paths.append(thisobj.name)
paths.reverse()
if paths[0] == 'Datacenters':
paths.remove('Datacenters')
return '/' + '/'.join(paths)


def main():
argument_spec = vmware_argument_spec()
Expand Down
1 change: 0 additions & 1 deletion test/integration/targets/vmware_guest_find/aliases
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
posix/ci/cloud/vcenter
cloud/vcenter
skip/python3
destructive
4 changes: 4 additions & 0 deletions test/integration/targets/vmware_guest_find/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Test code for the vmware_guest_find module.
# (c) 2017, James Tanner <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- name: make sure pyvmomi is installed
pip:
name: pyvmomi
Expand Down

0 comments on commit 8027aad

Please sign in to comment.