Introducing the new TrueNAS CLI

bodly

Dabbler
Joined
Jan 1, 2021
Messages
16
While I perfectly understand the sentiment, I'll nitpick and raise the argument that just maybe, you're selling your users short, especially once one looks at the threads that keep popping up here where they want more freedom and less hand holding :) Or maybe it's a difference in culture between FreeBSD and Linux users ¯\_(ツ)_/¯
I would say that the people who are using SCALE in the alpha are not the typical user.
 

Fox

Explorer
Joined
Mar 22, 2014
Messages
66
SCALE Users,
Pleased to let users of the nightly train know, that work on a new CLI interfaces has now landed in the SCALE nightly images, and will be available in the upcoming 21.02 release in the next few weeks.

This is cool.. I like it, but one suggestion, please make it accessble from SSH or putty. It doesn't need to have all the auto complete goodness, but I can't be the only one that loves picking their own SSH client, adjusting the font, and automating the login.. I would hate to only be able to use this new cli from a browser or the physical console..

Thanks, and good work!
 

Kris Moore

SVP of Engineering
Administrator
Moderator
iXsystems
Joined
Nov 12, 2015
Messages
1,471
This is cool.. I like it, but one suggestion, please make it accessble from SSH or putty. It doesn't need to have all the auto complete goodness, but I can't be the only one that loves picking their own SSH client, adjusting the font, and automating the login.. I would hate to only be able to use this new cli from a browser or the physical console..

Thanks, and good work!

Not to fear, it supports running over SSH. Most of us prefer to access it that way as well.
 

Fox

Explorer
Joined
Mar 22, 2014
Messages
66
Not to fear, it supports running over SSH. Most of us prefer to access it that way as well.
With autocomplete? As a programmer, I am curious how that works.. I'm going to reasearch how you are doing that!
 

ChrisRJ

Wizard
Joined
Oct 23, 2020
Messages
1,919
With autocomplete? As a programmer, I am curious how that works.. I'm going to reasearch how you are doing that!
The auto-complete is on the "shell level", so whether access happens through SSH or the console has no impact
 

Fox

Explorer
Joined
Mar 22, 2014
Messages
66
If you want to see more, here's the source repo:

https://github.com/truenas/midcli

And the toolkit we used to allow the autocomplete "suggestions" to work.

https://python-prompt-toolkit.readthedocs.io/en/master/

Cool!

Can we script it for automation? do something like the following from a shell script and monitor the return/exit codes?

Code:
root@freenas[~]#  cli service update id_or_name=ssh enable=true
root@freenas[~]#

Or even better have it return JSON so a python program, for example, can process the data returned. That would be cool..
 

Arwen

MVP
Joined
May 17, 2014
Messages
3,611
@Fox, Unix has some odd things in it. For example, using the examples from the main page:
Code:
root@freenas[~]# cli

> service ssh update rootlogin=true
> service update id_or_name=ssh enable=true
> service start service=ssh

Could be scripted as:
Code:
#!/bin/bash
cli <<HERE_IS_EOF
service ssh update rootlogin=true
service update id_or_name=ssh enable=true
service start service=ssh
exit
HERE_IS_EOF

That said, it would be cleaner to have command line options to perform simple tasks, like restart a service. Or change a service's parameter.
 

Kris Moore

SVP of Engineering
Administrator
Moderator
iXsystems
Joined
Nov 12, 2015
Messages
1,471
Thats the idea here, but it'll take some time to mature. We've already got a '.mode csv' option that changes output format, but JSON would be my next want as well :)
 

justin82

Cadet
Joined
Feb 16, 2021
Messages
6
I suffered an error while try cli in vmware

even re-install a fresh system using 21.02 w/o update

truenas# cli

************************************************************
Software in ALPHA state, highly experimental.
No bugs/features being accepted at the moment.
************************************************************

[truenas]> system info
Traceback (most recent call last):
File "/usr/bin/cli", line 12, in <module>
sys.exit(main())
File "/usr/lib/python3/dist-packages/midcli/__main__.py", line 106, in main
cli.run()
File "/usr/lib/python3/dist-packages/midcli/__main__.py", line 92, in run
self.context.process_input(text)
File "/usr/lib/python3/dist-packages/midcli/context.py", line 204, in process_input
namespace = self.current_namespace.process_input(text)
File "/usr/lib/python3/dist-packages/midcli/context.py", line 68, in process_input
return i.process_input(rest)
File "/usr/lib/python3/dist-packages/midcli/context.py", line 71, in process_input
i.process_input(rest)
File "/usr/lib/python3/dist-packages/midcli/command/common_syntax/command.py", line 25, in process_input
self.run(args, kwargs)
File "/usr/lib/python3/dist-packages/midcli/command/generic_call/__init__.py", line 104, in run
self._run_noninteractive(args, kwargs)
File "/usr/lib/python3/dist-packages/midcli/command/generic_call/__init__.py", line 144, in _run_noninteractive
call_args = self._call_args(args, kwargs)
File "/usr/lib/python3/dist-packages/midcli/command/generic_call/__init__.py", line 92, in _call_args
for i in range(0, max(args_dict.keys()) + 1):
ValueError: max() arg is an empty sequence
truenas#
 

Kris Moore

SVP of Engineering
Administrator
Moderator
iXsystems
Joined
Nov 12, 2015
Messages
1,471
Thanks. I'll pass that along to the developers.
 

flatline69

Dabbler
Joined
Jan 30, 2021
Messages
29
This helped me undo a change for isolated_gpu_pci_ids that I made from command line trying to get transcoding working in docker containers. Very nice, I was so dreading reinstalling :)
 

Jip-Hop

Contributor
Joined
Apr 13, 2021
Messages
118
Could anyone post an example of how to send an email using the cli?

Currently I'm using (inside a bash script):
echo "TEST" | mail -s "subject" "test@example.com"

But using the API would be better.
 
Last edited:

mkirchner

Cadet
Joined
Aug 17, 2021
Messages
2
Is there any documentation on the commands to configure the network? None of the commands are registering within the CLI in the latest beta just released.
 

artlessknave

Wizard
Joined
Oct 29, 2016
Messages
1,506
how does one.....exit it? me too dumb to figure that out apparently...
its not
glpnas1[]> ..
glpnas1[]> ..
glpnas1[]> exit
namespace exit not found
glpnas1[]> q
Illegal character 'q'
syntax error
glpnas1[]>

ctrl-C does nothing
ctrl-z at least suspended it, but that's a weird way to exit....
this was on truenascore 12u8
 

artlessknave

Wizard
Joined
Oct 29, 2016
Messages
1,506
ah, ctrl-D works. hopefully the final version has an actual "Exit" option...
 
Joined
Oct 22, 2019
Messages
3,641
I didn't think the CLI was in CORE.
I've noticed it from the early releases of the 12.0 series.

However, you're greeted to this message when invoking it (even on 12.0-U8):

Code:
root@truenas[~]# cli

************************************************************
Software in ALPHA state, highly experimental.
No bugs/features being accepted at the moment.
************************************************************
 

Jfs

Dabbler
Joined
Feb 23, 2023
Messages
23
So are there any plans on making this work from a remote management host using the Restful API? Something like the linode-cli tool lets your do alot of management remotely.

I'm mostly looking to provision NFS datasets and shares and then make changes more easily. I'm running TrueNAS Professional 13.x on an M40 HA pair, so anything to make automating my upcoming migration would be really helpful!
 
Top