Monday, December 31, 2012

Convert Port Numbers to Alias: BNT Style

I'm going to come right out and say it: networking is really really really picky.  I've seen 5 year olds with a more diverse palette than how 2 switches need to be tuned in order to communicate.  I'll try to post some tips about IBM's BNT switches in general  because there are some funky-tastic configuration settings.  And getting it to pair well with Cisco switches is something that can be fine tuning with a dial where a touch is all it takes to calibrate.  Also there is so little out there for BNT; I've spent so much time traversing the pathways of the internets trying so hard to find something a bit more than the manual.  You can find more dust in a clean room.
There's a speck.  It's on that chair

IBM (through BNT) has several different switches; one is a Chassis Switch, nicknamed "Compass" switch that allows connection into a chassis unit on a rack.  You really don't hit things like this unless you're in an enterprise system; however, some person who was really on top of their game made sure that the port conventions between switches was the same!  Bonus!

For things like confirmation and automation, the important thing to check is running-config.  From this mode you can see all the ports on the associated vlans, but the ports are only shown in their alias form.  It really annoys me that not only are the ports only displayed in alias so it's pretty difficult to do automation.  Also, the ports merge in a very weird way.  So the best way I've found to solve this problem is to make assumptions about inputs: everything is already sorted in the right order.  The script is also in groovy.

* Takes a list of ports in a String form and converts them to the compass
* port. The String can be one or more ports depending on what is passed in.
* ex: 1,3-42,60 -> INTA,INTA3-INTC14,EXT18
* @param ports
* @return String the Compass switch aliases of the ports
static _convertToAlias(String ports){
def commaSplit = ports.split(/,/)
def all = ""
def numsToLetters = ["A", "B", "C"]

commaSplit.each { piece ->
if(piece.isInteger()){ //singular
def working = piece.toInteger()
def letter = (working/14 > 3) ? "EXT" : "INT" + numsToLetters[(working%14 == 0 ? (working/14 -1) : (working/14) as int)]
def number = (working/14 <= 3) ? ((working%14 != 0) ? working%14 : 14) : working - (14*3)
all += (letter+number) + ','
} else { //range
def pieces = piece.split(/-/)
all += _convertToAlias(pieces[0]) + "-" + _convertToAlias(pieces[1])+ ","

return all[0..-2]

One incredibly effective way to use this code is to combine it with the other method that I wrote earlier to combine ranges of integers.  A few steps closer to automation!  The future isn't as exciting as the 70s thought it would be, it's more because you can't tell me that watching the computer configure itself isn't the future.  *cue epic music*