Skip to content

Instantly share code, notes, and snippets.

@toabctl
Created September 8, 2017 08:11
Show Gist options
  • Save toabctl/0dba262b9422c3d92e044dc83048db5a to your computer and use it in GitHub Desktop.
Save toabctl/0dba262b9422c3d92e044dc83048db5a to your computer and use it in GitHub Desktop.
Get a keystone token for time measurements
#!/usr/bin/python
# Copy that script to the node where keystone API is running.
# Use it with:
# PYTHONPATH=. python -m timeit -n 100 -r 1 -s "from keystone_token_get import do_get" "do_get()"
import requests
headers = {'Content-Type': 'application/json'}
data = """
{ "auth": {
"identity": {
"methods": ["password"],
"password": {
"user": {
"name": "admin",
"domain": { "id": "default" },
"password": "crowbar"
}
}
}
}
}
"""
def do_get():
r = requests.post(
'http://localhost:5000/v3/auth/tokens',
data=data,
headers=headers)
if r.status_code != 201:
raise Exception(r.status_code, r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment