On 01-Nov-2012, at 4:40 AM, Edison Su <edison...@citrix.com> wrote:

> Never mind, this stuff can be done in python. Seems we just need to override 
> completedefault in cmd, then get parameters for the API from the python files 
> generated by marvin.

Yes, we're overriding completedefault on cmd.Cmd. Please let me know if it 
won't work for you, probably it won't if you've incorrect 
readline.parse_and_bind for your environment.

--
Rohit

> 
>> -----Original Message-----
>> From: Frank Zhang [mailto:frank.zh...@citrix.com]
>> Sent: Wednesday, October 31, 2012 2:51 PM
>> To: cloudstack-dev@incubator.apache.org
>> Subject: RE: CLI for CloudStack: cloudmonkey
>> 
>> Then you cite a wrong example in your former mail. You stated:
>> 
>>>>> Seems doesn't support auto-completion for api parameters?
>>>>> 
>>>>> 🙉 cloudmonkey> api listUsers
>> 
>> This is running in cloudmonkey's terminal, what xe does is in native bash
>> terminal.
>> if you want native command line, bash-auto-completion is your friend. But
>> my reply is for your former mail which refers to cloudmonkey's terminal.
>> 
>>> -----Original Message-----
>>> From: Edison Su [mailto:edison...@citrix.com]
>>> Sent: Wednesday, October 31, 2012 2:46 PM
>>> To: cloudstack-dev@incubator.apache.org
>>> Subject: RE: CLI for CloudStack: cloudmonkey
>>> 
>>> Xenserver xe cli works great, and it uses bash auto completion. I
>>> don't see any difference between xe cli and cloudstack cli from the
>>> auto completion point view. If it can work for ocaml, it should work for
>> python.
>>> If there are python library can get it done, that's fine.
>>> 
>>>> -----Original Message-----
>>>> From: Frank Zhang [mailto:frank.zh...@citrix.com]
>>>> Sent: Wednesday, October 31, 2012 2:37 PM
>>>> To: cloudstack-dev@incubator.apache.org
>>>> Subject: RE: CLI for CloudStack: cloudmonkey
>>>> 
>>>> No.  I don't think so
>>>> bash auto completion is not for this purpose. You cannot run it in
>>>> your terminal as you grab the stdin by readline.
>>>> Bash-auto-completion essentially using compgen and several built-in
>>>> array must run in native bash terminal, otherwise you have to
>>>> complexly redirect user input from your terminal to a fake terminal
>>>> and
>>> parse the output.
>>>> I am sure there must be some python library supporting
>>>> auto-completion in own terminal, no needs to make your hands dirty
>>>> with the obscured
>>>> bash- auto-completion
>>>> 
>>>>> -----Original Message-----
>>>>> From: Edison Su [mailto:edison...@citrix.com]
>>>>> Sent: Wednesday, October 31, 2012 2:25 PM
>>>>> To: cloudstack-dev@incubator.apache.org
>>>>> Subject: RE: CLI for CloudStack: cloudmonkey
>>>>> 
>>>>> For a better auto completion support, you may take a look at bash
>>>>> auto
>>>>> completion(http://info2html.sourceforge.net/cgi-bin/info2html-
>>>>> demo/info2html?%28bash.info.gz%29Programmable%2520Completion),
>>>> and
>>>>> there is a great example written by xenserver guys:
>>>>> https://github.com/xen-org/xen-api/tree/master/ocaml/xe-cli
>>>>> 
>>>>>> -----Original Message-----
>>>>>> From: Rohit Yadav [mailto:rohit.ya...@citrix.com]
>>>>>> Sent: Wednesday, October 31, 2012 12:27 PM
>>>>>> To: cloudstack-dev@incubator.apache.org
>>>>>> Subject: RE: CLI for CloudStack: cloudmonkey
>>>>>> 
>>>>>> I did an autocompletion fix for Mac OSX (10.8 in my case, you
>>>>>> have to have
>>>>>> readline) and it works for me.
>>>>>> 
>>>>>> Are you using Windows or Linux, I have n't tested on Linux/Windows?
>>>>>> 
>>>>>> Check following code for your os?
>>>>>>        # Fix autocompletion issue
>>>>>>        if sys.platform == "darwin":
>>>>>>            readline.parse_and_bind("bind ^I rl_complete")
>>>>>>        else:
>>>>>>            readline.parse_and_bind("tab: complete")
>>>>>> 
>>>>>> Yes, help/doc and completion for parameters and parsing input is
>>>>>> tricky but I'm working on it, any help welcome!
>>>>>> 
>>>>>> ________________________________________
>>>>>> From: Edison Su [edison...@citrix.com]
>>>>>> Sent: Thursday, November 01, 2012 12:25 AM
>>>>>> To: cloudstack-dev@incubator.apache.org
>>>>>> Subject: RE: CLI for CloudStack: cloudmonkey
>>>>>> 
>>>>>> Seems doesn't support auto-completion for api parameters?
>>>>>> 
>>>>>> 🙉 cloudmonkey> api listUsers
>>>>>> 
>>>>>> The ideal cli should list all the parameter names for listUsers
>>>>>> api, if I type "tab" at the end of listUsers.
>>>>>>> -----Original Message-----
>>>>>>> From: Rohit Yadav [mailto:rohit.ya...@citrix.com]
>>>>>>> Sent: Wednesday, October 31, 2012 11:10 AM
>>>>>>> To: cloudstack-dev@incubator.apache.org
>>>>>>> Subject: CLI for CloudStack: cloudmonkey
>>>>>>> 
>>>>>>> Hi,
>>>>>>> 
>>>>>>> I was working on a CLI for cloudstack, it's based on Marvin
>>>>>>> (the neglected
>>>>>>> robot) and called cloudmonkey after our beloved mascot :D
>>>>>>> 
>>>>>>> I've committed that on master, please review:
>>>>>>> https://git-wip-us.apache.org/repos/asf?p=incubator-
>>>>>>> 
>>>>> 
>>> cloudstack.git;a=commit;h=2ceaa3911e792dbeb6c40dfb70961008a01f7e3c
>>>>>>> 
>>>>>>> Features:
>>>>>>> - it's a shell and also a terminal tool, accepts file
>>>>>>> redirection and pipes
>>>>>>> - 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 (disable using set color false)
>>>>>>> - 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
>>>>>>> 
>>>>>>> FIXMEs:
>>>>>>> - Reverse search over history
>>>>>>> - Fix input and output processing
>>>>>>> 
>>>>>>> It requires python and clint;
>>>>>>> pip install clint (or if you have to easy_install clint) mvn
>>>>>>> clean install -P developer cd tools/cli/cloudmonkey python
>>>>>>> cloudmonkey.py
>>>>>>> 
>>>>>>> If you want to have the terminal tool installed; cd tools/cli
>>>>>>> python setup.py sdist cd dist pip install
>>>>>>> cloudmonkey-0.0.4.tar.gz (or easy_install etc.)
>>>>>>> 
>>>>>>> You can do stuff like;
>>>>>>> cloudmonkey < file-with-commands, or cloudmonkey list Users,
>>>>>>> or as shell;
>>>>>>> 
>>>>>>> (If you see unicode chars cloud and monkey below, yes they
>>>>>>> were put intentionally :)
>>>>>>> 
>>>>>>> $ cloudmonkey
>>>>>>> ☁ Apache CloudStack CLI. Type help or ? to list commands.
>>>>>>> 🙉 cloudmonkey>  set apiKey <your key here>
>>>>>>> 🙉 cloudmonkey>  set secretKey <your key here>
>>>>>>> 🙉 cloudmonkey>  <tab><tab>
>>>>>>> add      api      create   delete   disable  enable   help     list     
>>>>>>> quit
>>> remove
>>>>>> set
>>>>>>> shell    update
>>>>>>> 🙉 cloudmonkey>  list <tab><tab>
>>>>>>> Accounts                   Alerts                     AsyncJobs         
>>>>>>>          Capabilities
>>>>>>> Capacity                   Clusters                   Configurations
>>>>>>> DiskOfferings              DomainChildren             Domains           
>>>>>>>          Events
>>>>>>> EventTypes                 FirewallRules              Hosts
>>>>>>> HypervisorCapabilities     Hypervisors                InstanceGroups
>>>>>>> IpForwardingRules          IsoPermissions             Isos
>>>>>>> LBStickinessPolicies
>>>>>>> LoadBalancerRuleInstances  LoadBalancerRules          NetworkACLs
>>>>>>> NetworkDevice              NetworkOfferings           Networks
>>>>>>> NetworkServiceProviders
>>>>>>> OsCategories               OsTypes                    PhysicalNetworks  
>>>>>>>          Pods
>>>>>>> PortForwardingRules        PrivateGateways            ProjectAccounts
>>>>>>> ProjectInvitations         Projects                   PublicIpAddresses
>>>>>>> RemoteAccessVpns           ResourceLimits             Routers
>>>>>>> SecurityGroups
>>>>>>> ServiceOfferings           SnapshotPolicies           Snapshots
>>>>>> SSHKeyPairs
>>>>>>> StaticRoutes               StorageNetworkIpRange      StoragePools
>>>>>>> SupportedNetworkServices   Swifts                     SystemVms
>>> Tags
>>>>>>> TemplatePermissions        Templates
>>> TrafficTypeImplementors
>>>>>>> TrafficTypes               Users                      VirtualMachines
>>>>>>> VirtualRouterElements      VlanIpRanges               Volumes
>>>>>>> VPCOfferings
>>>>>>> VPCs                       VpnConnections             
>>>>>>> VpnCustomerGateways
>>>>>>> VpnGateways                VpnUsers                   Zones
>>>>>>> 🙉 cloudmonkey>  list Users
>>>>>>> …
>>>>>>> 🙉 cloudmonkey>  !ls
>>>>>>> # this give you a shell too and one can do things like
>>>>>>> 🙉 cloudmonkey>  !for i in Users Account; do echo `cloudmonkey
>>>>>>> list $i
>>>>>>> | grep id`; done;
>>>>>>> 
>>>>>>> Example commands to deploy a datacenter; (fill in dynamic ids
>>>>>>> etc.) create Zone dns1=8.8.8.8 internaldns1=10.147.28.6
>>>>>>> name=Zone1 networktype=Basic create PhysicalNetwork
>>>>>>> name=test-network
>>>> zoneid=
>>>>>> add
>>>>>>> TrafficType traffictype=Guest physicalnetworkid= add
>>>>>>> TrafficType traffictype=Management physicalnetworkid= update
>>> PhysicalNetwork
>>>>>>> state=Enabled id= list NetworkServiceProviders
>>>>>>> name=VirtualRouter physicalNetworkId= list
>>>>>>> VirtualRouterElements nspid= api configureVirtualRouterElement
>>>>>>> enabled=true id= update NetworkServiceProvider state=Enabled
>>>>>>> id= list NetworkServiceProviders name=SecurityGroupProvider
>>>>>>> physicalNetworkId= update NetworkServiceProvider state=Enabled
>>>>>>> id= create Network zoneid= name=guestNetworkForBasicZone
>>>>>>> displaytext=guestNetworkForBasicZone
>>>>>>> networkofferingid= create Pod zoneid= name=Pod1
>>>>> gateway=10.147.28.1
>>>>>>> netmask=255.255.255.0
>>>>>>> startip=10.147.28.220 endip=10.147.28.235 create VlanIpRange
>>>>>>> podid= networkid= gateway=10.147.28.1 netmask=255.255.255.0
>>>>>>> startip=10.147.28.236 endip=10.147.28.250
>>>>>>> forVirtualNetwork=false add Cluster zoneid=
>>>>>>> hypervisor=XenServer clustertype=CloudManaged podid=
>>>>>>> clustername=Cluster1 add Host zoneid= podid= clusterid=
>>>>>>> hypervisor=XenServer clustertype=CloudManaged username=root
>>>>>>> password=password url=http://10.147.28.60 create StoragePool
>>>>>>> zoneid= clusterid= name=NFS1
>>>>>>> url=nfs://10.147.28.7/export/home/rohit/primary
>>>>>>> add SecondaryStorage zoneId=
>>>>>>> url=nfs://10.147.28.7/export/home/rohit/secondary
>>>>>>> update Zone allocationstate=Enabled id=
>>>>>>> 
>>>>>>> After some stabilisation, I can put it on pypi so any user can
>>>>>>> just do pip install cloudmonkey to get the CLI.
>>>>>>> 
>>>>>>> Regards.
>>>>>>> PS. Marvin the neglected robot and hipster cloudmonkey should
>>>>>>> rule the world :D

Reply via email to