summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-06-01 14:09:33 +0000
committerGerrit Code Review <review@openstack.org>2016-06-01 14:09:33 +0000
commit6ea67cd4580c5b76972d2b9273d9a65a2bc4afcf (patch)
tree38d783e1aeffe7e343e581082e8cfd18d349afa5
parent765c406c6927b9decc0faebf12e5d79f12014c18 (diff)
parent41ac1562b5a10f7dcbdd4131b56784763f40eb69 (diff)
downloados-client-config-6ea67cd4580c5b76972d2b9273d9a65a2bc4afcf.tar.gz
Merge "Add helper method for OpenStack SDK constructor"
-rw-r--r--README.rst37
-rw-r--r--os_client_config/__init__.py13
-rw-r--r--releasenotes/notes/sdk-helper-41f8d815cfbcfb00.yaml4
3 files changed, 54 insertions, 0 deletions
diff --git a/README.rst b/README.rst
index ff95c07..223fcfa 100644
--- a/README.rst
+++ b/README.rst
@@ -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
----------------------------------
diff --git a/os_client_config/__init__.py b/os_client_config/__init__.py
index be232fb..c88ccb2 100644
--- a/os_client_config/__init__.py
+++ b/os_client_config/__init__.py
@@ -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)
diff --git a/releasenotes/notes/sdk-helper-41f8d815cfbcfb00.yaml b/releasenotes/notes/sdk-helper-41f8d815cfbcfb00.yaml
new file mode 100644
index 0000000..a18b57d
--- /dev/null
+++ b/releasenotes/notes/sdk-helper-41f8d815cfbcfb00.yaml
@@ -0,0 +1,4 @@
+---
+features:
+ - Added helper method for constructing OpenStack SDK
+ Connection objects.