cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From muralire...@apache.org
Subject [37/50] [abbrv] git commit: refs/heads/gslb-wip - CLOUDSTACK-1708: Let cloudmonkey accept cfg passed in cmd line
Date Wed, 20 Mar 2013 01:41:17 GMT
CLOUDSTACK-1708: Let cloudmonkey accept cfg passed in cmd line

The patch adds feature in cloudmonkey to have multiple profiles by passing
custom cfg file to set custom profile in both interactive shell and cmd line tool
use cases.

Signed-off-by: Rohit Yadav <bhaisaab@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/4421f2bb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/4421f2bb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/4421f2bb

Branch: refs/heads/gslb-wip
Commit: 4421f2bb60ea44a6b28593eb7e0254d5108919ff
Parents: e28aa09
Author: Rohit Yadav <bhaisaab@apache.org>
Authored: Tue Mar 19 15:49:42 2013 +0530
Committer: Rohit Yadav <bhaisaab@apache.org>
Committed: Tue Mar 19 16:05:11 2013 +0530

----------------------------------------------------------------------
 tools/cli/cloudmonkey/cloudmonkey.py |   47 ++++++++++++++++++++++++-----
 1 files changed, 39 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4421f2bb/tools/cli/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py
index 2542241..f88632d 100644
--- a/tools/cli/cloudmonkey/cloudmonkey.py
+++ b/tools/cli/cloudmonkey/cloudmonkey.py
@@ -29,8 +29,9 @@ try:
     import types
 
     from cachemaker import loadcache, savecache, monkeycache, splitverbsubject
-    from config import __version__, cache_file
-    from config import read_config, write_config
+    from config import __version__, __description__, __projecturl__
+    from config import read_config, write_config, config_file
+    from optparse import OptionParser
     from prettytable import PrettyTable
     from printer import monkeyprint
     from requester import monkeyrequest
@@ -63,13 +64,14 @@ class CloudMonkeyShell(cmd.Cmd, object):
     intro = ("☁ Apache CloudStack 🐵 cloudmonkey " + __version__ +
              ". Type help or ? to list commands.\n")
     ruler = "="
-    cache_file = cache_file
     config_options = []
     verbs = []
 
-    def __init__(self, pname):
+    def __init__(self, pname, cfile):
         self.program_name = pname
-        self.config_options = read_config(self.get_attr, self.set_attr)
+        self.config_file = cfile
+        self.config_options = read_config(self.get_attr, self.set_attr,
+                                          self.config_file)
         self.loadcache()
         self.prompt = self.prompt.strip() + " "  # Cosmetic fix for prompt
 
@@ -364,7 +366,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
         key, value = (args[0], args[2])
         setattr(self, key, value)  # keys and attributes should have same names
         self.prompt = self.prompt.strip() + " "  # prompt fix
-        write_config(self.get_attr)
+        write_config(self.get_attr, self.config_file)
 
     def complete_set(self, text, line, begidx, endidx):
         mline = line.partition(" ")[2]
@@ -458,10 +460,39 @@ class CloudMonkeyShell(cmd.Cmd, object):
         return self.do_EOF(args)
 
 
+class MonkeyParser(OptionParser):
+    def format_help(self, formatter=None):
+        if formatter is None:
+            formatter = self.formatter
+        result = []
+        if self.usage:
+            result.append("Usage: cloudmonkey [options] [cmds] [params]\n\n")
+        if self.description:
+            result.append(self.format_description(formatter) + "\n")
+        result.append(self.format_option_help(formatter))
+        result.append("\nTry cloudmonkey [help|?]\n")
+        return "".join(result)
+
+
 def main():
-    shell = CloudMonkeyShell(sys.argv[0])
+    parser = MonkeyParser()
+    parser.add_option("-c", "--config-file",
+                      dest="cfile", default=config_file,
+                      help="config file for cloudmonkey", metavar="FILE")
+    parser.add_option("-v", "--version",
+                      action="store_true", dest="version", default=False,
+                      help="prints cloudmonkey version information")
+
+    (options, args) = parser.parse_args()
+    print 'args', args
+    print 'options', options
+    if options.version:
+        print "cloudmonkey", __version__
+        print __description__, "(%s)" % __projecturl__
+
+    shell = CloudMonkeyShell(sys.argv[0], options.cfile)
     if len(sys.argv) > 1:
-        shell.onecmd(' '.join(sys.argv[1:]))
+        shell.onecmd(' '.join(args))
     else:
         shell.cmdloop()
 


Mime
View raw message