The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::Telnet::Brcd - Perl libraries to contact Brocade switch

SYNOPSIS

    use Net::Telnet::Brcd;
    
    my $sw = new Net::Telnet::Brcd;
    
    $sw->connect($sw_name,$user,$pass) or die "\n";
    
    %wwn_port = $sw->switchShow(-bywwn=>1);
    my @lines = $sw->cmd("configShow");

DESCRIPTION

Perl libraries to contact Brocade switch with a telnet session. You could set this environment variable to simplify coding:

BRCD_USER

login name

BRCD_PASS

login password

BRCD_SWITCH

switch name or IP address

FUNCTIONS

new

    my $brcd = new Net::Telnet::Brcd;

Initialize Brocade object. No arguments needed.

connect

    $brcd->connect($switch,$user,$pass);

Connect to a Brocade switch with a telnet session (use Net::Telnet module). Return undef on error. Do it before any switch command.

The Net::Telnet object is stored in $brcd->{TELNET}. You could access Net::Telnet capabilities with this object.

One object is required for each connection. If you want simultaneous connection you need several objects.

cmd

    my @results = $brcd->cmd("configShow");
    my $ok      = $brcd->cmd("cfgsave");

This function is used to send command to a brocade switch. The command works as the 'cmd' function of Net::Telnet module and add differents features:

  • The command set the regular expression for Brocade prompt.

  • The command tracks the continue question and answer 'yes'. The goal of this module is to be used in silent mode.

  • The Brocade command answer is returned without carriage return (no \r \n).

  • Two methods is used to give parameters.

    scalar: The string command is sent as is.

    array: The command thinks that the first element is a command, the second the principal arguments and other members. It is very useful for ali* command.

Examples :

    my @results=$brcd->cmd("aliAdd","toto",":00:00:0:5:4:54:4:5");
    aliAdd "toto", "00:00:0:5:4:54:4:5"

The command does not decide that the command answer is an error or not. It just store the stdout of the brocade command and return it in a array.

sendcmd

    my $rc = $brcd->sendcmd("portperfshow");

This function execute command without trap standard output. It's useful for command that needs to be interrupted.

You have to use the readline function to read each line generated by the command.

sendeof

    my $rc = $brcd->sendeof();

Send Ctrl-D command to interrupt command (useful for portperfshow).

readline

    while (my ($str) = $brcd->readline()) {
        # Do what you want with $str
    }

Read telnet output as piped command. You have a to decided when to stop (If the line content a prompt, I return undef). The command accept the same argument as Net::Telnet getline command.

    $brcd->readline({Timeout => 60});

You have to set argument with a hash ref.

aliShow

    my %alias_to_wwn = $brcd->aliShow();

Send command aliShow "*" and return a hash. Some option, change the content of the returned hash :

default

Without option : return key = alias, value = WWN.

Be carefull !! If one alias contains multiple WWN, value is a ref array of all the WWN member.

-onlywwn

With option -onlywwn => 1 (default option) : does not return alias with port naming. Disable this option (-onlywwn => 0), if you want both.

-filter

By default, -filter is set to '*'. You could use an other filter to select specific alias. Recall of rbash regular expression, you could use in filter :

  • Any character.

  • ?

    One character.

  • [..]

    Character class. For instance a or b => [ab]

  • Examples

        -filter => '*sv*'
        -filter => 'w_??[ed]*'
-bywwn

With option -bywwwn => 1, return key = WWN, value = alias

    my %wwn_to_alias = $brcd->aliShow(-bywwn => 1);
-byport

With option -byport => 1, return key = port, value = alias

zoneShow

    my %zone = $brcd->zoneShow();

Return a hash with one key is a zone and value an array of alias member or WWN or ports.

    my %zone = $brcd->zoneShow();

    foreach my $zone (%zone) {
        print "$zone:\n\t";
        print join("; ", keys %{$zone{$zone}} ),"\n";
    }
    
-bymember => 1

If you set option -bymember = 1>, you have a hash with key a member and value an array of zones where member exists.

-filter => '*'

By default, select all zone but you could set a POSIX filter for your zone.

It's important to run this command before using the followings functions.

zoneMember

    my @member = $brcd->zoneMember("z_sctxp004_0");

