jclouds-cli is tool that allows you to interact with jclouds Compute, Blobstore and Chef services. It is easy to use, configurable, extensible and it comes into 2 flavors:
Both flavors support reading configuration from environmental variables, so that you don't have to repeat the same options again and again.
To install the jclouds cli you just need to download the zip or the tarball and extract it to the folder of your choice.
You can use the jclouds cli to perform misc operations, such as creating a node, run scripts on a node, list nodes, destroy a node etc. The cli also supports blobstore, so you can create, delete or access a blobstore.
Note that all cli invocations require parameters to be specified in the following order:
**[category]** **[action]** **[options]** **[arguments]**
Compute Service Usage:
./bin/jclouds **[category]** **[action]** **[options]** **[arguments]**.
Compute Service Examples: To create 10 nodes on EC2 under group: myGroupName using Ubuntu 10.04
./jclouds node create --provider aws-ec2 --identity [identity] --credential [credential] --os-family ubuntu --os-version 10.04 --adminAccess myGroupName 10
To list all nodes:
./jclouds node list --provider aws-ec2 --identity [identity] --credential [credential]
To destroy a node:
./jclouds node destroy [node id]
Blobstore Usage:
./bin/jclouds **[category]** **[action]** **[options]** **[arguments]**.
Blobstore Examples: To create a container on S3:
./jclouds blobstore create --provider aws-s3 --identity [identity] --credential [credential] mycontainer
To list the content of container:
./jclouds blobstore list --provider aws-s3 --identity [identity] --credential [credential] mycontainer
To copy a file to a blob:
./jclouds blobstore write --provider aws-s3 --identity [identity] --credential [credential] mycontainer myblob /path/to/file
To copy using a url to a blob:
./jclouds blobstore write --provider aws-s3 --identity [identity] --credential [credential] --url-payload mycontainer myblob myurl
To write a string value to a blob:
./jclouds blobstore write --provider aws-s3 --identity [identity] --credential [credential] --string-payload mycontainer myblob myvalue
APIs work in the same manner as providers, but you will also need to specify the endpoint. Chef Usage::
./bin/chef **[category]** **[action]** **[options]** **[arguments]**.
Chef Examples::
To list all cookbooks:
./bin/chef cookbook list --client-name [client name] --client-key-file [path to client key file] --endpoint [endpoint]
To bootstrap an existing compute node:
./bin/chef node bootstrap --provider aws-ec2 --identity [identity] --credential [credential] --client-name [client name] --client-key-file [path to client key file] --endpoint [endpoint] [node id] [recipe]
To bootstrap an existing compute group:
./bin/chef group bootstrap --provider aws-ec2 --identity [identity] --credential [credential] --client-name [client name] --client-key-file [path to client key file] --endpoint [endpoint] [group id] [recipe]
To create a new compute node and apply a recipe:
./jclouds node create --provider aws-ec2 --identity [identity] --credential [credential] --recipe chef/myrecipe [node group]
To start the interactive shell: ./bin/jclouds-cli
The interactive shell is a lightweight container powered by Apache Karaf which is modular and extensible. Out of the box it has installed support of all compute, blobstore providers and Chef. You can easily add or remove providers, apis, drivers etc using the features commands:
feature:list
Will list all the available features, that you can install. Some examples of adding additional feature:
feature:install jclouds-cloudsigma2-mia
All commands that are available from the script are also available in the interactive mode. The only difference is that in the interactive mode the category and action are encoded in the command name. So all jclouds and chef commands follow the following format:
scope:category-action [options] [arguments]
For example:
jclouds:node-list --provider aws-ec2 --identity [identity] --credential [credential] jclouds:blobstore-list --provider aws-s3 --identity [identity] --credential [credential] chef:cookbook-list --client-name [client name] --client-key-file [path to client key file] --endpoint [endpoint]
One of the advantages of using the interactive shell is that it provides the ability to reuse services, and avoid the options boilerplate.
Creating a reusable Compute Service
jclouds:compute-service-create --provider [provider] --identity [identity] --credential [credential] --name [service name] jclouds:compute-service-create --api [api] --identity [identity] --credential [credential] --endpoint [endpoint] --name [service name]
If no name option specified the provider or api will be used instead. To list the available compute services:
jclouds:compute-service-list
Here's an example output that list 2 services registered for the aws-ec2 provider. The service are named myec2 and yaec2:
Compute APIs: ------------- [id] [type] [service] ec2 compute [ ] stub compute [ ] Compute Providers: ------------------ [id] [type] [service] aws-ec2 compute [ myec2 yaec2 ]
Then you can reuse the service from the other commands with the following way:
jclouds:node-list --name [service name] jclouds:node-create --name [service name]
Note that if there is only a single compute service available then the --name is optional. The same applies if there is a single service per api or provider. You can just specify the provider or the api and the shell will pick up the right service for you. Recreating a service with the same name, will replace the the service. Finally you can destroy a service using the following command:
jclouds:compute-service-destroy [serice name]
Reusing Compute Services Examples: To create 10 nodes on EC2 under group: myGroupName using Ubuntu 10.04 and reusing myec2 service:
jclouds:node-create --name myec2 --os-version 10.04 --adminAccess myGroupName 10
To list all nodes:
jclouds:node-list --name myec2
To destroy a node:
jclouds:node-destroy --name myec2
Creating a reusable BlobStore Service
jclouds:blobstore-service-create --provider [provider] --identity [identity] --credential [credential] --name [service name] jclouds:blobstore-service-create --api [api] --identity [identity] --credential [credential] --endpoint [endpoint] --name [service name]
If no name option specified the provider or api will be used instead. To list the available blobstore services:
jclouds:blobstore-service-list
Here's an example output that list 2 services registered for the aws-s3 provider. The service are named mys3 and yas3:
BlobStore APIs: ------------- [id] [type] [service] s3 blobstore [ ] transient blobstore [ ] BlobStore Providers: ------------------ [id] [type] [service] aws-ec2 blobstore [mys3 yas3]
Then you can reuse the service from the other commands with the following way:
jclouds:blobstore-list --name [service name] jclouds:blobstore-write --name [service name]
Note that if there is only a single blobstore service available then the --name is optional. The same applies if there is a single service per api or provider. You can just specify the provider or the api and the shell will pick up the right service for you. Recreating a service with the same name, will replace the the service. Finally you can destroy a service using the following command:
jclouds:blobstore-service-destroy [serice name]
Reusing BlobStore Services Examples: To create a container on S3 using service mys3:
jclouds:blobstore-create --name mys3 mycontainer
To list the content of container:
jclouds:blobstore-list --name mys3 mycontainer
To copy a file to a blob:
jclouds:blobstore-write --name mys3 mycontainer myblob /path/to/file
To copy using a url to a blob:
jclouds:blobstore-write --name mys3 --url-payload mycontainer myblob myurl
To write a string value to a blob:
jclouds:blobstore-write --name mys3 --string-payload mycontainer myblob myvalue
Creating a reusable Chef Service
chef:service-create --api [api] --client-name [client name] --client-key-file [path to client key file] --endpoint [endpoint]
If no name option specified api will be used which defaults to “chef”.. To list the available chef services:
chef:chef-service-list
Here's an example output that list 2 services registered for the aws-s3 provider. The service are named mys3 and yas3:
Chef APIs: ------------- [id] [type] [service] chef chef [mychef yachef] transient chef [ ]
Then you can reuse the service from the other commands with the following way:
chef:cookbook-list --name [service name]
Note: In most cases, you‘ll only need a single service from the chef api, so it’s usually pretty safe to skip --api or --name option.
chef:service-destroy [serice name]
Reusing Chef Services Examples: To list all cookbooks for the chef service named mychef:
chef:cookbook-list --name mychef
To bootstrap an existing compute node that is managed by myec2 compute service (here we are reusing 2 services in a single command):
chef:node-bootstrap --name myec2 --chef-name mychef my-node-id java::openjdk
The same for an entire group:
chef:node-bootstrap --name myec2 --chef-name mychef my-group java::openjdk
To create a new compute node and apply a recipe:
jclouds:node-create --name mlycec2 --recipe mychef/myrecipe mygroup
Both in the interactive shell and cli modes, you may find repeating the provider information again and again not really friendly. You can completely skip those options by specifying them as environmental variables.
For Compute Services:
For Blob Stores:
For Chef:
As of jclouds-cli version 1.5.0 commands support output customization. The customization features are:
The configuration for all columns can be found inside the org.jclouds.shell pid. Each configuration key is prefixed using the command category (node, image, location, hardware etc). The suffix defines the configuration topic. For example hardware.headers defines the headers to be displayed by the hardware commands. In the following commands the hardware category will be used as example.
Defining the command headers To specify the headers of a command we need to place to specify the headers configuration as a semicolon separated list. For hardware:
hardware.headers=[id];[ram];[cpu];[cores]
Defining the display data Display data are configured as a comma separated list of expressions (using the scripting engine of your choice, default is groovy). The expressions will be evaluated on the object of interest (in our example the hardware object). To display the id field of the hardware object the expression to use is hardware.id. The reason for choosing groovy (as a default) for retrieving the data and not a simple expression language is that groovy is powerful and can be used for more complex expressions. For example the Hardware object contains a collection of Processors and each processor has a filed of cores. To display the sum of cores among processors, we can use the following expression: hardware.processors.sum{it.cores}.
You can change the scripting engine:
hardware.engine=groovy
Please note that if you don't specify the engine, then groovy will be assumed.
To specify the display data, now all you need to do is to provide the expressions:
hardware.expressions=hardware.id;hardware.ram;hardware.processors.sum{it.cores*it.speed};hardware.processors.sum{it.cores}
The configuration above will display the hardware id in the first column, the hardware ram in the second column, the sum of cores X speed per processor in the third column and finally the sum of cores for all processors in the last column.
Defining the sort order To specify the sort column, the sortBy option can be used to point to the header of the column of interest. For example hardware hardware.sortby=[cpu].
Changing the delimiter Most of the configuration options for the shell table are passed as delimited strings. What happens when you want to change the delimiter? By default the delimiter is the semicolon symbol, but for each command category you can specify the delimiter. For example:
hardware.delimiter=, hardware.headers=[id],[ram],[cpu],[cores]