2525 import logging
2626 import os
2727 import pdb
28- import readline
29- import rlcompleter
3028 import shlex
3129 import sys
3230 import types
3331
3432 from clint .textui import colored
3533 from ConfigParser import ConfigParser , SafeConfigParser
3634
35+ from version import __version__
3736 from marvin .cloudstackConnection import cloudConnection
3837 from marvin .cloudstackException import cloudstackAPIException
3938 from marvin .cloudstackAPI import *
4342 import sys
4443 sys .exit ()
4544
46- # Use following rules for versioning:
47- # <cli major version>.<cloudstack minor version>.<cloudstack major version>
48- # Example: For CloudStack 4.1.x, CLI version should be 0.1.4
49- __version__ = "0.0.4"
45+ # Fix autocompletion issue, can be put in .pythonstartup
46+ try :
47+ import readline
48+ except ImportError , e :
49+ print "Module readline not found, autocompletions will fail" , e
50+ else :
51+ import rlcompleter
52+ if 'libedit' in readline .__doc__ :
53+ readline .parse_and_bind ("bind ^I rl_complete" )
54+ else :
55+ readline .parse_and_bind ("tab: complete" )
5056
5157log_fmt = '%(asctime)s - %(filename)s:%(lineno)s - [%(levelname)s] %(message)s'
5258logger = logging .getLogger (__name__ )
@@ -65,8 +71,8 @@ class CloudStackShell(cmd.Cmd):
6571
6672 def __init__ (self ):
6773 self .config_fields = {'host' : 'localhost' , 'port' : '8080' ,
68- 'apiKey ' : '' , 'secretKey ' : '' ,
69- 'prompt' : 'cloudmonkey> ' , 'color' : 'true' ,
74+ 'apikey ' : '' , 'secretkey ' : '' ,
75+ 'prompt' : '🐵 cloudmonkey>' , 'color' : 'true' ,
7076 'log_file' :
7177 os .path .expanduser ('~/.cloudmonkey_log' ),
7278 'history_file' :
@@ -77,7 +83,7 @@ def __init__(self):
7783 for key in self .config_fields .keys ():
7884 setattr (self , key , self .config_fields [key ])
7985 config = self .write_config ()
80- print ("🐵 Set your apiKey, secretKey , host, port, prompt, color,"
86+ print ("Set your apikey, secretkey , host, port, prompt, color,"
8187 " log_file, history_file using the set command!" )
8288
8389 for key in self .config_fields .keys ():
@@ -93,12 +99,6 @@ def __init__(self):
9399 if not os .path .exists (self .config_file ):
94100 config = self .write_config ()
95101
96- # Fix autocompletion issue
97- if sys .platform == "darwin" :
98- readline .parse_and_bind ("bind ^I rl_complete" )
99- else :
100- readline .parse_and_bind ("tab: complete" )
101-
102102 # Enable history support
103103 try :
104104 if os .path .exists (self .history_file ):
@@ -204,7 +204,7 @@ def print_result_as_instance(node):
204204
205205 def make_request (self , command , requests = {}):
206206 conn = cloudConnection (self .host , port = int (self .port ),
207- apiKey = self .apiKey , securityKey = self .secretKey ,
207+ apiKey = self .apikey , securityKey = self .secretkey ,
208208 logging = logging .getLogger ("cloudConnection" ))
209209 try :
210210 response = conn .make_request (command , requests )
@@ -317,28 +317,25 @@ def complete_api(self, text, line, begidx, endidx):
317317 def do_set (self , args ):
318318 """
319319 Set config for CloudStack CLI. Available options are:
320- host, port, apiKey, secretKey , log_file, history_file
320+ host, port, apikey, secretkey , log_file, history_file
321321 You may also edit your ~/.cloudmonkey_config instead of using set.
322322
323323 Example:
324324 set host 192.168.56.2
325325 set prompt 🐵 cloudmonkey>
326326 set log_file /var/log/cloudmonkey.log
327327 """
328- args = shlex .split (args .strip ())
329- if len (args ) == 2 :
330- key , value = args
331- # Note: keys and fields should have same names
332- setattr (self , key , value )
333- self .write_config ()
334- else :
335- self .print_shell ("Please use the syntax: set valid-key value" )
328+ args = args .strip ().partition (" " )
329+ key , value = (args [0 ], args [2 ])
330+ # Note: keys and class attributes should have same names
331+ setattr (self , key , value )
332+ self .write_config ()
336333
337334 def complete_set (self , text , line , begidx , endidx ):
338335 mline = line .partition (" " )[2 ]
339336 offs = len (mline ) - len (text )
340337 return [s [offs :] for s in
341- ['host' , 'port' , 'apiKey ' , 'secretKey ' , 'prompt' , 'color' ,
338+ ['host' , 'port' , 'apikey ' , 'secretkey ' , 'prompt' , 'color' ,
342339 'log_file' , 'history_file' ] if s .startswith (mline )]
343340
344341 def do_shell (self , args ):
0 commit comments