How to create jail through API. TrueNAS-13.0-U3.1

deamonmv

Cadet
Joined
Mar 7, 2023
Messages
8
Hello
I run into trouble with creating a new jail through API.

What do I have//What I can do:

- FreeBSD 13.1-RELEASE-p2 n245412-484f039b1d0 TRUENAS
- I can start or stop jail.


What did I checked:
1)
I looked into this API doc https://www.truenas.com/docs/api/rest.html
Example is "empty" as for me, and understand what should be in body is not possible:
Code:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic [[basicHash]]" "http://realmini.tn.ixsystems.com/api/v2.0/jail"


But if run this request I response

Code:
{
 "message": "create() missing 1 required positional argument: 'data'",
 "traceback": "Traceback (most recent call last):\n  File \"/usr/local/lib/python3.9/site-packages/middlewared/restful.py\", line 575, in do\n    result = await self.middleware.call(methodname, *method_args, **method_kwargs)\n  File \"/usr/local/lib/python3.9/site-packages/middlewared/main.py\", line 1278, in call\n    return await self._call(\n  File \"/usr/local/lib/python3.9/site-packages/middlewared/main.py\", line 1235, in _call\n    return await methodobj(*prepared_call.args)\nTypeError: create() missing 1 required positional argument: 'data'\n"


At the end of tries, I discovered that to get 200OK need only two parameters
Code:
{"data":"asd", "uuid":"asd"}


But this didn't worked out


2)
I checked API doc directly on my own TrueNAS Core Instance by url http://my.truenas.local/api/docs/
Here I found Example values, and used such values(below). In response I getting 200 OK and some random number, but I do not see any new jail in jails

Code:
curl -X 'POST'   'http://my.truenas.local/api/v2.0/jail'   -H 'accept: */*'   -H 'Authorization: Bearer 1-xxx' -H 'Content-Type: application/json'   -d '{
  "release": "13.1-RELEASE-p7",
  "template": "0",
  "pkglist": [
    "nginx"
  ],
  "uuid": "test-3",
  "basejail": true,
  "empty": true,
  "short": true,
  "props": [
    null
  ],
  "https": true
}'



Question:

- How do a correct request to create a jail?

Thank you
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Possibly jail creation and management is not a part of the API, because there is iocage?

You can always call that directly via SSH. All jail parameters and data are stored in the jail dataset or child datasets thereof. There is one pool that has the org.freebsd.ioc:active attribute set for the top level dataset. Under that there is one dataset named iocage and in that, inside jails/<jailname>/config.json there is all configuration applicable to that particular jail. As far as I am aware the UI picks up the info straight from the pool and not from some shadow copy in the sqlite config database. Easily proven by manipulating jails in the CLI to your heart's content. The UI will pick up all changes.

Jails are to my knowledge the only subsystem that does not store its configuration in the DB and as outlined above I have reason to believe that therefore there is no API. I might be mistaken.

HTH
Patrick
 
Last edited:

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
midclt call jail.activate "<name of pool>", followed by midclt call jail.create '{ "release": "13.1-RELEASE" }' doesn't work?
 

deamonmv

Cadet
Joined
Mar 7, 2023
Messages
8
Hello
Thanks for replay.
I guess, I got a result
Seems that "midctl" can create a jail, I used this command

Code:
midclt call jail.create '{ "release": "13.1-RELEASE", "uuid": "dm-t-1" }'


Then I tried the same payload for API call, and this also worked out.

Code:
curl -X 'POST'   'http://192.168.155.33/api/v2.0/jail'   -H 'accept: */*'   -H 'Authorization: Bearer 1-xxx' -H 'Content-Type: application/json'  -d '{ "release": "13.1-RELEASE", "uuid": "dm-t-13" }'


I got two new jails with names "dm-t-1" and "dm-t-13"

Now I wonder where to check/see a list of fields, which I can use with "/api/v2.0/jail" action "POST", because jail were created without configuration.

For example I want to set
- Ip address/mask
- Interface to use
- user to start jail with
- mount points

Thank you.
 

deamonmv

Cadet
Joined
Mar 7, 2023
Messages
8
I found how to set option for jail. That how looks like complite example:

Code:
curl -X 'POST'   'http://192.168.155.33/api/v2.0/jail'  \
 -H 'accept: */*'  \
 -H 'Authorization: Bearer 1-xxx' -H 'Content-Type: application/json' \
 -d '{
 "release": "13.1-RELEASE", 
"uuid": "dm-t-13",
"basejail": "true",
"release": "13.1-RELEASE",
pkglist: [ "go", "nginx", "git" ]
"props": [ "vnet=1", "nat=1", "bpf=0", "dhcp=0", "nat_forwards=tcp(8443:8443,tcp(80:80), "vnet_default_interface=em0", "boot=0" ]
 }'


How to find props:

on truenas host do this for created jail:

Code:
iocage get all myjail


That will show all possible options.
 
Top