Skip to content

Instantly share code, notes, and snippets.

@complexsplit
Created April 28, 2014 12:40
Show Gist options
  • Save complexsplit/11370646 to your computer and use it in GitHub Desktop.
Save complexsplit/11370646 to your computer and use it in GitHub Desktop.
Searching datastores w/ pyVmomi
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim, vmodl
import argparse
import atexit
import sys
import pprint
si = SmartConnect(host="192.168.1.7", user="root", pwd="vmware")
servcontent = si.RetrieveServiceContent()
rf = servcontent.rootFolder
dc = rf.childEntity # what does this return? hint: look at the docs, or MOB
hostdatastorebrowser = dc[0].datastore[0].browser
# following is optional. without a SearchSpec, it will just find everything.
# searchspec = vim.Host.DatastoreBrowserSearchSpec()
# what if we wanted to find only .vmx files?
task = hostdatastorebrowser.SearchDatastore_Task(datastorePath='[datastore1]')
pp = pprint.PrettyPrinter()
pp.pprint(task.info.result)
print task.info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment