python libcloud vcloud连接

时间:2014-08-01 11:05:37

标签: python linux libcloud

我正在尝试使用lib cloud连接到Vcloud,使用来自firefox的rest API可以很好地进行身份验证,但是在python中失败了。我错过了什么吗?

__author__ = 'kshk'
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

import libcloud.security



def testConnection():
    #libcloud.security.VERIFY_SSL_CERT = False
    vcloud = get_driver(Provider.VCLOUD)
    driver = vcloud("login", "passwd", host = "https://portal.vcloud")

    nodes = driver.list_nodes()
    print nodes

def main():
    testConnection()

if __name__ == "__main__":
    main()

输出:

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/krishnaa/PycharmProjects/VCloud-API/vcloud_test.py
Traceback (most recent call last):
  File "/Users/krishnaa/PycharmProjects/VCloud-API/vcloud_test.py", line 21, in <module>
    main()
  File "/Users/krishnaa/PycharmProjects/VCloud-API/vcloud_test.py", line 18, in main
    testConnection()
  File "/Users/krishnaa/PycharmProjects/VCloud-API/vcloud_test.py", line 14, in testConnection
    nodes = driver.list_nodes()
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/compute/drivers/vcloud.py", line 559, in list_nodes
    return self.ex_list_nodes()
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/compute/drivers/vcloud.py", line 573, in ex_list_nodes
    vdcs = self.vdcs
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/compute/drivers/vcloud.py", line 407, in vdcs
    self.connection.check_org()  # make sure the org is set.
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/compute/drivers/vcloud.py", line 325, in check_org
    self._get_auth_token()
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/compute/drivers/vcloud.py", line 835, in _get_auth_token
    headers=self._get_auth_headers())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 973, in request
    self._send_request(method, url, body, headers)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1007, in _send_request
    self.endheaders(body)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 969, in endheaders
    self._send_output(message_body)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 829, in _send_output
    self.send(msg)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 791, in send
    self.connect()
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/httplib_ssl.py", line 96, in connect
    self.timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

1 个答案:

答案 0 :(得分:2)

您的代码无法运行,因为&#34;主机&#34;参数只需要一个主机名,而不是一个网址。

如果您将其更改为:

driver = vcloud("login", "passwd", host="portal.vcloud")

它应该有用。