You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2021/11/03 17:34:17 UTC

[libcloud] 03/05: OpenStack authentication token cache example

This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit 532aa1f3e92c666db743b91aed45c1e0a8aa1556
Author: Dan Peschman <dp...@godaddy.com>
AuthorDate: Wed May 5 14:18:34 2021 -0700

    OpenStack authentication token cache example
---
 docs/compute/drivers/openstack.rst            | 22 ++++++++++++++++++++--
 docs/examples/compute/openstack/auth_cache.py | 18 ++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/docs/compute/drivers/openstack.rst b/docs/compute/drivers/openstack.rst
index 78fd019..4922b71 100644
--- a/docs/compute/drivers/openstack.rst
+++ b/docs/compute/drivers/openstack.rst
@@ -2,7 +2,7 @@ OpenStack Compute Driver Documentation
 ======================================
 
 `OpenStack`_ is an open-source project which allows you to build and run your
-own public or a private cloud.
+own public or private cloud.
 
 .. figure:: /_static/images/provider_logos/openstack.png
     :align: center
@@ -100,7 +100,7 @@ Available arguments:
   driver obtains API endpoint URL from the server catalog, but if this argument
   is provided, this step is skipped and the provided value is used directly. Only valid 
   in case of api_version >= 2.0.
-  * ``ex_force_volume_url`` - Base URL to the OpenStack cinder API endpoint. By default,
+* ``ex_force_volume_url`` - Base URL to the OpenStack cinder API endpoint. By default,
   driver obtains API endpoint URL from the server catalog, but if this argument
   is provided, this step is skipped and the provided value is used directly. Only valid 
   in case of api_version >= 2.0.
@@ -179,6 +179,21 @@ public cloud providers support it.
    :language: python
 .. _`Cloud-Init examples`: http://cloudinit.readthedocs.org/en/latest/topics/examples.html
 
+8. Authentication token cache
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Since version ???, authentication tokens can be stored in an external cache.
+This enables multiple processes to reuse the tokens, reducing the number of
+token allocations in the OpenStack authentication service.
+
+.. literalinclude:: /examples/compute/openstack/auth_cache.py
+   :language: python
+
+If the cache implementation stores tokens somewhere outside the process - for
+instance, to disk or a remote system - running this program twice will
+allocate a token from OpenStack, store it in the cache, then reuse that token
+on the second run.
+
 Non-standard functionality and extension methods
 ------------------------------------------------
 
@@ -210,6 +225,9 @@ token on the first request or if the auth token is about to expire.
 As noted in the example 4 above, this doesn't hold true if you use
 ``ex_force_auth_token`` argument.
 
+Tokens can also be stored in an external cache for shared use among multiple
+processes; see example 8 above.
+
 Troubleshooting
 ---------------
 
diff --git a/docs/examples/compute/openstack/auth_cache.py b/docs/examples/compute/openstack/auth_cache.py
new file mode 100644
index 0000000..1da4fb9
--- /dev/null
+++ b/docs/examples/compute/openstack/auth_cache.py
@@ -0,0 +1,18 @@
+from libcloud.common.openstack_identity import OpenStackAuthenticationCache
+from libcloud.compute.types import Provider
+from libcloud.compute.providers import get_driver
+
+
+class MyAuthenticationCache(OpenStackAuthenticationCache):
+    pass  # implement...
+
+
+auth_cache = MyAuthenticationCache(...)
+
+OpenStack = get_driver(Provider.OPENSTACK)
+driver = OpenStack('your_auth_username', 'your_auth_password',
+                   ex_force_auth_url='http://192.168.1.101:5000',
+                   ex_force_auth_version='3.x_password',
+                   ex_auth_cache=auth_cache)
+
+driver.list_sizes()