Python - VMWare vSphere(WEB SDK) - SUDS
我如何通过 Python 通过某种形式的库或通过 SUDS 联系 vSphere(或 VMWare)以获取 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"
},
},
}
}
我尝试遵循以下“指南”:
http://www.vmware.com/支持/开发者/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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想尝试 psphere,这是一个 Python 库(基于 suds),它可以让您访问整个 vSphere网络服务 SDK。
安装它:
查找虚拟机并打印它拥有的 CPU 数量:
您可以在文档。
免责声明:我是psphere的作者。
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:
Find a virtual machine and print the number of CPUs it has:
You can find more examples in the documentation.
Disclaimer: I am the author of psphere.
使用新库解决了这个问题:pysphere
(easy_install pysphere)
它保持 vSphere 变量的命名空间完整,并且它像我需要的那样透明,这意味着它不会改变任何内容,这使得它很容易找到,它还支持批处理信息,所以我没有要在一个缓慢而痛苦的过程中逐一查询所有 1500 台服务器,需要几秒钟才能收集有关任何主机的信息。
Solved it with a new library: pysphere
(easy_install pysphere)
It keeps the namespace intact of the vSphere variables and it's as transparent as i need it to be, meaning it doesn't change anything which makes it easy to find, it also support batching up information so i don't have to query through all 1500 servers one by one in a slow painful process, it takes a few seconds to gather information regarding any host.