cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [3/3] git commit: requester: write to standard err if API fails
Date Fri, 03 Oct 2014 12:08:43 GMT
requester: write to standard err if API fails

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/commit/76bc92b5
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/76bc92b5
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/76bc92b5

Branch: refs/heads/master
Commit: 76bc92b59061290511d5ecf7eba1afb23508702b
Parents: 0981f6c
Author: Rohit Yadav <rohit.yadav@shapeblue.com>
Authored: Fri Oct 3 14:08:09 2014 +0200
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Fri Oct 3 14:08:09 2014 +0200

----------------------------------------------------------------------
 cloudmonkey/requester.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/76bc92b5/cloudmonkey/requester.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/requester.py b/cloudmonkey/requester.py
index 210b377..8e5e211 100644
--- a/cloudmonkey/requester.py
+++ b/cloudmonkey/requester.py
@@ -41,6 +41,11 @@ def logger_debug(logger, message):
         logger.debug(message)
 
 
+def writeError(msg):
+    sys.stderr.write(msg)
+    print msg
+
+
 def login(url, username, password):
     """
     Login and obtain a session to be used for subsequent API calls
@@ -60,18 +65,18 @@ def login(url, username, password):
     try:
         resp = session.post(url, params=args)
     except requests.exceptions.ConnectionError, e:
-        print "Connection refused by server"
+        writeError("Connection refused by server: %s" % e)
         return None, None
 
     if resp.status_code == 200:
         sessionkey = resp.json()['loginresponse']['sessionkey']
     elif resp.status_code == 405:
-        print "Method not allowed, unauthorized access on URL: %s" % url
+        writeError("Method not allowed, unauthorized access on URL: %s" % url)
         session = None
         sessionkey = None
     elif resp.status_code == 531:
-        print "Error authenticating at %s, with username: %s" \
-              ", and password: %s" % (url, username, password)
+        writeError("Error authenticating at %s using username: %s" \
+              ", and password: %s" % (url, username, password))
         session = None
         sessionkey = None
     else:
@@ -220,7 +225,7 @@ def monkeyrequest(command, args, isasync, asyncblock, logger, url,
             response = json.loads(str(response))
         except ValueError, e:
             logger_debug(logger, "Error processing json: %s" % e)
-            print "Error processing json:", str(e)
+            writeError("Error processing json: %s" % e)
             response = None
             error = e
         return response


Mime
View raw message