Tuesday, September 15, 2015

Bash wrapper around ibswitches that shows switch names rather than their GUIDs

Please look at the blog entry right before this one to understand what this script does and where it comes handy.


Without Wrapper

[2015-09-15 22:59:02:7798 root@master post]# cat /usr/local/sbin/ibswitches_wrapper
#!/bin/bash

# by Sreedhar Manchu

sw_guid=(0xf45214030095b2c0 0xf4521403009564e0 0x0002c9020048d260 0x0002c9020048d9b8 0x0002c9020048d940 0x0002c9020048d8e8 0x0002c9020048d240 0x0002c90200489d18 0x0002c902004a7998 0x0002c902004b5d00 0xf452140300f61d20 0xf4521403009571c0 0x0002c902004100f0 0x0002c9020040ff28 0x0002c90200422938 0x0002c902004239c8 0x0002c90200423950 0x0002c90200423a60 0x0002c9020040fe80 0x0002c9020040d668 0xf452140300868de0 0xf452140300680100 0xf452140300680180 0xf45214030067f800 0xf452140300680080 0x0002c9020041e098 0x0002c9020040c868 0x0002c90200422498 0x0002c90200422258 0x0002c9020041e0c0 0x0002c9020041e108 0x0002c903006be3f0 0x0002c903006bfa70 0x0002c903006bfb70 0x0002c903006bfe70 0x0002c903006be6f0 0x0002c903006be7f0 0x0002c903007b6a30 0x0002c903006bfaf0 0x0002c903006be670 0x0002c903006bf970)

sw_name=(ibswcore0 ibswcore1 ibswspine0 ibswspine1 ibswspine2 ibswspine3 ibswspine4 ibswspine5/spmercerib0 ibswspine6 ibswspine7/spmercerib1 ibswspine8/spmercerib3 ibswspine9/spmercerib4 ibswspine10/spboweryib ibswspine11 ibswspine12 ibswspine13 ibswspine14 ibswspine15 ibswspine16/splibb ibswspine17 ibswspine18/spmercerib2 ibswedge0 ibswedge1 ibswedge2 ibswedge3 ibswedge4 ibswedge5 ibswedge6 ibswedge7 ibswedge8 ibswedge9 ibswedge14 ibswedge15 ibswedge16 ibswedge17 ibswedge18 ibswedge19 ibswedge20 ibswedge21 ibswedge22 ibswedge23)

/usr/sbin/ibswitches > /tmp/ibswitches_wrapper_$$

