Last active
August 29, 2015 14:05
-
-
Save bartv/aaf1ee744dec7bc4fc8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import httplib, socket, sys, os | |
if len(sys.argv) != 2: | |
print("The first argument should be the path of the file with the user credentials") | |
sys.exit(2) | |
if not os.path.exists(sys.argv[1]): | |
print("Unable to read the credential file") | |
sys.exit(2) | |
lines = [] | |
with open(sys.argv[1], "r") as fd: | |
lines = fd.readlines() | |
if len(lines) != 2: | |
print("Invalid file") | |
sys.exit(2) | |
username = lines[0].strip() | |
password = lines[1].strip() | |
tenant = "openvpn" | |
body = '{"auth": {"tenantName": "%s", "passwordCredentials": {"username": "%s", "password": "%s"}}}' % (tenant, username, password) | |
# do the request | |
try: | |
conn = httplib.HTTPConnection("keystone.example.com", 5000) | |
conn.request("POST", "/v2.0/tokens", body = body, headers = { | |
"Content-Type" : "application/json", | |
"Accept" : "application/json", | |
"User-Agent": "python-httplib"}) | |
r1 = conn.getresponse() | |
if r1.status == 200: | |
sys.exit(0) | |
except socket.error as e: | |
print("Unable to connect to keystone") | |
sys.exit(10) | |
print("Authentication to openstack failed.") | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment