CLI (local)

CLI (local)

Local Management commands

If you have access to the server/VM hosting your cavaliba system, you can use the built-in management commands from the Django/Docker frameworks.

First, create these 2 aliases for easy access:

### add to your .bashrc for persistence
$ alias cavaliba="docker exec -it cavaliba_app python manage.py cavaliba"
$ alias cavmanage="docker exec -it cavaliba_app python manage.py"

The cavalibacommand starts a custom Django command to perform various tasks and queries agains the cavaliba system.

The cavmanagecommand will give access to Django built-in management framework for system oriented tasks.

You can now type :

$ cavmanage
$ cavaliba --help

You’ll see all available commands.

version

$ cavaliba version
3.29.0

start

Run startup bootstrap/migration (also runs automatically on container start):

$ cavaliba start

Load schema and data

$ cavaliba load /files/demo/
$ cavaliba load /files/demo/100_site.yaml --pass 2

Note: absolute folder for /files, inside containers ; local folder is files/ on host.

Dry run (no writes, use --verbose to see what would be loaded):

$ cavaliba load /files/import/data.yaml --dryrun --verbose

Override every row’s _action regardless of what’s in the file (e.g. force a safe dry inspection of a file without risking any writes even if it contains real actions):

$ cavaliba load /files/import/data.yaml --force_action noop

Load CSV data file

$ cavaliba load /files/demo/user/user.csv –pipeline user_import_csv

A pipeline is needed to map columns to Schema fields and usually apply some transformations.

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 dependencies.

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

log view

$ cavaliba log
$ cavaliba log --first 0 --last 1000

log purge

apply automatic log purge:

$ cavaliba log --log_purge
log entries: 203718
log deleted (old) : 48 entries
log done

purge all logs (!):

$ cavaliba log --log_purge_all
log entries: 203676
log deleted (all) : 203676 entries
log done

conf view

$ cavaliba conf
$ cavaliba conf --text
$ cavaliba conf --json
$ cavaliba conf --yaml
$ cavaliba conf --yaml --key LOG_KEEP_DAYS_ERROR

conf sync

Creates default entries / purge orphan. Run automatically during startup.

$ cavaliba conf --confsync --verbose

conf backup/restore

Backup conf:

$ cavaliba conf > files/export/conf_backup.json

Reload conf (from container accessible folder)

$ cavaliba conf --conf_file /files/export/conf_backup.json --verbose

cache / eav

Refresh or purge the EAV search cache (cache and eav are equivalent actions):

$ cavaliba cache --cache_refresh
$ cavaliba cache --cache_purge
$ cavaliba eav --cache_refresh --force
$ cavaliba cache --cache_purge --dryrun

pipeline

Run a named pipeline against one or more schemas. The pipeline runs as an async Celery task; the command polls for completion and prints progress.

$ cavaliba pipeline --pipeline NAME --schema s1,s2

Options:

Flag Description
--pipeline NAME Pipeline name (required)
--schema s1,s2 Comma-separated schema names (required)
--dryrun Simulate run, no changes written to DB
--sync Run synchronously in the current process (no Celery)
--verbose Print per-object errors

Example:

$ cavaliba pipeline --pipeline user_import_csv --schema _user
pipeline:  user_import_csv
schemas:   _user
dryrun:    False
sync:      False
handle:    550e8400-e29b-41d4-a716-446655440000
  state=RUNNING  10%  100/1000
  state=RUNNING  50%  500/1000
  state=DONE    100%  1000/1000
  _user                          ok=998  discarded=2  errors=0
total:     ok=998  discarded=2  errors=0

Dry-run example:

$ cavaliba pipeline --pipeline cleanup --schema server --dryrun

Synchronous mode (no Celery required):

$ cavaliba pipeline --pipeline cleanup --schema server --sync

adminrole

List users currently in the built-in role_admin role:

$ cavaliba adminrole
admin
alice

Add a user to role_admin:

$ cavaliba adminrole --username alice
Added alice to role_admin

If the user is already a member:

$ cavaliba adminrole --username alice
alice is already in role_admin

keyname rename

Rename an instance’s keyname, cascading the change to every other instance that references it through a schema-type field.

$ cavaliba keyname --schema site --old site01 --new site01bis

