Skip to content

Instantly share code, notes, and snippets.

@G-Goldstein
Created August 22, 2016 10:15
Show Gist options
  • Save G-Goldstein/51fde814dad088639fd9a0ef8673cfca to your computer and use it in GitHub Desktop.
Save G-Goldstein/51fde814dad088639fd9a0ef8673cfca to your computer and use it in GitHub Desktop.
import pyVmomi # Use the pyVmomi module we downloaded
import pyVim.connect
import ssl # Use the ssl module from the standard library to avoid certification here.
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
context.verify_mode = ssl.CERT_NONE
host='???' ## Ask another team member for these credentials, or use your own!
user = '???' ## Be careful about uploading credentials to public source repositories!
password = '???'
server = pyVim.connect.SmartConnect(host=host, # Connect to our server
user=user,
pwd=password,
port=443,
sslContext=context
)
content = server.RetrieveContent() # Retrieve content from our server - this is how the pyVmomi module works
container = content.rootFolder
viewType = [pyVmomi.vim.VirtualMachine] # https://github.com/vmware/pyvmomi/blob/master/docs/vim/VirtualMachine.rst
recursive = True
containerView = content.viewManager.CreateContainerView(
container, viewType, recursive)
vm_list = containerView.view
for vm in vm_list:
print(vm.summary.guest.ipAddress, vm.summary.guest.guestFullName) # We can see the options available to us at https://github.com/vmware/pyvmomi/blob/master/docs/vim/VirtualMachine.rst - All these links came from searching for what we're after!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment