Add keystone get-token.py utility

+ Can be used to validate that you switched from uuid to fernet
  tokens on a cloud

Example usages:

(Get a token from the undercloud)
[stack@ospd utils]$ . ../../stackrc
[stack@ospd utils]$ ./get-token.py
b8b597133d3040b1ad87381591f9965c

(Get a token from the overcloud)
[stack@ospd utils]$ . ../../overcloudrc
[stack@ospd utils]$ ./get-token.py
5968d8c4149f443d8f3484e0b8353bfa

(Get a token from overcloud after adjusting to fernet tokens)
[stack@ospd utils]$ ./get-token.py
gAAAAABXhlqfbX0n0MtiBXDLk2WSk7XLc1cKzQ4Q6Xmb8MjGHgEFGYRu ...

Change-Id: Idfba4848b35e05023ea2a32bd830c5d0d50e685a
This commit is contained in:
Alex Krzos 2016-07-13 08:29:54 -04:00
parent 4dddfa019b
commit db61db310c

32
utils/get-token.py Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Gets a token using rc file credentials."""
from keystoneclient.v2_0 import client
import os
import sys
os_auth_url = os.environ.get('OS_AUTH_URL')
os_username = os.environ.get('OS_USERNAME')
os_password = os.environ.get('OS_PASSWORD')
if os_auth_url is None or os_username is None or os_password is None:
print "source rc file(stackrc/overcloudrc etc) before running."
sys.exit(1)
project_scoped = client.Client(
username=os_username,
password=os_password,
project_name='admin',
auth_url=os_auth_url)
print('%s' % project_scoped.auth_token)