Scripting Alias and Zone creation for Brocade Switches

Whenever a new array is added in our environment we usually have to add hundreds and hundreds of new zones to our core brocade fabric.  It’s a very tedious job so I started investigating ways to script the process.

Here is the syntax for running an ssh command remotely (telnet is disabled on all of our switches):

ssh userid@switchname [command]
 

so, if I wanted to show all of the zones on a switch the command would look like this:

ssh admin@10.0.0.1 zoneshow
 

While those commands work perfectly and could be added in to a bash script as-is, the caveat is that the password must be typed in for every command.  That’s not very practical if there are hundreds of lines in the script.  You could set up ssh keys on every switch, but I was looking for a quicker, easier solution.  I found that quick solution with an opensource package called sshpass (http://sourceforge.net/projects/sshpass).  It allows you to enter the password on the command line.  I use Cygwin on a windows server for all my bash scripts and it was a very simple installation in that environment, and I’m sure would be just as easy on Linux.  Download it to a folder,  uncompress it, run “./configure”, “make”, and “make install” and you’re all done.

Once sshpass is installed, the syntax for showing the zones on a brocade switch would look like this:

sshpass –p “[password]” ssh admin@10.0.0.1 zoneshow
 

Now that the commands can be run very easily from a remote shell, I needed to make creating the script much easier.  That’s where a spreadsheet application helps tremendously.  Divide the script line into different cells on the spreadsheet, making sure to separate any part of the command that’s going to change.  In the last cell on the line, you concatenate all of the previous cells together to create the complete command.  Below is how I did it.

Here’s the syntax output I want for creating a zone:

sshpass -p ‘password’ ssh [User_ID]@[Switch_Name] zonecreate “[Zone_Name]”,”[Host_Alias]”,”[SP_Alias]”
 

Here’s how I divide the command up in the spreadsheet:

A1          sshpass  -p ‘password’ ssh

B1          [User_ID]

C1          @

D1          [switch_name]

E1           Zonecreate “

F1           [Zone_Name]

G1           “,”

H1           [Host_Alias]

I1            “,”

J1            [Clarrion/VNX_SP_Alias]

K1           “

L1           =concatenate(A1,B1,C1,D1,E1,F1,G1,H1,J1,K1)

Now you can copy line 1 of the spreadsheet to as many lines as you need, change the User ID, Switch Name, Zone_Name, Host Alias, and Clariion/VNX SP Alias as needed, and the L column will have all the completed commands for you that you can cut and paste into a bash script.  Create a blank script file with ‘touch file.sh’, do a ‘chmod +X file.sh’ and ‘chmod 777 file.sh’ on it, use vi to copy and paste in the script data, then run it with ‘./file.sh’ from the prompt.

The same thing can be done for creating the initial aliases, here’s the syntax of the command for that:

sshpass -p ‘password’ ssh [User_ID]@[Switch_Name] alicreate “[Alias_Name]”,”[WWN]”
 

And finally, here’s what it looks like entered into a spreadsheet:

BrocadeScript

Advertisements

3 thoughts on “Scripting Alias and Zone creation for Brocade Switches”

  1. Hi There,
    sshpass is a great and useful tool but remember that any evidence of commands being run using this (and plink.exe) will not appear in the cli history … just bear that in mind if you are looking to audit what you are configuring 🙂

  2. Great use of a spreadsheet to create the command strings. I usually use ponderosa as my terminal emulator and you can just take the output of the script and drop in a sash session to the switch. It will run one line at a time and basically accomplish the same as what os being done here. I will create the spreadsheet for future ease of creating the zone sets and possibly reduce the human error element of typos or subjective zone naming.

    1. I’m glad you found it useful. I also figured out that you can simply cut and paste directly into the terminal emulator session, that saves some time.

Leave a Reply