Automating iScsi and LUN creation with ansible / API

iSCSI related applications
Post Reply
swinchester
New here
Posts: 5
Joined: Sat Oct 26, 2013 1:06 pm

Automating iScsi and LUN creation with ansible / API

Post by swinchester » Wed Nov 20, 2019 6:52 pm

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

User avatar
storageman
Ask me anything
Posts: 5203
Joined: Thu Sep 22, 2011 10:57 pm

Re: Automating iScsi and LUN creation with ansible / API

Post by storageman » Wed Nov 20, 2019 7:41 pm


swinchester
New here
Posts: 5
Joined: Sat Oct 26, 2013 1:06 pm

Re: Automating iScsi and LUN creation with ansible / API

Post by swinchester » Wed Nov 20, 2019 8:14 pm

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

swinchester
New here
Posts: 5
Joined: Sat Oct 26, 2013 1:06 pm

Re: Automating iScsi and LUN creation with ansible / API

Post by swinchester » 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

User avatar
storageman
Ask me anything
Posts: 5203
Joined: Thu Sep 22, 2011 10:57 pm

Re: Automating iScsi and LUN creation with ansible / API

Post by storageman » Wed Nov 27, 2019 11:38 pm

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!

swinchester
New here
Posts: 5
Joined: Sat Oct 26, 2013 1:06 pm

Re: Automating iScsi and LUN creation with ansible / API

Post by swinchester » Thu Nov 28, 2019 10:31 pm

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

Post Reply

Return to “iSCSI – Target & Virtual Disk”