Options:

Flag Description
--schema NAME Schema/classname of the instance to rename (required)
--old KEY Current keyname (required)
--new KEY New keyname (required)
--dryrun Report what would change, without writing anything
--verbose Print each changed referrer field
--force Allow rename on user/group/role instances

user, group and role are refused by default since their keyname may be used by auth/session/permission code outside the generic EAV system; --force unblocks ordinary instances of those schemas but still refuses builtin objects and protected keynames (user/admin, role/role_admin, role/role_default).

Example:

$ cavaliba keyname --schema site --old site01 --new site01bis --verbose
keyname rename: site/site01 -> site01bis
referrers scanned: 3, changed: 2
  server/srv01.site: ['site01'] -> ['site01bis']
  contact/c01.site: ['site01', 'site02'] -> ['site01bis', 'site02']
keyname rename done.

Dry-run example (no writes):

$ cavaliba keyname --schema site --old site01 --new site01bis --dryrun
** dryrun **
keyname rename: site/site01 -> site01bis
referrers scanned: 3, changed: 2
keyname rename dryrun done (no writes).

schema list

Get available schemas (field definitions, not instance data):

$ cavaliba schema

Query a single schema’s field definitions:

$ cavaliba schema --schema user

data query/export

cavaliba get queries and exports instance data for a schema.

$ cavaliba get --schema user

Query a specific object with --key:

$ cavaliba get --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
  _action: noop

Options:

Flag Description
--schema NAME Schema/classname to query (required)
--key KEY Specific instance keyname (omit to list, bounded by --first/--last)
--first N First item to process (default 0)
--last N Last item to process (default 10)
--yaml YAML output (default if no format flag given)
--json JSON output
--csv CSV output
--text One line per object: keyname displayname
--refs LIST Comma-separated schema names to inline as _refs (e.g. user,site or * for all)
--rev N Number of revisions to include as _revision
--field GRAMMAR Field filter - "a,b,c*" (whitelist) / "*" (all, default) / "!a,b,c*" (blacklist)
--delimiter CHAR CSV delimiter, single character (default: CSV_DELIMITER configuration); --csv only
--encoding ENC CSV output encoding (default: utf-8); --csv only

Every exported row in YAML/JSON includes an _action: noop key so the file can be re-imported with cavaliba load as-is without changing anything - replace noop with create/update/… to actually apply it. CSV export never gets an _action column (nor id, nor classname unless explicitly requested via --field - see below), since a CSV export is never re-importable as-is anyway.

Specify an output format:

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

CSV export, semicolon delimiter, only keyname/email fields:

$ cavaliba get --schema user --csv --delimiter ";" --field "keyname,email"
keyname;email
testuser01;testuser01@test.com

CSV export with a non-UTF-8 encoding (e.g. for Excel compatibility):

$ cavaliba get --schema user --csv --encoding cp1252 > users.csv

Inline every referenced schema’s objects as _refs:

$ cavaliba get --schema server --refs "*"

Inline specific schemas and include revision history:

$ cavaliba get --schema server --key srv01 --refs user,site --rev 5

Field filter, wildcard blacklist, paginated:

$ cavaliba get --schema user --field "!last_login,last_update,last_sync,displayname" --first 0 --last 500

Backup/restore roundtrip (safe by default via _action: noop):

$ cavaliba get --schema user --yaml > users_backup.yaml
$ cavaliba load users_backup.yaml

Develop references:

./cavctl/bin/cavctl get --schema test --id 968 --refs '_user,*' 
{
  "id": 968,
  "classname": "test",
  (...)
  "_refs": {
    "_user": [
      {
        "login": "adela81",
        "displayname": "Marijn Torrecilla",
        "firstname": "Marijn",
        "lastname": "Torrecilla",
        "email": "Torrecilla@demo.cavaliba",
        "mobile": "+56-16832089",
        "external_id": "BA-948192"
      }
    ],
    "test": [
      {
        "keyname": "test02",
        "classname": "test",
        "displayname": "test02"
      }
    ],
    "site": [
      {
        "keyname": "GAVLE",
        "classname": "site",
        "displayname": "Gavle Rehabilitation Center"
      }
    ]
  }
}