From 45cca0b2722e456a069b9716f64e40efd06a7f1a Mon Sep 17 00:00:00 2001 From: Dmitry Mescheryakov Date: Tue, 12 Mar 2013 17:37:45 +0400 Subject: [PATCH] Enhanced get_auth_token: It can get credentials and tenant from console It could be launched from any directory, not just project root --- tools/get_auth_token | 2 +- tools/get_auth_token.py | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/tools/get_auth_token b/tools/get_auth_token index 2bb84040..42b91350 100755 --- a/tools/get_auth_token +++ b/tools/get_auth_token @@ -1,3 +1,3 @@ #!/bin/bash -.venv/bin/python tools/get_auth_token.py +$(dirname $0)/../.venv/bin/python $(dirname $0)/get_auth_token.py $* diff --git a/tools/get_auth_token.py b/tools/get_auth_token.py index 415dcbb6..61ef6175 100644 --- a/tools/get_auth_token.py +++ b/tools/get_auth_token.py @@ -1,33 +1,54 @@ +import os.path, sys + from flask import Config from keystoneclient.v2_0 import Client as keystone_client def main(): - config = Config('etc') + if len(sys.argv) > 1 and len(sys.argv) != 4: + print "You must either specify no parameters or exactly 3: .\n" \ + "If you specify no parameters, credentials and tenant will be taken from config" + exit + + scriptDir = os.path.dirname(os.path.realpath(__file__)) + config = Config(scriptDir + '/../etc') config.from_pyfile('local.cfg') - print "Configuration has been loaded from 'etc/local.cfg': %s" % config + print "Configuration has been loaded from 'etc/local.cfg'" - user = config['OS_ADMIN_USER'] - password = config['OS_ADMIN_PASSWORD'] - tenant = config['OS_ADMIN_TENANT'] + if len(sys.argv) == 4: + user = sys.argv[1] + password = sys.argv[2] + tenant = sys.argv[3] + else: + print "You didn't provided credentials, using ones found in config" + user = config['OS_ADMIN_USER'] + password = config['OS_ADMIN_PASSWORD'] + tenant = config['OS_ADMIN_TENANT'] protocol = config['OS_AUTH_PROTOCOL'] host = config['OS_AUTH_HOST'] port = config['OS_AUTH_PORT'] + auth_url = "%s://%s:%s/v2.0/" % (protocol, host, port) + + print "User: %s" % user + print "Password: %s" % password + print "Tenant: %s" % tenant + print "Auth URL: %s" % auth_url + keystone = keystone_client( username=user, password=password, tenant_name=tenant, - auth_url="%s://%s:%s/v2.0/" % (protocol, host, port) + auth_url=auth_url ) result = keystone.authenticate() - print "Auth result: %s" % result + print "Auth succeed: %s" % result print "Auth token: %s" % keystone.auth_token - + print "Tenant [%s] id: %s" % (tenant, keystone.tenant_id) if __name__ == "__main__": main()