You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ch...@apache.org on 2013/10/17 03:02:50 UTC
git commit: Fix pep8 errors. Note: still has flake8 errors related to
unused imports and unused variables cloudmonkey.py:26:1: F401 'pdb' imported
but unused cloudmonkey.py:56:1: F401 'rlcompleter' imported but unused
cloudmonkey.py:177:1: F841 local var
Updated Branches:
refs/heads/username_password_support 08148ebbd -> 147ce1067
Fix pep8 errors.
Note: still has flake8 errors related to unused imports and unused variables
cloudmonkey.py:26:1: F401 'pdb' imported but unused
cloudmonkey.py:56:1: F401 'rlcompleter' imported but unused
cloudmonkey.py:177:1: F841 local variable 'myresults' is assigned to but never used
cloudmonkey.py:180:1: F821 undefined name 'x'
cloudmonkey.py:183:1: F821 undefined name 'x'
requester.py:24:1: F401 'httplib' imported but unused
requester.py:26:1: F401 'os' imported but unused
requester.py:27:1: F401 'pdb' imported but unused
requester.py:28:1: F401 're' imported but unused
requester.py:30:1: F401 'shlex' imported but unused
requester.py:33:1: F401 'types' imported but unused
requester.py:36:1: F401 'urlopen' imported but unused
requester.py:209:1: F841 local variable 'error' is assigned to but never used
Signed-off-by: Chiradeep Vittal <ch...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/commit/147ce106
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/147ce106
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/147ce106
Branch: refs/heads/username_password_support
Commit: 147ce1067f92e05638d1408727defe622b867104
Parents: 08148eb
Author: Chiradeep Vittal <ch...@apache.org>
Authored: Wed Oct 16 18:02:06 2013 -0700
Committer: Chiradeep Vittal <ch...@apache.org>
Committed: Wed Oct 16 18:02:06 2013 -0700
----------------------------------------------------------------------
cloudmonkey/cloudmonkey.py | 11 +++++------
cloudmonkey/requester.py | 24 +++++++++++++-----------
2 files changed, 18 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/147ce106/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py
index 9db225e..5a3d1b3 100644
--- a/cloudmonkey/cloudmonkey.py
+++ b/cloudmonkey/cloudmonkey.py
@@ -75,8 +75,9 @@ class CloudMonkeyShell(cmd.Cmd, object):
self.config_file = cfile
self.config_options = read_config(self.get_attr, self.set_attr,
self.config_file)
- self.credentials = {'apikey':self.apikey, 'secretkey': self.secretkey,
- 'username': self.username, 'password': self.password}
+ self.credentials = {'apikey': self.apikey, 'secretkey': self.secretkey,
+ 'username': self.username,
+ 'password': self.password}
self.loadcache()
self.prompt = self.prompt.strip() + " " # Cosmetic fix for prompt
@@ -94,7 +95,6 @@ class CloudMonkeyShell(cmd.Cmd, object):
logger.debug("Error: Unable to read history. " + str(e))
atexit.register(readline.write_history_file, self.history_file)
-
def get_attr(self, field):
return getattr(self, field)
@@ -421,7 +421,8 @@ class CloudMonkeyShell(cmd.Cmd, object):
def do_login(self, args):
"""
- Login using stored credentials. Starts a session to be reused for subsequent api calls
+ Login using stored credentials. Starts a session to be reused for
+ subsequent api calls
"""
url = "%s://%s:%s%s" % (self.protocol, self.host, self.port, self.path)
session, sessionkey = login(url, self.username, self.password)
@@ -437,7 +438,6 @@ class CloudMonkeyShell(cmd.Cmd, object):
self.credentials['session'] = None
self.credentials['sessionkey'] = None
-
def pipe_runner(self, args):
if args.find(' |') > -1:
pname = self.program_name
@@ -554,7 +554,6 @@ def main():
print __description__, "(%s)" % __projecturl__
sys.exit(0)
-
shell = CloudMonkeyShell(sys.argv[0], options.cfile)
if len(args) > 0:
http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/147ce106/cloudmonkey/requester.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/requester.py b/cloudmonkey/requester.py
index 93400e1..d5c78a8 100644
--- a/cloudmonkey/requester.py
+++ b/cloudmonkey/requester.py
@@ -65,15 +65,14 @@ def login(url, username, password):
resp = session.post(url, params=args)
if resp.status_code == 200:
sessionkey = resp.json()['loginresponse']['sessionkey']
- userid = resp.json()['loginresponse']['userid']
elif resp.status_code == 531:
- print "Error authenticating at %s, with username: %s, and password: %s" % (url, username, password)
+ print "Error authenticating at %s, with username: %s" \
+ ", and password: %s" % (url, username, password)
session = None
sessionkey = None
else:
resp.raise_for_status()
-
return session, sessionkey
@@ -82,6 +81,7 @@ def logout(url, session):
return
session.get(url, params={'command': 'logout'})
+
def make_request_with_password(command, args, logger, url, credentials):
error = None
@@ -100,7 +100,7 @@ def make_request_with_password(command, args, logger, url, credentials):
sessionkey = credentials.get('sessionkey')
session = credentials.get('session')
tries += 1
-
+
#obtain a valid session if not supplied
if not (session and sessionkey):
session, sessionkey = login(url, username, password)
@@ -110,25 +110,25 @@ def make_request_with_password(command, args, logger, url, credentials):
credentials['sessionkey'] = sessionkey
args['sessionkey'] = sessionkey
-
+
#make the api call
resp = session.get(url, params=args)
result = resp.text
logger_debug(logger, "Response received: %s" % resp.text)
- if resp.status_code == 200: #success
+ if resp.status_code == 200: # success
retry = False
break
- if resp.status_code == 401: #sessionkey is wrong
+ if resp.status_code == 401: # sessionkey is wrong
credentials['session'] = None
credentials['sessionkey'] = None
continue
if resp.status_code != 200 and resp.status_code != 401:
- error = "%s: %s" % (str(resp.status_code), resp.headers.get('X-Description'))
+ error = "%s: %s" %\
+ (str(resp.status_code), resp.headers.get('X-Description'))
result = None
retry = False
-
return result, error
@@ -152,7 +152,8 @@ def make_request(command, args, logger, host, port,
#if not present, use the username/password method
if not credentials['apikey']:
url = "%s://%s:%s%s" % (protocol, host, port, path)
- return make_request_with_password(command, args, logger, url, credentials)
+ return make_request_with_password(command, args,
+ logger, url, credentials)
args['apikey'] = credentials['apikey']
secretkey = credentials['secretkey']
@@ -193,7 +194,8 @@ def monkeyrequest(command, args, isasync, asyncblock, logger, host, port,
error = None
logger_debug(logger, "======== START Request ========")
logger_debug(logger, "Requesting command=%s, args=%s" % (command, args))
- response, error = make_request(command, args, logger, host, port, credentials, protocol, path)
+ response, error = make_request(command, args, logger, host,
+ port, credentials, protocol, path)
logger_debug(logger, "======== END Request ========\n")