Created
February 13, 2018 14:05
-
-
Save Akasurde/d4737878729f0f7f31a2a743a338bda6 to your computer and use it in GitHub Desktop.
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 | |
def connect(): | |
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) | |
context.verify_mode = ssl.CERT_NONE | |
username = '' | |
password = '' | |
hostname = '' | |
si = SmartConnect(host=hostname, user=username, pwd=password, port=443, sslContext=context) | |
atexit.register(Disconnect, si) | |
content = si.RetrieveContent() | |
return content | |
def get_obj(content, vimtype, name): | |
""" | |
Return an object by name, if name is None the | |
first found object is returned | |
""" | |
obj = None | |
container = content.viewManager.CreateContainerView( | |
content.rootFolder, vimtype, True) | |
for c in container.view: | |
if name: | |
if c.name == name: | |
obj = c | |
break | |
else: | |
obj = c | |
break | |
container.Destroy() | |
return obj | |
content = connect() | |
cluster_name = '' | |
cluster = get_obj(content, [vim.ClusterComputeResource], cluster_name) | |
print(cluster.resourcePool.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment