You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@libcloud.apache.org by mahendra <gi...@git.apache.org> on 2012/12/24 14:03:42 UTC

[dev] libcloud pull request: LIBCLOUD-272 : Implement CLI tools for libcloud

GitHub user mahendra opened a pull request:

    https://github.com/apache/libcloud/pull/81

    LIBCLOUD-272 : Implement CLI tools for libcloud

    ## Overview
    This pull request is for implementing a CLI framework for libcloud. Libcloud does a good job of abstracting cloud operations. If this functionality can be made available via command line tools, it will be an added advantage for libcloud usage. Some other cloud libraries provide such functionality (Like Boto).
    
    ## Design goals are to provide
    * Command line tools for all of libcloud's functionality
    * Command line options to control auth information
    * Ability to use config files (/etc/libcloud.conf, ~/.libcloud.conf) etc. These options can be over-written via command line arguments
    * Support for logging (controlled via config files).
    * Provide different commands for each functionality
      * ```cloud_compute```
      * ```cloud_dns```
      * ```cloud_storage```
      * ```cloud_lb``` (load balancing)
    * A hierarchical command structure within each command
      ```$ cloud_storage providers - list storage providers```
      ```$ cloud_storage container <list>/<create>/<delete>```
      ```$ cloud_storage object <list>/<put>/<get>/...```
    * Provide simpler to remember aliases for sub-commands
      ```$ cloud_storage container list/ls```
    
    ### In future
    * Provide commands for other libcloud functionality
    * Provide support for output formatting (output as JSON/XML/CSV etc.) to make it easier for scripting
    
    ## Implementation
    * For providing most of the functionality mentioned in design goals, the python cement library was used. (http://builtoncement.com/). This provides an excellent framework for solving our design goals. 
    It is tested for Python 2.6, 2.7, 3.1, and 3.2. However, I am not sure of it's support for Python 2.5.
    * As of now only the cloud_storage command is implemented.
    
    ## Config file structure
    ```
    [base]
    storage_provider=s3_us_west
    username=*******
    access_key=********
    
    [log]
    level=NONE
    file=/tmp/cli1.log
    to_console=False
    rotate=False
    max_bytes=512000
    max_file=5
    ```
    
    ## ```cloud_storage``` command
    ### Lists the available storage providers
    
    ```$ cloud_storage providers```
    
    ### Container operations
    #### Lists available containers
    ```$ cloud_storage container <list|ls>```
    #### Create a container
    ```$ cloud_storage container create <container_name>```
    #### Delete a container
    ```$ cloud_storage container delete -r -f -v <container_name>```
    By default container is not deleted if it is not empty
    * If ```-r``` is provided, all objects are recursively deleted after being prompted for each object
    * If ```-f``` is provided, all objects are recursively deleted without user prompt
    * If ```-rfv``` is mentioned, each deleted object is mentioned in the output
    
    ### Object operations
    #### List objects in a container
    ```$ cloud_storage object <list|ls> -v <container_name>```
    List all objects in the container
    If ```-v``` is mentioned, object size is also listed out
    
    #### Delete an object
    ```$ cloud_storage object <delete|rm|del|remove> -f <container_name> <object_name>```
    Deletes the object in the container after prompting user for confirmation
    If ```-f``` is specified, user is not prompted
    
    #### Upload an object from a local file or Unix pipe
    ```
    $ cloud_storage object <put|upload|store|create> <container_name> <object_name> <local_file>
    $ cat /path/to/file | cloud_storage object put <container_name> <object_name> 
    $ cat /path/to/file | cloud_storage object put <container_name> <object_name> -
    ```
    
    #### Download an object ot a local file or unix pipe
    ```
    $ cloud_storage object <get|download|stream> <container_name> <object_name> <local_file>
    $ cloud_storage object get <container_name> <object_name> > /path/to/file
    $ cloud_storage object get <container_name> <object_name> - > /path/to/file
    ```
    
    ### Other changes
    * Minor bug fix in S3
    * ```setup.py``` was modified to install the ```cloud_storage``` command
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/mahendra/libcloud cli

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/libcloud/pull/81.patch

----
commit 44cf0335ba567ce5d565040caf3682dfd59a8362
Author: Mahendra M <ma...@gmail.com>
Date:   2012-12-24T12:54:18Z

    LIBCLOUD-272 : Implement CLI tools for libcloud

----