Using pyrax with standard OpenStack clouds
Posted on 01, Dec 2015
Before we start, have a look at the pyrax documentation and the installation instructions. Note that at the time of writing, pyrax is "being deprecated in favor of the OpenStack SDK". Although it is worth noting if you have been using pyrax in any comprehensive way, falling back to the OpenStack SDK is going to involve a lot of work in my opinion.
RackSpace uses its own authentication endpoint, whereas a standard OpenStack installation will utilise username/password, token, or certificate (tokenless) authentication via the
Keystone OpenStack Identiy Service
guide provides information on the various ways authentication information can be injected into pyrax, however we will use a configuration file that specifies multiple environments, and separate credentials files.
Critically pyrax expects this configuration file to reside at
, however you may want to specify your own file location.
Your configuration file should look something like this:
[testing] identity_type = keystone auth_endpoint = http://<ip>:5000/v2.0/ [deployment] identity_type = rackspace region = SYD
And your credentials files (which you will be storing separately) will look something like this:
[keystone] username = <user> password = <password> tenant_id = <tennant id>
[rackspace_cloud] username = <user> api_key = <api key>
From Python, we can connect to either endpoint by specifying the environment and credentials file to use:
import pyrax pyrax.settings.read_config("~/.pyrax.cfg") pyrax.set_environment("deployment") pyrax.set_credential_file("./deployment.creds") pyrax.cloudservers.servers.create(...)
In this way we can keep credentials separate from our configuration for multiple endpoints, whether it be RackSpace, or vanilla OpenStack.
Copyright, Christopher Poole 2008-2016.