Created
July 22, 2019 07:06
-
-
Save Akasurde/103ea6aa630c2cee9df2526a513ccddc to your computer and use it in GitHub Desktop.
Vmware test code
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
from pyVim.connect import SmartConnect, Disconnect | |
import ssl | |
import atexit | |
from pyVmomi import vim, vmodl | |
def connect(hostname, username, password): | |
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) | |
context.verify_mode = ssl.CERT_NONE | |
si = SmartConnect(host=hostname, | |
user=username, | |
pwd=password, | |
port=443, sslContext=context) | |
atexit.register(Disconnect, si) | |
content = si.RetrieveContent() | |
return content | |
def get_all_objs(content, vimtype): | |
""" | |
Return an object by name, if name is None the | |
first found object is returned | |
""" | |
obj = {} | |
container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True) | |
for c in container.view: | |
obj.update({c: c.name}) | |
container.Destroy() | |
return obj | |
hostname = '' | |
username = '[email protected]' | |
password = 'Esxi@123$%' | |
content = connect(hostname, username, password) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment