Velocity • Durability

Version 12.0.0

13. Scripting

The table layout is for reading. Machines should read JSON, and scripts should test the exit code (see 5.5).

13.1 Take the Id from the Create

tenant_id=$(panctl tenants create --name=acme --display-name="ACME Corp" \
  --email=admin@acme.example.com --format jsonpath='{.id}')
lc_id=$(panctl lc create --scope=storage --format jsonpath='{.id}')

A create returns the new object, so no second call is needed, and {.id} is the identifier on every resource.

13.2 Find Something You Did Not Just Create

tenant_id=$(panctl tenants list --format 'jsonpath={.tenants[?(@.name=="acme")].id}')

# Every addable node: unassigned, and of a role that carries storage
panctl nodes list --format \
  'jsonpath={.nodes[?(@.role=="vosd" || @.role=="vhost" && @.storageset_id==0)].dataserial}'

Single-quote the expression. Terms fold from left to right with no precedence and no grouping, so a && b || c means (a && b) || c. To read a narrowed list instead of capturing a field, use --filter (see 5.8). The two compose.

13.3 One Line per Row

panctl volumes list --format \
  'jsonpath={range .volumes[*]}{.id}{"\t"}{.pathname}{"\n"}{end}'
panctl volumes list --no-header | awk '{print $2}'

13.4 Empty Results and Several Matches

  • An empty capture is silent. A selector that matches nothing prints nothing and exits 0, and a failed create leaves standard output empty, so check for an empty variable yourself.
  • Several matches are joined with a space. Use read -r -a to split them, or reject values that contain one.

13.5 Collect and Fetch Logs Unattended

id=$(panctl lc create --format jsonpath='{.id}') || exit
panctl lc get "$id" -o jsonpath='{.status}' --wait-for='it != running' --wait-timeout=2h
panctl lc download "$id" --output "logs-$(date +%F).tar"

13.6 Run Unattended

export PANCTL_API_TOKEN=vdt1_...
export PANCTL_API_SERVER=10.97.26.200
export PANCTL_NO_PAGER=1
panctl volumes list          # no login step, and no profile is read
panctl volumes delete 7 --yes

Token mode reads no profiles.toml, renews nothing, and exits 3 if the token is rejected. A destructive command run with no terminal needs --yes (see 5.10).

This guide reflects the command set and behavior of PanCTL as of the version documented in the pan-ctl repository. Run panctl <command> --help for the most current flag list on your installed version.