Add NFS shares via the shell

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Hi All,

Does anyone know how to add NFS shares via the shell? I have several hundred to create and doing it via the GUI is somewhat slow.

Thanks,
Fab
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,545
Navigate to https://<ip of server>/api/docs. You can in principle make the API calls from the CLI using "midclt". For example: midclt call sharing.nfs.create '{<payload>}'
 

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Thank you. I'll give this a try.
 

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Thanks. I managed to get that working!

But now I'm trying to figure how how to query a for a particular share by name (not by id) so that I can operate on it, say for example if I want to delete it.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,740
Code:
root@freenas-pmh[~]# midclt call sharing.nfs.query | jq
[
  {
    "id": 3,
    "paths": [
      "/mnt/hdd/share/medien"
    ],
    "comment": "",
    "hosts": [],
    "alldirs": false,
    "ro": true,
    "quiet": false,
    "maproot_user": null,
    "maproot_group": null,
    "mapall_user": null,
    "mapall_group": null,
    "security": [],
    "enabled": true,
    "networks": []
  }
]

Then you "just" need to parse the json :wink:
 
Last edited:

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Thanks. Is this the only way to query? If I have several hundred ids then that command will produce a large output that will become almost impossible to manipulate without risk of potential errors. What I was hoping I would be able to do is query for a specific path and have the resulting info be for that path only.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,740
If I read the documentation correctly, this is the only way to get a list and obtain the id to name mapping. Once you have the id you can manipulate only this particular share with the other API calls.

But ... this should in theory all be rather easy. Since iXsystems implemented their entire UI on top of that API, I would be really surprised if there weren't all python libraries needed for REST calls, turning json into python dictionaries etc. already on the system and ready to use.

You just have to let go of shell scripts.
Been there, ... ;-)
 
Last edited:

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Apologies for the slow delay.

Thanks for your comments. I'm not a python person so understanding how this actually works is going to take time I guess.

Nothing wrong with the shell ;-)
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,740
Same here. Literal greybeard who took his first steps on Minix on an Atari ST. Shell and C for more than three decades!

But hey, getting all that information handed on a silver platter, i.e. in a real data structure, does have its points. Don't fear the python
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Same here. Literal greybeard who took his first steps on Minix on an Atari ST. Shell and C for more than three decades!

But hey, getting all that information handed on a silver platter, i.e. in a real data structure, does have its points. Don't fear the python

I've been meaning to learn it for years. Even bought myself a book many moons ago.

As it happens, either one of these works for me.... in case anyone (n)ever has a need. :smile:

midclt call sharing.nfs.query | jq '.[] | .id,.comment' | grep -B 1 ${username} | head -n 1
midclt call sharing.nfs.query | jq '.[] | .id,.paths' | grep -B 2 ${username} | head -n 1

I can wrap this around some more robust checks in a script which works for now whilst I brush up on my python skills (lockdown seems the perfect opportunity to do this)!
 

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Top