How To Get Started with Apache libcloud and OpenStackWeb Development
Updated on Friday, April 18, 2014
Updated on Friday, April 18, 2014
Libcloud is a Python library that provides an abstract API to interact with many popular cloud service providers. It allows you to write code once in a unified API and have it work with all the different providers that it supports.
Currently, there is an OpenStack driver for the compute component of Libcloud. It allows you to create, manage and delete all of your existing cloud servers in an OpenStack cloud. In this short tutorial, we’ll explain on how to get started with it on our cloud computing platform as an example.
The first step to using
libcloud is to install the library on your machine. In this tutorial, we’re going to assume you have a basic Python installation which you can install modules to using
# pip install apache-libcloud
pip should take care of installing all the necessary dependencies for you and it will let you know once it’s installed. You can now start using it in your projects, however, you’ll likely need a cloud computing account somewhere to use this account.
Please note that this part is provider specific. We’re going to demonstrate on how to get your API credentials from our cloud service, however, we’re going to discuss the case of general Vanilla OpenStack clouds (such as private clouds) and what fields you need.
In order to get started with it, you’ll be needing the Keystone API endpoint, username, tenant name and password. Typically, you can acquire this information from Horizon if you’re running a vanilla OpenStack cloud. It will be available under “Access & Security”.
If you’re using our service, you an simply login to your own control panel by logging to your customer centre and clicking on “CloudConsole”. From there, you can click on “API credentials” and you will see all your API credentials displayed there.
We’ll go over the basics of getting
libcloud configured with your OpenStack cloud. The sample code below should allow you to authenticate to your private OpenStack Cloud or to our cloud computing service. In the example, we’ll be connecting to our cloud platform.
You’ll need to make sure that the
ex_force_service_region and other arguments are matching the ones that you are using from your cloud. If you’re not sure of those, you should be able to list them from Keystone or ask for assistance from your cloud operator.
from libcloud.compute.types import Provider from libcloud.compute.providers import get_driver import libcloud.security # This assumes you don't have SSL set up. # Note: Code like this poses a security risk (MITM attack) and # that's the reason why you should never use it for anything else # besides testing. You have been warned. libcloud.security.VERIFY_SSL_CERT = False OpenStack = get_driver(Provider.OPENSTACK) driver = OpenStack('**insert_tenant_username**', '**insert_tenant_password**', ex_force_auth_version='2.0_password', ex_force_auth_url='http://auth.api.thenebulacloud.com:5000', ex_tenant_name='**insert_tenant_name**', ex_force_service_name='nova', ex_force_service_region='na-yul-nhs1')
Once you have that in place, you should be able to use the Compute driver like any other driver in
libcloud. The documentation is very detailed and explains many different examples of using it, you can refer to the examples page for more information. You can now use
libcloud to speak with your cloud service provider of choice, hopefully us!