Python - VMWare vSphere (WEB SDK) - SUDS [英] Python - VMWare vSphere (WEB SDK) - SUDS
问题描述
我如何通过某种形式的库或通过 SUDS 联系 vSphere(或 VMWare)形式的 Python 以获取 vCPU 或特定主机/来宾/虚拟机的数量?
目前我正在尝试:
from suds.client import Clientfrom suds.sudsobject import 属性client = Client("https:///sdk/vimService?wsdl")queryCon = client.wsdl.services[0].ports[0].methods['QueryConnectionInfo']打印查询控制
这行得通,它给了我某种形式的输出:
(方法){名称 = "查询连接信息"location = "https://localhost/sdk/vimService"绑定 =(捆绑){input = output = }肥皂 =(肥皂){action = ""urn:vim25/4.1""样式 = "文档"输入 =(输入){身体 =(身体){零件[] =(部分){root = <part name="parameters" element="vim25:QueryConnectionInfo"/>名称=参数"qname[] =参数","骨灰盒:vim25",element = "(u'QueryConnectionInfo', u'urn:vim25')"类型 = "无"},使用 = "文字"命名空间[] ="vim25","骨灰盒:vim25",包裹 = 真}标头[] = <空>}输出 =(输出){身体 =(身体){零件[] =(部分){root = <part name="parameters" element="vim25:QueryConnectionInfoResponse"/>名称=参数"qname[] =参数","骨灰盒:vim25",element = "(u'QueryConnectionInfoResponse', u'urn:vim25')"类型 = "无"},使用 = "文字"命名空间[] ="vim25","骨灰盒:vim25",包裹 = 真}标头[] = <空>}故障[] =(过错){name = "InvalidLoginFault"使用 = "文字"零件[] =(部分){root = 名称 = "故障"qname[] =过错","骨灰盒:vim25",element = "(u'InvalidLoginFault', u'urn:vim25')"类型 = "无"},},(过错){name = "HostConnectFaultFault"使用 = "文字"零件[] =(部分){root = 名称 = "故障"qname[] =过错","骨灰盒:vim25",element = "(u'HostConnectFaultFault', u'urn:vim25')"类型 = "无"},},(过错){名称 = "运行时故障"使用 = "文字"零件[] =(部分){root = <part name="fault" element="vim25:RuntimeFaultFault"/>名称 = "故障"qname[] =过错","骨灰盒:vim25",element = "(u'RuntimeFaultFault', u'urn:vim25')"类型 = "无"},},}}
我尝试遵循以下指南":
http://communities.vmware.com/thread/273616
我知道所有信息可能都在这里,我只是看不到整个图片:/
尝试了一段时间后,我陷入了困境:
client = Client("https:///sdk/vimService?wsdl")#queryCon = client.wsdl.services[0].ports[0].methods['QueryConnectionInfo']打印 client.service.QueryConnectionInfo("https:///sdk", None, r'domain\user', 'Password')
输出为:
urllib2.URLError: <urlopen error [Errno 1] _ssl.c:490: error:140770FC:SSLroutines:SSL23_GET_SERVER_HELLO:unknown protocol>
你可能想试试 psphere,一个 Python 库(基于 suds),可让您访问整个 vSphere Web Services SDK.
安装:
$ pip install psphere
找到一个虚拟机并打印它拥有的 CPU 数量:
<预><代码>>>>从 psphere.client 导入客户端>>>从 psphere.managedobjects 导入 VirtualMachine>>>客户端 = 客户端(服务器=vcenter.mydomain.com",用户名=管理员",密码=强")>>>vm = VirtualMachine.get(client, name="genesis")>>>虚拟机<psphere.managedobjects.VirtualMachine 对象在 0xd3fbccc>>>>print("%s 有 %s 个 CPU" % (vm.name, vm.config.hardware.numCPU))创世纪有 2 个 CPU您可以在文档中找到更多示例.
免责声明:我是 psphere 的作者.
How do i contact the vSphere (or VMWare) form Python either with some form of library or via SUDS to get the number of number of vCPU or a specific host/guest/virtual-machine?
Currently i'm trying:
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
And that works, and it gives me some form of output:
(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"
},
},
}
}
I've tried following the following "guides":
SUDS - programmatic access to methods and types
http://communities.vmware.com/thread/273616
I know that all the information probably is here, i just can't see the entire picture :/
After a while of trying this is where i get stuck:
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')
And the output is:
urllib2.URLError: <urlopen error [Errno 1] _ssl.c:490: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol>
You might want to try psphere, a Python library (based on suds) which will give you access the entire vSphere Web Services SDK.
Install it:
$ pip install psphere
Find a virtual machine and print the number of CPUs it has:
>>> 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
You can find more examples in the documentation.
Disclaimer: I am the author of psphere.
这篇关于Python - VMWare vSphere (WEB SDK) - SUDS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!