Launching a computation with the CLI

Download and install the CLI

The Qarnot Command Line Interface (CLI) is a tool designed to interact with Qarnot cloud computing service.

It allows users to launch, manage and monitor payloads running on distributed computing nodes. The following paragraphs are an overview of the basic CLI commands, you can refer to the CLI documentation for a more in depth look.

Install the CLI binary

The simplest way to install the CLI is to directly download the binary. You can go to the CLI release page, on our public github, and download the appropriate binary file for your operating system. We will be using the linux-x64 binary file for these examples, but there are also binaries for Windows and OSX.

Configure the binary

After downloading the file, you can rename it to qarnot, and move it to your binary directory to use it as in the examples that will follow. To do all of the above, you can run the following commands from the directory where you saved your binary file:

# Renaming the binary file to qarnot
mv qarnot-linux-x64 qarnot

# Changing permissions to be an executable
chmod +x qarnot

# Moving the binary to /usr/bin for example (or you could add it to your PATH)
sudo mv qarnot /usr/bin/

# Making sure it is working
qarnot --version

Create a connection

In order to set your connection information, you will need to get your secret token. It will be available on your Qarnot account page once you have created one. Below are some of the ways you can connect to your Qarnot account.

Using the CLI

You can use the CLI directly to configure your Qarnot token by running the following command in your terminal.

qarnot config -t <<<MY_TOKEN>>>

Using environment variables

It is also possible to set environment variables that will contain all of your login information, for example you can set the following variables to change your token, compute and storage uri:

Create a task

Simple Hello World

It is very easy to create and submit a task  using the Qarnot CLI  . Here we will create a simple task that prints Hello World on Tasq  . This can be done in just one simple line of code as shown below:

qarnot task create  --name "Hello World - CLI" --profile docker-batch --instance 1 --constants "DOCKER_CMD=echo Hello World"

Which outputs on your terminal the following message with the UUID (unique identifer) and state of the task.

create task
Uuid : f1c2008e-7c9d-45a5-95b8-a8fba4c60407
Message : New task created, state : Submitted

For this example, we launched a task of 1 instance  using the docker-batch profile, which is an all purpose general computing profile.

You can do much more with the CLI, like using a JSON file to configure your task and more. Make sure to have a look at the CLI documentation for more details.

Manage buckets

It is possible to manage your buckets using the CLI. Here is how to create a bucket and upload files to it.

Create a bucket

Run the following line of code in your terminal to create a bucket named test-bucket and upload 2 files to it, file1.txt and file2.txt:

qarnot bucket create -n test-bucket --files file1.txt file2.txt

Delete a bucket

You can easily delete that bucket by running the following code:

qarnot bucket delete --name test-bucket

Which outputs on your terminal:

 -------------------------------- 
 | Uuid        | Message        |
 -------------------------------- 
 | test-bucket | Bucket deleted |
 -------------------------------- 

Retrieve results

It is also possible to download contents of a bucket on your machine using the CLI. First, you can create a task that outputs Hello World ! into a file stored in a bucket named hello-world-output, by running the following line of code:

qarnot task create --name "hello world - file" --profile docker-batch --instance 1 \
--constants DOCKER_CMD='sh -c "echo Hello World ! > output.txt"' \
--result hello-world-output

Once it's done, you can download the file on your machine and print out it's content by running:

qarnot bucket get --name hello-world-output \
--bucket-file output.txt --string output.txt

Monitor

It is possible to print out the STDOUT of the task on your terminal as a way to monitor it. After you have launched the previous Hello World - CLI task, run the following code in your terminal using the UUID of the task:

qarnot task wait -eo --id "<<<UUID>>>"

This will wait for the task to be completed and print out its STDOUT and STDERR on your local terminal:

Stdout:
" 0> Hello World"
 ------------------------------------------------------------------------- 
 | Uuid                                 | Message                        |
 ------------------------------------------------------------------------- 
 | 1285d237-b9fc-446e-a34f-ba5bf211970f | Task Wait end status : Success |
 ------------------------------------------------------------------------- 

Related Article

For more information on Launching tasks please consult the following articles