vsphare API 的使用

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值