TrueNAS midclt examples
A compilation of examples on how to use midclt and interpret the API documentation
Export a pool
id=$(midclt call pool.query '[["name", "=", "offline-archive"]]' | jq '.[0].id')
arg1=$(jq --argjson id $id -n '[["id", "=", $id]]')
midclt call pool.query "$arg1"
midclt call pool.export $id
Import a pool
This is simplified, if there are more than one exported pools available the first one may not be the one you want.
job=$(midclt call pool.import_find)
echo $job
jobstate="$(midclt call core.get_jobs "$(jq -n --argjson job $job '[["id", "=", $job]]')")"
while [ "RUNNING" = "$(echo "$jobstate" | jq -r '.[0].state')" ]; do
sleep 5
jobstate="$(midclt call core.get_jobs "$(jq -n --argjson job $job '[["id", "=", $job]]')")"
done
guid="$jobstate" | jq '.result[0].guid'
echo $guid
midclt call pool.import_pool "$(jq -n --arg guid $guid '{"guid": $guid}'
A job result looks like:
[
{
"id": 237603,
"method": "pool.import_find",
"arguments": [],
"logs_path": null,
"logs_excerpt": null,
"progress": {
"percent": 100,
"description": null,
"extra": null
},
"result": [
{
"name": "offline-archive",
"guid": "15184964332646039596",
"status": "ONLINE",
"hostname": "mynas"
}
],
"error": null,
"exception": null,
"exc_info": null,
"state": "SUCCESS",
"time_started": {
"$date": 1711466929836
},
"time_finished": {
"$date": 1711466930190
}
}
]
Query filters
See (https://github.com/truenas/midcli/blob/master/midcli/command/query/parse.py)[parse.py] for details.
String matching operators:
op | description |
---|---|
~ | full reg ex match |
^ | string starts with |
$ | string ends with |
Equivalence operators:
op name | op | rhs notes |
---|---|---|
ast.Eq | = | numbers, strings |
ast.NotEq | != | numbers, strings |
ast.Gt | > | numbers |
ast.GtE | >= | numbers |
ast.Lt | < | numbers |
ast.LtE | <= | numbers |
ast.In | in | list for members |
ast.NotIn | nin | list of not members |
operators with gt/lt can be applied to strings but with questionable sense.
Also has “NOT” “AND” and “OR”