You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2012/11/20 07:54:17 UTC

git commit: CLOUDSTACK-522: Log requests in cloudmonkey's log

Updated Branches:
  refs/heads/master 51784362e -> 5a2e15f67


CLOUDSTACK-522: Log requests in cloudmonkey's log

Patch fixes cloudmonkey to log requests in the log_file.
Summary:
  - Fixes logger
  - Fixes color print issue
  - Fixes welcome message
  - Makes code pep8 compliant

BUG-ID : CLOUDSTACK-522
Reviewed-by: Rohit Yadav <bh...@apache.org>
Reported-by: Rohit Yadav

Signed-off-by: Rohit Yadav <bh...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/5a2e15f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/5a2e15f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/5a2e15f6

Branch: refs/heads/master
Commit: 5a2e15f67caf7ab2f804ece42eea216ee883660d
Parents: 5178436
Author: Rohit Yadav <bh...@apache.org>
Authored: Tue Nov 20 12:20:23 2012 +0530
Committer: Rohit Yadav <bh...@apache.org>
Committed: Tue Nov 20 12:20:23 2012 +0530

----------------------------------------------------------------------
 tools/cli/cloudmonkey/cloudmonkey.py |   23 +++++++++++------------
 tools/cli/cloudmonkey/common.py      |    2 +-
 2 files changed, 12 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5a2e15f6/tools/cli/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py
index f0672d5..4904a64 100644
--- a/tools/cli/cloudmonkey/cloudmonkey.py
+++ b/tools/cli/cloudmonkey/cloudmonkey.py
@@ -81,13 +81,14 @@ class CloudStackShell(cmd.Cmd):
             for key in self.config_fields.keys():
                 setattr(self, key, self.config_fields[key])
             config = self.write_config()
-            print("Set your apikey, secretkey, host, port, prompt,"
-                  " protocol, path, color, log_file and history_file"
-                  " using the set command!")
+            print "Welcome! Using `set` configure the necessary settings"
+            print " ".join(sorted(self.config_fields.keys()))
+            print "For debugging, tail -f", self.log_file, "\n"
 
         for key in self.config_fields.keys():
             try:
                 setattr(self, key, config.get('CLI', key))
+                self.config_fields[key] = config.get('CLI', key)
             except Exception:
                 print "Please fix `%s` config in %s" % (key, self.config_file)
                 sys.exit()
@@ -95,6 +96,7 @@ class CloudStackShell(cmd.Cmd):
         self.prompt += " "  # Cosmetic fix for prompt
         logging.basicConfig(filename=self.log_file,
                             level=logging.DEBUG, format=log_fmt)
+        logger.debug("Loaded config fields:\n%s" % self.config_fields)
 
         cmd.Cmd.__init__(self)
         # Update config if config_file does not exist
@@ -114,10 +116,6 @@ class CloudStackShell(cmd.Cmd):
         try:
             with open(self.config_file, 'r') as cfg:
                 config.readfp(cfg)
-            for section in config.sections():
-                for option in config.options(section):
-                    logger.debug("[%s] %s=%s" % (section, option,
-                                                 config.get(section, option)))
         except IOError, e:
             self.print_shell("Error: config_file not found", e)
         return config
@@ -143,6 +141,8 @@ class CloudStackShell(cmd.Cmd):
                 if self.color == 'true':
                     if str(arg).count(self.ruler) == len(str(arg)):
                         print colored.green(arg),
+                    elif 'Error' in arg:
+                        print colored.red(arg),
                     elif ":\n=" in arg:
                         print colored.red(arg),
                     elif ':' in arg:
@@ -155,8 +155,6 @@ class CloudStackShell(cmd.Cmd):
                         print colored.cyan(arg),
                     elif 'name =' in arg:
                         print colored.magenta(arg),
-                    elif 'Error' in arg:
-                        print colored.red(arg),
                     else:
                         print arg,
                 else:
@@ -199,16 +197,17 @@ class CloudStackShell(cmd.Cmd):
                                asyncTimeout=self.timeout, logging=logger,
                                protocol=self.protocol, path=self.path)
         response = None
+        logger.debug("====START Request====")
+        logger.debug("Requesting command=%s, args=%s" % (command, requests))
         try:
-            self.print_shell("Starting call")
             response = conn.make_request_with_auth(command, requests)
-            self.print_shell("Ending call")
         except cloudstackAPIException, e:
             self.print_shell("API Error:", e)
         except HTTPError, e:
             self.print_shell(e)
         except URLError, e:
             self.print_shell("Connection Error:", e)
+        logger.debug("====END Request====\n")
 
         def process_json(response):
             try:
@@ -489,7 +488,7 @@ def main():
                     res = self.cache_verbs[rule][args_partition[0]]
 
                 except KeyError, e:
-                    self.print_shell("Error: no such command on %s" % rule)
+                    self.print_shell("Error: invalid %s api arg" % rule, e)
                     return
                 if ' --help' in args or ' -h' in args:
                     self.print_shell(res[2])

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5a2e15f6/tools/cli/cloudmonkey/common.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/common.py b/tools/cli/cloudmonkey/common.py
index a6f3a77..0799017 100644
--- a/tools/cli/cloudmonkey/common.py
+++ b/tools/cli/cloudmonkey/common.py
@@ -30,7 +30,7 @@ except ImportError, e:
 # Add config key:value
 config_file = os.path.expanduser('~/.cloudmonkey_config')
 config_fields = {'host': 'localhost', 'port': '8080',
-                 'protocol': 'http', 'path': '/client/api', 
+                 'protocol': 'http', 'path': '/client/api',
                  'apikey': '', 'secretkey': '',
                  'timeout': '3600', 'asyncblock': 'true',
                  'prompt': '🐵 cloudmonkey>', 'color': 'true',