Return an array of member of one zone. Need to execute $brcd-zoneShow> before.

memberZone

    my @zones = $brcd->memberZone("w_sctxp004_0");

Return an array of zones where member exist. Need to execute $brcd-zoneShow> before.

switchShow

    my %port = $brcd->switchShow();

This function send the switchShow command on the connected switch (see only one switch not all the fabric). It returns the following structure:

    $port{port number}->{SPEED}  = <2G|1G|...>
                      ->{STATUS} = <OnLine|NoLight|...>
                      ->{SLOT}   = blade number
                      ->{NUMBER} = port number on blade
                      ->{TYPE}   = <E-Port|F-Port|...>
                      ->{WWN}    if connected

If you set -bywwn=1, it's return only a hash of WWN as key and port number as value.

    my %wwn_to_port = $brcd->switchShow(-bywwn => 1);

If you set -withportname=1, the portName command is execute on each port of the switch to get the portname.

If you set -byslot=1, it's return only a hash of slot/number as key and portname and port number as value.

toSlot

    my ($slot,$slot_number) = $brcd->toSlot(36);
    my $slot_address        = $brcd->toSlot(36);

The function need to have an exectution of $brcd-switchShow>. It's usefull for a Director Switch to have the translation between absolute port number and slot/port number value.

If you use it in scalar context, the command return the string slot/slot_number (portShow format).

portShow

    my %port     = $brcd->portShow($port_number);
    my $portname = $brcd->portShow($port_number);

Need to have running the $brcd-switchShow> command. The function use the toSlot function before sending the portShow command.

In array context, function return a hash with key as the portName. In scalar context returns the portname.

output

    print $brcd->output();

Return the last function output.

wwn_re

    my $wwn_re = $brcd->wwn_re();

    if (m/($wwn_re)/) {
        ...
    }

Return the WWN re.

fabricShow

    my %fabric = $brcd->fabricShow();

Return a hash with all the switch in the fabric. Return the result byswitch name -byswitch or -bydomain=1.

currentFabric

    my $dns_fabric = $brcd->currentFabric();

Return the current fabric NAME.

isWwn

    if ($brcd->isWwn($str)) {
        ...
    }

Test a string to check if it is a WWN.

portAlias

    my ($domain, $port_number) = $brcd->portAlias("199,6");

Split a string whith zoning format in domain and port number in the switch.

cfgSave

    my $boolean = $brcd->cfgSave();
    

The function execute cfgSave command an return true if ok or exit. You can trap this exception whith eval {}; block. Error message always begin with Error - .

zone

    my @rc = $brcd->zone(
        -add     => 1,
        -name    => 'z_toto1',
        -members => '10:00:00:00:C9:3D:F3:04',
    );
        
    my @rc = $brcd->zone(
        -add     => 1,
        -name    => 'z_toto2',
        -members => [
            '10:00:00:00:C9:3D:F3:04',
            '10:00:00:00:C9:48:08:E2',
        ],
    );

Supported sub commmand are -add, -create, -delete, -remove.

ali

    my @rc = $brcd->ali(
        -create  => 1,
        -name    => 'w_toto1',
        -members => '10:00:00:00:C9:51:FB:29',
    );
        
    my @rc = $brcd->ali(
        -add     => 1,
        -name    => 'w_toto2',
        -members => [
            '10:00:00:00:C9:46:D8:FD',
            '10:00:00:00:C9:46:DA:A7',
        ],
    );
    
    my @rc = $brcd->ali(
        -add     => 1,
        -name    => 'w_toto3',
        -members => [
            '10:00:00:00:C9:46:D5:B7',
        ],
    );

Supported sub commmand are -add, -create, -delete, -remove.

SEE ALSO

Brocade Documentation, BrcdAPI, Net::Telnet.

BUGS

...

AUTHOR

Laurent Bendavid, <bendavid.laurent@fre.fr>

COPYRIGHT AND LICENSE

Copyright (C) 2005 by Laurent Bendavid

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.

Version

1.9

History

Created 6/27/2005, Modified 8/14/07 18:41:02

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 304:

Expected '=item *'

Around line 308:

Expected '=item *'

Around line 312:

Expected '=item *'