Page 1 of 1

Automating iScsi and LUN creation with ansible / API

Posted: Wed Nov 20, 2019 6:52 pm
by swinchester
Hi All,

Just wondering if there is any documentation on automating the creation of LUNs/iScsi targets on qnap devices - i'm hoping to achieve this via an API or command line tools rather than going via the web user interface. Is this possible? Any pointers will be greatly appreciated,

Many Thanks,

Stu

Re: Automating iScsi and LUN creation with ansible / API

Posted: Wed Nov 20, 2019 7:41 pm
by storageman

Re: Automating iScsi and LUN creation with ansible / API

Posted: Wed Nov 20, 2019 8:14 pm
by swinchester
This article https://www.qnap.com/en-au/how-to/tutor ... -qnap-nas/ is more from the client side that wants to use the disk. I'm trying to automate the provisioning of a system whereby I could create an iSCSI Target, and create a number of LUNs beneath that target - but ideally I would like to do this via a script rather than via the web gui (which although functional is a little bit cumbersome). Happy to ssh into the qnap appliance in order to do this. I need to be able to create 50+ LUNs (hence why the web GUI isn't great)

Some API in the back end must be doing something similar to the following:
CreateLUN(): Name, Storage Pool, Size, Allocation, Allocation Type (thick/thin), Sector Size
MapLUN(): LunName, iScsiTargetName

Re: Automating iScsi and LUN creation with ansible / API

Posted: Wed Nov 27, 2019 10:55 pm
by swinchester
Just to update this thread...

So you can ssh into the NAS and use a number of utilities in sbin for this... For example:

Code: Select all

qcli -l user=admin pw=admin
Authentication success!
sid is AAAAAA 
qcli_iscsi -C Alias=mytarget Name=mytarget sid=AAAAAA
qcli_iscsi -c Name=lun1 Allocation=Instant Capacity=10 SectorSize=512 LUNType=Block poolID=2 sid=AAAAAA
qcli_iscsi -m lunID=1 targetID=3 sid=AAAAAA

Re: Automating iScsi and LUN creation with ansible / API

Posted: Wed Nov 27, 2019 11:38 pm
by storageman
swinchester wrote:
Wed Nov 27, 2019 10:55 pm
Just to update this thread...

So you can ssh into the NAS and use a number of utilities in sbin for this... For example:

Code: Select all

qcli -l user=admin pw=admin
Authentication success!
sid is AAAAAA 
qcli_iscsi -C Alias=mytarget Name=mytarget sid=AAAAAA
qcli_iscsi -c Name=lun1 Allocation=Instant Capacity=10 SectorSize=512 LUNType=Block poolID=2 sid=AAAAAA
qcli_iscsi -m lunID=1 targetID=3 sid=AAAAAA
Nice, cheers
Qnap keeps that one hidden!

Re: Automating iScsi and LUN creation with ansible / API

Posted: Thu Nov 28, 2019 10:31 pm
by swinchester
I didn't find anything on google about it..! Anyway, I've created a quick and dirty ansible playbook which create a new iSCSI target and a bunch of LUNs attached to it based on the variables in a yaml file. For the interested it's at:

https://github.com/welshstew/create-qnap-luns