如何使用某种形式的库或通过SUDS联系vSphere (或VMWare) form Python,以获得vCPU或特定主机/客户/虚拟机的数量?
目前我正在尝试:
from suds.client import Client
from suds.sudsobject import Property
client = Client("https://<server>/sdk/vimService?wsdl")
queryCon = client.wsdl.services[0].ports[0].methods['QueryConnectionInfo']
print queryCon这是可行的,它给了我某种形式的输出:
(Method){
name = "QueryConnectionInfo"
location = "https://localhost/sdk/vimService"
binding =
(binding){
input = <suds.bindings.document.Document instance at 0x0775C080>
output = <suds.bindings.document.Document instance at 0x0775C080>
}
soap =
(soap){
action = ""urn:vim25/4.1""
style = "document"
input =
(Input){
body =
(Body){
parts[] =
(Part){
root = <part name="parameters" element="vim25:QueryConnectionInfo"/>
name = "parameters"
qname[] =
"parameters",
"urn:vim25",
element = "(u'QueryConnectionInfo', u'urn:vim25')"
type = "None"
},
use = "literal"
namespace[] =
"vim25",
"urn:vim25",
wrapped = True
}
headers[] = <empty>
}
output =
(Output){
body =
(Body){
parts[] =
(Part){
root = <part name="parameters" element="vim25:QueryConnectionInfoResponse"/>
name = "parameters"
qname[] =
"parameters",
"urn:vim25",
element = "(u'QueryConnectionInfoResponse', u'urn:vim25')"
type = "None"
},
use = "literal"
namespace[] =
"vim25",
"urn:vim25",
wrapped = True
}
headers[] = <empty>
}
faults[] =
(Fault){
name = "InvalidLoginFault"
use = "literal"
parts[] =
(Part){
root = <part name="fault" element="vim25:InvalidLoginFault"/>
name = "fault"
qname[] =
"fault",
"urn:vim25",
element = "(u'InvalidLoginFault', u'urn:vim25')"
type = "None"
},
},
(Fault){
name = "HostConnectFaultFault"
use = "literal"
parts[] =
(Part){
root = <part name="fault" element="vim25:HostConnectFaultFault"/>
name = "fault"
qname[] =
"fault",
"urn:vim25",
element = "(u'HostConnectFaultFault', u'urn:vim25')"
type = "None"
},
},
(Fault){
name = "RuntimeFault"
use = "literal"
parts[] =
(Part){
root = <part name="fault" element="vim25:RuntimeFaultFault"/>
name = "fault"
qname[] =
"fault",
"urn:vim25",
element = "(u'RuntimeFaultFault', u'urn:vim25')"
type = "None"
},
},
}
}我试着遵循以下“指南”:
SUDS - programmatic access to methods and types
http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.VirtualMachine.html#field_detail
http://communities.vmware.com/thread/273616
我知道所有的信息可能都在这里,我只是看不到整个画面:/
在尝试了一段时间之后,这就是我被卡住的地方:
client = Client("https://<server>/sdk/vimService?wsdl")
#queryCon = client.wsdl.services[0].ports[0].methods['QueryConnectionInfo']
print client.service.QueryConnectionInfo("https://<server>/sdk", None, r'domain\user', 'Password')输出结果为:
urllib2.URLError: <urlopen error [Errno 1] _ssl.c:490: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol>发布于 2011-10-29 18:05:09
您可能想尝试使用psphere,这是一个Python库(基于suds),它将使您能够访问整个vSphere Web Services SDK。
安装它:
$ pip install psphere查找虚拟机并打印其拥有的CPU数量:
>>> from psphere.client import Client
>>> from psphere.managedobjects import VirtualMachine
>>> client = Client(server="vcenter.mydomain.com", username="Administrator", password="strong")
>>> vm = VirtualMachine.get(client, name="genesis")
>>> vm
<psphere.managedobjects.VirtualMachine object at 0xd3fbccc>
>>> print("%s has %s CPUs" % (vm.name, vm.config.hardware.numCPU))
genesis has 2 CPUs您可以在documentation中找到更多示例。
免责声明:我是psphere的作者。
发布于 2011-12-07 17:13:32
用一个新的库解决了这个问题: pysphere (easy_install pysphere)
from pysphere import VIServer
server = VIServer()
server.connect("server", 'user', "pass")
vm = server.get_vm_by_name("virtual_host_name")
info = vm.get_properties()它保持了vSphere变量的名称空间的完整性,并且它是我想要的那样透明,这意味着它不会改变任何容易找到的东西,它还支持批量信息,所以我不必在缓慢而痛苦的过程中逐个查询所有1500台服务器,它需要几秒钟来收集任何主机的信息。
https://stackoverflow.com/questions/7889762
复制相似问题