.. _usage:

Usage
#####

Here is the list of available commands and sub-commands.

Aliases
=======

LAVA aliases can be managed by:

.. code-block:: shell

    lavacli aliases add <name>
    lavacli aliases delete <name>
    lavacli aliases list
    lavacli aliases show <name>

Device types
============

LAVA device types can be managed by:

.. code-block:: shell

    lavacli device-types add [...]
    lavacli device-types aliases add <name> <alias>
    lavacli device-types aliases delete <name> <alias>
    lavacli device-types aliases list
    lavacli device-types health-check get <name>
    lavacli device-types health-check set <name> <health-check.yaml>
    lavacli device-types list
    lavacli device-types show <name>
    lavacli device-types template get <name>
    lavacli device-types template set <name> <template.jinja2>
    lavacli device-types update [...]

Devices
=======

LAVA devices can be managed by:

.. code-block:: shell

    lavacli devices add [...]
    lavacli devices control <hostname> (on|off|reset|connect) [--dry-run]
    lavacli devices dict get <hostname>
    lavacli devices dict set <hostname>
    lavacli devices list
    lavacli devices maintenance <hostname> [--force] [--no-wait] [--reason <text>]
    lavacli devices show <hostname>
    lavacli devices tags add <hostname> <name>
    lavacli devices tags delete <hostname> <name>
    lavacli devices tags list
    lavacli devices update [...]

The **control** command allows controlling the device power and serial
connection directly from the workstation, using the commands defined in the
device dictionary:

* **on**: turn the device on (``commands.power_on``)
* **off**: turn the device off (``commands.power_off``)
* **reset**: hard reset the device (``commands.hard_reset``)
* **connect**: connect to the device primary serial port (``commands.connections.<primary>.connect``)

Use ``--dry-run`` (or ``-n``) to print the command that would be run without
executing it.

Events
======

LAVA events can be used by:

.. code-block:: shell

    lavacli events listen
    lavacli events wait device [...]
    lavacli events wait job [...]
    lavacli events wait worker [...]

Groups
======

LAVA groups can be managed by:

.. code-block:: shell

    lavacli add [...]
    lavacli delete <group>
    lavacli list
    lavacli perms add [...]
    lavacli perms list
    lavacli perms delete [...]
    lavacli show <group>

Identities
==========

lavacli identities can be managed by:

.. code-block:: shell

    lavacli identities add [...]
    lavacli identities delete <id>
    lavacli identities list
    lavacli identities show <id>

Jobs
====

LAVA jobs can be managed by:

.. code-block:: shell

    lavacli jobs cancel <job_id>
    lavacli jobs config <job_i>
    lavacli jobs definition <job_id>
    lavacli jobs list
    lavacli jobs logs <job_id>
    lavacli jobs queue <device-type>
    lavacli jobs resubmit <job_id>
    lavacli jobs run <definition.yaml>
    lavacli jobs show <job_id>
    lavacli jobs submit <definition.yaml>
    lavacli jobs validate <definition.yaml>
    lavacli jobs wait <job_id>
    lavacli jobs find-errors

Lab
===

LAVA lab can be managed by:

.. code-block:: shell

    lavacli lab apply <config>
    lavacli lab import <config>

MCP
===

Start an MCP server for the selected LAVA instance. You can then connect your
LLM to LAVA via this MCP server:

.. code-block:: shell

    lavacli mcp
    lavacli mcp --transport streamable-http [--host <address>] [--port <port>]

The instance is the one selected by **--identity** or **--uri**, reached over
the same XML-RPC calls as every other lavacli command.

The server provides tools to list and show jobs, device-types, devices and
workers, to read a job definition, its logs and a device dictionary, to browse
the results of a job (its suites, test cases and metadata), and to read
the official LAVA documentation. The documentation is read from the markdown
sources of the lava repository, at the tag of the release the instance runs
when there is one, falling back to the development branch.

A few tools change the instance: submitting and canceling a job, setting a
device-type template or a device dictionary. They are advertised as
such in their MCP annotations, so that the client can ask for a confirmation
before running them, while the other tools are flagged read-only. The tools act
with the permissions of the token used by **--identity** or **--uri**: give the
server a token without the matching permissions to keep it read-only.

This command requires the ``mcp`` python module, which is not installed by
default:

.. code-block:: shell

    pip install lavacli[mcp]

Only the FastMCP 1.x series is supported.

Results
=======

LAVA results can be managed by:

.. code-block:: shell

    lavacli results <job_id>
    lavacli results <job_id> <suite>
    lavacli results <job_id> <suite> <case>

System
======

LAVA instance can be managed by:

.. code-block:: shell

    lavacli system active
    lavacli system api
    lavacli system maintenance
    lavacli system methods list
    lavacli system methods help <method>
    lavacli system methods signature <method>
    lavacli system version
    lavacli system whoami

In order to put a full instance into maintenance, an admin could call **system
maintenance**. This function will:

* set all workers health to *MAINTENANCE*
* wait for all jobs to finish

If the instance should be put into into maintenance immediately, addind **--force** will:

* set all workers health to *MAINTENANCE*
* cancel all running jobs
* wait for all jobs to finish

It also possible to exclude some workers with **--exclude**.

When the maintenance is finished, calling **system active** will move every
worker into *MAINTENANCE* to *ACTIVE*.

Tags
====

LAVA tag can be managed by:

.. code-block:: shell

    lavacli tags add [...]
    lavacli tags delete <tag>
    lavacli tags list
    lavacli tags show <tag>

Tokens
======

Manage user remote artifact tokens:

.. code-block:: shell

    lavacli add [...]
    lavacli delete <token>
    lavacli list
    lavacli show <token>


Users
=====

Manage LAVA users with:

.. code-block:: shell

    lavacli add [...]
    lavacli delete <user>
    lavacli groups add <user> [...]
    lavacli groups list
    lavacli groups delete [...]
    lavacli perms add <user> [...]
    lavacli perms list
    lavacli perms delete [...]
    lavacli list
    lavacli show <user>
    lavacli update <user> [...]

Utils
=====

Some utilities are available with:

.. code-block:: shell

    lavacli utils logs print <output.yaml>
    lavacli utils templates render <output.yaml>

Printing logs
*************

When working with raw logs, lavacli might help by coloring the logs by levels.

It's also possible to filter the logs by level. To only print the serial output
and the commands sent by LAVA to the board, use:

.. code-block:: shell

    lavacli utils logs print --filter target,input

Available log levels are: exception, error, warning, info, debug, target,
input, feedback, results.

Workers
=======

LAVA workers can be managed by:

.. code-block:: shell

    lavacli workers add [...]
    lavacli workers config get <hostname>
    lavacli workers config set <hostname> <config.yaml>
    lavacli workers env get <hostname>
    lavacli workers env set <hostname> <env.yaml>
    lavacli workers list
    lavacli workers maintenance <hostname>
    lavacli workers update [...]
    lavacli workers show <hostname>
