Add helper method for OpenStack SDK constructor

openstacksdk already has a helper method for dealing with occ, but if a
user is already using the occ helper methods, there is no reason we
should not provide them an easy path to using the SDK.

Change-Id: I1040efb94385fdac0aa02ac960ba95089b954377
This commit is contained in:
Monty Taylor 2016-05-30 18:33:38 -04:00
parent 090a265669
commit 41ac1562b5
No known key found for this signature in database
GPG Key ID: 3390DB68041A12F0
3 changed files with 54 additions and 0 deletions

View File

@ -355,6 +355,43 @@ with - as well as a consumption argument.
cloud = cloud_config.get_one_cloud(argparse=options)
Constructing OpenStack SDK object
---------------------------------
If what you want to do is get an OpenStack SDK Connection and you want it to
do all the normal things related to clouds.yaml, `OS_` environment variables,
a helper function is provided. The following will get you a fully configured
`openstacksdk` instance.
.. code-block:: python
import os_client_config
sdk = os_client_config.make_sdk()
If you want to do the same thing but on a named cloud.
.. code-block:: python
import os_client_config
sdk = os_client_config.make_sdk(cloud='mtvexx')
If you want to do the same thing but also support command line parsing.
.. code-block:: python
import argparse
import os_client_config
sdk = os_client_config.make_sdk(options=argparse.ArgumentParser())
It should be noted that OpenStack SDK has ways to construct itself that allow
for additional flexibility. If the helper function here does not meet your
needs, you should see the `from_config` method of
`openstack.connection.Connection <http://developer.openstack.org/sdks/python/openstacksdk/users/guides/connect_from_config.html>`_
Constructing Legacy Client objects
----------------------------------

View File

@ -67,3 +67,16 @@ def make_client(service_key, constructor=None, options=None, **kwargs):
if not constructor:
constructor = cloud_config._get_client(service_key)
return cloud.get_legacy_client(service_key, constructor)
def make_sdk(options=None, **kwargs):
"""Simple wrapper for getting an OpenStack SDK Connection.
For completeness, provide a mechanism that matches make_client and
session_client. The heavy lifting here is done in openstacksdk.
:rtype: :class:`~openstack.connection.Connection`
"""
from openstack import connection
cloud = get_config(options=options, **kwargs)
return connection.from_config(cloud_config=cloud, options=options)

View File

@ -0,0 +1,4 @@
---
features:
- Added helper method for constructing OpenStack SDK
Connection objects.