Pages

7/02/2013

Powershell: Cisco MDS Fibre Channel Switch Zone Configuration Builder

Create Commands to configure zones on Cisco MDS 91xx switch


####################################################################################################
#
#  fc-cfg-bldr.ps1
#
#  Create cmd file for Cisco MDS fibre channel switch to create zones for new servers
#  INPUT:  CSV file containing list of server names and WWN's.
#  OUTPUT:  2 TXT files containing commands to create zones in Fabric A and Fabric B.
#

$inputfile = ".\test.csv"
#$inputfile = ".\servers.csv"
$outfile = ".\fc-cmds.txt"
$tempA = ".\\configA.txt"
$tempB = ".\\configB.txt"

$profiles = get-content $inputfile

$today = get-date
$day = $today.Day
$mth = $today.Month
$year = $today.Year
$hour = $today.Hour
$min = $today.Minute
$sec = $today.Second
$date = "$year-$mth-$day-$hour$min$sec"

clear-host

"------------------------------------------------------------------------------"
write "! $date Fabric A Configuration" | out-file $tempA -encoding ascii
write "! $date Fabric B Configuration" | out-file $tempB -encoding ascii

$zonesetA = @"
    zoneset name SAN1-SAN2-FAB-A vsan 2
"@
$zonesetB = @"
    zoneset name SAN1-SAN2-FAB-B vsan 3
"@

foreach ($profile in $profiles) {
    "!------------------------------------------------------------------------------" | out-file $tempA -encoding ascii -append
    "!------------------------------------------------------------------------------" | out-file $tempB -encoding ascii -append
    $profile
    $server = ($profile -split',')
    $name = $server[0]
    "    $name"    
    $wwn1 = $server[1]
    "    $wwn1"
    $wwn2 = $server[2]
    "    $wwn2"
    
    $zoneA1 = $name+"_hba_A_to_cmp1"
    $zoneA2 = $name+"_hba_A_to_cmp2"
    $zoneB1 = $name+"_hba_B_to_cmp1"
    $zoneB2 = $name+"_hba_B_to_cmp2"
      
    #create commands
    "    Generate Commands"


    #Create Zones in Fabric A
    "        Fab A Zones"
    $configA = @"
    zone name $zoneA1 vsan 2
        member pwwn 50:00:d3:10:00:0c:80:03
        member pwwn 50:00:d3:10:00:0c:80:09
        member pwwn 50:00:d3:10:00:0c:80:11
        member pwwn 50:00:d3:10:00:0c:80:17
        member pwwn $wwn1
    
    zone name $zoneA2 vsan 2
        member pwwn 50:00:d3:10:00:0c:82:03
        member pwwn 50:00:d3:10:00:0c:82:0b
        member pwwn 50:00:d3:10:00:0c:82:13
        member pwwn 50:00:d3:10:00:0c:82:1b
        member pwwn $wwn1
"@
    write $configA | out-file $tempA -encoding ascii -append
    
    #Add to zonesetA
    "        Add to ZonesetA"
    $configA = @"
    
        member $zoneA1    
        member $zoneA2
"@
    $zonesetA = $zonesetA + $configA
    
    #Create Zones in Fabric B
    "        Fab B Zones"
    $configB = @"
    zone name $zoneB1 vsan 3
        member pwwn 50:00:d3:10:00:0c:80:0d
        member pwwn 50:00:d3:10:00:0c:80:05
        member pwwn 50:00:d3:10:00:0c:80:1b
        member pwwn 50:00:d3:10:00:0c:80:13
        member pwwn $wwn2
    
    zone name $zoneB2 vsan 3
        member pwwn 50:00:d3:10:00:0c:82:0f
        member pwwn 50:00:d3:10:00:0c:82:05
        member pwwn 50:00:d3:10:00:0c:82:1f
        member pwwn 50:00:d3:10:00:0c:82:15
        member pwwn $wwn2    
"@
    write $configB | out-file $tempB -encoding ascii -append
    
    #Add to zonesetB
    "        Add to ZonesetB"
    $configB = @"
    
        member $zoneB1    
        member $zoneB2
"@
    $zonesetB = $zonesetB + $configB
    "-------------------------------------------------------------------------------"
}#end foreach
    "!------------------------------------------------------------------------------" | out-file $tempA -encoding ascii -append
    "!------------------------------------------------------------------------------" | out-file $tempB -encoding ascii -append


#Config zonesets
    write $zonesetA | out-file $tempA -encoding ascii -append
    write $zonesetB | out-file $tempB -encoding ascii -append

#Activate & Save
"        Complete Configs"
    $configA = @"

        zoneset activate name SAN1-SAN2-FAB-A vsan 2
    
        zone commit vsan 2
    
        copy run start
"@
    write $configA | out-file $tempA -encoding ascii -append
    
    $configB = @"

    zoneset activate name SAN1-SAN2-FAB-B vsan 3
    
    zone commit vsan 3
    
    copy run start
"@
    write $configB | out-file $tempB -encoding ascii -append    

"-------------------------------------------------------------------------------"
"    COMPLETE - Configuration commands saved to $tempA, $tempB"
"-------------------------------------------------------------------------------"

No comments: