From 1a7552f40095904d8aa1bacd51ac8962717cad91 Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Sun, 28 Feb 2016 08:59:43 -0600 Subject: [PATCH] Update Client examples to use sessions The docstring examples in the v2_0 and v3 Client classes showed passing username and password. Passing username and password is deprecated in favor of using keystoneauth session. The examples shouldn't use deprecated behavior otherwise we'll never get developers to stop using it. Change-Id: Ia79ed7a02a48553eba8eb83a654c3c75601fa07d --- keystoneclient/v2_0/client.py | 35 +++++++++++++++++++++++------------ keystoneclient/v3/client.py | 17 ++++++++++------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/keystoneclient/v2_0/client.py b/keystoneclient/v2_0/client.py index 7553164ff..393f12c60 100644 --- a/keystoneclient/v2_0/client.py +++ b/keystoneclient/v2_0/client.py @@ -93,11 +93,15 @@ class Client(httpclient.HTTPClient): Example:: + >>> from keystoneauth1.identity import v2 + >>> from keystoneauth1 import session >>> from keystoneclient.v2_0 import client - >>> keystone = client.Client(username=USER, - ... password=PASS, - ... tenant_name=TENANT_NAME, - ... auth_url=KEYSTONE_URL) + >>> auth = v2.Password(auth_url=KEYSTONE_URL, + ... username=USER, + ... password=PASS, + ... tenant_name=TENANT_NAME) + >>> sess = session.Session(auth=auth) + >>> keystone = client.Client(session=sess) >>> keystone.tenants.list() ... >>> user = keystone.users.get(USER_ID) @@ -108,11 +112,15 @@ class Client(httpclient.HTTPClient): returns as a dictionary-like-object so that you can export and cache it, re-using it when initiating another client:: + >>> from keystoneauth1.identity import v2 + >>> from keystoneauth1 import session >>> from keystoneclient.v2_0 import client - >>> keystone = client.Client(username=USER, - ... password=PASS, - ... tenant_name=TENANT_NAME, - ... auth_url=KEYSTONE_URL) + >>> auth = v2.Password(auth_url=KEYSTONE_URL, + ... username=USER, + ... password=PASS, + ... tenant_name=TENANT_NAME) + >>> sess = session.Session(auth=auth) + >>> keystone = client.Client(session=sess) >>> auth_ref = keystone.auth_ref >>> # pickle or whatever you like here >>> new_client = client.Client(auth_ref=auth_ref) @@ -124,11 +132,14 @@ class Client(httpclient.HTTPClient): Example:: + >>> from keystoneauth1.identity import v2 + >>> from keystoneauth1 import session >>> from keystoneclient.v2_0 import client - >>> admin_client = client.Client( - ... token='12345secret7890', - ... endpoint='http://localhost:35357/v2.0') - >>> admin_client.tenants.list() + >>> auth = v2.Token(auth_url='http://localhost:35357/v2.0', + ... token='12345secret7890') + >>> sess = session.Session(auth=auth) + >>> keystone = client.Client(session=sess) + >>> keystone.tenants.list() """ diff --git a/keystoneclient/v3/client.py b/keystoneclient/v3/client.py index 38be932eb..759783494 100644 --- a/keystoneclient/v3/client.py +++ b/keystoneclient/v3/client.py @@ -92,14 +92,17 @@ class Client(httpclient.HTTPClient): Example:: + >>> from keystoneauth1.identity import v3 + >>> from keystoneauth1 import session >>> from keystoneclient.v3 import client - >>> keystone = client.Client(user_domain_name=DOMAIN_NAME, - ... username=USER, - ... password=PASS, - ... project_domain_name=PROJECT_DOMAIN_NAME, - ... project_name=PROJECT_NAME, - ... auth_url=KEYSTONE_URL) - ... + >>> auth = v3.Password(user_domain_name=DOMAIN_NAME, + ... username=USER, + ... password=PASS, + ... project_domain_name=PROJECT_DOMAIN_NAME, + ... project_name=PROJECT_NAME, + ... auth_url=KEYSTONE_URL) + >>> sess = session.Session(auth=auth) + >>> keystone = client.Client(session=sess) >>> keystone.projects.list() ... >>> user = keystone.users.get(USER_ID)