summaryrefslogtreecommitdiffstats
path: root/yardstick/common/openstack_utils.py
diff options
context:
space:
mode:
authorJingLu5 <lvjing5@huawei.com>2016-12-13 05:42:41 +0000
committerJingLu5 <lvjing5@huawei.com>2016-12-13 12:13:06 +0000
commit99736a3882982aef0776f80056202ee745eb3fa4 (patch)
treed1dbbe7cab86e53eabc2f8483fcf815e07115260 /yardstick/common/openstack_utils.py
parent3c3ac5d9e89af36bb609017e69f6d03b52d8b251 (diff)
Add support for OpenSrack Newton
JIRA: YARDSTICK-410 This patch uses keystoneauth1.session to initialize the client for Heat The keystoneauth1.session.Session class was introduced into keystoneauth1 as an attempt to bring a unified interface to the various OpenStack clients that share common authentication and request parameters between a variety of services. Change-Id: Ie6287b50a36cf03950fa1174791df826e9bdafd3 Signed-off-by: JingLu5 <lvjing5@huawei.com>
Diffstat (limited to 'yardstick/common/openstack_utils.py')
-rw-r--r--yardstick/common/openstack_utils.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py
new file mode 100644
index 000000000..25dcffadd
--- /dev/null
+++ b/yardstick/common/openstack_utils.py
@@ -0,0 +1,97 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+# yardstick: this file is copied from rally and slightly modified
+##############################################################################
+
+import os
+import logging
+
+from keystoneauth1 import loading
+from keystoneauth1 import session
+
+log = logging.getLogger(__name__)
+
+DEFAULT_HEAT_API_VERSION = '1'
+
+
+def get_credentials():
+ """Returns a creds dictionary filled with parsed from env"""
+ creds = {}
+
+ keystone_api_version = os.getenv('OS_IDENTITY_API_VERSION')
+
+ if keystone_api_version is None or keystone_api_version == '2':
+ keystone_v3 = False
+ tenant_env = 'OS_TENANT_NAME'
+ tenant = 'tenant_name'
+ else:
+ keystone_v3 = True
+ tenant_env = 'OS_PROJECT_NAME'
+ tenant = 'project_name'
+
+ # The most common way to pass these info to the script is to do it
+ # through environment variables.
+ creds.update({
+ "username": os.environ.get("OS_USERNAME"),
+ "password": os.environ.get("OS_PASSWORD"),
+ "auth_url": os.environ.get("OS_AUTH_URL"),
+ tenant: os.environ.get(tenant_env)
+ })
+
+ if keystone_v3:
+ if os.getenv('OS_USER_DOMAIN_NAME') is not None:
+ creds.update({
+ "user_domain_name": os.getenv('OS_USER_DOMAIN_NAME')
+ })
+ if os.getenv('OS_PROJECT_DOMAIN_NAME') is not None:
+ creds.update({
+ "project_domain_name": os.getenv('OS_PROJECT_DOMAIN_NAME')
+ })
+
+ cacert = os.environ.get("OS_CACERT")
+
+ if cacert is not None:
+ # each openstack client uses differnt kwargs for this
+ creds.update({"cacert": cacert,
+ "ca_cert": cacert,
+ "https_ca_cert": cacert,
+ "https_cacert": cacert,
+ "ca_file": cacert})
+ creds.update({"insecure": "True", "https_insecure": "True"})
+ if not os.path.isfile(cacert):
+ log.info("WARNING: The 'OS_CACERT' environment variable is set\
+ to %s but the file does not exist." % cacert)
+
+ return creds
+
+
+def get_session_auth():
+ loader = loading.get_plugin_loader('password')
+ creds = get_credentials()
+ auth = loader.load_from_options(**creds)
+ return auth
+
+
+def get_session():
+ auth = get_session_auth()
+ return session.Session(auth=auth)
+
+
+def get_endpoint(service_type, endpoint_type='publicURL'):
+ auth = get_session_auth()
+ return get_session().get_endpoint(auth=auth,
+ service_type=service_type,
+ endpoint_type=endpoint_type)
+
+
+def get_heat_api_version():
+ api_version = os.getenv('HEAT_API_VERSION')
+ if api_version is not None:
+ log.info("HEAT_API_VERSION is set in env as '%s'", api_version)
+ return api_version
+ return DEFAULT_HEAT_API_VERSION