qinling/doc/source/function_developer/openstack_integration.rst
Lingxian Kong b72d57c6c7 Correct devstack config in the doc
etcd service must be disabled in devstack environment.

Change-Id: I327653fb81e408d33327e56dbbc9770a7593f966
2017-09-26 01:08:45 +13:00

2.0 KiB

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.