Apache LibCloud - Does it work with compute?

dreamcompute

#1

How do I use apache libcloud to list nodes?

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
key='myusername’
secret='g/yp4lM7UzTIm*********'
Driver = get_driver(Provider.DREAMHOST)
conn = Driver(key, secret)
nodes = conn.list_nodes()
print nodes

File “/home/ubuntu/workspace/rtb-devops/classes/cloudUtilities.py”, line 22, in
nodes = conn.list_nodes()
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/compute/drivers/dreamhost.py”, line 185, in list_nodes
’/’, {‘cmd’: ‘dreamhost_ps-list_ps’}).object
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/base.py”, line 721, in request
headers=headers)
File “/usr/lib/python2.7/httplib.py”, line 973, in request
self._send_request(method, url, body, headers)
File “/usr/lib/python2.7/httplib.py”, line 1007, in _send_request
self.endheaders(body)
File “/usr/lib/python2.7/httplib.py”, line 969, in endheaders
self._send_output(message_body)
File “/usr/lib/python2.7/httplib.py”, line 829, in _send_output
self.send(msg)
File “/usr/lib/python2.7/httplib.py”, line 791, in send
self.connect()
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/httplib_ssl.py”, line 264, in connect
self.timeout)
File “/usr/lib/python2.7/socket.py”, line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
TypeError: getaddrinfo() argument 1 must be string or None


#2

Not using that driver. The Provider.DREAMHOST driver for libcloud interacts with DreamHost VPSes, not DreamCompute.

Use the Provider.OPENSTACK driver as detailed in the libcloud documentation: http://libcloud.readthedocs.org/en/latest/compute/examples.html#create-a-node-on-a-cloudstack-provider-using-a-provided-key-pair-and-security-groups


#3

I still dont get how to use libcloud with OpenStack as it relates to dreamcompute.

Driver = get_driver(Provider.OPENSTACK)
conn = Driver(key=ACCESS_ID, secret=SECRET_KEY, port=8774, secure=False ,host=HOST, path=PATH)
libcloud.common.types.LibcloudError: <LibcloudError in None ‘OpenStack instance must have auth_url set’>

File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/compute/drivers/openstack.py”, line 121, in init
super(OpenStackNodeDriver, self).init(*args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/compute/base.py”, line 651, in init
api_version=api_version, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/base.py”, line 1013, in init
self.connection = self.connectionCls(*args, **conn_kwargs)
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/openstack.py”, line 164, in init
’have auth_url set’)
libcloud.common.types.LibcloudError: <LibcloudError in None ‘OpenStack instance must have auth_url set’>

Goggline that error leads to a diffenet solution

OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack(‘your_auth_username’, ‘your_auth_password’,
ex_force_auth_url=‘http://192.168.1.101:5000’,
ex_force_auth_version=‘2.0_password’)

I am finding it difficult to map the correct endpoint to what us required

This is what I have
HOST = 'https://compute.dream.io
PATH = '/v2/9c5acd7test’
port=8774

So…If I use the later…what is the ex_force_auth_version? and what is the ex_force_auth_url?


#4

PS

I tried the following and got the below error:

conn = Driver(‘your_auth_username’, ‘your_auth_password’,
ex_force_auth_url=‘https://keystone.dream.io/v2.0’,
ex_force_auth_version=‘2.0_password’)

Traceback (most recent call last):
File “/home/ubuntu/workspace/rtb-devops/classes/cloudUtilities.py”, line 42, in
nodes = conn.list_nodes()
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/compute/drivers/openstack.py”, line 149, in list_nodes
self.connection.request(’/servers/detail’, params=params).object)
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/openstack.py”, line 200, in request
raw=raw)
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/base.py”, line 657, in request
action = self.morph_action_hook(action)
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/openstack.py”, line 255, in morph_action_hook
self._populate_hosts_and_request_paths()
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/openstack.py”, line 288, in _populate_hosts_and_request_paths
osa = osa.authenticate(**kwargs) # may throw InvalidCreds
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/openstack_identity.py”, line 841, in authenticate
return self._authenticate_2_0_with_password()
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/openstack_identity.py”, line 866, in _authenticate_2_0_with_password
return self._authenticate_2_0_with_body(reqbody)
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/openstack_identity.py”, line 871, in _authenticate_2_0_with_body
method=‘POST’)
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/base.py”, line 736, in request
response = responseCls(**kwargs)
File “/usr/local/lib/python2.7/dist-packages/apache_libcloud-0.16.0-py2.7.egg/libcloud/common/base.py”, line 117, in init
raise Exception(self.parse_error())
Exception: {“error”: {“message”: “get_version_v2() got an unexpected keyword argument ‘auth’”, “code”: 400, “title”: “Bad Request”}}


#5

I just did some very basic testing and it looks like you should set the provider like this:

[code]from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack(‘username’, ‘password’,
ex_force_auth_url=‘https://keystone.dream.io/v2.0/tokens’,
ex_force_auth_version=‘2.0_password’,
ex_tenant_name=‘tenant_name’)[/code]

Where tenant_name is in the format of dhc123456. You can find that in your localrc file which can be downloaded from the API Access tab of the Access & Security page.


#6

Here’s an example to create a subsonic sized (1vCPU/1GB) Ubuntu 14.04 VM:

[code]
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack(‘username’, ‘password’,
ex_force_auth_url=‘https://keystone.dream.io/v2.0/tokens’,
ex_force_auth_version=‘2.0_password’,
ex_tenant_name=‘dhc12345678’)

sizes = driver.list_sizes()
images = driver.list_images()

size = [s for s in sizes if s.name == ‘subsonic’][0]
image = [i for i in images if ‘Ubuntu-14.04-Trusty’ in i.name][0]

node = driver.create_node(name=‘libcloud’, size=size, image=image, ex_keyname=‘my-keypair’)
print(node)[/code]