Created
August 12, 2015 21:27
-
-
Save cuibonobo/f92f80acedced68f1e28 to your computer and use it in GitHub Desktop.
Grab the UUID from an ESXi machine using PyVmomi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ssl | |
| import requests | |
| import atexit | |
| from pyVim import connect | |
| from pyVmomi import vim | |
| # Be sure to set these first | |
| # IP_ADDRESS = '' | |
| # USER = '' | |
| # PASS = '' | |
| # Disable SSL warnings | |
| requests.packages.urllib3.disable_warnings() | |
| # Change our SSL context to accept self-signed certificates | |
| # This is a hack that will be fixed once this is merged: | |
| # https://github.com/vmware/pyvmomi/issues/235 | |
| _create_unverified_https_context = ssl._create_unverified_context | |
| ssl._create_default_https_context = _create_unverified_https_context | |
| # Connect to the service instance | |
| si = connect.SmartConnect(host=IP_ADDRESS, user=USER, pwd=PASS) | |
| # Register to disconnect the service instance when we exit | |
| atexit.register(connect.Disconnect, si) | |
| # Create an object view for the info we want to inspect | |
| content = si.RetrieveContent() | |
| object_view = content.viewManager.CreateContainerView(content.rootFolder, | |
| [vim.HostSystem], | |
| True) | |
| # We only listed `vim.HostSystem` above, so that should be our only element | |
| host = object_view.view[0] | |
| # The `host` variable now has everything we need, so we can destroy this. | |
| object_view.Destroy() | |
| # Grab stuff | |
| uuid = host.hardware.systemInfo.uuid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment