Interact with other OpenStack services

Interact with other OpenStack services

It’s very easy to interact with other OpenStack services in your function. Let’s take Python programming language and integration with Swift service for an example.

At the time you create a function, you specify an entry, which is a function in your code module that Qinling can invoke when the service executes your code. Use the following general syntax structure when creating a function in Python which will interact with Swift service in OpenStack.

import swiftclient

def main(region_name, container, object, context=None, **kwargs):
    conn = swiftclient.Connection(
        session=context['os_session'],
        os_options={'region_name': region_name},
    )

    obj_info = conn.head_object(container, object)
    return obj_info

In the above code, note the following:

  • Qinling supports most of OpenStack service clients, so you don’t need to install python-swiftclient in your code package.
  • There is a parameter named context, this is a parameter provided by Qinling that is usually of the Python dict type. You can easily get a valid Keystone session object from it. As a result, you don’t need to pass any sensitive data to Qinling in order to interact with OpenStack services.

Note

Please avoid using context as your own parameter in the code.

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.