28 Commits

Author SHA1 Message Date
Rohit Yadav
bbb2a56acb cli: refactoring, new grammar rules and command fixes
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-17 17:38:18 +05:30
Rohit Yadav
7ce53e89aa cli: make parse in posix mode
Posix mode allows the parse to:
- split by whitespace but value="between quotes are retained or enclose"
- quotes are stripped out

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-17 04:07:35 +05:30
Rohit Yadav
aa3ae45e6b CLOUDSTACK-499: Fix cloudmonkey's request and response methods
The old way of parsing involved complex object loading and traversing, in
new implementation json is used directly and authenticated requests via port
8080 making use of api and secret keys are recommended.

All args on shell are created in {"key": "value"} pairs which are used to create
url with &key=value. This way maps can be passed as args, example:

create networkoffering name=unique-name guestiptype=Isolated traffictype=GUEST
supportedservices=Dhcp,Dns serviceproviderlist[0].service=Dhcp
serviceproviderlist[0].provider=VirtualRouter serviceproviderlist[1].service=Dns
serviceproviderlist[1].provider=VirtualRouter

Added new conf variables:
- timeout: the no. of seconds after which an async job query timeouts
  default value of 3600 seconds
- asycnblock: if user wants their async commands to be tracked
  default value is 'true', if set to false, user can query using jobid which is
  returned by the async command and queried using:
     query asyncjobresult jobid=<jobid>

BUG-ID : CLOUDSTACK-499
Reviewed-by: Rohit Yadav <bhaisaab@apache.org>
Reported-by: Dave Cahill

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-16 22:18:32 +05:30
Rohit Yadav
08d16cf4d1 cli: Handle HTTP and URL errors
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-15 18:43:51 +05:30
Rohit Yadav
7ae8c4ad7e cli: Split using only space
Patch fixes lexical parser for default argument on shell.

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-15 18:43:51 +05:30
Rohit Yadav
c667eee570 cli: make commands pipe-able as on bash, on the shell
Makes commands pipe-able like bash.
Example while inside shell:
  > list virtualmachines | grep id
  > list accounts | more

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-08 12:35:20 +05:30
Rohit Yadav
8e64f34012 cli: autocomplete to assignment, adds syntactic sugar
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-07 18:34:23 +05:30
Rohit Yadav
a5ad9c3c50 cli: fix keyerror in help doc handler
- Check and then print help docs
- Add verb configure

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-07 16:05:01 +05:30
Rohit Yadav
36e7a7884e cli: fix autocompletion binding bug, make all params lowercase
- fix weird autocompletion bug which won't let you enter the letter b [0]
- make set params, api and secret key vars lowercase
- use partition to get strings for do_set
- while installing, check and only then add readline (requires gcc and can fail)
- show monkey prompt by default, let users change if needed

[0] http://superuser.com/questions/297527/cant-type-the-b-letter-in-python-shell-in-os-x

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-06 19:41:07 +05:30
Rohit Yadav
ac8ae30658 cli: fix argument parsing for set command, fixes unicode monkey char
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-06 17:59:53 +05:30
Rohit Yadav
77e957c91b cli: fix python sdist, add readline as installation requirement
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-06 17:06:11 +05:30
Rohit Yadav
a94f6f19bb cli: make parsing robust using shlex
Parsing bug fixed using the simple lexical analysis library

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-06 15:19:08 +05:30
Rohit Yadav
5c24c34d7f cli: use partition instead of split to parse through args
Use partition instead of splitting on whitespace. This is little robust, but
may still fail for parameters whose values have whitespaces such as names etc.

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-06 14:54:35 +05:30
Rohit Yadav
9e6b366023 cli: add autocompletion and dynamic help doc
- autocompletions for help docs
- more verbose doc strings with __doc__ import from the module and list of
  required args and all args

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-06 14:28:40 +05:30
Rohit Yadav
a1089c4304 cli: move code, refactor and add docstring
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-06 14:28:40 +05:30
Rohit Yadav
d0f9610355 cli: add feature to cache docstrings for an api
cached verb dictionary stores the following as a list:
- name of the API
- params (list of args)
- docstring

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-06 14:28:39 +05:30
Rohit Yadav
00d5c3f35c cli: fix help and doc strings, comments
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-06 14:28:39 +05:30
Rohit Yadav
c10eeb6036 cli: strip args else this fails on parsing
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-05 21:59:03 +05:30
Rohit Yadav
64907c1da4 cli: fix parsing args
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-05 21:59:03 +05:30
Rohit Yadav
c444bb3811 cli: don't get the required list as params
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-05 21:59:03 +05:30
Rohit Yadav
98d341d932 cli: add grammar to class
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-05 21:59:03 +05:30
Rohit Yadav
94649491be cli: fix color parsing
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-05 21:59:03 +05:30
Rohit Yadav
8c12f49dbe cli: fix intro message
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-05 21:59:03 +05:30
Rohit Yadav
5611a8eda2 cli: add logic to complete api parameters and use caching to optimize runtime
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-05 21:59:02 +05:30
Rohit Yadav
49b4786de6 cli: don't search rule in apis, filter apis that start with that rule
Search verb in apis takes more time than filtering out apis that start with
that verb from the grammar.

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-05 18:15:48 +05:30
Rohit Yadav
46ad8d6f4e cli: remind user to set host, port too
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-05 18:15:47 +05:30
Rohit Yadav
51a5377d05 cli: add more verbs to grammar
Adds additional verbs to grammar of cli

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-11-01 14:12:08 +05:30
Rohit Yadav
2ceaa3911e cli: cloudmonkey the command line interface
cloudmonkey
-----------
Apache CloudStack's very own monkey powered command line interface based on Marvin.
The neglected robot and monkey should rule the world!

Features:
- it's a shell and also a terminal tool
- scalable to find and run old and new APIs
- intuitive grammar and verbs
- autocompletion (functional hack)
- shell execution using ! or shell
- cfg support: user defined variables, like prompt, ruler, host, port etc.
- history
- colors
- dynamic API loading and rule generation
- leverages Marvin to get latest autogenerated APIs
- emacs like shortcuts on prompt
- uses apiKey and secretKey to interact with mgmt server
- logs all client commands
- PEP-8 compliant code

TODOs:
- Reverse search
- Fix input and output processing

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2012-10-31 23:19:14 +05:30