1) 目前测试了pyVmomi ,例子都跑起来了,需要注意的是 账号密码是 vSphere web client 的账号密码 ip 是vcent 的ip地址, VIHOST 是指HOST 主机IP
例子中有个运行时报错,SmartConnectNoSSL 什么的,是因为pyVmomi 的connect.py 文件比较老,到官网查看对应文件,照着修改本地的文件就可以了
pyVmomi is the Python SDK for the VMware vSphere API that allows you to manage ESX, ESXi, and vCenter.
https://github.com/vmware/pyvmomi/
使用例子
https://github.com/vmware/pyvmomi-community-samples
2)另外,有一个c++代码的库,没有试,如果到时一定要用c++来做,可以试一下.
https://github.com/bfzhao/Native-vShpere-Linux
3) 其它语言的没有试过
----------------------------------------------------------------------------------------------------------------------------------------------------
pyVmomi使用
1) 连接到vcent
serviceInstance = SmartConnect(host=host,
user=user,
pwd=password,
port=443)
serviceInstance 代表一个连接
也可以这样,但用python 一般不这样做
VimServiceLocator locator = new VimServiceLocator();
locator.setMaintainSession(true);
VimPortType serviceConnection = locator.getVimPort("https://your_server/sdk");
ServiceInstanceContent serviceContent = serviceConnection.retrieveContent(svcRef);
ManagedObjectReference sessionManager = serviceInstance.getSessionManager();
UserSession us = serviceConnection.login(sessionManager, username, password, null);
2)创建一个content
content = serviceInstance.RetrieveContent()
3) 创建view
host_view = content.viewManager.CreateContainerView(content.rootFolder,
[vim.HostSystem],
True)
说明:view 有下面几种
Folder [vim.Folder ]
Datacenter [vim.Datacenter]
ComputeResource [vim.ComputeResource]
ResourcePool [vim.ResourcePool]
HostSystem [vim.HostSystem]
4) 使用view
obj = [host for host in host_view.view]
host_view.Destroy()
//使用 obj