pythonlinuxlibcloud

python libcloud vcloud connection


I am trying to connect to Vcloud using lib cloud, the authentication works fine using rest API from firefox, but fails in python. am I missing something?

__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()

OUTPUT:

/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

Solution

  • Your code doesn't work because the "host" argument expects just a hostname and not a url.

    If you change it to:

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

    it should work.