Creating lots of iSCSI LUNs Quickly on Netapp

Netapp_logo.svgI’ve been using Netapp technology since Ontap 6 before flexible volumes were around, and it’s my favorite commercial storage platform.  They provide a robust CLI and you can automate repetitive tasks by using SSH and a bit of creativity.  Recently I needed to deploy a large amount of iSCSI LUNs quickly on many hosts on Ontap 8.2 C-Mode.  If I had to do this manually via the GUI tools I’d rake my eyes out.  This is how I did it, hoping this helps others in a similar situation.

The Task

  • Create 50 x 150G iSCSI LUNs
  • Create 50 x initiator groups, one per Linux server
  • Map each server to it’s respective initiator group and LUN
  • Do this quickly

How to Proceed
We’re going to use shell to pre-generate the commands we need to run on the Netapp CLI to do all this work for us.  You’re going to need a file with all the iSCSI initiator names handy like below which should contain them all.

cat initiators.txt

You’re then going to run some simple shell one-liners to generate everything you need.  Save the output for each one of these below.  Replace my lun, volume, host, vserver and igroup names to match your environment in the examples below.

Generate your LUN Create Commands
First you’re going to create your LUNs, this assumes the parent volume that houses them is already created and has enough space if you’re not using thin provisioning.

This would be the command to generate all the LUNs needed:

lun create -vserver vs1 -path /vol/tmp/lun0 -size 150G -ostype linux

Who wants to type that fifty times or more?  Worse yet, who wants to click around awkwardly in a GUI and do it?  Let’s use a shell command to generate this for us:

for x in `cat initiators.txt| awk -F ":" '{print $2}' | awk -F "." \
'{print $1}'| sed 's/-/_/g'`; do echo "lun create -vserver vs1 \
-path /vol/tmp/"$x"_lun0 -size 150G -ostype linux"; done

You should now see the following output, save this off to a file somewhere for later.

lun create -vserver vs1 -path /vol/tmp/h1_r6_lun0 -size 150G -ostype linux
lun create -vserver vs1 -path /vol/tmp/h2_r6_lun0 -size 150G -ostype linux
lun create -vserver vs1 -path /vol/tmp/h3_r6_lun0 -size 150G -ostype linux
lun create -vserver vs1 -path /vol/tmp/h4_r4_lun0 -size 150G -ostype linux
lun create -vserver vs1 -path /vol/tmp/h4_r6_lun0 -size 150G -ostype linux
lun create -vserver vs1 -path /vol/tmp/h5_r4_lun0 -size 150G -ostype linux
lun create -vserver vs1 -path /vol/tmp/h5_r6_lun0 -size 150G -ostype linux
-- snip --

Generate your Create igroup Commands
Next you want to create your igroups and associate each respective initiator into it.  For this example we’re assuming the igroup should be named after the server shortname, and each server only gets one LUN.

The command to do this manually would be:

igroup create -vserver vs1 -igroup h1_r6 -protocol iscsi -ostype linux -initiator

Let’s generate these commands and save the command output off somewhere for all the hosts:

for y in `cat initiators.txt`; do hostpart=$(echo $y | awk -F ":" \
'{print $2}' | awk -F "." '{print $1}'| sed 's/-/_/g'); echo \
igroup create -vserver vs1 -igroup $hostpart -protocol iscsi \
-ostype linux -initiator $y ; done

Again, you’ll have similar output to use later and paste into the CLI.

igroup create -vserver vs1 -igroup h1_r6 -protocol iscsi -ostype linux -initiator
igroup create -vserver vs1 -igroup h2_r6 -protocol iscsi -ostype linux -initiator
igroup create -vserver vs1 -igroup h3_r6 -protocol iscsi -ostype linux -initiator
igroup create -vserver vs1 -igroup h4_r4 -protocol iscsi -ostype linux -initiator

Map your LUNs
The last step is to generate commands needed to map the LUNs to your initiator groups (igroups).  Done manually, the command would look like this:

lun map -vserver vs1 -path /vol/tmp/h1_r6_lun0 -igroup h1_r6 -lun-id 0

Let’s auto-generate this to save lots of time:

for x in `cat initiators.txt| awk -F ":" '{print $2}' | awk -F "." \
'{print $1}'| sed 's/-/_/g'`; do echo lun map -vserver vs1 -path \
/vol/tmp/"$x"_lun0 -igroup $x -lun-id 0; done

You should see output like below, save this somewhere:

lun map -vserver vs1 -path /vol/tmp/h1_r6_lun0 -igroup h1_r6 -lun-id 0
lun map -vserver vs1 -path /vol/tmp/h2_r6_lun0 -igroup h2_r6 -lun-id 0
lun map -vserver vs1 -path /vol/tmp/h3_r6_lun0 -igroup h3_r6 -lun-id 0
lun map -vserver vs1 -path /vol/tmp/h4_r4_lun0 -igroup h4_r4 -lun-id 0

Finish the Drill
Now you can take the saved command output from each section above and paste them into the Netapp CLI in the order that it was generated:

  1. Create LUNs
  2. Create initiator groups and associate initiator names
  3. Map the LUNs to the initiator group
  4. Check mappings via lun show command if needed

We had one issue with pasting large amounts of commands into the Netapp CLI on Ontap 8.2 that we’ve never had with 7-mode.  SSH disconnected us if we tried to paste too much data, so we had to break up the commands pasted into sets of 3 to 5 lines each.

There might be a setting to fix this (maybe an intentional security setting for data rate?) Leave a comment below if you have any pointers and we’ll update this post.

Passing commands broken into individual SSH sessions will work.  Reddit user dismal_scientist points out that you can do non-interactive ssh commands on CDOT, which will get around having to do small batches. You can do something like:

cat commandfile | while read -r $line; do ssh admin@cluster $line; if [ $? -ne 0 ]; then exit; fi; done.

Update: speaking with some Netapp Engineers it seems there’s a limit to the amount of SSH connections (higher than 10 per second) they will be disconnected, however I’ve not yet found anything about the data rate from a single connection – in this case pasting commands into the CLI via SSH.

About Will Foster

hobo devop/sysadmin/SRE
This entry was posted in open source, sysadmin and tagged , , , , , . Bookmark the permalink.

Have a Squat, Leave a Reply ..

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.