cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject cloudstack-cloudmonkey git commit: cloudmonkey: add -p option to allow overriding profile
Date Wed, 10 Dec 2014 11:28:22 GMT
Repository: cloudstack-cloudmonkey
Updated Branches:
  refs/heads/master c2c2524b3 -> 4f2f6c8b0


cloudmonkey: add -p option to allow overriding profile

- -p or --profile overrides current selected profile for cloudmonkey
- this won't write the new profile/selection to config thereby allowing many
  cloudmonkey instances run both in interpretor and bash modes with different
  profile sharing common ui and core config options

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/4f2f6c8b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/4f2f6c8b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/4f2f6c8b

Branch: refs/heads/master
Commit: 4f2f6c8b08f1352001c42403155f1fbbf13df1e8
Parents: c2c2524
Author: Rohit Yadav <rohit.yadav@shapeblue.com>
Authored: Wed Dec 10 16:44:32 2014 +0530
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Wed Dec 10 16:58:03 2014 +0530

----------------------------------------------------------------------
 CHANGES.md                 |  3 ++-
 cloudmonkey/cloudmonkey.py | 12 +++++++++---
 cloudmonkey/config.py      | 13 ++++++++++---
 3 files changed, 21 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/4f2f6c8b/CHANGES.md
----------------------------------------------------------------------
diff --git a/CHANGES.md b/CHANGES.md
index 225428a..0a68b16 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -12,6 +12,7 @@ This release includes
 - Pass verifysslcert option while user logs in using username/password
 - Importing readline no longer outputs escape characters
 - CloudMonkey will not output extra empty lines in stdout output
+- New command line arg: -p for profile
 
 Version 5.3.0
 =============
@@ -23,13 +24,13 @@ This release includes
 - Server profile related bugfixes, blank profile names are not allowed
 - Filtering support for default display output
 - Filtering by single key only outputs results without key names
-- New command line arg: -d for display (json, table or default)
 - Non-interactive commands from command line are outputted without colors
 - Parameter completion uses list api heuristics and related APIs as fallback
 - Parameter completion options are cached to speed up rendering of options
 - CloudMonkey returns non-zero exit code when run on shell and a error is return
   from managment server, the error message is written to stderr
 - Adds new config parameter 'verifysslcert' to enable/disable SSL cert checking
+- New command line arg: -d for display (json, table or default)
 
 Make sure you backup your config before you upgrade cloudmonkey from previous releases.
 With this release `cloudmonkey` will automatically fix your config file, add missing

http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/4f2f6c8b/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py
index b02393c..7981cb2 100644
--- a/cloudmonkey/cloudmonkey.py
+++ b/cloudmonkey/cloudmonkey.py
@@ -88,11 +88,13 @@ class CloudMonkeyShell(cmd.Cmd, object):
     port = "8080"
     path = "/client/api"
 
-    def __init__(self, pname, cfile):
+    def __init__(self, pname, cfile, profile=None):
         self.program_name = pname
         self.config_file = cfile
         self.config_options = read_config(self.get_attr, self.set_attr,
-                                          self.config_file)
+                                          self.config_file, profile)
+        if profile and profile.strip() != '':
+            self.profile = profile
         self.loadcache()
         self.init_credential_store()
         logging.basicConfig(filename=self.log_file,
@@ -754,13 +756,17 @@ def main():
                         help="output display type, json, table or default",
                         choices=tuple(displayTypes))
 
+    parser.add_argument("-p", "--profile",
+                        dest="serverProfile", default=None,
+                        help="override current server profile to use")
+
     parser.add_argument("commands", nargs=argparse.REMAINDER,
                         help="API commands")
 
     argcomplete.autocomplete(parser)
     args = parser.parse_args()
 
-    shell = CloudMonkeyShell(sys.argv[0], args.configFile)
+    shell = CloudMonkeyShell(sys.argv[0], args.configFile, args.serverProfile)
 
     if args.displayType and args.displayType in displayTypes:
         shell.set_attr("display", args.displayType)

http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/4f2f6c8b/cloudmonkey/config.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/config.py b/cloudmonkey/config.py
index c6bcc3a..7879e8c 100644
--- a/cloudmonkey/config.py
+++ b/cloudmonkey/config.py
@@ -91,7 +91,7 @@ def write_config(get_attr, config_file):
     if profile is None or profile == '':
         profile = default_profile_name
     if profile in mandatory_sections:
-        print "Server profile name cannot be", profile
+        print "Server profile name cannot be '%s'" % profile
         sys.exit(1)
 
     has_profile_changed = False
@@ -131,7 +131,7 @@ def write_config(get_attr, config_file):
     return config
 
 
-def read_config(get_attr, set_attr, config_file):
+def read_config(get_attr, set_attr, config_file, require_profile=None):
     global config_fields, config_dir, mandatory_sections
     global default_profile, default_profile_name
     if not os.path.exists(config_dir):
@@ -160,6 +160,12 @@ def read_config(get_attr, set_attr, config_file):
     else:
         global default_profile_name
         profile = default_profile_name
+
+    if require_profile and require_profile.strip() != '':
+        profile = require_profile
+    elif require_profile is not None:
+        print "Invalid profile, falling back to current profile"
+
     if profile is None or profile == '' or profile in mandatory_sections:
         print "Server profile cannot be", profile
         sys.exit(1)
@@ -168,7 +174,8 @@ def read_config(get_attr, set_attr, config_file):
                                      config.sections()))
 
     if not config.has_section(profile):
-        print "Selected profile (%s) does not exist, using defaults" % profile
+        print ("Selected profile (%s) does not exist," +
+               " using default values") % profile
         try:
             config.add_section(profile)
         except ValueError, e:


Mime
View raw message