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 2014/12/10 17:46:12 UTC
cloudstack-cloudmonkey git commit: cloudmonkey: fix server profile
loading using -p flag
Repository: cloudstack-cloudmonkey
Updated Branches:
refs/heads/master 4f2f6c8b0 -> aad3800f0
cloudmonkey: fix server profile loading using -p flag
Signed-off-by: Rohit Yadav <ro...@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/aad3800f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/aad3800f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/aad3800f
Branch: refs/heads/master
Commit: aad3800f0220e1cb9e5a21127c6fc5e7237aecb7
Parents: 4f2f6c8
Author: Rohit Yadav <ro...@shapeblue.com>
Authored: Wed Dec 10 22:15:42 2014 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Wed Dec 10 22:15:42 2014 +0530
----------------------------------------------------------------------
cloudmonkey/cloudmonkey.py | 17 ++++++++++-------
cloudmonkey/config.py | 7 +------
2 files changed, 11 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/aad3800f/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py
index 7981cb2..7880314 100644
--- a/cloudmonkey/cloudmonkey.py
+++ b/cloudmonkey/cloudmonkey.py
@@ -80,6 +80,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
config_options = []
profile_names = []
verbs = []
+ interpreterMode = False
error_on_last_command = False
param_cache = {}
prompt = "🐵 > "
@@ -88,13 +89,11 @@ class CloudMonkeyShell(cmd.Cmd, object):
port = "8080"
path = "/client/api"
- def __init__(self, pname, cfile, profile=None):
+ def __init__(self, pname, cfile):
self.program_name = pname
self.config_file = cfile
self.config_options = read_config(self.get_attr, self.set_attr,
- self.config_file, profile)
- if profile and profile.strip() != '':
- self.profile = profile
+ self.config_file)
self.loadcache()
self.init_credential_store()
logging.basicConfig(filename=self.log_file,
@@ -138,6 +137,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
pass
def cmdloop(self, intro=None):
+ interpreterMode = True
print(self.intro)
print "Using management server profile:", self.profile, "\n"
while True:
@@ -592,7 +592,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
write_config(self.get_attr, self.config_file)
read_config(self.get_attr, self.set_attr, self.config_file)
self.init_credential_store()
- if key.strip() == 'profile':
+ if key.strip() == 'profile' and self.interpreterMode:
print "\nLoaded server profile '%s' with options:" % value
for option in default_profile.keys():
value = self.get_attr(option)
@@ -758,7 +758,7 @@ def main():
parser.add_argument("-p", "--profile",
dest="serverProfile", default=None,
- help="override current server profile to use")
+ help="server profile to load")
parser.add_argument("commands", nargs=argparse.REMAINDER,
help="API commands")
@@ -766,11 +766,14 @@ def main():
argcomplete.autocomplete(parser)
args = parser.parse_args()
- shell = CloudMonkeyShell(sys.argv[0], args.configFile, args.serverProfile)
+ shell = CloudMonkeyShell(sys.argv[0], args.configFile)
if args.displayType and args.displayType in displayTypes:
shell.set_attr("display", args.displayType)
+ if args.serverProfile and args.serverProfile.strip() != '':
+ shell.do_set("profile %s" % args.serverProfile)
+
if len(args.commands) > 0:
shell.set_attr("color", "false")
commands = []
http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/aad3800f/cloudmonkey/config.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/config.py b/cloudmonkey/config.py
index 7879e8c..6840526 100644
--- a/cloudmonkey/config.py
+++ b/cloudmonkey/config.py
@@ -131,7 +131,7 @@ def write_config(get_attr, config_file):
return config
-def read_config(get_attr, set_attr, config_file, require_profile=None):
+def read_config(get_attr, set_attr, config_file):
global config_fields, config_dir, mandatory_sections
global default_profile, default_profile_name
if not os.path.exists(config_dir):
@@ -161,11 +161,6 @@ def read_config(get_attr, set_attr, config_file, require_profile=None):
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)