diff options
author | Linda Wang <wangwulin@huawei.com> | 2017-05-18 01:53:18 +0000 |
---|---|---|
committer | Linda Wang <wangwulin@huawei.com> | 2017-05-19 07:16:25 +0000 |
commit | 8d8af3c360b360c982b44ba343a97cf5949c8c20 (patch) | |
tree | 6b34aa85679d88c635404657d8ac03f9247ec687 /snaps/openstack/utils/keystone_utils.py | |
parent | 956acc7da293b931c3e21e64fa0a9011f995c11c (diff) |
Add the function of getting endpoint
Functest is trying to leverage SNAPS-OO library to replace some
utility functions, in which def get_endpoint is called by testcases
onos, odl, multisite and cloudify_ims.
JIRA: SNAPS-78
Change-Id: Icb2778e0337a5d4246762ac3037773b39d5d554d
Signed-off-by: Linda Wang <wangwulin@huawei.com>
Diffstat (limited to 'snaps/openstack/utils/keystone_utils.py')
-rw-r--r-- | snaps/openstack/utils/keystone_utils.py | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/snaps/openstack/utils/keystone_utils.py b/snaps/openstack/utils/keystone_utils.py index 8175b9a..622481c 100644 --- a/snaps/openstack/utils/keystone_utils.py +++ b/snaps/openstack/utils/keystone_utils.py @@ -24,6 +24,27 @@ logger = logging.getLogger('keystone_utils') V2_VERSION = 'v2.0' +def get_session_auth(os_creds): + """ + Return the session auth for keystone session + :param os_creds: the OpenStack credentials (OSCreds) object + :return: the auth + """ + if os_creds.identity_api_version == 3: + auth = v3.Password(auth_url=os_creds.auth_url, + username=os_creds.username, + password=os_creds.password, + project_name=os_creds.project_name, + user_domain_id=os_creds.user_domain_id, + project_domain_id=os_creds.project_domain_id) + else: + auth = v2.Password(auth_url=os_creds.auth_url, + username=os_creds.username, + password=os_creds.password, + tenant_name=os_creds.project_name) + return auth + + def keystone_session(os_creds): """ Creates a keystone session used for authenticating OpenStack clients @@ -32,13 +53,7 @@ def keystone_session(os_creds): """ logger.debug('Retrieving Keystone Session') - if os_creds.identity_api_version == 3: - auth = v3.Password(auth_url=os_creds.auth_url, username=os_creds.username, password=os_creds.password, - project_name=os_creds.project_name, user_domain_id=os_creds.user_domain_id, - project_domain_id=os_creds.project_domain_id) - else: - auth = v2.Password(auth_url=os_creds.auth_url, username=os_creds.username, password=os_creds.password, - tenant_name=os_creds.project_name) + auth = get_session_auth(os_creds) req_session = None if os_creds.proxy_settings: @@ -56,6 +71,20 @@ def keystone_client(os_creds): return Client(version=os_creds.identity_api_version, session=keystone_session(os_creds)) +def get_endpoint(os_creds, service_type, endpoint_type='publicURL'): + """ + Returns the endpoint of specific service + :param os_creds: the OpenStack credentials (OSCreds) object + :param service_type: the type of specific service + :param endpoint_type: the type of endpoint + :return: the endpoint url + """ + auth = get_session_auth(os_creds) + return keystone_session(os_creds).get_endpoint(auth=auth, + service_type=service_type, + endpoint_type=endpoint_type) + + def get_project(keystone=None, os_creds=None, project_name=None): """ Returns the first project object or None if not found |