for ((i=0;i<${#sw_guid[@]};i++));do
 awk -F'"' -v OFS=\" -v ss="${sw_guid[$i]}" -v rs="${sw_name[$i]}" '$0 ~ ss {$2 = rs; print }' /tmp/ibswitches_wrapper_$$
done

rm -f /tmp/ibswitches_wrapper_$$

[2015-09-15 22:55:25:7796 root@master post]# ibswitches
Switch : 0x0002c9020040fe80 ports 36 "splibb SW-1" enhanced port 0 lid 2 lmc 0
Switch : 0xf452140300680180 ports 32 "SwitchX -  Mellanox Technologies" base port 0 lid 376 lmc 0
Switch : 0xf452140300680100 ports 32 "SwitchX -  Mellanox Technologies" base port 0 lid 375 lmc 0
Switch : 0xf452140300680080 ports 32 "SwitchX -  Mellanox Technologies" base port 0 lid 379 lmc 0
Switch : 0xf45214030067f800 ports 32 "SwitchX -  Mellanox Technologies" base port 0 lid 377 lmc 0
Switch : 0x0002c90200422938 ports 36 "Infiniscale-IV Mellanox Technologies" base port 0 lid 301 lmc 0
Switch : 0x0002c902004239c8 ports 36 "Infiniscale-IV Mellanox Technologies" base port 0 lid 424 lmc 0
Switch : 0xf4521403009571c0 ports 36 "MF0;switch-a8fcc2:SX6036/U1" enhanced port 0 lid 373 lmc 0
Switch : 0xf452140300f61d20 ports 36 "MF0;switch-534ae0:SX6036/U1" enhanced port 0 lid 374 lmc 0
Switch : 0x0002c9020040d668 ports 36 "Infiniscale-IV Mellanox Technologies" base port 0 lid 355 lmc 0
Switch : 0x0002c9020040c868 ports 32 "Infiniscale-IV Mellanox Technologies" base port 0 lid 354 lmc 0
Switch : 0x0002c9020041e098 ports 32 "Infiniscale-IV Mellanox Technologies" base port 0 lid 395 lmc 0
Switch : 0x0002c90200422258 ports 32 "Infiniscale-IV Mellanox Technologies" base port 0 lid 334 lmc 0
Switch : 0x0002c90200422498 ports 32 "Infiniscale-IV Mellanox Technologies" base port 0 lid 394 lmc 0
Switch : 0x0002c9020041e108 ports 32 "Infiniscale-IV Mellanox Technologies" base port 0 lid 260 lmc 0
Switch : 0x0002c9020041e0c0 ports 32 "Infiniscale-IV Mellanox Technologies" base port 0 lid 418 lmc 0
Switch : 0x0002c90200423a60 ports 36 "Infiniscale-IV Mellanox Technologies" base port 0 lid 342 lmc 0
Switch : 0x0002c902004100f0 ports 36 "spboweryib SW-1" enhanced port 0 lid 442 lmc 0
Switch : 0x0002c9020040ff28 ports 36 "Infiniscale-IV Mellanox Technologies" base port 0 lid 289 lmc 0
Switch : 0x0002c90200423950 ports 36 "Infiniscale-IV Mellanox Technologies" base port 0 lid 325 lmc 0
Switch : 0x0002c902004b5d00 ports 36 "MF0;spmercerib1:IS5030/U1" enhanced port 0 lid 18 lmc 0
Switch : 0x0002c902004a7998 ports 36 "ibswspine6__" base port 0 lid 150 lmc 0
Switch : 0x0002c90200489d18 ports 36 "MF0;spmercerib0:IS5030/U1" enhanced port 0 lid 99 lmc 0
Switch : 0x0002c9020048d240 ports 36 "ibswspine4__" base port 0 lid 22 lmc 0
Switch : 0x0002c9020048d8e8 ports 36 "ibswspine3__" base port 0 lid 33 lmc 0
Switch : 0x0002c9020048d940 ports 36 "ibswspine2__" base port 0 lid 23 lmc 0
Switch : 0x0002c9020048d9b8 ports 36 "ibswspine1__" base port 0 lid 32 lmc 0
Switch : 0xf452140300868de0 ports 36 "MF0;spmercerib2:SX6036/U1" enhanced port 0 lid 130 lmc 0
Switch : 0x0002c903006be3f0 ports 36 "SwitchX -  Mellanox Technologies" base port 0 lid 34 lmc 0
Switch : 0x0002c903006bfa70 ports 36 "SwitchX -  Mellanox Technologies" base port 0 lid 26 lmc 0
Switch : 0x0002c903006bfb70 ports 36 "SwitchX -  Mellanox Technologies" base port 0 lid 27 lmc 0
Switch : 0x0002c903006bfaf0 ports 36 "SwitchX -  Mellanox Technologies" base port 0 lid 154 lmc 0
Switch : 0x0002c903006bfe70 ports 36 "SwitchX -  Mellanox Technologies" base port 0 lid 28 lmc 0
Switch : 0xf45214030095b2c0 ports 36 "MF0;ibswcore0:SX6036/U1" enhanced port 0 lid 463 lmc 0
Switch : 0xf4521403009564e0 ports 36 "MF0;ibswcore1:SX6036/U1" enhanced port 0 lid 464 lmc 0
Switch : 0x0002c903006be670 ports 36 "SwitchX -  Mellanox Technologies" base port 0 lid 24 lmc 0
Switch : 0x0002c903006bf970 ports 36 "SwitchX -  Mellanox Technologies" base port 0 lid 25 lmc 0
Switch : 0x0002c903007b6a30 ports 36 "SwitchX -  Mellanox Technologies" base port 0 lid 20 lmc 0
Switch : 0x0002c903006be7f0 ports 36 "SwitchX -  Mellanox Technologies" base port 0 lid 36 lmc 0
Switch : 0x0002c903006be6f0 ports 36 "SwitchX -  Mellanox Technologies" base port 0 lid 35 lmc 0
Switch : 0x0002c9020048d260 ports 36 "ibswspine0__" base port 0 lid 120 lmc 0


With Wrapper

[2015-09-15 22:58:40:7797 root@master post]# bash /usr/local/sbin/ibswitches_wrapper 
Switch : 0xf45214030095b2c0 ports 36 "ibswcore0" enhanced port 0 lid 463 lmc 0
Switch : 0xf4521403009564e0 ports 36 "ibswcore1" enhanced port 0 lid 464 lmc 0
Switch : 0x0002c9020048d260 ports 36 "ibswspine0" base port 0 lid 120 lmc 0
Switch : 0x0002c9020048d9b8 ports 36 "ibswspine1" base port 0 lid 32 lmc 0
Switch : 0x0002c9020048d940 ports 36 "ibswspine2" base port 0 lid 23 lmc 0
Switch : 0x0002c9020048d8e8 ports 36 "ibswspine3" base port 0 lid 33 lmc 0
Switch : 0x0002c9020048d240 ports 36 "ibswspine4" base port 0 lid 22 lmc 0
Switch : 0x0002c90200489d18 ports 36 "ibswspine5/spmercerib0" enhanced port 0 lid 99 lmc 0
Switch : 0x0002c902004a7998 ports 36 "ibswspine6" base port 0 lid 150 lmc 0
Switch : 0x0002c902004b5d00 ports 36 "ibswspine7/spmercerib1" enhanced port 0 lid 18 lmc 0
Switch : 0xf452140300f61d20 ports 36 "ibswspine8/spmercerib3" enhanced port 0 lid 374 lmc 0
Switch : 0xf4521403009571c0 ports 36 "ibswspine9/spmercerib4" enhanced port 0 lid 373 lmc 0
Switch : 0x0002c902004100f0 ports 36 "ibswspine10/spboweryib" enhanced port 0 lid 442 lmc 0
Switch : 0x0002c9020040ff28 ports 36 "ibswspine11" base port 0 lid 289 lmc 0
Switch : 0x0002c90200422938 ports 36 "ibswspine12" base port 0 lid 301 lmc 0
Switch : 0x0002c902004239c8 ports 36 "ibswspine13" base port 0 lid 424 lmc 0
Switch : 0x0002c90200423950 ports 36 "ibswspine14" base port 0 lid 325 lmc 0
Switch : 0x0002c90200423a60 ports 36 "ibswspine15" base port 0 lid 342 lmc 0
Switch : 0x0002c9020040fe80 ports 36 "ibswspine16/splibb" enhanced port 0 lid 2 lmc 0
Switch : 0x0002c9020040d668 ports 36 "ibswspine17" base port 0 lid 355 lmc 0
Switch : 0xf452140300868de0 ports 36 "ibswspine18/spmercerib2" enhanced port 0 lid 130 lmc 0
Switch : 0xf452140300680100 ports 32 "ibswedge0" base port 0 lid 375 lmc 0
Switch : 0xf452140300680180 ports 32 "ibswedge1" base port 0 lid 376 lmc 0
Switch : 0xf45214030067f800 ports 32 "ibswedge2" base port 0 lid 377 lmc 0
Switch : 0xf452140300680080 ports 32 "ibswedge3" base port 0 lid 379 lmc 0
Switch : 0x0002c9020041e098 ports 32 "ibswedge4" base port 0 lid 395 lmc 0
Switch : 0x0002c9020040c868 ports 32 "ibswedge5" base port 0 lid 354 lmc 0
Switch : 0x0002c90200422498 ports 32 "ibswedge6" base port 0 lid 394 lmc 0
Switch : 0x0002c90200422258 ports 32 "ibswedge7" base port 0 lid 334 lmc 0
Switch : 0x0002c9020041e0c0 ports 32 "ibswedge8" base port 0 lid 418 lmc 0
Switch : 0x0002c9020041e108 ports 32 "ibswedge9" base port 0 lid 260 lmc 0
Switch : 0x0002c903006be3f0 ports 36 "ibswedge14" base port 0 lid 34 lmc 0
Switch : 0x0002c903006bfa70 ports 36 "ibswedge15" base port 0 lid 26 lmc 0
Switch : 0x0002c903006bfb70 ports 36 "ibswedge16" base port 0 lid 27 lmc 0
Switch : 0x0002c903006bfe70 ports 36 "ibswedge17" base port 0 lid 28 lmc 0
Switch : 0x0002c903006be6f0 ports 36 "ibswedge18" base port 0 lid 35 lmc 0
Switch : 0x0002c903006be7f0 ports 36 "ibswedge19" base port 0 lid 36 lmc 0
Switch : 0x0002c903007b6a30 ports 36 "ibswedge20" base port 0 lid 20 lmc 0
Switch : 0x0002c903006bfaf0 ports 36 "ibswedge21" base port 0 lid 154 lmc 0
Switch : 0x0002c903006be670 ports 36 "ibswedge22" base port 0 lid 24 lmc 0
Switch : 0x0002c903006bf970 ports 36 "ibswedge23" base port 0 lid 25 lmc 0

No comments:

Post a Comment