老问题,但如果外面有人正在寻找解决方案(这是谷歌的第一个结果),这将直接从数据存储中收集信息:
from pysphere import VIServer, VIProperty
import ssl
default_context = ssl._create_default_https_context
server = VIServer()
#user = the-user-to-connect-to-vsphere
#password = the-password-from-the-user
#host = the-vsphere-hostname-or-ip
try:
ssl._create_default_https_context = ssl._create_unverified_context
server.connect(host, user, password)
for ds_mor, name in server.get_datastores().items():
props = VIProperty(server, ds_mor)
print "Datastore name: ", name
server.disconnect()
finally:
ssl._create_default_https_context = default_context
这将连接到自签名的 VSphere,这在 Intranet 中很常见。