summaryrefslogtreecommitdiffstats
path: root/echo
diff options
context:
space:
mode:
authorJesse Andrews <anotherjesse@gmail.com>2011-04-24 23:30:35 -0700
committerJesse Andrews <anotherjesse@gmail.com>2011-04-24 23:30:35 -0700
commitf60dc8658f801088eefbc8aa66802bec44930036 (patch)
tree503796e62d130f6901f673ef06c67218035ed749 /echo
parent3ae7e740a14327acccb3e35c71c21b8f7914ed1e (diff)
downloadkeystone-f60dc8658f801088eefbc8aa66802bec44930036.tar.gz
keystone-f60dc8658f801088eefbc8aa66802bec44930036.tar.xz
keystone-f60dc8658f801088eefbc8aa66802bec44930036.zip
pythonizing
Diffstat (limited to 'echo')
-rw-r--r--echo/echo/echo.py5
-rw-r--r--echo/echo_client.py22
2 files changed, 14 insertions, 13 deletions
diff --git a/echo/echo/echo.py b/echo/echo/echo.py
index 5b6b571b..1219f877 100644
--- a/echo/echo/echo.py
+++ b/echo/echo/echo.py
@@ -20,12 +20,9 @@ import sys
import eventlet
from eventlet import wsgi
#from httplib2 import Http
+import json
from lxml import etree
from paste.deploy import loadapp
-try:
- import simplejson as json
-except ImportError:
- import json
import urllib
# If ../echo/__init__.py exists, add ../ to Python search path, so that
diff --git a/echo/echo_client.py b/echo/echo_client.py
index 61f0fbff..fc4b62fa 100644
--- a/echo/echo_client.py
+++ b/echo/echo_client.py
@@ -18,21 +18,26 @@ Implement a client for Echo service using Identity service
"""
import httplib
-import simplejson
+import json
def get_auth_token(username, password, tenant):
headers = {"Content-type": "application/json", "Accept": "text/json"}
- params = '{"passwordCredentials": { "username": "' + username + '", "password": "' + password + '", "tenantId": "1"}}'
+ params = {"passwordCredentials": {"username": username,
+ "password": password,
+ "tenantId": "1"}}
conn = httplib.HTTPConnection("localhost:8080")
- conn.request("POST", "/v1.0/token", params, headers=headers)
+ conn.request("POST", "/v1.0/token", json.dumps(params), headers=headers)
response = conn.getresponse()
data = response.read()
ret = data
return ret
+
def call_service(token):
- headers = {"X-Auth-Token": token, "Content-type": "application/json", "Accept": "text/json"}
+ headers = {"X-Auth-Token": token,
+ "Content-type": "application/json",
+ "Accept": "text/json"}
params = '{"ping": "abcdefg"}'
conn = httplib.HTTPConnection("localhost:8090")
conn.request("POST", "/", params, headers=headers)
@@ -42,13 +47,12 @@ def call_service(token):
return ret
if __name__ == '__main__':
- # Call the keystone service to get a token (assumes the test_setup.sql script has loaded this user)
+ # Call the keystone service to get a token
+ # NOTE: assumes the test_setup.sql script has loaded this user
auth = get_auth_token("joeuser", "secrete", "1")
- obj = simplejson.loads(auth)
+ obj = json.loads(auth)
token = obj["auth"]["token"]["id"]
print "Token:", token
-
- # Use that token to call an OpenStack service (we're using the Echo sample service for now)
+ # Use that token to call an OpenStack service (echo)
data = call_service(token)
print "Response:", data
- \ No newline at end of file