CLI tools

Command Line tools

Cavaliba comes with various command-line tools.

First, create an alias for easy access :

$ alias cavaliba="docker exec -it cavaliba_app python manage.py"

The cavalibacommand will launch the integrated management framework.

You can now type :

$ cavaliba
$ cavaliba cavaliba --help

You’ll see all available commands.

Load schema and data

$ cavaliba cavaliba_load /files/import/demo/
$ cavaliba cavaliba_load /files/import/demo/cmdb/site.yaml --pass 2
$ cavaliba cavaliba_load /files/import/demo/cmdb/site_data.yaml

Load CSV data file

$ cavaliba cavaliba_load /files/import/user.csv --pipeline user_import_csv

multipass

--pass 2

The --pass option is recommanded for schema, because cross-references between schemas requires some schemas to be created before others. Multiple pass resolve dependecies.

progress

Display progression for large files :

--progress 

File: /files/import/user.csv ...
Found: 55456 objects
Pipeline: user_import_csv
Loading to DB...
100 done
200 done
(...)

first/last

Choose quantity (first/last lines to process) ; 0 for last is unlimited.

--first 1 
--last 0

view logs

$ cavaliba cavaliba log --log_list

view conf

$ cavaliba cavaliba conf

query/export

Get available schemas:

$ cavaliba cavaliba_export --list

Query a schema:

$ cavaliba cavaliba_export --schema user 
- login: admin
  displayname: Built-in Global Admin user
  is_enabled: true
  want_notifications: true
  want_24: true
  want_email: true
  classname: _user

- login: i.trento
  displayname: Izongua Trento
  is_enabled: true
  want_notifications: true
  want_24: true
  want_email: true
  classname: _user

  (...)

Query a schema and a key:

$ cavaliba cavaliba_export --schema user --key testuser01
- login: testuser01
  email: testuser01@test.com
  mobile: 0123456789
  displayname: Test User 01
  description: Test User 01
  is_enabled: true
  want_notifications: true
  want_24: true
  want_sms: true
  want_email: true
  classname: _user

Specify an output format:

$ cavaliba cavaliba_export --schema site --key testsite01 --format json
[
    {
        "classname": "site",
        "keyname": "testsite01",
        "handle": "testsite01",
        "displayname": "Test Site 01",
        "p_read": null,
        "p_update": null,
        "p_delete": null,
        "is_enabled": true,
        "sirene_group": [
            "testgroup01"
        ]
    }
]

Run the integrated test suite

First, either create an empty test database in your database server or use the root DµB user in your docker .env file for variable CAVALIBA_DB_USER. Alternatively you may prefer to grant create database privileges to your current CAVALIBA_DB_USER.

Then,

$ cavaliba test

Options exists such as:

$ cavaliba test --keepdb
$ cavaliba test -v 2
$ cavaliba test --keepdb app_home.tests.test_home.ConfTest

You may need to create a test database manually in MariaDB. Example:

docker exec -it cavaliba_db mysql -u root -p
create database test_cavaliba;
show grants for 'cavaliba';
GRANT ALL PRIVILEGES ON `test_cavaliba`.* TO `cavaliba`@`%`;
flush privileges;