If you would like to access the functionality of the OpenStack Services from an application written in a particular programming language, you might find that calling the REST APIs is a bit inconvenient. In these situations you may want to use a Software Development Kit (SDK) that "wraps" the REST API calls to make them easier to invoke from a programming language.

The OpenStack wiki maintains a list of known OpenStack SDKs. Since anyone can create an SDK to wrap the OpenStack API, this list may not be complete and inclusion on the list does not mean that an SDK is "official". Some of the SDKs on the list also provide access to cloud services other than OpenStack. These "multi-cloud" SDKs might be a good choice if you would like your application to run both on Jetstream2 and other cloud platforms. This list of SDKs offers more detailed information about a selection of the known SDKs from the list above.

If you are choosing an SDK for use in an application that will work with Jetstream2, your first consideration will probably be the programming language that you want to use. From the available options, you should look at some documentation and examples to see which SDKs provide the sort of access and programming style you would like. In particular, note any limitations or exclusions that the SDK has - they do not all span the complete set of OpenStack functionality.

A Python Example

The remainder of this page and the following page provide an example of using a Python SDK to work with Jetstream2. For this purpose, we will use the (rather broadly named) OpenStack SDK. The SDK is well documented, with user guides, code samples and API references linked throughout. The example will create a Jetstream2 instance using steps similar to those in the CLI workflows page.

Installing the SDK

The SDK package can easily be installed using Python's "pip" package manager. Once you have installed Python, you must also make sure that its "wheel" package is installed. You can do that, install the SDK and confirm its installation with these commands:


pip install wheel
pip install openstacksdk
python -m openstack version
Configuration and Connection

You can connect to Jetstream2 with the OpenStack SDK in three ways. You could:

  • Hard-code all of the necessary connection parameters into the program's source.
  • Run the application in an environment where the OS_* environment variables are defined and have it use them to define the connection.
  • Create a configuration file and specify the name of the connection you want to use.

The SDK developers recommend that you connect using a configuration file, and that is demonstrated in the example below. If you follow the steps to Create an openrc.sh file, in the last step you will have the option to download an options.yaml file instead of an openrc.sh file. Do that, and place the file in the location ~/.config/openstack/clouds.yaml. This sample configuration file (with comments and whitespace removed) defines a cloud connection with the default name "openstack". You can include multiple such configurations in this file, but each must have a unique name.


clouds:
  openstack:
    auth:
      auth_url: https://js2.jetstream-cloud.org:5000/v3/
      application_credential_id: "REDACTED"
      application_credential_secret: "REDACTED"
    region_name: "IU"
    interface: "public"
    identity_api_version: 3
    auth_type: "v3applicationcredential"

With such a configuration in place, this Python code will find the configuration and connect to the named cloud, returning an object of type Connection.


import openstack

connection = openstack.connect("openstack")

If you connect to a "cloud" named "envvars", the values in your OS_* environment variables will be used for the connection. At least the variables OS_AUTH_URL, OS_APPLICATION_CREDENTIAL_ID and OS_APPLICATION_CREDENTIAL_SECRET must be defined in order for this to work. If you encounter difficulties connecting and would like to view your configuration information, try running some Python like this:


for cloud in openstack.config.loader.OpenStackConfig().get_all_clouds():
    print(cloud.name, cloud.get_auth_args())

Once you have a working connection you can proceed to try out some Python SDK workflows.

 
©   Cornell University  |  Center for Advanced Computing  |  Copyright Statement  |  Inclusivity Statement